Skip to content

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 26 commits into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
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 Aug 21, 2015
fbd87bd
Remove-AAConnectionType cmdlet and Optional RunbookName- addressed co…
safeermohammed Aug 24, 2015
65079c3
powershell model udpate for dsc node report
avkaur Aug 26, 2015
3507b64
powershell model udpate for dsc node report2
avkaur Aug 26, 2015
cf5144e
powershell model udpate for dsc node report3
avkaur Aug 27, 2015
694947e
import mof powershell sdk update
avkaur Sep 4, 2015
802904b
report model update2
avkaur Sep 9, 2015
28e8804
report model update2
avkaur Sep 9, 2015
b5de0f2
report model update3
avkaur Sep 10, 2015
147200b
report model update4
avkaur Sep 11, 2015
d6e3c28
report model update5
avkaur Sep 11, 2015
aaa144b
Runbook params should accept any type
Sep 15, 2015
b570b9b
Webhook should accept any param types
Sep 15, 2015
9a5ea29
Init hashtable
Sep 17, 2015
b86f77c
Handling Json deserialization error
Sep 17, 2015
76ae1e1
Merge pull request #6 from avkaur/dev
safeermohammed Sep 18, 2015
2eaa48f
Merge pull request #7 from shipram/dev
safeermohammed Sep 18, 2015
27b2187
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed Sep 19, 2015
73047f9
Latest changes from Azure dev
safeermohammed Sep 19, 2015
4622847
Making name of new cmdlets consistent as AzureRM
safeermohammed Sep 24, 2015
2bc816e
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed Sep 24, 2015
e18aa9c
Added remove connectiontype test
safeermohammed Sep 29, 2015
84abd53
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed Sep 29, 2015
bdf05e9
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
safeermohammed Sep 29, 2015
c11ec70
dsc bugifx
safeermohammed Sep 29, 2015
0c73381
Address Review comments
safeermohammed Sep 29, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<Compile Include="UnitTests\RegisterAzureAutomationScheduledRunbookTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationAccountTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationCertificateTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationConnectionTypeTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationConnectionTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationModuleTest.cs" />
<Compile Include="UnitTests\RemoveAzureAutomationRunbookTest.cs" />
Expand Down
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]
Copy link
Member

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)

Copy link
Contributor Author

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.

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());
}
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public class ImportAzureAutomationRunbook : AzureAutomationBaseCmdlet
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook description.")]
public string Description { get; set; }

/// <summary>
/// Gets or sets the runbook name
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the runbook to import, if different from the file name. Not supported for PowerShell Workflow runbooks.")]
[Alias("RunbookName")]
public string Name { get; set; }

/// <summary>
/// Gets or sets the runbook tags.
/// </summary>
Expand Down Expand Up @@ -98,7 +105,8 @@ protected override void AutomationProcessRecord()
this.LogProgress,
this.LogVerbose,
this.Published.IsPresent,
this.Force.IsPresent);
this.Force.IsPresent,
this.Name);

this.WriteObject(runbook);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using Microsoft.Azure.Commands.Automation.Properties;
using Microsoft.WindowsAzure.Commands.Common;
using System;
using System.Collections.Generic;
using System.Collections;
using System.Management.Automation;
using System.Security.Permissions;

Expand Down Expand Up @@ -66,7 +66,7 @@ public class NewAzureAutomationWebhook : AzureAutomationBaseCmdlet
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The Runbook parameters name/value.")]
public IDictionary<string, string> Parameters { get; set; }
public IDictionary Parameters { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Skip warning message about one-time viewable webhook URL")]
public SwitchParameter Force { get; set; }
Expand All @@ -91,7 +91,7 @@ protected override void AutomationProcessRecord()
this.RunbookName,
this.IsEnabled,
this.ExpiryTime,
this.Parameters.ToHashtable())));
this.Parameters)));

}
}
Expand Down
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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Collections;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.WindowsAzure.Commands.Common;
using System.Collections.Generic;
using System.Management.Automation;
using System.Security.Permissions;

Expand Down Expand Up @@ -48,7 +48,7 @@ public class SetAzureAutomationWebhook : AzureAutomationBaseCmdlet
/// </summary>
[Parameter(Position = 4, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The Runbook parameters name/value.")]
public IDictionary<string, string> Parameters { get; set; }
public IDictionary Parameters { get; set; }

/// <summary>
/// Execute this cmdlet.
Expand All @@ -60,7 +60,7 @@ protected override void AutomationProcessRecord()
this.ResourceGroupName,
this.AutomationAccountName,
this.Name,
this.Parameters.ToHashtable(),
this.Parameters,
this.IsEnabled);
this.WriteObject(updatedWebhook);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Management.Automation;
using System.Security.Permissions;
using Microsoft.Azure.Commands.Automation.Common;
using Microsoft.Azure.Commands.Automation.Model;
using Microsoft.Azure.Commands.Automation.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Common;

namespace Microsoft.Azure.Commands.Automation.Cmdlet
Expand All @@ -42,6 +45,12 @@ public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
[Parameter(Mandatory = false, HelpMessage = "The compilation job parameters.")]
public IDictionary Parameters { get; set; }

/// <summary>
/// Gets or sets the configuration data.
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "The compilation job configuration data.")]
public IDictionary ConfigurationData { get; set; }

/// <summary>
/// Execute this cmdlet.
/// </summary>
Expand All @@ -50,7 +59,15 @@ protected override void AutomationProcessRecord()
{
CompilationJob job = null;

job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters);
if (this.Parameters != null && this.Parameters.Contains("ConfigurationData"))
{
throw new ArgumentException(
string.Format(
CultureInfo.CurrentCulture,
Resources.ConfigurationDataShouldNotBeInJobParameters, "-ConfigurationData"));
}

job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters, this.ConfigurationData);

this.WriteObject(job);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.0.50.2-prerelease\lib\portable-net45+wp8+wpa81+win\Microsoft.Azure.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.7-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
Expand All @@ -79,10 +83,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.0.50.1-prerelease\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
Expand Down Expand Up @@ -127,6 +127,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
<Compile Include="Cmdlet\ImportAzureAutomationDscNodeConfiguration.cs" />
<Compile Include="Cmdlet\ExportAzureAutomationDscConfiguration.cs" />
<Compile Include="Cmdlet\ExportAzureAutomationDscNodeReportContent.cs" />
<Compile Include="Cmdlet\GetAzureAutomationCertificate.cs" />
Expand Down Expand Up @@ -159,6 +160,7 @@
<Compile Include="Cmdlet\RegisterAzureAutomationDscNode.cs" />
<Compile Include="Cmdlet\RegisterAzureAutomationScheduledRunbook.cs" />
<Compile Include="Cmdlet\RemoveAzureAutomationCertificate.cs" />
<Compile Include="Cmdlet\RemoveAzureAutomationConnectionType.cs" />
<Compile Include="Cmdlet\RemoveAzureAutomationConnection.cs" />
<Compile Include="Cmdlet\RemoveAzureAutomationCredential.cs" />
<Compile Include="Cmdlet\RemoveAzureAutomationModule.cs" />
Expand Down
Loading