-
Notifications
You must be signed in to change notification settings - Fork 4k
Dev: Azure Automation cmdlets #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
aee2f5a
Remove-AAConnectionType cmdlet and Optional RunbookName
safeermohammed fbd87bd
Remove-AAConnectionType cmdlet and Optional RunbookName- addressed co…
safeermohammed 65079c3
powershell model udpate for dsc node report
avkaur 3507b64
powershell model udpate for dsc node report2
avkaur cf5144e
powershell model udpate for dsc node report3
avkaur 694947e
import mof powershell sdk update
avkaur 802904b
report model update2
avkaur 28e8804
report model update2
avkaur b5de0f2
report model update3
avkaur 147200b
report model update4
avkaur d6e3c28
report model update5
avkaur aaa144b
Runbook params should accept any type
b570b9b
Webhook should accept any param types
9a5ea29
Init hashtable
b86f77c
Handling Json deserialization error
76ae1e1
Merge pull request #6 from avkaur/dev
safeermohammed 2eaa48f
Merge pull request #7 from shipram/dev
safeermohammed 27b2187
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed 73047f9
Latest changes from Azure dev
safeermohammed 4622847
Making name of new cmdlets consistent as AzureRM
safeermohammed 2bc816e
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed e18aa9c
Added remove connectiontype test
safeermohammed 84abd53
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed bdf05e9
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed c11ec70
dsc bugifx
safeermohammed 0c73381
Address Review comments
safeermohammed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationConnectionTypeTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.Automation.Cmdlet; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; | ||
using Moq; | ||
|
||
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests | ||
{ | ||
[TestClass] | ||
public class RemoveAzureAutomationConnectionTypeTest : RMTestBase | ||
{ | ||
private Mock<IAutomationClient> mockAutomationClient; | ||
|
||
private MockCommandRuntime mockCommandRuntime; | ||
|
||
private RemoveAzureAutomationConnectionType cmdlet; | ||
|
||
[TestInitialize] | ||
public void SetupTest() | ||
{ | ||
this.mockAutomationClient = new Mock<IAutomationClient>(); | ||
this.mockCommandRuntime = new MockCommandRuntime(); | ||
this.cmdlet = new RemoveAzureAutomationConnectionType | ||
{ | ||
AutomationClient = this.mockAutomationClient.Object, | ||
CommandRuntime = this.mockCommandRuntime | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
public void RemoveAzureAutomationConnectionTypeByNameSuccessfull() | ||
{ | ||
// Setup | ||
string resourceGroupName = "resourceGroup"; | ||
string accountName = "automation"; | ||
string connectionTypeName = "connectionType"; | ||
|
||
this.mockAutomationClient.Setup(f => f.DeleteConnectionType(resourceGroupName, accountName, connectionTypeName)); | ||
|
||
// Test | ||
this.cmdlet.ResourceGroupName = resourceGroupName; | ||
this.cmdlet.AutomationAccountName = accountName; | ||
this.cmdlet.Name = connectionTypeName; | ||
this.cmdlet.Force = true; | ||
this.cmdlet.ExecuteCmdlet(); | ||
|
||
// Assert | ||
this.mockAutomationClient.Verify(f => f.DeleteConnectionType(resourceGroupName, accountName, connectionTypeName), Times.Once()); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...anager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Security.Permissions; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.Azure.Commands.Automation.Model; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Cmdlet | ||
{ | ||
/// <summary> | ||
/// Imports dsc node configuration script | ||
/// </summary> | ||
[Cmdlet(VerbsData.Import, "AzureRmAutomationDscNodeConfiguration")] | ||
[OutputType(typeof(NodeConfiguration))] | ||
public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet | ||
{ | ||
/// <summary> | ||
/// True to overwrite the existing configuration; false otherwise. | ||
/// </summary> | ||
private bool overwriteExistingConfiguration; | ||
|
||
/// <summary> | ||
/// Gets or sets the source path. | ||
/// </summary> | ||
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration .mof to import.")] | ||
[ValidateNotNullOrEmpty] | ||
public string Path { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the configuration name for the node configuration. | ||
/// </summary> | ||
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the DSC Configuration to import the Node Configuration under. All Node Configurations in Azure Automation must exist under a Configuration. The name of the Configuration will become the namespace of the imported Node Configuration, in the form of 'ConfigurationName.MofFileName'")] | ||
public string ConfigurationName { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// Gets or sets switch parameter to confirm overwriting of existing configurations. | ||
/// </summary> | ||
[Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing Node Configuration.")] | ||
public SwitchParameter Force | ||
{ | ||
get { return this.overwriteExistingConfiguration; } | ||
set { this.overwriteExistingConfiguration = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Execute this cmdlet. | ||
/// </summary> | ||
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] | ||
protected override void ProcessRecord() | ||
{ | ||
var nodeConfiguration = this.AutomationClient.CreateNodeConfiguration( | ||
this.ResourceGroupName, | ||
this.AutomationAccountName, | ||
this.Path, | ||
this.ConfigurationName, | ||
this.Force); | ||
|
||
this.WriteObject(nodeConfiguration); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Security.Permissions; | ||
using Microsoft.Azure.Commands.Automation.Common; | ||
using Microsoft.Azure.Commands.Automation.Properties; | ||
|
||
namespace Microsoft.Azure.Commands.Automation.Cmdlet | ||
{ | ||
/// <summary> | ||
/// Removes a Connection type for automation. | ||
/// </summary> | ||
[Cmdlet(VerbsCommon.Remove, "AzureRmAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] | ||
public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet | ||
{ | ||
/// <summary> | ||
/// Gets or sets the connection name. | ||
/// </summary> | ||
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connection type name.")] | ||
[ValidateNotNullOrEmpty] | ||
public string Name { get; set; } | ||
|
||
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 3, HelpMessage = "Confirm the removal of the connection type")] | ||
public SwitchParameter Force { get; set; } | ||
|
||
/// <summary> | ||
/// Execute this cmdlet. | ||
/// </summary> | ||
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] | ||
protected override void AutomationProcessRecord() | ||
{ | ||
var nextLink = string.Empty; | ||
var removeMessageWarning = Resources.RemovingAzureAutomationResourceWarning; | ||
|
||
// check if any connections exists that use this connection type | ||
do | ||
{ | ||
var ret = this.AutomationClient.ListConnections(this.ResourceGroupName, this.AutomationAccountName, ref nextLink); | ||
|
||
if (ret.ToList().Any(connection => 0 == | ||
string.Compare(connection.ConnectionTypeName, this.Name, | ||
StringComparison.CurrentCultureIgnoreCase))) | ||
{ | ||
removeMessageWarning = Resources.RemoveConnectionTypeThatHasConnectionWarning; | ||
break; | ||
} | ||
|
||
} while (!string.IsNullOrEmpty(nextLink)); | ||
|
||
|
||
ConfirmAction( | ||
Force.IsPresent, | ||
string.Format(removeMessageWarning, "ConnectionType"), | ||
string.Format(Resources.RemoveAzureAutomationResourceDescription, "ConnectionType"), | ||
Name, | ||
() => this.AutomationClient.DeleteConnectionType(this.ResourceGroupName, this.AutomationAccountName, Name)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please convert to xunit. We do not run any MSTest tests as part of Pull Request validation.
(https://github.com/Azure/azure-powershell/blob/dev/AzurePowershell.Test.targets#L96)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are unit tests only. Will take up in next release cycle to move them to xunit.
Our Scenario tests are xunit based.