From c168df55d02bdfa86ca5d61e17113925588bb523 Mon Sep 17 00:00:00 2001 From: Prasad Suthram Date: Thu, 9 Apr 2015 23:32:25 -0700 Subject: [PATCH 1/3] Import configuration cmdlet implemented --- .../ImportAzureAutomationDscConfiguration.cs | 54 +++++++++++-- .../Common/AutomationClientDSC.cs | 79 +++++++++++++++++-- .../Common/IAutomationClient.cs | 2 +- .../Properties/Resources.Designer.cs | 27 +++++++ .../Properties/Resources.resx | 12 +++ 5 files changed, 160 insertions(+), 14 deletions(-) diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs index d5e67d256b46..3c7c1acb0100 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs @@ -12,6 +12,8 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using System; +using System.Collections; using System.Collections.Generic; using System.Management.Automation; using System.Security.Permissions; @@ -38,38 +40,51 @@ public class ImportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet /// /// Gets or sets the configuration name. /// - [Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration name.")] + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration name.")] public string ConfigurationName { get; set; } /// /// Gets or sets the source path. /// - [Parameter(Position = 3, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The source path for importing the configuration script.")] + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The source path for importing the configuration script.")] public string SourcePath { get; set; } + /// + /// Gets or sets the configuration tags. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc configuration tags.")] + [Alias("Tag")] + public IDictionary Tags { get; set; } + /// /// Gets or sets the description. /// - [Parameter(Position = 4, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the configuration being imported.")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The description of the configuration being imported.")] public string Description { get; set; } /// /// Gets or sets the switch parameter to /// - [Parameter(Position = 5, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Import the configuration in published state.")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Import the configuration in published state.")] public SwitchParameter Published { get; set; } /// /// Gets or sets switch parameter to confirm overwriting of existing configurations. /// - [Parameter(Position = 6, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Overwrites an existing configuration with same name.")] + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Overwrites an existing configuration with same name.")] public SwitchParameter Overwrite { get; set; } /// /// Gets or sets a value indicating whether verbose logging should be turned on or off. /// - [Parameter(Position = 7, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Indicate whether verbose logging should be turned on or off.")] - public bool? LogVerbose { get; set; } + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Indicate whether verbose logging should be turned on or off.")] + public SwitchParameter LogVerbose { get; set; } + + /// + /// Gets or sets a value indicating whether log progress should be turned on or off. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Indicate whether progress logging should be turned on or off.")] + public SwitchParameter LogProgress { get; set; } /// /// Execute this cmdlet. @@ -77,7 +92,30 @@ public class ImportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] public override void ExecuteCmdlet() { - var configuration = this.AutomationClient.CreateConfiguration(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.SourcePath, this.Description, this.LogVerbose); + bool logVerbose = false; + if (this.LogVerbose.IsPresent) logVerbose = true; + + bool logProgress = false; + if (this.LogProgress.IsPresent) logProgress = true; + + bool published = false; + if (this.Published.IsPresent) published = true; + + bool overWrite = false; + if (this.Overwrite.IsPresent) overWrite = true; + + var configuration = this.AutomationClient.CreateConfiguration( + this.ResourceGroupName, + this.AutomationAccountName, + this.ConfigurationName, + this.SourcePath, + this.Tags, + this.Description, + logVerbose, + logProgress, + published, + overWrite); + this.WriteObject(configuration); } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index a5de480166c5..20d4f9d3f13e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -34,6 +34,8 @@ namespace Microsoft.Azure.Commands.Automation.Common { + using Microsoft.Azure.Management.Resources.Models; + using AutomationManagement = Azure.Management.Automation; using Microsoft.Azure.Common.Authentication; using Hyak.Common; @@ -86,33 +88,76 @@ public Model.DscConfiguration CreateConfiguration( string automationAccountName, string configurationName, string sourcePath, + IDictionary tags, string description, - bool? logVerbose) + bool logVerbose, + bool logProgress, + bool published, + bool overWrite) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); Requires.Argument("ConfigurationName", configurationName).NotNull(); Requires.Argument("SourcePath", sourcePath).NotNull(); + // for the private preivew, configuration can be imported in Published mode only + // Draft mode is not implemented + if (!published) + { + throw new NotImplementedException( + string.Format( + CultureInfo.CurrentCulture, + Resources.ConfigurationNotPublished)); + } + + // if configuration already exists, ensure overwrite flag is specified + if (this.TryGetConfigurationModel(resourceGroupName, automationAccountName, configurationName) != null) + { + if (!overWrite) + { + throw new ResourceCommonException(typeof(Model.DscConfiguration), + string.Format(CultureInfo.CurrentCulture, Resources.ConfigurationAlreadyExists, configurationName)); + } + } + string fileContent = null; - if (File.Exists(Path.GetFullPath(sourcePath))) + try { - fileContent = System.IO.File.ReadAllText(sourcePath); + 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)); + } + + // location of the configuration is set to same as that of automation account string location = this.GetAutomationAccount(resourceGroupName, automationAccountName).Location; + + IDictionary configurationTags = null; + if (tags != null) configurationTags = tags.Cast().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString()); + var configurationCreateParameters = new DscConfigurationCreateOrUpdateParameters() { Name = configurationName, Location = location, + Tags = configurationTags, Properties = new DscConfigurationCreateOrUpdateProperties() { Description = String.IsNullOrEmpty(description) ? String.Empty : description, - LogVerbose = logVerbose.GetValueOrDefault(), + LogVerbose = logVerbose, + LogProgress = logProgress, Source = new Microsoft.Azure.Management.Automation.Models.ContentSource() { // only embeddedContent supported for now - ContentType = "embeddedContent", + ContentType = Model.ContentSourceType.embeddedContent.ToString(), Value = fileContent } } @@ -127,6 +172,30 @@ public Model.DscConfiguration CreateConfiguration( return new Model.DscConfiguration(resourceGroupName, automationAccountName, configuration); } + private Model.DscConfiguration TryGetConfigurationModel(string resourceGroupName, string automationAccountName, string configurationName) + { + Model.DscConfiguration configuration = null; + try + { + configuration = this.GetConfiguration( + resourceGroupName, + automationAccountName, + configurationName); + } + catch (CloudException e) + { + if (e.Response.StatusCode == HttpStatusCode.NotFound) + { + configuration = null; + } + else + { + throw; + } + } + return configuration; + } + #endregion #region AgentRegistration Operations diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index e7908bcfa5a7..16f058717708 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -45,7 +45,7 @@ public interface IAutomationClient DscConfiguration GetConfiguration(string resourceGroupName, string automationAccountName, string configurationName); - DscConfiguration CreateConfiguration(string resourceGroupName, string automationAccountName, string configurationName, string sourcePath, string description, bool? logVerbose); + DscConfiguration CreateConfiguration(string resourceGroupName, string automationAccountName, string configurationName, string sourcePath, IDictionary tags, string description, bool logVerbose, bool logProgress, bool published, bool overWrite); #endregion diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index 112e6f07708b..8223bbabd817 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -114,6 +114,33 @@ internal static string CertificateNotFound { } } + /// + /// Looks up a localized string similar to Configuration already exists. Specify the parameter to force an overwrite. Configuration name: {0}. + /// + internal static string ConfigurationAlreadyExists { + get { + return ResourceManager.GetString("ConfigurationAlreadyExists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Configuration can be imported in published state only in the current preview. Use the -Published switch.. + /// + internal static string ConfigurationNotPublished { + get { + return ResourceManager.GetString("ConfigurationNotPublished", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invalid SourcePath. Verify file path is valid and file exists.. + /// + internal static string ConfigurationSourcePathInvalid { + get { + return ResourceManager.GetString("ConfigurationSourcePathInvalid", resourceCulture); + } + } + /// /// Looks up a localized string similar to The Connection already exists. Connection name: {0}.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index ac55f018ec24..aad302bb6737 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -275,4 +275,16 @@ Create account arguments are invalid. Provide valid account name and location. Account Name: {0}, Location: {1} Automation + + Configuration already exists. Specify the parameter to force an overwrite. Configuration name: {0} + Automation + + + Configuration can be imported in published state only in the current preview. Use the -Published switch. + Automation + + + Invalid SourcePath. Verify file path is valid and file exists. + Automation + \ No newline at end of file From 5703ce5b326c97c824d4e66bb1b68e1fc774a172 Mon Sep 17 00:00:00 2001 From: Prasad Suthram Date: Fri, 10 Apr 2015 00:46:43 -0700 Subject: [PATCH 2/3] review comments addressed and MetaConfig Work in progress --- ...eAutomationAgentRegistrationInformation.cs | 7 -- .../Cmdlet/GetAzureAutomationConfiguration.cs | 7 -- .../Cmdlet/GetDscMetaConfiguration.cs | 50 +++++++++++++ .../ImportAzureAutomationDscConfiguration.cs | 7 -- .../Cmdlet/NewAzureAutomationKey.cs | 7 -- ...mands.ResourceManagement.Automation.csproj | 2 + .../Common/AutomationClientDSC.cs | 15 ++++ .../Common/IAutomationClient.cs | 4 + .../Model/DscOnboardingMetaconfig.cs | 75 +++++++++++++++++++ 9 files changed, 146 insertions(+), 28 deletions(-) create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs create mode 100644 src/ResourceManager/Automation/Commands.Automation/Model/DscOnboardingMetaconfig.cs diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs index 3b067f139cb6..29991c83a324 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs @@ -28,13 +28,6 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet [OutputType(typeof(AgentRegistration))] public class GetAzureAutomationAgentRegistrationInformation : AzureAutomationBaseCmdlet { - /// - /// Gets or sets the automation account name. - /// - [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")] - [ValidateNotNullOrEmpty] - public string AutomationAccountName { get; set; } - /// /// Execute this cmdlet. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs index fa40e26af5c4..ec029921780c 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs @@ -28,13 +28,6 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet [OutputType(typeof(DscConfiguration))] public class GetAzureAutomationConfiguration : AzureAutomationBaseCmdlet { - /// - /// Gets or sets the automation account name. - /// - [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")] - [ValidateNotNullOrEmpty] - public string AutomationAccountName { get; set; } - /// /// Gets or sets the configuration name. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs new file mode 100644 index 000000000000..7c9f8fbc1d00 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs @@ -0,0 +1,50 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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 +{ + /// + /// Gets azure automation dsc onboarding meta configuration information for a given account. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationDscOnboardingMetaconfig")] + [OutputType(typeof(DscOnboardingMetaconfig))] + public class GetDscMetaConfiguration : AzureAutomationBaseCmdlet + { + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + IEnumerable ret = null; + + ret = new List + { + this.AutomationClient.GetDscMetaConfig( + this.ResourceGroupName, + this.AutomationAccountName) + }; + + this.GenerateCmdletOutput(ret); + } + + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs index 3c7c1acb0100..ae3b332a1f03 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs @@ -30,13 +30,6 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet [OutputType(typeof(DscConfiguration))] public class ImportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet { - /// - /// Gets or sets the automation account name. - /// - [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")] - [ValidateNotNullOrEmpty] - public string AutomationAccountName { get; set; } - /// /// Gets or sets the configuration name. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationKey.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationKey.cs index a24bb4363601..fa57b2efb153 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationKey.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationKey.cs @@ -28,13 +28,6 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet [OutputType(typeof(AgentRegistration))] public class NewAzureAutomationKey : AzureAutomationBaseCmdlet { - /// - /// Gets or sets the automation account name. - /// - [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")] - [ValidateNotNullOrEmpty] - public string AutomationAccountName { get; set; } - /// /// Gets or sets the KeyType. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index 2462cd975573..88dce9aa1b5d 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -118,6 +118,7 @@ + @@ -142,6 +143,7 @@ + True diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 20d4f9d3f13e..ea6275754955 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -198,6 +198,21 @@ private Model.DscConfiguration TryGetConfigurationModel(string resourceGroupName #endregion + #region DscMetaConfig Operations + public Model.DscOnboardingMetaconfig GetDscMetaConfig(string resourceGroupName, string automationAccountName) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + + var dscMetaConfig = this.automationManagementClient.AgentRegistrationInformation.Get( + resourceGroupName, + automationAccountName).AgentRegistration; + + return new DscOnboardingMetaconfig(resourceGroupName, automationAccountName, dscMetaConfig); + } + + #endregion + #region AgentRegistration Operations public Model.AgentRegistration GetAgentRegistration(string resourceGroupName, string automationAccountName) { diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 16f058717708..abcd47906e21 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -54,5 +54,9 @@ public interface IAutomationClient Microsoft.Azure.Commands.Automation.Model.AgentRegistration NewAgentRegistrationKey(string resourceGroupName, string automationAccountName, string keyType); #endregion + + #region DscMetaConfiguration + Microsoft.Azure.Commands.Automation.Model.DscOnboardingMetaconfig GetDscMetaConfig(string resourceGroupName, string automationAccountName); + #endregion } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/DscOnboardingMetaconfig.cs b/src/ResourceManager/Automation/Commands.Automation/Model/DscOnboardingMetaconfig.cs new file mode 100644 index 000000000000..9be071248018 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/DscOnboardingMetaconfig.cs @@ -0,0 +1,75 @@ +// ---------------------------------------------------------------------------------- +// +// 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 Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using Microsoft.Azure.Management.Automation.Models; + + using AutomationManagement = Microsoft.Azure.Management.Automation; + + /// + /// DSC Onboarding Meta Configuration + /// + public class DscOnboardingMetaconfig + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The resource group name. + /// + /// + /// The automation account. + /// + /// + /// The dsc onboarding meta configuration. + /// /// + public DscOnboardingMetaconfig(string resourceGroupName, string automationAccountName, AutomationManagement.Models.AgentRegistration dscOnboardingMetaConfig) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + + this.ResourceGroupName = resourceGroupName; + this.AutomationAccountName = automationAccountName; + this.DscMetaConfiguration = dscOnboardingMetaConfig.DscMetaConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + public DscOnboardingMetaconfig() + { + } + + /// + /// Gets or sets the resource group name. + /// + public string ResourceGroupName { get; set; } + + /// + /// Gets or sets the automation account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the dsc meta configuration information + /// + public string DscMetaConfiguration { get; set; } + + } +} From 9065ae5f72011443762a45277234ce7ef661fdfc Mon Sep 17 00:00:00 2001 From: Prasad Suthram Date: Tue, 14 Apr 2015 02:13:09 -0700 Subject: [PATCH 3/3] Dsc Node, Dsc Configurations and Dsc MetaConfig cmdlets --- ...eAutomationAgentRegistrationInformation.cs | 2 +- .../Cmdlet/GetAzureAutomationConfiguration.cs | 4 +- .../Cmdlet/GetAzureAutomationDscNode.cs | 102 +++++ ...tAzureAutomationDscOnboardingMetaconfig.cs | 75 ++++ .../Cmdlet/GetDscMetaConfiguration.cs | 50 --- .../ImportAzureAutomationDscConfiguration.cs | 59 ++- .../Cmdlet/SetAzureAutomationDscNode.cs | 73 +++ .../UnregisterAzureAutomationDscNode.cs | 66 +++ ...mands.ResourceManagement.Automation.csproj | 7 +- .../Common/AutomationClientDSC.cs | 417 ++++++++++++++++-- .../Common/AutomationCmdletParameterSet.cs | 11 + .../Common/IAutomationClient.cs | 26 +- .../Model/AgentRegistration.cs | 14 +- .../Model/Configuration.cs | 27 +- .../Commands.Automation/Model/DscNode.cs | 102 +++++ .../Properties/Resources.Designer.cs | 90 ++++ .../Properties/Resources.resx | 39 ++ 17 files changed, 997 insertions(+), 167 deletions(-) create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNode.cs create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscOnboardingMetaconfig.cs delete mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationDscNode.cs create mode 100644 src/ResourceManager/Automation/Commands.Automation/Cmdlet/UnregisterAzureAutomationDscNode.cs create mode 100644 src/ResourceManager/Automation/Commands.Automation/Model/DscNode.cs diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs index 29991c83a324..307bc348e389 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// [Cmdlet(VerbsCommon.Get, "AzureAutomationRegistrationInfo")] [OutputType(typeof(AgentRegistration))] - public class GetAzureAutomationAgentRegistrationInformation : AzureAutomationBaseCmdlet + public class GetAzureAutomationRegistrationInfo : AzureAutomationBaseCmdlet { /// /// Execute this cmdlet. diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs index ec029921780c..7312ccb51c27 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationConfiguration.cs @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet /// [Cmdlet(VerbsCommon.Get, "AzureAutomationDscConfiguration", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] [OutputType(typeof(DscConfiguration))] - public class GetAzureAutomationConfiguration : AzureAutomationBaseCmdlet + public class GetAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet { /// /// Gets or sets the configuration name. @@ -52,7 +52,7 @@ public override void ExecuteCmdlet() } else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll) { - ret = this.AutomationClient.ListAutomationConfigurations(this.ResourceGroupName, this.AutomationAccountName); + ret = this.AutomationClient.ListDscConfigurations(this.ResourceGroupName, this.AutomationAccountName); } this.GenerateCmdletOutput(ret); diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNode.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNode.cs new file mode 100644 index 000000000000..0f4907154f9f --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNode.cs @@ -0,0 +1,102 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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 +{ + /// + /// Gets azure automation dsc node. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationDscNode", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(DscNode))] + public class GetAzureAutomationDscNode : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ById, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")] + [Alias("NodeId")] + public Guid Id { get; set; } + + /// + /// Gets or sets the status of a dsc node. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = false, HelpMessage = "Filter dsc nodes based on their status.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByNodeConfiguration, Mandatory = false, HelpMessage = "Filter dsc nodes based on their status.")] + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter dsc nodes based on their status.")] + [ValidateSet("Compliant", "Not Compliant", "Failed", "Pending", "Received", "Unresponsive")] + public string Status { get; set; } + + /// + /// Gets or sets the node name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = true, ValueFromPipeline = true, HelpMessage = "The node name.")] + [ValidateNotNullOrEmpty] + public string Name { get; set; } + + /// + /// Gets or sets the nodeconfiguration name. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByNodeConfiguration, Mandatory = true, HelpMessage = "The nodeconfiguration name.")] + [ValidateNotNullOrEmpty] + public string NodeConfigurationName { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + IEnumerable ret = null; + + if (this.ParameterSetName == AutomationCmdletParameterSets.ById) + { + ret = new List + { + this.AutomationClient.GetDscNodeById(this.ResourceGroupName, this.AutomationAccountName, this.Id) + }; + } + else if (this.ParameterSetName == AutomationCmdletParameterSets.ByName) + { + ret = this.AutomationClient.ListDscNodesByName( + this.ResourceGroupName, + this.AutomationAccountName, + this.Name, + this.Status); + } + else if (this.ParameterSetName == AutomationCmdletParameterSets.ByNodeConfiguration) + { + ret = this.AutomationClient.ListDscNodesByNodeConfiguration( + this.ResourceGroupName, + this.AutomationAccountName, + this.NodeConfigurationName, + this.Status); + } + else + { + // ByAll + ret = this.AutomationClient.ListDscNodes(this.ResourceGroupName, this.AutomationAccountName, this.Status); + } + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscOnboardingMetaconfig.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscOnboardingMetaconfig.cs new file mode 100644 index 000000000000..b9b32ad36e81 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscOnboardingMetaconfig.cs @@ -0,0 +1,75 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Generic; +using System.Globalization; +using System.IO; +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 +{ + /// + /// Gets azure automation dsc onboarding meta configuration information for a given account. + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationDscOnboardingMetaconfig")] + [OutputType(typeof(DscOnboardingMetaconfig))] + public class GetAzureAutomationDscOnboardingMetaconfig : AzureAutomationBaseCmdlet + { + /// + /// True to overwrite the existing meta.mof; false otherwise. + /// + private bool overwriteExistingFile; + + /// + /// Gets or sets the output folder for the metaconfig mof files + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The folder where metaconfig mof files to be placed.")] + public string OutputFolder { get; set; } + + /// + /// Gets or sets the list of computer names + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The names of computers. If not specified Localhost will be used.")] + [Alias("ComputerName")] + public string[] ComputerNames { get; set; } + + /// + /// Gets or sets switch parameter to confirm overwriting of existing configurations. + /// + [Parameter(Mandatory = false, HelpMessage = "Overwrites an existing configuration with same name.")] + public SwitchParameter Force + { + get { return this.overwriteExistingFile; } + set { this.overwriteExistingFile = value; } + } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + var ret = + this.AutomationClient.GetDscMetaConfig(this.ResourceGroupName, this.AutomationAccountName, this.OutputFolder, this.ComputerNames, this.Force); + + this.WriteObject(ret, true); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs deleted file mode 100644 index 7c9f8fbc1d00..000000000000 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetDscMetaConfiguration.cs +++ /dev/null @@ -1,50 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// 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.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 -{ - /// - /// Gets azure automation dsc onboarding meta configuration information for a given account. - /// - [Cmdlet(VerbsCommon.Get, "AzureAutomationDscOnboardingMetaconfig")] - [OutputType(typeof(DscOnboardingMetaconfig))] - public class GetDscMetaConfiguration : AzureAutomationBaseCmdlet - { - /// - /// Execute this cmdlet. - /// - [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] - public override void ExecuteCmdlet() - { - IEnumerable ret = null; - - ret = new List - { - this.AutomationClient.GetDscMetaConfig( - this.ResourceGroupName, - this.AutomationAccountName) - }; - - this.GenerateCmdletOutput(ret); - } - - } -} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs index ae3b332a1f03..865847d0f4c4 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscConfiguration.cs @@ -31,15 +31,20 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet public class ImportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet { /// - /// Gets or sets the configuration name. - /// - [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration name.")] - public string ConfigurationName { get; set; } + /// True to overwrite the existing configuration; false otherwise. + /// + private bool overwriteExistingConfiguration; + + /// + /// True to publish the configuration; false otherwise. + /// + private bool publishConfiguration; /// /// Gets or sets the source path. /// [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The source path for importing the configuration script.")] + [ValidateNotNullOrEmpty] public string SourcePath { get; set; } /// @@ -56,58 +61,46 @@ public class ImportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet public string Description { get; set; } /// - /// Gets or sets the switch parameter to + /// Gets or sets the switch parameter to publish the configuration /// - [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Import the configuration in published state.")] - public SwitchParameter Published { get; set; } + [Parameter(Mandatory = false, HelpMessage = "Import the configuration in published state.")] + public SwitchParameter Published + { + get { return this.publishConfiguration; } + set { this.publishConfiguration = value; } + } /// /// Gets or sets switch parameter to confirm overwriting of existing configurations. /// - [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Overwrites an existing configuration with same name.")] - public SwitchParameter Overwrite { get; set; } + [Parameter(Mandatory = false, HelpMessage = "Overwrites an existing configuration with same name.")] + public SwitchParameter Overwrite + { + get { return this.overwriteExistingConfiguration; } + set { this.overwriteExistingConfiguration = value; } + } /// /// Gets or sets a value indicating whether verbose logging should be turned on or off. /// [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Indicate whether verbose logging should be turned on or off.")] - public SwitchParameter LogVerbose { get; set; } + public bool? LogVerbose { get; set; } - /// - /// Gets or sets a value indicating whether log progress should be turned on or off. - /// - [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Indicate whether progress logging should be turned on or off.")] - public SwitchParameter LogProgress { get; set; } - /// /// Execute this cmdlet. /// [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] public override void ExecuteCmdlet() { - bool logVerbose = false; - if (this.LogVerbose.IsPresent) logVerbose = true; - - bool logProgress = false; - if (this.LogProgress.IsPresent) logProgress = true; - - bool published = false; - if (this.Published.IsPresent) published = true; - - bool overWrite = false; - if (this.Overwrite.IsPresent) overWrite = true; - var configuration = this.AutomationClient.CreateConfiguration( this.ResourceGroupName, this.AutomationAccountName, - this.ConfigurationName, this.SourcePath, this.Tags, this.Description, - logVerbose, - logProgress, - published, - overWrite); + this.LogVerbose, + this.Published, + this.Overwrite); this.WriteObject(configuration); } diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationDscNode.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationDscNode.cs new file mode 100644 index 000000000000..6e40aaf3f125 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationDscNode.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.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 +{ + /// + /// Updates configuration on the dsc node. + /// + [Cmdlet(VerbsCommon.Set, "AzureAutomationDscNode")] + [OutputType(typeof(DscNode))] + public class SetAzureAutomationDscNode : AzureAutomationBaseCmdlet + { + /// + /// True to overwrite the existing configuration; false otherwise. + /// + private bool overwriteExistingNodeConfiguration; + + /// + /// Gets or sets the node id. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ById, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")] + [Alias("NodeId")] + [ValidateNotNullOrEmpty] + public Guid Id { get; set; } + + /// + /// Gets or sets the nodeconfiguration name. + /// + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The nodeconfiguration name.")] + [ValidateNotNullOrEmpty] + public string NodeConfigurationName { get; set; } + + /// + /// Gets or sets switch parameter to confirm overwriting of existing nodeconfigurations. + /// + [Parameter(Mandatory = false, HelpMessage = "Overwrites an existing nodeconfiguration with same name.")] + public SwitchParameter Force + { + get { return this.overwriteExistingNodeConfiguration; } + set { this.overwriteExistingNodeConfiguration = value; } + } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + var node = this.AutomationClient.SetDscNodeById(this.ResourceGroupName, this.AutomationAccountName, this.Id, this.NodeConfigurationName, this.Force); + this.WriteObject(node); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/UnregisterAzureAutomationDscNode.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/UnregisterAzureAutomationDscNode.cs new file mode 100644 index 000000000000..8121ed5d86b8 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/UnregisterAzureAutomationDscNode.cs @@ -0,0 +1,66 @@ +// ---------------------------------------------------------------------------------- +// +// 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.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 +{ + /// + /// Removes the dsc node. + /// + [Cmdlet(VerbsLifecycle.Unregister, "AzureAutomationDscNode")] + [OutputType(typeof(DscNode))] + public class UnregisterAzureAutomationDscNode : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the node id. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ById, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")] + [Alias("NodeId")] + [ValidateNotNullOrEmpty] + public Guid Id { get; set; } + + /// + /// Gets or sets the switch parameter not to confirm on removing the dsc node. + /// + [Parameter(Mandatory = false, HelpMessage = "Forces the command to run without asking for user confirmation.")] + public SwitchParameter Force { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + public override void ExecuteCmdlet() + { + this.ConfirmAction( + this.Force.IsPresent, + string.Format(CultureInfo.CurrentCulture, Resources.RemovDscNodeWarning), + string.Format(CultureInfo.CurrentCulture, Resources.RemoveDscNodeDescription, this.Id.ToString()), + this.Id.ToString(), + () => + { + AutomationClient.DeleteDscNode(this.ResourceGroupName, this.AutomationAccountName, this.Id); + }); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index 88dce9aa1b5d..7a70fedf72cc 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -118,13 +118,16 @@ - + + + + @@ -143,6 +146,7 @@ + @@ -154,6 +158,7 @@ PreserveNewest + Designer diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index ea6275754955..77a4a8397097 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -19,40 +19,28 @@ using System.Linq; using System.IO; using System.Net; -using System.Security; -using System.Security.Cryptography.X509Certificates; using Microsoft.Azure.Commands.Automation.Properties; using Microsoft.Azure.Commands.Automation.Model; using Microsoft.Azure.Management.Automation; +using AutomationManagement = Microsoft.Azure.Management.Automation; using Microsoft.Azure.Management.Automation.Models; -using Microsoft.WindowsAzure.Commands.Common; -using Microsoft.Azure.Common.Authentication.Models; -using Newtonsoft.Json; +using Hyak.Common; -using AutomationAccount = Microsoft.Azure.Commands.Automation.Model.AutomationAccount; - - -namespace Microsoft.Azure.Commands.Automation.Common + namespace Microsoft.Azure.Commands.Automation.Common { - using Microsoft.Azure.Management.Resources.Models; - - using AutomationManagement = Azure.Management.Automation; - using Microsoft.Azure.Common.Authentication; - using Hyak.Common; - + using DscNode = Microsoft.Azure.Management.Automation.Models.DscNode; public partial class AutomationClient : IAutomationClient { #region DscConfiguration Operations - public IEnumerable ListAutomationConfigurations( + public IEnumerable ListDscConfigurations( string resourceGroupName, string automationAccountName) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); - // todo fix paging return AutomationManagementClient.ContinuationTokenHandler( skipToken => { @@ -86,20 +74,39 @@ public Model.DscConfiguration GetConfiguration( public Model.DscConfiguration CreateConfiguration( string resourceGroupName, string automationAccountName, - string configurationName, string sourcePath, IDictionary tags, string description, - bool logVerbose, - bool logProgress, + bool? logVerbose, bool published, bool overWrite) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); - Requires.Argument("ConfigurationName", configurationName).NotNull(); Requires.Argument("SourcePath", sourcePath).NotNull(); + string fileContent = null; + string configurationName = 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)); + } + + // configuration name is same as filename + configurationName = Path.GetFileNameWithoutExtension(sourcePath); + // for the private preivew, configuration can be imported in Published mode only // Draft mode is not implemented if (!published) @@ -111,7 +118,11 @@ public Model.DscConfiguration CreateConfiguration( } // if configuration already exists, ensure overwrite flag is specified - if (this.TryGetConfigurationModel(resourceGroupName, automationAccountName, configurationName) != null) + var configurationModel = this.TryGetConfigurationModel( + resourceGroupName, + automationAccountName, + configurationName); + if (configurationModel != null) { if (!overWrite) { @@ -120,24 +131,6 @@ public Model.DscConfiguration CreateConfiguration( } } - string fileContent = null; - - 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)); - } - // location of the configuration is set to same as that of automation account string location = this.GetAutomationAccount(resourceGroupName, automationAccountName).Location; @@ -152,8 +145,7 @@ public Model.DscConfiguration CreateConfiguration( Properties = new DscConfigurationCreateOrUpdateProperties() { Description = String.IsNullOrEmpty(description) ? String.Empty : description, - LogVerbose = logVerbose, - LogProgress = logProgress, + LogVerbose = (logVerbose.HasValue) ? logVerbose.Value : false, Source = new Microsoft.Azure.Management.Automation.Models.ContentSource() { // only embeddedContent supported for now @@ -199,16 +191,132 @@ private Model.DscConfiguration TryGetConfigurationModel(string resourceGroupName #endregion #region DscMetaConfig Operations - public Model.DscOnboardingMetaconfig GetDscMetaConfig(string resourceGroupName, string automationAccountName) + public DirectoryInfo GetDscMetaConfig(string resourceGroupName, string automationAccountName, string outputFolder, string[] computerNames, bool overwriteExistingFile) { Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); - + + string outputFolderFullPath = this.GetCurrentDirectory(); // initialize with current directory; + + if (!String.IsNullOrEmpty(outputFolder)) + { + outputFolderFullPath = this.ValidateAndGetFullPath(outputFolder); + } + var dscMetaConfig = this.automationManagementClient.AgentRegistrationInformation.Get( resourceGroupName, automationAccountName).AgentRegistration; - return new DscOnboardingMetaconfig(resourceGroupName, automationAccountName, dscMetaConfig); + // get the metaconfig value + string dscMetaConfigValue = new DscOnboardingMetaconfig(resourceGroupName, automationAccountName, dscMetaConfig).DscMetaConfiguration; + + if (computerNames == null) + { + computerNames = new[] { "localhost" }; // No computer specified. Initialize with Localhost + } + + string outputFilePath = String.Empty; + const string FileExtension = ".meta.mof"; // this will be .meta.mof + const string DscMetaConfigsFolder = "DscMetaConfigs"; // Folder name where metaconfigs are stored + + outputFolderFullPath = System.IO.Path.Combine(outputFolderFullPath, DscMetaConfigsFolder); + + this.CreateOutputFolder(outputFolderFullPath); + + foreach (string computerName in computerNames) + { + outputFilePath = outputFolderFullPath + "\\" + computerName + FileExtension; + + // file exists and overwrite Not specified + if (File.Exists(outputFilePath) && !overwriteExistingFile) + { + throw new ArgumentException( + string.Format(CultureInfo.CurrentCulture, Resources.MetaconfigAlreadyExists, outputFilePath)); + } + + // Write to the file + this.WriteMetaConfigMofFile(outputFilePath, dscMetaConfigValue); + } + + return new DirectoryInfo(outputFolderFullPath); + } + + private void CreateOutputFolder(string folderPath) + { + try + { + if (!Directory.Exists(folderPath)) + { + System.IO.Directory.CreateDirectory(folderPath); + } + } + catch (UnauthorizedAccessException) + { + throw new UnauthorizedAccessException( + string.Format(CultureInfo.CurrentCulture, Resources.UnauthorizedAccess, folderPath)); + } + } + + /// + /// Get the current directory path + /// + /// full path of the current directory + private string GetCurrentDirectory() + { + string currentDirectory = String.Empty; + + try + { + currentDirectory = Directory.GetCurrentDirectory(); + } + catch (UnauthorizedAccessException) + { + throw new UnauthorizedAccessException( + string.Format(CultureInfo.CurrentCulture, Resources.UnauthorizedAccess, currentDirectory)); + } + + return currentDirectory; + } + + /// + /// Validate and return the full folder path + /// + /// Folder path to be validated + private string ValidateAndGetFullPath(string folderPath) + { + string fullPath = String.Empty; + + // check if folder exists - path can be absolute or relative + if (Directory.Exists(folderPath)) + { + // get the full path + fullPath = Path.GetFullPath(folderPath); + } + else + { + throw new ArgumentException( + string.Format(CultureInfo.CurrentCulture, Resources.InvalidFolderPath, folderPath)); + } + + return fullPath; + } + + private void WriteMetaConfigMofFile(string outputFilePath, string fileContent) + { + try + { + File.WriteAllText(outputFilePath, fileContent); + } + catch (ArgumentException) + { + throw new ArgumentException( + string.Format(CultureInfo.CurrentCulture, Resources.InvalidFilePath, outputFilePath)); + } + catch (UnauthorizedAccessException) + { + throw new UnauthorizedAccessException( + string.Format(CultureInfo.CurrentCulture, Resources.UnauthorizedAccess, outputFilePath)); + } } #endregion @@ -245,5 +353,224 @@ public Model.AgentRegistration NewAgentRegistrationKey( return new Model.AgentRegistration(resourceGroupName, automationAccountName, agentRegistration); } #endregion + + #region DscNode Operations + public Model.DscNode GetDscNodeById( + string resourceGroupName, + string automationAccountName, + Guid nodeId) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + Requires.Argument("NodeId", nodeId).NotNull(); + + var node = + this.automationManagementClient.Nodes.Get( + resourceGroupName, + automationAccountName, + nodeId).Node; + + return new Model.DscNode(resourceGroupName, automationAccountName, node); + } + + public IEnumerable ListDscNodesByName( + string resourceGroupName, + string automationAccountName, + string nodeName, + string status) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + Requires.Argument("NodeName", nodeName).NotNull(); + + IEnumerable dscNodes; + + if (!String.IsNullOrEmpty(status)) + { + dscNodes = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Nodes.List( + resourceGroupName, + automationAccountName, + new DscNodeListParameters { Status = status, Name = nodeName }); + + return new ResponseWithSkipToken(response, response.Nodes); + }); + } + else + { + dscNodes = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Nodes.List( + resourceGroupName, + automationAccountName, + new DscNodeListParameters { Name = nodeName }); + + return new ResponseWithSkipToken(response, response.Nodes); + }); + } + + return dscNodes.Select(dscNode => new Model.DscNode(resourceGroupName, automationAccountName, dscNode)); + } + + public IEnumerable ListDscNodesByNodeConfiguration( + string resourceGroupName, + string automationAccountName, + string nodeConfigurationName, + string status) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + Requires.Argument("NodeConfigurationName", nodeConfigurationName).NotNull(); + + IEnumerable dscNodes; + + if (!String.IsNullOrEmpty(status)) + { + dscNodes = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Nodes.List( + resourceGroupName, + automationAccountName, + new DscNodeListParameters { Status = status, NodeConfigurationName = nodeConfigurationName }); + + return new ResponseWithSkipToken(response, response.Nodes); + }); + } + else + { + dscNodes = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Nodes.List( + resourceGroupName, + automationAccountName, + new DscNodeListParameters { NodeConfigurationName = nodeConfigurationName }); + + return new ResponseWithSkipToken(response, response.Nodes); + }); + } + + return dscNodes.Select(dscNode => new Model.DscNode(resourceGroupName, automationAccountName, dscNode)); + } + + public IEnumerable ListDscNodes( + string resourceGroupName, + string automationAccountName, + string status) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + + IEnumerable dscNodes; + + if (!String.IsNullOrEmpty(status)) + { + dscNodes = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Nodes.List( + resourceGroupName, + automationAccountName, + new DscNodeListParameters { Status = status }); + + return new ResponseWithSkipToken(response, response.Nodes); + }); + } + else + { + dscNodes = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.Nodes.List( + resourceGroupName, + automationAccountName, + new DscNodeListParameters {}); + + return new ResponseWithSkipToken(response, response.Nodes); + }); + } + + return dscNodes.Select(dscNode => new Model.DscNode(resourceGroupName, automationAccountName, dscNode)); + } + + public Model.DscNode SetDscNodeById( + string resourceGroupName, + string automationAccountName, + Guid nodeId, + string nodeConfigurationName, + bool force) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + Requires.Argument("NodeId", nodeId).NotNull(); + Requires.Argument("NodeConfigurationName", nodeConfigurationName).NotNull(); + + string existingConfigurationName = String.Empty; + + try + { + var getNode = this.automationManagementClient.Nodes.Get( + resourceGroupName, + automationAccountName, + nodeId).Node; + + existingConfigurationName = getNode.NodeConfiguration.Name; + } + catch (CloudException cloudException) + { + if (cloudException.Response.StatusCode == HttpStatusCode.NotFound) + { + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.NodeNotFound), cloudException); + } + + throw; + } + + if (!String.IsNullOrEmpty(existingConfigurationName) && !force) + { + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.NodeConfigurationAlreadyExists)); + } + + var nodeConfiguration = new DscNodeConfigurationAssociationProperty { Name = nodeConfigurationName }; + + var node = + this.automationManagementClient.Nodes.Patch( + resourceGroupName, + automationAccountName, + new DscNodePatchParameters + { + Id = nodeId, + NodeConfiguration = nodeConfiguration + }).Node; + + return new Model.DscNode(resourceGroupName, automationAccountName, node); + } + + public void DeleteDscNode(string resourceGroupName, string automationAccountName, Guid nodeId) + { + try + { + this.automationManagementClient.Nodes.Delete( + resourceGroupName, + automationAccountName, + nodeId); + } + catch (CloudException cloudException) + { + if (cloudException.Response.StatusCode == HttpStatusCode.NoContent) + { + throw new ResourceNotFoundException(typeof(DscNode), + string.Format(CultureInfo.CurrentCulture, Resources.DscNodeNotFound, nodeId.ToString())); + } + + throw; + } + } + + #endregion } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs index d8027a1a7a46..ec6a7c643405 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs @@ -20,6 +20,8 @@ namespace Microsoft.Azure.Commands.Automation.Common { + using System.Runtime.Remoting.Messaging; + internal static class AutomationCmdletParameterSets { /// @@ -37,6 +39,10 @@ internal static class AutomationCmdletParameterSets /// internal const string ByPath = "ByPath"; + /// + /// By Id parameter set + /// + internal const string ById = "ById"; /// /// The one time schedule parameter set. @@ -112,5 +118,10 @@ internal static class AutomationCmdletParameterSets /// Parameter set for updating variable description /// internal const string UpdateVariableDescription = "UpdateVariableDescription"; + + /// + /// Parameter set for NodeConfiguration + /// + internal const string ByNodeConfiguration = "ByNodeConfiguration"; } } diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index abcd47906e21..035c42d920d3 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -13,6 +13,7 @@ // ---------------------------------------------------------------------------------- using System; +using System.IO; using System.Collections; using System.Collections.Generic; using System.Security; @@ -41,22 +42,37 @@ public interface IAutomationClient #region Configurations - IEnumerable ListAutomationConfigurations(string resourceGroupName, string automationAccountName); + IEnumerable ListDscConfigurations(string resourceGroupName, string automationAccountName); DscConfiguration GetConfiguration(string resourceGroupName, string automationAccountName, string configurationName); - DscConfiguration CreateConfiguration(string resourceGroupName, string automationAccountName, string configurationName, string sourcePath, IDictionary tags, string description, bool logVerbose, bool logProgress, bool published, bool overWrite); + DscConfiguration CreateConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, IDictionary tags, string description, bool? logVerbose, bool published, bool overWrite); #endregion #region AgentRegistrationInforamtion - Microsoft.Azure.Commands.Automation.Model.AgentRegistration GetAgentRegistration(string resourceGroupName, string automationAccountName); + AgentRegistration GetAgentRegistration(string resourceGroupName, string automationAccountName); - Microsoft.Azure.Commands.Automation.Model.AgentRegistration NewAgentRegistrationKey(string resourceGroupName, string automationAccountName, string keyType); + AgentRegistration NewAgentRegistrationKey(string resourceGroupName, string automationAccountName, string keyType); #endregion #region DscMetaConfiguration - Microsoft.Azure.Commands.Automation.Model.DscOnboardingMetaconfig GetDscMetaConfig(string resourceGroupName, string automationAccountName); + DirectoryInfo GetDscMetaConfig(string resourceGroupName, string automationAccountName, string outputFolder, string[] computerNames, bool overwriteExistingFile); + #endregion + + #region DscNode Operations + + DscNode GetDscNodeById(string resourceGroupName, string automationAccountName, Guid nodeId); + + IEnumerable ListDscNodes(string resourceGroupName, string automationAccountName, string status); + + IEnumerable ListDscNodesByName(string resourceGroupName, string automationAccountName, string nodeName, string status); + IEnumerable ListDscNodesByNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string status); + + DscNode SetDscNodeById(string resourceGroupName, string automationAccountName, Guid nodeId, string nodeConfigurationName, bool force); + + void DeleteDscNode(string resourceGroupName, string automationAccountName, Guid nodeId); + #endregion } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/AgentRegistration.cs b/src/ResourceManager/Automation/Commands.Automation/Model/AgentRegistration.cs index 743228975185..37ae2fdcf03f 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/AgentRegistration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/AgentRegistration.cs @@ -15,13 +15,11 @@ using System; using System.Collections; using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Management.Automation.Models; +using AutomationManagement = Microsoft.Azure.Management.Automation; namespace Microsoft.Azure.Commands.Automation.Model { - using Microsoft.Azure.Management.Automation.Models; - - using AutomationManagement = Microsoft.Azure.Management.Automation; - /// /// The Agent Registration. /// @@ -46,8 +44,12 @@ public AgentRegistration(string resourceGroupName, string automationAccountName, this.ResourceGroupName = resourceGroupName; this.AutomationAccountName = automationAccountName; - this.PrimaryKey = agentRegistration.Keys.Primary; - this.SecondaryKey = agentRegistration.Keys.Secondary; + if (agentRegistration.Keys != null) + { + this.PrimaryKey = agentRegistration.Keys.Primary; + this.SecondaryKey = agentRegistration.Keys.Secondary; + } + this.Endpoint = agentRegistration.Endpoint; } diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/Configuration.cs b/src/ResourceManager/Automation/Commands.Automation/Model/Configuration.cs index 033e434d33c6..a8881033874a 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Model/Configuration.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Model/Configuration.cs @@ -15,11 +15,10 @@ using System; using System.Collections; using Microsoft.Azure.Commands.Automation.Common; +using AutomationManagement = Microsoft.Azure.Management.Automation; namespace Microsoft.Azure.Commands.Automation.Model { - using AutomationManagement = Microsoft.Azure.Management.Automation; - /// /// The Configuration. /// @@ -64,28 +63,6 @@ public DscConfiguration(string resourceGroupName, string automationAccountName, this.Tags.Add(kvp.Key, kvp.Value); } - this.Source = null; - if (configuration.Properties.Source != null) - { - ContentHash hash = null; - if (!String.IsNullOrEmpty(configuration.Properties.Source.ContentHash.Value)) - { - hash = new ContentHash() - { - Algorithm = configuration.Properties.Source.ContentHash.Algorithm, - Value = configuration.Properties.Source.ContentHash.Value - }; - } - - this.Source = new ContentSource() - { - ContentHash = hash, - ContentType = configuration.Properties.Source.ContentType, - Value = configuration.Properties.Source.Value, - Version = configuration.Properties.Source.Version, - }; - } - this.Parameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase); foreach (var kvp in configuration.Properties.Parameters) { @@ -155,10 +132,12 @@ public DscConfiguration() /// public bool LogVerbose { get; set; } + /* /// /// Gets or sets the content source. /// public ContentSource Source { get; set; } + */ } /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/DscNode.cs b/src/ResourceManager/Automation/Commands.Automation/Model/DscNode.cs new file mode 100644 index 000000000000..63790d27032e --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/DscNode.cs @@ -0,0 +1,102 @@ +// ---------------------------------------------------------------------------------- +// +// 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 Microsoft.Azure.Commands.Automation.Common; +using AutomationManagement = Microsoft.Azure.Management.Automation; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + /// + /// The Dsc Node. + /// + public class DscNode + { + /// + /// Initializes a new instance of the class. + /// + /// The resource group name. + /// The automation account. + /// The dsc node. + public DscNode(string resourceGroupName, string automationAccountName, AutomationManagement.Models.DscNode node) + { + Requires.Argument("ResourceGroupName", resourceGroupName).NotNull(); + Requires.Argument("AutomationAccountName", automationAccountName).NotNull(); + Requires.Argument("Node", node).NotNull(); + + this.ResourceGroupName = resourceGroupName; + this.AutomationAccountName = automationAccountName; + this.Name = node.Name; + this.Id = node.Id; + this.Ip = node.Ip; + this.LastSeen = node.LastSeen.ToLocalTime(); + this.RegistrationTime = node.RegistrationTime.ToLocalTime(); + this.Status = node.Status; + this.NodeConfigurationName = node.NodeConfiguration.Name; + } + + /// + /// Initializes a new instance of the class. + /// + public DscNode() + { + } + + /// + /// Gets or sets the resource group name. + /// + public string ResourceGroupName { get; set; } + + /// + /// Gets or sets the automation account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the name. + /// + public string Name { get; set; } + + /// + /// Gets or sets the registration time. + /// + public DateTimeOffset RegistrationTime { get; set; } + + /// + /// Gets or sets the last seen time. + /// + public DateTimeOffset LastSeen { get; set; } + + /// + /// Gets or sets the IP address. + /// + public string Ip { get; set; } + + /// + /// Gets or sets the Id. + /// + public string Id { get; set; } + + /// + /// Gets or sets the nodeconfiguration. + /// + public string NodeConfigurationName { get; set; } + + /// + /// Gets or sets the status. + /// + public string Status { 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 8223bbabd817..b645ce13c588 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -177,6 +177,33 @@ internal static string CredentialNotFound { } } + /// + /// Looks up a localized string similar to The Dsc node was not found. Node id {0}.. + /// + internal static string DscNodeNotFound { + get { + return ResourceManager.GetString("DscNodeNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invalid path {0}.. + /// + internal static string InvalidFilePath { + get { + return ResourceManager.GetString("InvalidFilePath", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invalid folder path. Folder {0}.. + /// + internal static string InvalidFolderPath { + get { + return ResourceManager.GetString("InvalidFolderPath", resourceCulture); + } + } + /// /// Looks up a localized string similar to Invalid runbook parameters.. /// @@ -213,6 +240,15 @@ internal static string JobScheduleWithIdNotFound { } } + /// + /// Looks up a localized string similar to Metaconfig already exists. Specify the parameter to force an overwrite. File: {0}. + /// + internal static string MetaconfigAlreadyExists { + get { + return ResourceManager.GetString("MetaconfigAlreadyExists", resourceCulture); + } + } + /// /// Looks up a localized string similar to The module was not found. Module name: {0}.. /// @@ -222,6 +258,33 @@ internal static string ModuleNotFound { } } + /// + /// Looks up a localized string similar to A node configuration already exists. Specify the parameter to force an overwrite.. + /// + internal static string NodeConfigurationAlreadyExists { + get { + return ResourceManager.GetString("NodeConfigurationAlreadyExists", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The node was not found.. + /// + internal static string NodeNotFound { + get { + return ResourceManager.GetString("NodeNotFound", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} File(s) written to output folder. + /// + internal static string NumberOfFilesWritten { + get { + return ResourceManager.GetString("NumberOfFilesWritten", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} is empty.. /// @@ -240,6 +303,15 @@ internal static string PowershellJsonDecrypterFailed { } } + /// + /// Looks up a localized string similar to Are you sure you want to remove the Azure Automation Dsc node ?. + /// + internal static string RemovDscNodeWarning { + get { + return ResourceManager.GetString("RemovDscNodeWarning", resourceCulture); + } + } + /// /// Looks up a localized string similar to Disassociating the Azure Automation runbook and schedule.. /// @@ -303,6 +375,15 @@ internal static string RemoveAzureAutomationScheduleWarning { } } + /// + /// Looks up a localized string similar to Removing the Dsc node with Id {0}.. + /// + internal static string RemoveDscNodeDescription { + get { + return ResourceManager.GetString("RemoveDscNodeDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Are you sure you want to remove the Azure Automation {0} ?. /// @@ -420,6 +501,15 @@ internal static string SetCertificateInvalidArgs { } } + /// + /// Looks up a localized string similar to Unauthorized access to {0}.. + /// + internal static string UnauthorizedAccess { + get { + return ResourceManager.GetString("UnauthorizedAccess", resourceCulture); + } + } + /// /// Looks up a localized string similar to The variable already exists. Variable name {0}.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index aad302bb6737..e6122de67db3 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -287,4 +287,43 @@ Invalid SourcePath. Verify file path is valid and file exists. Automation + + Invalid folder path. Folder {0}. + Automation + + + Unauthorized access to {0}. + Automation + + + {0} File(s) written to output folder + Automation + + + Invalid path {0}. + + + Metaconfig already exists. Specify the parameter to force an overwrite. File: {0} + Automation + + + A node configuration already exists. Specify the parameter to force an overwrite. + Automation + + + The node was not found. + Automation + + + The Dsc node was not found. Node id {0}. + Automation + + + Are you sure you want to remove the Azure Automation Dsc node ? + Automation + + + Removing the Dsc node with Id {0}. + Automation + \ No newline at end of file