|
| 1 | +// ---------------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// Copyright Microsoft Corporation |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +// ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.Collections; |
| 17 | +using System.Collections.Generic; |
| 18 | +using System.Globalization; |
| 19 | +using System.Management.Automation; |
| 20 | +using System.Security.Permissions; |
| 21 | +using Microsoft.Azure.Commands.Automation.Common; |
| 22 | +using Microsoft.Azure.Commands.Automation.Model; |
| 23 | +using Microsoft.Azure.Commands.Automation.Properties; |
| 24 | +using Microsoft.WindowsAzure.Commands.Utilities.Common; |
| 25 | + |
| 26 | +namespace Microsoft.Azure.Commands.Automation.Cmdlet |
| 27 | +{ |
| 28 | + /// <summary> |
| 29 | + /// Registers the dsc node. |
| 30 | + /// </summary> |
| 31 | + [Cmdlet(VerbsLifecycle.Register, "AzureAutomationDscNode")] |
| 32 | + // [OutputType(typeof(DscNode))] |
| 33 | + public class RegisterAzureAutomationDscNode : AzureAutomationBaseCmdlet |
| 34 | + { |
| 35 | + /// <summary> |
| 36 | + /// True to reboot the node if needed. False otherwise. |
| 37 | + /// </summary> |
| 38 | + private bool rebootIfNeeded = false; |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// True to overwrite modules. False otherwise. |
| 42 | + /// </summary> |
| 43 | + private bool overwriteModulesFlag = false; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Default value for ConfigurationModeFrequencyMins |
| 47 | + /// </summary> |
| 48 | + private int configurationModeFrequencyMins = 15; |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Default value for RefreshFrequencyMins |
| 52 | + /// </summary> |
| 53 | + private int refreshFrequencyMins = 30; |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Default value for ActionAfterReboot |
| 57 | + /// </summary> |
| 58 | + private string actionAfterReboot = "ContinueConfiguration"; |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Default value for NodeConfigurationName |
| 62 | + /// </summary> |
| 63 | + private string nodeConfigurationName = String.Empty; |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Default value for ConfigurationMode |
| 67 | + /// </summary> |
| 68 | + private string configurationMode = "ApplyAndMonitor"; |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Gets or sets the VM name. |
| 72 | + /// </summary> |
| 73 | + [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the Azure virtual machine to register for management with Azure Automation DSC.")] |
| 74 | + [ValidateNotNullOrEmpty] |
| 75 | + public string AzureVMName { get; set; } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Gets or sets the node configuration name. |
| 79 | + /// </summary> |
| 80 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The node configuration name the VM should be configured to grab from Azure Automation DSC.")] |
| 81 | + public string NodeConfigurationName |
| 82 | + { |
| 83 | + get { return this.nodeConfigurationName; } |
| 84 | + set { this.nodeConfigurationName = value; } |
| 85 | + } |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Gets or sets the configuration mode |
| 89 | + /// </summary> |
| 90 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "DSC configuration mode.")] |
| 91 | + [ValidateSet("ApplyAndMonitor", "ApplyAndAutocorrect", "ApplyOnly")] |
| 92 | + public string ConfigurationMode |
| 93 | + { |
| 94 | + get { return this.configurationMode; } |
| 95 | + set { this.configurationMode = value; } |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Gets or sets the configuration mode frequency in minutes. |
| 100 | + /// </summary> |
| 101 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Represents the frequency (in minutes) at which the background application of DSC attempts to implement the current configuration on the target node.")] |
| 102 | + [ValidateRange(15, 44640)] |
| 103 | + public int ConfigurationModeFrequencyMins |
| 104 | + { |
| 105 | + get { return this.configurationModeFrequencyMins; } |
| 106 | + set { this.configurationModeFrequencyMins = value; } |
| 107 | + } |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Gets or sets the refresh frequency in minutes. |
| 111 | + /// </summary> |
| 112 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Represents the frequency (in minutes) at which the Local Configuration Manager contacts the pull server to download the current configuration.")] |
| 113 | + [ValidateRange(30, 44640)] |
| 114 | + public int RefreshFrequencyMins |
| 115 | + { |
| 116 | + get { return this.refreshFrequencyMins; } |
| 117 | + set { this.refreshFrequencyMins = value; } |
| 118 | + } |
| 119 | + |
| 120 | + /// <summary> |
| 121 | + /// Gets or sets a value indicating whether to reboot the node if needed. |
| 122 | + /// </summary> |
| 123 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "True to Reboot the node if needed.")] |
| 124 | + public bool RebootNodeIfNeeded |
| 125 | + { |
| 126 | + get { return this.rebootIfNeeded; } |
| 127 | + set { this.rebootIfNeeded = value; } |
| 128 | + } |
| 129 | + |
| 130 | + /// <summary> |
| 131 | + /// Gets or sets the action to perform post reboot. |
| 132 | + /// </summary> |
| 133 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Action to perform after a reboot.")] |
| 134 | + [ValidateSet("ContinueConfiguration", "StopConfiguration")] |
| 135 | + public string ActionAfterReboot |
| 136 | + { |
| 137 | + get { return this.actionAfterReboot; } |
| 138 | + set { this.actionAfterReboot = value; } |
| 139 | + } |
| 140 | + |
| 141 | + /// <summary> |
| 142 | + /// Gets or sets a value indicating whether to overwrite the module. |
| 143 | + /// </summary> |
| 144 | + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, |
| 145 | + HelpMessage = "Controls whether new configurations downloaded from the configuration server are allowed to overwrite the old ones on the target node.")] |
| 146 | + public bool AllowModuleOverwrite |
| 147 | + { |
| 148 | + get { return this.overwriteModulesFlag; } |
| 149 | + set { this.overwriteModulesFlag = value; } |
| 150 | + } |
| 151 | + |
| 152 | + /// <summary> |
| 153 | + /// Execute this cmdlet. |
| 154 | + /// </summary> |
| 155 | + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] |
| 156 | + public override void ExecuteCmdlet() |
| 157 | + { |
| 158 | + this.AutomationClient.RegisterDscNode(this.ResourceGroupName, this.AutomationAccountName,this.AzureVMName, this.NodeConfigurationName, this.ConfigurationMode, this.ConfigurationModeFrequencyMins, this.RefreshFrequencyMins, this.RebootNodeIfNeeded, this.ActionAfterReboot, this.AllowModuleOverwrite); |
| 159 | + } |
| 160 | + } |
| 161 | +} |
0 commit comments