From aee2f5af2d0c5cbdaa56c163c5aa1881405ba79d Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Fri, 21 Aug 2015 12:33:49 -0700 Subject: [PATCH 01/20] Remove-AAConnectionType cmdlet and Optional RunbookName --- .../Cmdlet/ImportAzureAutomationRunbook.cs | 10 ++- .../RemoveAzureAutomationConnectionType.cs | 73 +++++++++++++++++++ ...mands.ResourceManagement.Automation.csproj | 1 + .../Common/AutomationClient.cs | 37 +++++++++- .../Common/IAutomationClient.cs | 8 +- .../Properties/Resources.Designer.cs | 27 +++++++ .../Properties/Resources.resx | 11 +++ .../RemoveAzureAutomationConnectionType.cs | 73 +++++++++++++++++++ .../Commands.Automation.csproj | 1 + .../Common/AutomationClient.cs | 22 ++++++ .../Common/IAutomationClient.cs | 6 ++ .../Properties/Resources.Designer.cs | 20 ++++- .../Properties/Resources.resx | 8 ++ 13 files changed, 293 insertions(+), 4 deletions(-) create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs create mode 100644 src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs index dd56a875d372..21d13181c9bc 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs @@ -43,6 +43,13 @@ public class ImportAzureAutomationRunbook : AzureAutomationBaseCmdlet [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook description.")] public string Description { get; set; } + /// + /// Gets or sets the runbook name + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook name.")] + [Alias("RunbookName")] + public string Name { get; set; } + /// /// Gets or sets the runbook tags. /// @@ -98,7 +105,8 @@ protected override void AutomationExecuteCmdlet() this.LogProgress, this.LogVerbose, this.Published.IsPresent, - this.Force.IsPresent); + this.Force.IsPresent, + this.Name); this.WriteObject(runbook); } diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs new file mode 100644 index 000000000000..cf7ad86b22c5 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -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 +{ + /// + /// Removes a ConnectionType for automation. + /// + [Cmdlet(VerbsCommon.Remove, "AzureAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the connection name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connectiontype name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 3, HelpMessage = "Confirm the removal of the connectiontype")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + 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)); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index fc63c227b462..69f202d69901 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -149,6 +149,7 @@ + diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs index fc11e4a165fd..ab1d32ea3600 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs @@ -475,7 +475,7 @@ public Runbook CreateRunbookByName(string resourceGroupName, string automationAc } } - public Runbook ImportRunbook(string resourceGroupName, string automationAccountName, string runbookPath, string description, IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool published, bool overwrite) + public Runbook ImportRunbook(string resourceGroupName, string automationAccountName, string runbookPath, string description, IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool published, bool overwrite, string name) { var fileExtension = Path.GetExtension(runbookPath); @@ -503,6 +503,20 @@ public Runbook ImportRunbook(string resourceGroupName, string automationAccountN var runbookName = Path.GetFileNameWithoutExtension(runbookPath); + if (String.IsNullOrWhiteSpace(name) == false) + { + if (0 == string.Compare(type, Constants.RunbookType.PowerShellWorkflow, StringComparison.OrdinalIgnoreCase)) + { + if (0 != string.Compare(runbookName, name, StringComparison.CurrentCultureIgnoreCase)) + { + throw new ResourceCommonException(typeof(Runbook), + string.Format(CultureInfo.CurrentCulture, Resources.FileNameRunbookNameMismatch)); + } + } + + runbookName = name; + } + using (var request = new RequestSettings(this.automationManagementClient)) { var runbook = this.CreateRunbookByName(resourceGroupName, automationAccountName, runbookName, description, tags, type, logProgress, logVerbose, overwrite); @@ -1478,6 +1492,27 @@ public void UnregisterScheduledRunbook(string resourceGroupName, string automati #endregion + #region ConnectionType + + public void DeleteConnectionType(string resourceGroupName, string automationAccountName, string name) + { + try + { + this.automationManagementClient.ConnectionTypes.Delete(resourceGroupName, automationAccountName, name); + } + catch (CloudException cloudException) + { + if (cloudException.Response.StatusCode == HttpStatusCode.NoContent) + { + throw new ResourceNotFoundException(typeof(ConnectionType), + string.Format(CultureInfo.CurrentCulture, Resources.ConnectionTypeNotFound, name)); + } + + throw; + } + } + + #endregion #region Private Methods diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index e60b1cd216e2..9932bd0df1f0 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -187,7 +187,7 @@ Model.Webhook CreateWebhook( Runbook CreateRunbookByName(string resourceGroupName, string automationAccountName, string runbookName, string description, IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool overwrite); - Runbook ImportRunbook(string resourceGroupName, string automationAccountName, string runbookPath, string description, IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool published, bool overwrite); + Runbook ImportRunbook(string resourceGroupName, string automationAccountName, string runbookPath, string description, IDictionary tags, string type, bool? logProgress, bool? logVerbose, bool published, bool overwrite, string runbookName); void DeleteRunbook(string resourceGroupName, string automationAccountName, string runbookName); @@ -283,6 +283,12 @@ IEnumerable GetJobStream(string resourceGroupName, string automationA void UnregisterScheduledRunbook(string resourceGroupName, string automationAccountName, string runbookName, string scheduleName); + #endregion + + #region ConnectionType + + void DeleteConnectionType(string resourceGroupName, string automationAccountName, string name); + #endregion } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 157b7fa2e9c2..6dc58b48ba2c 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -231,6 +231,15 @@ internal static string ConnectionNotFound { } } + /// + /// Looks up a localized string similar to The connectiontype was not found. ConnectionType name: {0}.. + /// + internal static string ConnectionTypeNotFound { + get { + return ResourceManager.GetString("ConnectionTypeNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to The credential was not found. Credential name: {0}.. /// @@ -267,6 +276,15 @@ internal static string DscNodeNotFound { } } + /// + /// Looks up a localized string similar to FileName and RunbookName should be same for PowerShellWorkflow runbook type.. + /// + internal static string FileNameRunbookNameMismatch { + get { + return ResourceManager.GetString("FileNameRunbookNameMismatch", resourceCulture); + } + } + /// /// Looks up a localized string similar to Invalid configuration parameters.. /// @@ -492,6 +510,15 @@ internal static string RemoveAzureAutomationScheduleWarning { } } + /// + /// Looks up a localized string similar to This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ?. + /// + internal static string RemoveConnectionTypeThatHasConnectionWarning { + get { + return ResourceManager.GetString("RemoveConnectionTypeThatHasConnectionWarning", resourceCulture); + } + } + /// /// Looks up a localized string similar to Removing the Dsc node with Id {0}.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index a5e5111c1626..80f1c02dcfa0 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -403,4 +403,15 @@ Runbook file already exists. Specify the force switch switch overwrite. Runbook file name: {0} Automation + + FileName and RunbookName should be same for PowerShellWorkflow runbook type. + Automation + + + The connectiontype was not found. ConnectionType name: {0}. + + + This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? + Automation + \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs new file mode 100644 index 000000000000..e31a93aa81c0 --- /dev/null +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -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 +{ + /// + /// Removes a ConnectionType for automation. + /// + [Cmdlet(VerbsCommon.Remove, "AzureAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the connection name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connectiontype name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, HelpMessage = "Confirm the removal of the connectiontype")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + 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.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.AutomationAccountName, Name)); + } + } +} diff --git a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj index a876709cccbc..e292ee4328e3 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj +++ b/src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj @@ -125,6 +125,7 @@ + diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs index b8e4b3e71509..c9fe57f27b0b 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs @@ -1421,6 +1421,28 @@ public void UnregisterScheduledRunbook(string automationAccountName, string runb #endregion + #region ConnectionType + + public void DeleteConnectionType(string automationAccountName, string name) + { + try + { + this.automationManagementClient.ConnectionTypes.Delete(automationAccountName, name); + } + catch (CloudException cloudException) + { + if (cloudException.Response.StatusCode == HttpStatusCode.NoContent) + { + throw new ResourceNotFoundException(typeof(ConnectionType), + string.Format(CultureInfo.CurrentCulture, Resources.ConnectionTypeNotFound, name)); + } + + throw; + } + } + + #endregion + #region Private Methods private Schedule CreateScheduleFromScheduleModel(string automationAccountName, AutomationManagement.Models.Schedule schedule) diff --git a/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs index 0577a4ecf255..c3340971401d 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -186,6 +186,12 @@ public interface IAutomationClient void UnregisterScheduledRunbook(string automationAccountName, string runbookName, string scheduleName); + #endregion + + #region ConnectionType + + void DeleteConnectionType(string automationAccountName, string name); + #endregion } } \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs index 3db90ac47b88..5a989858a84a 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18449 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -150,6 +150,15 @@ internal static string ConnectionNotFound { } } + /// + /// Looks up a localized string similar to The connectiontype was not found. ConnectionType name: {0}.. + /// + internal static string ConnectionTypeNotFound { + get { + return ResourceManager.GetString("ConnectionTypeNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to The credential was not found. Credential name: {0}.. /// @@ -285,6 +294,15 @@ internal static string RemoveAzureAutomationScheduleWarning { } } + /// + /// Looks up a localized string similar to This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ?. + /// + internal static string RemoveConnectionTypeThatHasConnectionWarning { + get { + return ResourceManager.GetString("RemoveConnectionTypeThatHasConnectionWarning", resourceCulture); + } + } + /// /// Looks up a localized string similar to Are you sure you want to remove the Azure Automation {0} ?. /// diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx index d6811d83fa86..03a6f934e0db 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx @@ -278,4 +278,12 @@ The Compilation Job having Id: {0} was not found. + + The connectiontype was not found. ConnectionType name: {0}. + Automation + + + This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? + Automation + \ No newline at end of file From fbd87bd735ed4abc6a4eb7e84bfdc930e47a3ec1 Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Mon, 24 Aug 2015 12:24:58 -0700 Subject: [PATCH 02/20] Remove-AAConnectionType cmdlet and Optional RunbookName- addressed commets --- .../Cmdlet/ImportAzureAutomationRunbook.cs | 2 +- .../Cmdlet/RemoveAzureAutomationConnectionType.cs | 6 +++--- .../Commands.Automation/Properties/Resources.Designer.cs | 6 +++--- .../Commands.Automation/Properties/Resources.resx | 6 +++--- .../Cmdlet/RemoveAzureAutomationConnectionType.cs | 8 ++++---- .../Commands.Automation/Properties/Resources.Designer.cs | 4 ++-- .../Commands.Automation/Properties/Resources.resx | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs index 21d13181c9bc..d540753cb71c 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationRunbook.cs @@ -46,7 +46,7 @@ public class ImportAzureAutomationRunbook : AzureAutomationBaseCmdlet /// /// Gets or sets the runbook name /// - [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook name.")] + [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; } diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs index cf7ad86b22c5..960c7ed7f81d 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet { /// - /// Removes a ConnectionType for automation. + /// Removes a Connection type for automation. /// [Cmdlet(VerbsCommon.Remove, "AzureAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet @@ -30,11 +30,11 @@ public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet /// /// Gets or sets the connection name. /// - [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connectiontype name.")] + [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 connectiontype")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 3, HelpMessage = "Confirm the removal of the connection type")] public SwitchParameter Force { get; set; } /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 6dc58b48ba2c..71102b9808d8 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -232,7 +232,7 @@ internal static string ConnectionNotFound { } /// - /// Looks up a localized string similar to The connectiontype was not found. ConnectionType name: {0}.. + /// Looks up a localized string similar to The connection type was not found. ConnectionType name: {0}.. /// internal static string ConnectionTypeNotFound { get { @@ -277,7 +277,7 @@ internal static string DscNodeNotFound { } /// - /// Looks up a localized string similar to FileName and RunbookName should be same for PowerShellWorkflow runbook type.. + /// Looks up a localized string similar to File name and runbook name must be the same for PowerShell Workflow runbooks.. /// internal static string FileNameRunbookNameMismatch { get { @@ -511,7 +511,7 @@ internal static string RemoveAzureAutomationScheduleWarning { } /// - /// Looks up a localized string similar to This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ?. + /// Looks up a localized string similar to This connection type has connections associated with it. If you delete this connection type, all connections associated with it will be unusable and should be removed, unless you create a new connection type with the same name that has the same field definitions as the deleted connection type. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ?. /// internal static string RemoveConnectionTypeThatHasConnectionWarning { get { diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index 80f1c02dcfa0..ba9710dba860 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -404,14 +404,14 @@ Automation - FileName and RunbookName should be same for PowerShellWorkflow runbook type. + File name and runbook name must be the same for PowerShell Workflow runbooks. Automation - The connectiontype was not found. ConnectionType name: {0}. + The connection type was not found. ConnectionType name: {0}. - This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? + This connection type has connections associated with it. If you delete this connection type, all connections associated with it will be unusable and should be removed, unless you create a new connection type with the same name that has the same field definitions as the deleted connection type. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? Automation \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs index e31a93aa81c0..dda11368ef90 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -22,19 +22,19 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet { /// - /// Removes a ConnectionType for automation. + /// Removes a Connection type for automation. /// [Cmdlet(VerbsCommon.Remove, "AzureAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet { /// - /// Gets or sets the connection name. + /// Gets or sets the connection type name. /// - [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connectiontype name.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The connection type name.")] [ValidateNotNullOrEmpty] public string Name { get; set; } - [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, HelpMessage = "Confirm the removal of the connectiontype")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Position = 2, HelpMessage = "Confirm the removal of the connection type")] public SwitchParameter Force { get; set; } /// diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs index 5a989858a84a..d3183f59b99d 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -151,7 +151,7 @@ internal static string ConnectionNotFound { } /// - /// Looks up a localized string similar to The connectiontype was not found. ConnectionType name: {0}.. + /// Looks up a localized string similar to The connection type was not found. ConnectionType name: {0}.. /// internal static string ConnectionTypeNotFound { get { @@ -295,7 +295,7 @@ internal static string RemoveAzureAutomationScheduleWarning { } /// - /// Looks up a localized string similar to This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ?. + /// Looks up a localized string similar to This connection type has connections associated with it. If you delete this connection type, all connections associated with it will be unusable and should be removed, unless you create a new connection type with the same name that has the same field definitions as the deleted connection type. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ?. /// internal static string RemoveConnectionTypeThatHasConnectionWarning { get { diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx index 03a6f934e0db..d77181be64b8 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx @@ -279,11 +279,11 @@ The Compilation Job having Id: {0} was not found. - The connectiontype was not found. ConnectionType name: {0}. + The connection type was not found. ConnectionType name: {0}. Automation - This connectiontype has connections associated with it. If you delete this connectiontype, all connections associated with it will be unusable and should be removed, unless you create a new connectiontype with the same name that has the same field definitions as the deleted connectiontype. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? + This connection type has connections associated with it. If you delete this connection type, all connections associated with it will be unusable and should be removed, unless you create a new connection type with the same name that has the same field definitions as the deleted connection type. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? Automation \ No newline at end of file From 65079c3d52906d62af59a64a588461da7cf152a2 Mon Sep 17 00:00:00 2001 From: avkaur Date: Wed, 26 Aug 2015 12:53:36 -0700 Subject: [PATCH 03/20] powershell model udpate for dsc node report --- .../Model/DscNodeReport.cs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs b/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs index fba205af7b81..ed92db408aeb 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs @@ -43,8 +43,13 @@ public DscNodeReport(string resourceGroupName, string automationAccountName, str this.EndTime = dscNodeReport.EndTime; this.LastModifiedTime = dscNodeReport.LastModifiedTime; this.ReportType = dscNodeReport.Type; - this.Id = dscNodeReport.Id; + this.Id = dscNodeReport.Id.ToString(); this.NodeId = nodeId; + this.Status = dscNodeReport.Status; + this.RefreshMode = dscNodeReport.RefreshMode; + this.RebootRequested = dscNodeReport.RebootRequested; + this.ReportFormatVersion = dscNodeReport.ReportFormatVersion; + this.ConfigurationVersion = dscNodeReport.ConfigurationVersion; } /// @@ -93,5 +98,30 @@ public DscNodeReport() /// Gets or sets the Node id. /// public string NodeId { get; set; } + + /// + /// Gets or sets the Status. + /// + public string Status { get; set; } + + /// + /// Gets or sets the Refresh Mode. + /// + public string RefreshMode { get; set; } + + /// + /// Gets or sets the Reboot Requested. + /// + public string RebootRequested { get; set; } + + /// + /// Gets or sets the Report Format Version. + /// + public string ReportFormatVersion { get; set; } + + /// + /// Gets or sets the Configuration Version. + /// + public string ConfigurationVersion { get; set; } } } From 3507b644de304cff3747fb9838c22ab450dd80fc Mon Sep 17 00:00:00 2001 From: avkaur Date: Wed, 26 Aug 2015 14:07:35 -0700 Subject: [PATCH 04/20] powershell model udpate for dsc node report2 --- .../Automation/Commands.Automation/Model/DscNodeReport.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs b/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs index ed92db408aeb..21dd9971993f 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs @@ -36,6 +36,7 @@ public DscNodeReport(string resourceGroupName, string automationAccountName, str Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); Requires.Argument("dscNodeReport", dscNodeReport).NotNull(); + Requires.Argument("dscNodeReport", dscNodeReport.Id).NotNull(); this.ResourceGroupName = resourceGroupName; this.AutomationAccountName = automationAccountName; @@ -43,7 +44,7 @@ public DscNodeReport(string resourceGroupName, string automationAccountName, str this.EndTime = dscNodeReport.EndTime; this.LastModifiedTime = dscNodeReport.LastModifiedTime; this.ReportType = dscNodeReport.Type; - this.Id = dscNodeReport.Id.ToString(); + this.Id = dscNodeReport.Id.ToString("D"); this.NodeId = nodeId; this.Status = dscNodeReport.Status; this.RefreshMode = dscNodeReport.RefreshMode; From cf5144ee9b79587dfa219c346019648189308007 Mon Sep 17 00:00:00 2001 From: avkaur Date: Wed, 26 Aug 2015 17:02:38 -0700 Subject: [PATCH 05/20] powershell model udpate for dsc node report3 --- .../Automation/Commands.Automation/Model/DscNodeReport.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs b/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs index 21dd9971993f..a0c675392531 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/DscNodeReport.cs @@ -50,7 +50,6 @@ public DscNodeReport(string resourceGroupName, string automationAccountName, str this.RefreshMode = dscNodeReport.RefreshMode; this.RebootRequested = dscNodeReport.RebootRequested; this.ReportFormatVersion = dscNodeReport.ReportFormatVersion; - this.ConfigurationVersion = dscNodeReport.ConfigurationVersion; } /// @@ -119,10 +118,5 @@ public DscNodeReport() /// Gets or sets the Report Format Version. /// public string ReportFormatVersion { get; set; } - - /// - /// Gets or sets the Configuration Version. - /// - public string ConfigurationVersion { get; set; } } } From 694947e4add6aefb41202e851d943225f89cb7eb Mon Sep 17 00:00:00 2001 From: avkaur Date: Fri, 4 Sep 2015 12:47:59 -0700 Subject: [PATCH 06/20] import mof powershell sdk update --- ...portAzureAutomationDscNodeConfiguration.cs | 71 +++++++++++++++++++ ...mands.ResourceManagement.Automation.csproj | 1 + .../Common/AutomationClientDSC.cs | 57 +++++++++++++++ .../Common/IAutomationClient.cs | 2 + 4 files changed, 131 insertions(+) create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs new file mode 100644 index 000000000000..a97c7a83d8ea --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -0,0 +1,71 @@ +// ---------------------------------------------------------------------------------- +// +// 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 +{ + /// + /// Imports dsc node configuration script + /// + [Cmdlet(VerbsData.Import, "ImportAzureAutomationDscNodeConfiguration")] + [OutputType(typeof(DscConfiguration))] + public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the source path. + /// + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration script .mof to import.")] + [Alias("Path")] + [ValidateNotNullOrEmpty] + public string SourcePath { get; set; } + + /// + /// Gets or sets the node configuration name. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node configuration name for which .mof is imported.")] + [Alias("Name")] + public string Name { get; set; } + + /// + /// Gets or sets the configuration name for the node configuration. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc configuration name for .mof imported")] + [Alias("ConfigurationName")] + public string ConfigurationName { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + var nodeConfiguration = this.AutomationClient.CreateNodeConfiguration( + this.ResourceGroupName, + this.AutomationAccountName, + this.SourcePath, + this.Name, + this.ConfigurationName); + + this.WriteObject(nodeConfiguration); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index 69f202d69901..55dfd9fc3530 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -117,6 +117,7 @@ + diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 731de4eaaaa8..771f422befc0 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -1118,6 +1118,63 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st } } + public Model.NodeConfiguration CreateNodeConfiguration( + string resourceGroupName, + string automationAccountName, + string sourcePath, + string nodeConfiguraionName, + string configurationName) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + Requires.Argument("SourcePath", sourcePath).NotNull(); + + string fileContent = null; + string nodeConfigurationName = String.Empty; + + try + { + if (File.Exists(Path.GetFullPath(sourcePath))) + { + fileContent = System.IO.File.ReadAllText(sourcePath); + } + } + catch (Exception) + { + // exception in accessing the file path + throw new FileNotFoundException( + string.Format( + CultureInfo.CurrentCulture, + Resources.ConfigurationSourcePathInvalid)); + } + + var nodeConfigurationCreateParameters = new DscNodeConfigurationCreateOrUpdateParameters() + { + Name = nodeConfiguraionName, + Source = new Microsoft.Azure.Management.Automation.Models.ContentSource() + { + // only embeddedContent supported for now + ContentType = Model.ContentSourceType.embeddedContent.ToString(), + Value = fileContent + }, + Configuration = new DscConfigurationAssociationProperty() + { + Name = configurationName + } + }; + + var configuration = + this.automationManagementClient.NodeConfigurations.CreateOrUpdate( + resourceGroupName, + automationAccountName, + nodeConfigurationCreateParameters).NodeConfiguration; + + return new Model.NodeConfiguration(resourceGroupName, automationAccountName, configuration); + } + } + #endregion #region dsc reports diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 9932bd0df1f0..2e421c31fcb2 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -59,6 +59,8 @@ public interface IAutomationClient IEnumerable ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName, string rollupStatus); IEnumerable ListNodeConfigurations(string resourceGroupName, string automationAccountName, string rollupStatus); + + NodeConfiguration CreateNodeConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, IDictionary tags); #endregion #region Configurations From 802904b396945f894c54231a020a82e529691844 Mon Sep 17 00:00:00 2001 From: avkaur Date: Tue, 8 Sep 2015 17:47:39 -0700 Subject: [PATCH 07/20] report model update2 --- ...portAzureAutomationDscNodeConfiguration.cs | 37 +++-- .../Common/AutomationClientDSC.cs | 142 +++++++++++++----- .../Common/IAutomationClient.cs | 2 +- .../Properties/Resources.Designer.cs | 11 +- .../Properties/Resources.resx | 4 + 5 files changed, 146 insertions(+), 50 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index a97c7a83d8ea..6111bf1d7689 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -26,31 +26,40 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// Imports dsc node configuration script /// - [Cmdlet(VerbsData.Import, "ImportAzureAutomationDscNodeConfiguration")] - [OutputType(typeof(DscConfiguration))] + [Cmdlet(VerbsData.Import, "AzureAutomationDscNodeConfiguration")] + [OutputType(typeof(NodeConfiguration))] public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet - { + { + /// + /// True to overwrite the existing configuration; false otherwise. + /// + private bool overwriteExistingConfiguration; + /// /// Gets or sets the source path. /// - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration script .mof to import.")] + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration .mof to import.")] [Alias("Path")] [ValidateNotNullOrEmpty] public string SourcePath { get; set; } /// - /// Gets or sets the node configuration name. + /// Gets or sets the configuration name for the node configuration. /// - [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node configuration name for which .mof is imported.")] - [Alias("Name")] - public string Name { get; set; } + [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'")] + [Alias("NodeConfigurationName")] + public string ConfigurationName { get; set; } + /// - /// Gets or sets the configuration name for the node configuration. + /// Gets or sets switch parameter to confirm overwriting of existing configurations. /// - [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc configuration name for .mof imported")] - [Alias("ConfigurationName")] - public string ConfigurationName { get; set; } + [Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing configuration.")] + public SwitchParameter Force + { + get { return this.overwriteExistingConfiguration; } + set { this.overwriteExistingConfiguration = value; } + } /// /// Execute this cmdlet. @@ -62,8 +71,8 @@ public override void ExecuteCmdlet() this.ResourceGroupName, this.AutomationAccountName, this.SourcePath, - this.Name, - this.ConfigurationName); + this.ConfigurationName, + this.Force); this.WriteObject(nodeConfiguration); } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 771f422befc0..f9e3d7fb193a 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -257,6 +257,48 @@ private Model.DscConfiguration TryGetConfigurationModel(string resourceGroupName return configuration; } + public Model.DscConfiguration CreateConfiguration( + string resourceGroupName, + string automationAccountName, + string configrationName, + string nodeName) + { + string configurationContent = "Configuration {0} { Node {1} { } } "; + configurationContent = string.Format(configurationContent,configrationName,nodeName); + + using (var request = new RequestSettings(this.automationManagementClient)) + { + + // location of the configuration is set to same as that of automation account + string location = this.GetAutomationAccount(resourceGroupName, automationAccountName).Location; + + var configurationCreateParameters = new DscConfigurationCreateOrUpdateParameters() + { + Name = configrationName, + Location = location, + Properties = new DscConfigurationCreateOrUpdateProperties() + { + Description = String.Empty, + LogVerbose = false, + Source = new Microsoft.Azure.Management.Automation.Models.ContentSource() + { + // only embeddedContent supported for now + ContentType = Model.ContentSourceType.embeddedContent.ToString(), + Value = configurationContent + } + } + }; + + var configuration = + this.automationManagementClient.Configurations.CreateOrUpdate( + resourceGroupName, + automationAccountName, + configurationCreateParameters).Configuration; + + return new Model.DscConfiguration(resourceGroupName, automationAccountName, configuration); + } + } + #endregion #region DscMetaConfig Operations @@ -1122,17 +1164,19 @@ public Model.NodeConfiguration CreateNodeConfiguration( string resourceGroupName, string automationAccountName, string sourcePath, - string nodeConfiguraionName, - string configurationName) + string nodeConfigurationName, + bool overWrite) { using (var request = new RequestSettings(this.automationManagementClient)) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); Requires.Argument("SourcePath", sourcePath).NotNull(); + Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNull(); string fileContent = null; - string nodeConfigurationName = String.Empty; + string configurationName = null; + string nodeName = null; try { @@ -1150,9 +1194,57 @@ public Model.NodeConfiguration CreateNodeConfiguration( Resources.ConfigurationSourcePathInvalid)); } + try + { + var configuration = nodeConfigurationName.Split('.'); + if(configuration.Length == 2) + { + configurationName = configuration[0]; + nodeName = configuration[1]; + } + else + { + throw new Exception(); + } + } + catch (Exception) + { + // exception in getting the config name from NodeConfigName + throw new FileNotFoundException( + string.Format( + CultureInfo.CurrentCulture, + Resources.NodeConfigurationNameInvalid)); + } + + // if node configuration already exists, ensure overwrite flag is specified + var nodeConfigurationModel = this.GetNodeConfiguration( + resourceGroupName, + automationAccountName, + nodeConfigurationName, + null); + if (nodeConfigurationModel != null) + { + if (!overWrite) + { + throw new ResourceCommonException(typeof(Model.NodeConfiguration), + string.Format(CultureInfo.CurrentCulture, Resources.NodeConfigurationAlreadyExists, nodeConfigurationName)); + } + } + + // if configuration already exists, ensure overwrite flag is specified + var configurationModel = this.TryGetConfigurationModel( + resourceGroupName, + automationAccountName, + configurationName); + if (configurationModel == null) + { + //create empty configuration if its empty + this.CreateConfiguration(resourceGroupName, automationAccountName, configurationName, nodeName); + } + var nodeConfigurationCreateParameters = new DscNodeConfigurationCreateOrUpdateParameters() { - Name = nodeConfiguraionName, + Name = nodeConfigurationName, Source = new Microsoft.Azure.Management.Automation.Models.ContentSource() { // only embeddedContent supported for now @@ -1165,13 +1257,14 @@ public Model.NodeConfiguration CreateNodeConfiguration( } }; - var configuration = + var nodeConfiguration = this.automationManagementClient.NodeConfigurations.CreateOrUpdate( resourceGroupName, automationAccountName, nodeConfigurationCreateParameters).NodeConfiguration; - return new Model.NodeConfiguration(resourceGroupName, automationAccountName, configuration); + + return new Model.NodeConfiguration(resourceGroupName, automationAccountName, nodeConfiguration, null); } } @@ -1396,39 +1489,20 @@ private string FormatDateTime(DateTimeOffset dateTime) private IDictionary ProcessConfigurationParameters(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters) { parameters = parameters ?? new Dictionary(); - IEnumerable> configurationParameters = this.ListConfigurationParameters(resourceGroupName, automationAccountName, configurationName); - var filteredParameters = new Dictionary(); - - foreach (var configParameter in configurationParameters) - { - if (parameters.Contains(configParameter.Key)) + var filteredParameters = new Dictionary(); + foreach (var configParameter in parameters.Keys) + { + try { - object paramValue = parameters[configParameter.Key]; - try - { - filteredParameters.Add(configParameter.Key, paramValue.ToString()); - } - catch (JsonSerializationException) - { - throw new ArgumentException( - string.Format( - CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, configParameter.Key)); - } + filteredParameters.Add(configParameter.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(parameters[configParameter])); } - else if (configParameter.Value.IsMandatory) + catch (JsonSerializationException) { throw new ArgumentException( - string.Format( - CultureInfo.CurrentCulture, Resources.ConfigurationParameterValueRequired, configParameter.Key)); - } + string.Format( + CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, configParameter.ToString())); + } } - - if (filteredParameters.Count != parameters.Count) - { - throw new ArgumentException( - string.Format(CultureInfo.CurrentCulture, Resources.InvalidConfigurationParameters)); - } - return filteredParameters; } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 2e421c31fcb2..477d3dcd13b8 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -60,7 +60,7 @@ public interface IAutomationClient IEnumerable ListNodeConfigurations(string resourceGroupName, string automationAccountName, string rollupStatus); - NodeConfiguration CreateNodeConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, IDictionary tags); + NodeConfiguration CreateNodeConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, string nodeConfiguraionName, bool overWrite); #endregion #region Configurations diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 71102b9808d8..3f306836a314 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -393,6 +393,15 @@ internal static string NodeConfigurationAlreadyExists { } } + /// + /// Looks up a localized string similar to Invalid node configuration name. Please specify in the format <node name>.<config name>. + /// + internal static string NodeConfigurationNameInvalid { + get { + return ResourceManager.GetString("NodeConfigurationNameInvalid", resourceCulture); + } + } + /// /// Looks up a localized string similar to NodeConfiguration {0} not found.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index ba9710dba860..7973fd09c8e3 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -414,4 +414,8 @@ This connection type has connections associated with it. If you delete this connection type, all connections associated with it will be unusable and should be removed, unless you create a new connection type with the same name that has the same field definitions as the deleted connection type. However, it can have additional fields as well. Are you sure you want to remove the Azure Automation {0} ? Automation + + Invalid node configuration name. Please specify in the format <node name>.<config name> + Automation + \ No newline at end of file From 28e88049475a5308ec8457a714a2a6af076a922e Mon Sep 17 00:00:00 2001 From: avkaur Date: Wed, 9 Sep 2015 11:11:05 -0700 Subject: [PATCH 08/20] report model update2 --- ...portAzureAutomationDscNodeConfiguration.cs | 8 ++-- .../Common/AutomationClientDSC.cs | 46 +++++++++---------- .../Commands.Automation/Common/Requires.cs | 18 ++++++++ .../Properties/Resources.Designer.cs | 2 +- .../Properties/Resources.resx | 2 +- 5 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index 6111bf1d7689..441eaa0363ad 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -46,15 +46,15 @@ public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl /// /// Gets or sets the configuration name for the node configuration. /// - [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'")] + [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'")] [Alias("NodeConfigurationName")] - public string ConfigurationName { get; set; } + public string Name { get; set; } /// /// Gets or sets switch parameter to confirm overwriting of existing configurations. /// - [Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing configuration.")] + [Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing Node Configuration.")] public SwitchParameter Force { get { return this.overwriteExistingConfiguration; } @@ -71,7 +71,7 @@ public override void ExecuteCmdlet() this.ResourceGroupName, this.AutomationAccountName, this.SourcePath, - this.ConfigurationName, + this.Name, this.Force); this.WriteObject(nodeConfiguration); diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index f9e3d7fb193a..16c2b456424e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -1169,25 +1169,22 @@ public Model.NodeConfiguration CreateNodeConfiguration( { using (var request = new RequestSettings(this.automationManagementClient)) { - Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); - Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); - Requires.Argument("SourcePath", sourcePath).NotNull(); - Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNull(); + Requires.Argument("ResourceGroupName", resourceGroupName).NotNullOrEmpty(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNullOrEmpty(); + Requires.Argument("SourcePath", sourcePath).NotNullOrEmpty(); + Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNullOrEmpty(); string fileContent = null; string configurationName = null; string nodeName = null; - try + if (File.Exists(Path.GetFullPath(sourcePath))) { - if (File.Exists(Path.GetFullPath(sourcePath))) - { - fileContent = System.IO.File.ReadAllText(sourcePath); - } + fileContent = System.IO.File.ReadAllText(sourcePath); } - catch (Exception) + else { - // exception in accessing the file path + // file path not valid. throw new FileNotFoundException( string.Format( CultureInfo.CurrentCulture, @@ -1196,21 +1193,25 @@ public Model.NodeConfiguration CreateNodeConfiguration( try { - var configuration = nodeConfigurationName.Split('.'); - if(configuration.Length == 2) + int index = nodeConfigurationName.IndexOf("."); + if (index > 0) { - configurationName = configuration[0]; - nodeName = configuration[1]; + nodeName = nodeConfigurationName.Substring(0, index); + int configNameStartIndex = index + 1; + int configNameLenght = nodeConfigurationName.Length - index -1; + configurationName = nodeConfigurationName.Substring(configNameStartIndex, configNameLenght); } else { - throw new Exception(); + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, + Resources.NodeConfigurationNameInvalid)); } } catch (Exception) { - // exception in getting the config name from NodeConfigName - throw new FileNotFoundException( + // exception in getting the config name from configurationName + throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Resources.NodeConfigurationNameInvalid)); @@ -1490,17 +1491,16 @@ private IDictionary ProcessConfigurationParameters(string resour { parameters = parameters ?? new Dictionary(); var filteredParameters = new Dictionary(); - foreach (var configParameter in parameters.Keys) + foreach (var key in parameters.Keys) { try { - filteredParameters.Add(configParameter.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(parameters[configParameter])); + filteredParameters.Add(key.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(parameters[key])); } catch (JsonSerializationException) { - throw new ArgumentException( - string.Format( - CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, configParameter.ToString())); + throw new ArgumentException(string.Format( + CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, key.ToString())); } } return filteredParameters; diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/Requires.cs b/src/ResourceManager/Automation/Commands.Automation/Common/Requires.cs index 5f35eb17186a..4eae63c6a3d3 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/Requires.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/Requires.cs @@ -73,6 +73,24 @@ public ArgumentRequirements NotNull() return this; } + + /// + /// Checks argument value for not null or empty + /// + /// The not null requirement + public ArgumentRequirements NotNullOrEmpty() + { + if (this.Value == null) + { + throw new ArgumentNullException(this.Name); + } + else if (string.IsNullOrEmpty(this.Value.ToString())) + { + throw new ArgumentNullException(this.Name); + } + + return this; + } } } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 3f306836a314..41539d0c0f1f 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -394,7 +394,7 @@ internal static string NodeConfigurationAlreadyExists { } /// - /// Looks up a localized string similar to Invalid node configuration name. Please specify in the format <node name>.<config name>. + /// Looks up a localized string similar to Invalid node configuration name. Please specify in the format <config name>.<node name>. /// internal static string NodeConfigurationNameInvalid { get { diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index 7973fd09c8e3..f1cec079b933 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -415,7 +415,7 @@ Automation - Invalid node configuration name. Please specify in the format <node name>.<config name> + Invalid node configuration name. Please specify in the format <config name>.<node name> Automation \ No newline at end of file From b5de0f2761226218b38e7a553bf567ea13b6c6da Mon Sep 17 00:00:00 2001 From: avkaur Date: Thu, 10 Sep 2015 16:08:26 -0700 Subject: [PATCH 09/20] report model update3 --- ...portAzureAutomationDscNodeConfiguration.cs | 6 +-- .../Common/AutomationClientDSC.cs | 53 ++++++++----------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index 441eaa0363ad..59afd1fcb704 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -47,8 +47,8 @@ public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl /// Gets or sets the configuration name for the node configuration. /// [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'")] - [Alias("NodeConfigurationName")] - public string Name { get; set; } + [Alias("ConfigurationName")] + public string ConfigName { get; set; } /// @@ -71,7 +71,7 @@ public override void ExecuteCmdlet() this.ResourceGroupName, this.AutomationAccountName, this.SourcePath, - this.Name, + this.ConfigName, this.Force); this.WriteObject(nodeConfiguration); diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 16c2b456424e..4786c99a797b 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -1065,6 +1065,22 @@ public Model.CompilationJob StartCompilationJob(string resourceGroupName, string #endregion #region node configuration + public Model.NodeConfiguration TryGetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string rollupStatus) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + try + { + return GetNodeConfiguration(resourceGroupName, automationAccountName, nodeConfigurationName, rollupStatus); + } + catch (ResourceNotFoundException resourceNotFoundException) + { + Console.Write(resourceNotFoundException.Message); + return null; + } + } + } + public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string rollupStatus) { using (var request = new RequestSettings(this.automationManagementClient)) @@ -1164,7 +1180,7 @@ public Model.NodeConfiguration CreateNodeConfiguration( string resourceGroupName, string automationAccountName, string sourcePath, - string nodeConfigurationName, + string configurationName, bool overWrite) { using (var request = new RequestSettings(this.automationManagementClient)) @@ -1172,15 +1188,16 @@ public Model.NodeConfiguration CreateNodeConfiguration( Requires.Argument("ResourceGroupName", resourceGroupName).NotNullOrEmpty(); Requires.Argument("AutomationAccountName", automationAccountName).NotNullOrEmpty(); Requires.Argument("SourcePath", sourcePath).NotNullOrEmpty(); - Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNullOrEmpty(); + Requires.Argument("configurationName", configurationName).NotNullOrEmpty(); string fileContent = null; - string configurationName = null; + string nodeConfigurationName = null; string nodeName = null; if (File.Exists(Path.GetFullPath(sourcePath))) { fileContent = System.IO.File.ReadAllText(sourcePath); + nodeConfigurationName = configurationName + "." + System.IO.Path.GetFileNameWithoutExtension(sourcePath); } else { @@ -1190,35 +1207,9 @@ public Model.NodeConfiguration CreateNodeConfiguration( CultureInfo.CurrentCulture, Resources.ConfigurationSourcePathInvalid)); } - - try - { - int index = nodeConfigurationName.IndexOf("."); - if (index > 0) - { - nodeName = nodeConfigurationName.Substring(0, index); - int configNameStartIndex = index + 1; - int configNameLenght = nodeConfigurationName.Length - index -1; - configurationName = nodeConfigurationName.Substring(configNameStartIndex, configNameLenght); - } - else - { - throw new ArgumentException(string.Format( - CultureInfo.CurrentCulture, - Resources.NodeConfigurationNameInvalid)); - } - } - catch (Exception) - { - // exception in getting the config name from configurationName - throw new ArgumentException( - string.Format( - CultureInfo.CurrentCulture, - Resources.NodeConfigurationNameInvalid)); - } - + // if node configuration already exists, ensure overwrite flag is specified - var nodeConfigurationModel = this.GetNodeConfiguration( + var nodeConfigurationModel = this.TryGetNodeConfiguration( resourceGroupName, automationAccountName, nodeConfigurationName, From 147200b3b8733fd2dbd866d026469c8984617c39 Mon Sep 17 00:00:00 2001 From: avkaur Date: Fri, 11 Sep 2015 09:36:11 -0700 Subject: [PATCH 10/20] report model update4 --- .../Cmdlet/StartAzureAutomationDscCompilationJob.cs | 10 ++++++++++ .../Commands.Automation/Common/AutomationClientDSC.cs | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs index 7238fcd19852..f892ae07acd4 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs @@ -42,6 +42,12 @@ public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet [Parameter(Mandatory = false, HelpMessage = "The compilation job parameters.")] public IDictionary Parameters { get; set; } + /// + /// Gets or sets the configuration data. + /// + [Parameter(Mandatory = false, HelpMessage = "The compilation job configuration data.")] + public IDictionary ConfigurationData { get; set; } + /// /// Execute this cmdlet. /// @@ -50,6 +56,10 @@ protected override void AutomationExecuteCmdlet() { CompilationJob job = null; + if (this.ConfigurationData != null) + { + Parameters.Add("ConfigurationData", this.ConfigurationData); + } job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters); this.WriteObject(job); diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 4786c99a797b..589a3312c12a 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -1073,9 +1073,8 @@ public Model.NodeConfiguration TryGetNodeConfiguration(string resourceGroupName, { return GetNodeConfiguration(resourceGroupName, automationAccountName, nodeConfigurationName, rollupStatus); } - catch (ResourceNotFoundException resourceNotFoundException) + catch (ResourceNotFoundException) { - Console.Write(resourceNotFoundException.Message); return null; } } From d6e3c286072067b44616ea808b85da3b818eb92b Mon Sep 17 00:00:00 2001 From: avkaur Date: Fri, 11 Sep 2015 11:54:48 -0700 Subject: [PATCH 11/20] report model update5 --- .../ImportAzureAutomationDscNodeConfiguration.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index 59afd1fcb704..0e3744e98904 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -38,17 +38,15 @@ public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl /// /// Gets or sets the source path. /// - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration .mof to import.")] - [Alias("Path")] + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration .mof to import.")] [ValidateNotNullOrEmpty] - public string SourcePath { get; set; } + public string Path { get; set; } /// /// Gets or sets the configuration name for the node configuration. /// - [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'")] - [Alias("ConfigurationName")] - public string ConfigName { get; set; } + [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; } /// @@ -70,8 +68,8 @@ public override void ExecuteCmdlet() var nodeConfiguration = this.AutomationClient.CreateNodeConfiguration( this.ResourceGroupName, this.AutomationAccountName, - this.SourcePath, - this.ConfigName, + this.Path, + this.ConfigurationName, this.Force); this.WriteObject(nodeConfiguration); From aaa144b059d4e992f778a3f9caae0ee00c5068e1 Mon Sep 17 00:00:00 2001 From: shipra Date: Tue, 15 Sep 2015 12:23:19 -0700 Subject: [PATCH 12/20] Runbook params should accept any type --- .../Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs | 5 +++-- .../Commands.Automation/Common/AutomationClientWebhook.cs | 6 ++---- .../Commands.Automation/Common/IAutomationClient.cs | 3 ++- .../Automation/Commands.Automation/Model/Webhook.cs | 6 +++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs index b27e5446681d..cf0d1ea38b6e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs @@ -16,6 +16,7 @@ using Microsoft.Azure.Commands.Automation.Properties; using Microsoft.WindowsAzure.Commands.Common; using System; +using System.Collections; using System.Collections.Generic; using System.Management.Automation; using System.Security.Permissions; @@ -66,7 +67,7 @@ public class NewAzureAutomationWebhook : AzureAutomationBaseCmdlet /// [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The Runbook parameters name/value.")] - public IDictionary 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; } @@ -91,7 +92,7 @@ protected override void AutomationExecuteCmdlet() this.RunbookName, this.IsEnabled, this.ExpiryTime, - this.Parameters.ToHashtable()))); + this.Parameters))); } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs index bff062dc7152..d9e5d89e302a 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs @@ -37,7 +37,7 @@ public Model.Webhook CreateWebhook( string runbookName, bool isEnabled, DateTimeOffset expiryTime, - Hashtable runbookParameters) + IDictionary runbookParameters) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); @@ -57,9 +57,7 @@ public Model.Webhook CreateWebhook( }; if (runbookParameters != null) { - createOrUpdateProperties.Parameters = - runbookParameters.Cast() - .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value); + createOrUpdateProperties.Parameters = this.ProcessRunbookParameters(resourceGroupName, automationAccountName, runbookName, runbookParameters); } var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters( diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 9932bd0df1f0..389b73c3b10a 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -16,6 +16,7 @@ using System.IO; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Security; using Microsoft.Azure.Commands.Automation.Model; using Microsoft.Azure.Common.Authentication.Models; @@ -139,7 +140,7 @@ Model.Webhook CreateWebhook( string runbookName, bool isEnabled, DateTimeOffset expiryTime, - Hashtable parameters); + IDictionary parameters); Model.Webhook GetWebhook(string resourceGroupName, string automationAccountName, string name); diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs b/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs index 802c55f6f2cd..4c09cf44d1c6 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs @@ -65,7 +65,11 @@ public Webhook( } this.LastModifiedTime = webhook.Properties.LastModifiedTime.ToLocalTime(); - this.Parameters = new Hashtable(webhook.Properties.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); + foreach (var kvp in webhook.Properties.Parameters) + { + this.Parameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value)); + } + this.RunbookName = webhook.Properties.Runbook.Name; this.WebhookURI = webhookUri; } From b570b9b2a479b1383baf3ede5d752302198e7e0d Mon Sep 17 00:00:00 2001 From: shipra Date: Tue, 15 Sep 2015 12:39:48 -0700 Subject: [PATCH 13/20] Webhook should accept any param types --- .../Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs | 1 - .../Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs | 6 +++--- .../Commands.Automation/Common/AutomationClientWebhook.cs | 5 ++--- .../Commands.Automation/Common/IAutomationClient.cs | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs index cf0d1ea38b6e..32f2acee3651 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs @@ -17,7 +17,6 @@ using Microsoft.WindowsAzure.Commands.Common; using System; using System.Collections; -using System.Collections.Generic; using System.Management.Automation; using System.Security.Permissions; diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs index ed80470c1f86..0e77f10a1841 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs @@ -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; @@ -48,7 +48,7 @@ public class SetAzureAutomationWebhook : AzureAutomationBaseCmdlet /// [Parameter(Position = 4, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The Runbook parameters name/value.")] - public IDictionary Parameters { get; set; } + public IDictionary Parameters { get; set; } /// /// Execute this cmdlet. @@ -60,7 +60,7 @@ protected override void AutomationExecuteCmdlet() this.ResourceGroupName, this.AutomationAccountName, this.Name, - this.Parameters.ToHashtable(), + this.Parameters, this.IsEnabled); this.WriteObject(updatedWebhook); } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs index d9e5d89e302a..faaf5d41b790 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs @@ -152,7 +152,7 @@ public Model.Webhook UpdateWebhook( string resourceGroupName, string automationAccountName, string name, - Hashtable parameters, + IDictionary parameters, bool? isEnabled) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); @@ -171,8 +171,7 @@ public Model.Webhook UpdateWebhook( if (parameters != null) { webhookPatchProperties.Parameters = - parameters.Cast() - .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value); + this.ProcessRunbookParameters(resourceGroupName, automationAccountName, webhookModel.Properties.Runbook.Name, parameters); } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 389b73c3b10a..d167bbc47e06 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -146,7 +146,7 @@ Model.Webhook CreateWebhook( IEnumerable ListWebhooks(string resourceGroupName, string automationAccountName, string runbooName, ref string nextLink); - Model.Webhook UpdateWebhook(string resourceGroupName, string automationAccountName, string name, Hashtable parameters, bool? isEnabled); + Model.Webhook UpdateWebhook(string resourceGroupName, string automationAccountName, string name, IDictionary parameters, bool? isEnabled); void DeleteWebhook(string resourceGroupName, string automationAccountName, string name); From 9a5ea29ac71b2ae684216b0561ac1c0fdf10d3b2 Mon Sep 17 00:00:00 2001 From: shipra Date: Thu, 17 Sep 2015 12:07:25 -0700 Subject: [PATCH 14/20] Init hashtable --- .../Automation/Commands.Automation/Model/Webhook.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs b/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs index 4c09cf44d1c6..d9b97ede917c 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs @@ -65,6 +65,7 @@ public Webhook( } this.LastModifiedTime = webhook.Properties.LastModifiedTime.ToLocalTime(); + this.Parameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase); foreach (var kvp in webhook.Properties.Parameters) { this.Parameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value)); From b86f77c08f440f429d5ea8fadea521d0ddefb386 Mon Sep 17 00:00:00 2001 From: shipra Date: Thu, 17 Sep 2015 14:14:21 -0700 Subject: [PATCH 15/20] Handling Json deserialization error --- .../Automation/Commands.Automation/Model/Job.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/Job.cs b/src/ResourceManager/Automation/Commands.Automation/Model/Job.cs index 79b7a3f1e7c9..05aea998d0a6 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/Job.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/Job.cs @@ -16,6 +16,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; +using System.Management.Automation; namespace Microsoft.Azure.Commands.Automation.Model { @@ -65,7 +67,20 @@ public Job(string resourceGroupName, string accountName, Azure.Management.Automa if (0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) && 0 != String.Compare(kvp.Key, Constants.JobRunOnParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase)) { - this.JobParameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value)); + object paramValue; + try + { + paramValue = ((object) PowerShellJsonConverter.Deserialize(kvp.Value)); + } + catch (CmdletInvocationException exception) + { + if (!exception.Message.Contains("Invalid JSON primitive")) + throw; + + paramValue = kvp.Value; + } + this.JobParameters.Add(kvp.Key, paramValue); + } } } From 73047f9f3aa40dd1a89fc92179bbb6b6efeb0c22 Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Fri, 18 Sep 2015 18:09:02 -0700 Subject: [PATCH 16/20] Latest changes from Azure dev --- .../Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs | 2 +- .../Cmdlet/RemoveAzureAutomationConnectionType.cs | 2 +- .../Commands.ResourceManagement.Automation.csproj | 8 ++++---- .../Automation/Commands.Automation/packages.config | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index 0e3744e98904..c0f4b3d26f5e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -63,7 +63,7 @@ public SwitchParameter Force /// Execute this cmdlet. /// [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] - public override void ExecuteCmdlet() + protected override void ProcessRecord() { var nodeConfiguration = this.AutomationClient.CreateNodeConfiguration( this.ResourceGroupName, diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs index 960c7ed7f81d..b8242daa5bf4 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -41,7 +41,7 @@ public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet /// Execute this cmdlet. /// [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] - protected override void AutomationExecuteCmdlet() + protected override void AutomationProcessRecord() { var nextLink = string.Empty; var removeMessageWarning = Resources.RemovingAzureAutomationResourceWarning; diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index ca3f5227b1ee..18afebae32de 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -63,6 +63,10 @@ ..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.0-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll True + + False + ..\..\..\packages\Microsoft.Azure.Management.Automation.0.50.2-prerelease\lib\portable-net45+wp8+wpa81+win\Microsoft.Azure.Management.Automation.dll + False ..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.7-preview\lib\net40\Microsoft.Azure.ResourceManager.dll @@ -79,10 +83,6 @@ False ..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll - - False - ..\..\..\packages\Microsoft.Azure.Management.Automation.0.50.1-prerelease\lib\net40\Microsoft.Azure.Management.Automation.dll - False ..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll diff --git a/src/ResourceManager/Automation/Commands.Automation/packages.config b/src/ResourceManager/Automation/Commands.Automation/packages.config index 94bde317b5e4..65e4524784b0 100644 --- a/src/ResourceManager/Automation/Commands.Automation/packages.config +++ b/src/ResourceManager/Automation/Commands.Automation/packages.config @@ -4,7 +4,7 @@ - + From 4622847784a9203c7196438c4ec711d633bab17d Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Thu, 24 Sep 2015 15:10:26 -0700 Subject: [PATCH 17/20] Making name of new cmdlets consistent as AzureRM --- .../Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs | 2 +- .../Cmdlet/RemoveAzureAutomationConnectionType.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index c0f4b3d26f5e..ac4ddb11220c 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// Imports dsc node configuration script /// - [Cmdlet(VerbsData.Import, "AzureAutomationDscNodeConfiguration")] + [Cmdlet(VerbsData.Import, "AzureRMAutomationDscNodeConfiguration")] [OutputType(typeof(NodeConfiguration))] public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet { diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs index b8242daa5bf4..c73944ed0a89 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// Removes a Connection type for automation. /// - [Cmdlet(VerbsCommon.Remove, "AzureAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + [Cmdlet(VerbsCommon.Remove, "AzureRMAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet { /// From e18aa9cfbef816334ca6bbd854cdb6eb3f4a8a82 Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Mon, 28 Sep 2015 17:01:02 -0700 Subject: [PATCH 18/20] Added remove connectiontype test --- .../Commands.Automation.Test.csproj | 1 + ...RemoveAzureAutomationConnectionTypeTest.cs | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationConnectionTypeTest.cs diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj b/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj index ef67184c9de3..0efd6a55bea0 100644 --- a/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj +++ b/src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj @@ -149,6 +149,7 @@ + diff --git a/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationConnectionTypeTest.cs b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationConnectionTypeTest.cs new file mode 100644 index 000000000000..834d3db1e7d7 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RemoveAzureAutomationConnectionTypeTest.cs @@ -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 mockAutomationClient; + + private MockCommandRuntime mockCommandRuntime; + + private RemoveAzureAutomationConnectionType cmdlet; + + [TestInitialize] + public void SetupTest() + { + this.mockAutomationClient = new Mock(); + 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()); + } + } +} From c11ec70c39992ff0e30760ed18ba3bb63c4ce7ac Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Mon, 28 Sep 2015 18:13:59 -0700 Subject: [PATCH 19/20] dsc bugifx --- .../StartAzureAutomationDscCompilationJob.cs | 15 +++++++++++---- .../Common/AutomationClientDSC.cs | 12 ++++++++---- .../Common/IAutomationClient.cs | 2 +- .../Properties/Resources.Designer.cs | 11 ++++++++++- .../Commands.Automation/Properties/Resources.resx | 3 +++ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs index 967fd8ff0a16..fcaa51f4cb5d 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs @@ -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 @@ -25,7 +28,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// starts azure automation compilation job /// - [Cmdlet(VerbsLifecycle.Start, "AzureRmAutomationDscCompilationJob")] + [Cmdlet(VerbsLifecycle.Start, "AzureRMAutomationDscCompilationJob")] [OutputType(typeof(CompilationJob))] public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet { @@ -56,11 +59,15 @@ protected override void AutomationProcessRecord() { CompilationJob job = null; - if (this.ConfigurationData != null) + if (this.Parameters != null && this.Parameters.Contains("ConfigurationData")) { - Parameters.Add("ConfigurationData", this.ConfigurationData); + throw new ArgumentException( + string.Format( + CultureInfo.CurrentCulture, + Resources.ConfigurationDataShouldNotBeInJobParameters, "-ConfigurationData")); } - job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters); + + job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters, this.ConfigurationData); this.WriteObject(job); } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 0197b1c2f46f..75fd2438ccbd 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -1015,7 +1015,7 @@ public Model.CompilationJob GetCompilationJob(string resourceGroupName, string a } } - public Model.CompilationJob StartCompilationJob(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters) + public CompilationJob StartCompilationJob(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters, IDictionary configurationData) { using (var request = new RequestSettings(this.automationManagementClient)) { @@ -1027,7 +1027,7 @@ public Model.CompilationJob StartCompilationJob(string resourceGroupName, string { Name = configurationName }, - Parameters = this.ProcessConfigurationParameters(resourceGroupName, automationAccountName, configurationName, parameters) + Parameters = this.ProcessConfigurationParameters(parameters, configurationData) } }; @@ -1477,15 +1477,19 @@ private string FormatDateTime(DateTimeOffset dateTime) return string.Format(CultureInfo.InvariantCulture, "{0:O}", dateTime.ToUniversalTime()); } - private IDictionary ProcessConfigurationParameters(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters) + private IDictionary ProcessConfigurationParameters(IDictionary parameters, IDictionary configurationData) { parameters = parameters ?? new Dictionary(); var filteredParameters = new Dictionary(); + if (configurationData != null) + { + filteredParameters.Add("ConfigurationData", JsonConvert.SerializeObject(configurationData)); + } foreach (var key in parameters.Keys) { try { - filteredParameters.Add(key.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(parameters[key])); + filteredParameters.Add(key.ToString(), JsonConvert.SerializeObject(parameters[key])); } catch (JsonSerializationException) { diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 1b769b24a0bc..550006958d50 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -49,7 +49,7 @@ public interface IAutomationClient IEnumerable ListCompilationJobs(string resourceGroupName, string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus); - CompilationJob StartCompilationJob(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters); + CompilationJob StartCompilationJob(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters, IDictionary configurationData); IEnumerable GetDscCompilationJobStream(string resourceGroupName, string automationAccountname, Guid jobId, DateTimeOffset? time, string streamType); #endregion diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 41539d0c0f1f..db513eb8c67d 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -141,6 +141,15 @@ internal static string ConfigurationContentNotFound { } } + /// + /// Looks up a localized string similar to ConfigurationData cannot be part of the job parameters. You can specify the ConfigurationData using the {0} switch. + /// + internal static string ConfigurationDataShouldNotBeInJobParameters { + get { + return ResourceManager.GetString("ConfigurationDataShouldNotBeInJobParameters", resourceCulture); + } + } + /// /// Looks up a localized string similar to Configuration content can not be in edit/draft mode in current preview. Use the Published option.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index f1cec079b933..999997efde7f 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -418,4 +418,7 @@ Invalid node configuration name. Please specify in the format <config name>.<node name> Automation + + ConfigurationData cannot be part of the job parameters. You can specify the ConfigurationData using the {0} switch + \ No newline at end of file From 0c733816f20651a8513f3c847574b5b4bc8444f0 Mon Sep 17 00:00:00 2001 From: safeermohammed Date: Tue, 29 Sep 2015 10:16:19 -0700 Subject: [PATCH 20/20] Address Review comments --- .../ImportAzureAutomationDscNodeConfiguration.cs | 2 +- .../Cmdlet/RemoveAzureAutomationConnectionType.cs | 2 +- .../Cmdlet/StartAzureAutomationDscCompilationJob.cs | 2 +- .../Commands.Automation/Common/AutomationClientDSC.cs | 10 ++++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs index ac4ddb11220c..4c73c25fe887 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// Imports dsc node configuration script /// - [Cmdlet(VerbsData.Import, "AzureRMAutomationDscNodeConfiguration")] + [Cmdlet(VerbsData.Import, "AzureRmAutomationDscNodeConfiguration")] [OutputType(typeof(NodeConfiguration))] public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet { diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs index c73944ed0a89..7684f8ce41de 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationConnectionType.cs @@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// Removes a Connection type for automation. /// - [Cmdlet(VerbsCommon.Remove, "AzureRMAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] + [Cmdlet(VerbsCommon.Remove, "AzureRmAutomationConnectionType", DefaultParameterSetName = AutomationCmdletParameterSets.ByName)] public class RemoveAzureAutomationConnectionType : AzureAutomationBaseCmdlet { /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs index fcaa51f4cb5d..53a8afe1cc11 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs @@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// /// starts azure automation compilation job /// - [Cmdlet(VerbsLifecycle.Start, "AzureRMAutomationDscCompilationJob")] + [Cmdlet(VerbsLifecycle.Start, "AzureRmAutomationDscCompilationJob")] [OutputType(typeof(CompilationJob))] public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet { diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 75fd2438ccbd..e611c2a75f04 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -263,8 +263,9 @@ public Model.DscConfiguration CreateConfiguration( string configrationName, string nodeName) { - string configurationContent = "Configuration {0} { Node {1} { } } "; - configurationContent = string.Format(configurationContent,configrationName,nodeName); + string configurationContent = "Configuration #configrationName# { Node #nodeName# { } } "; + configurationContent = configurationContent.Replace("#configrationName#", configrationName); + configurationContent = configurationContent.Replace("#nodeName#", nodeName); using (var request = new RequestSettings(this.automationManagementClient)) { @@ -1163,7 +1164,7 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st var nodeConfigurations = new List(); foreach (var nodeConfiguration in nodeConfigModels) { - string computedRollupStatus = GetRollupStatus(resourceGroupName, automationAccountName, nodeConfiguration.Name); + string computedRollupStatus = GetRollupStatus(resourceGroupName, automationAccountName, nodeConfiguration.Configuration.Name); if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus))) { @@ -1196,7 +1197,8 @@ public Model.NodeConfiguration CreateNodeConfiguration( if (File.Exists(Path.GetFullPath(sourcePath))) { fileContent = System.IO.File.ReadAllText(sourcePath); - nodeConfigurationName = configurationName + "." + System.IO.Path.GetFileNameWithoutExtension(sourcePath); + nodeName = System.IO.Path.GetFileNameWithoutExtension(sourcePath); + nodeConfigurationName = configurationName + "." + nodeName; } else {