|
| 1 | +// |
| 2 | +// Copyright (c) Microsoft and contributors. All rights reserved. |
| 3 | +// |
| 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 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | + |
| 17 | +// Warning: This code was generated by a tool. |
| 18 | +// |
| 19 | +// Changes to this file may cause incorrect behavior and will be lost if the |
| 20 | +// code is regenerated. |
| 21 | + |
| 22 | +using System; |
| 23 | +using System.Collections; |
| 24 | +using System.Collections.Generic; |
| 25 | +using System.Linq; |
| 26 | +using System.Management.Automation; |
| 27 | +using Microsoft.Azure.Commands.Compute.Automation.Models; |
| 28 | +using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; |
| 29 | +using Microsoft.Azure.Management.Compute; |
| 30 | +using Microsoft.Azure.Management.Compute.Models; |
| 31 | +using Microsoft.WindowsAzure.Commands.Utilities.Common; |
| 32 | +using System.Security; |
| 33 | + |
| 34 | +namespace Microsoft.Azure.Commands.Compute.Automation |
| 35 | +{ |
| 36 | + [Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssRunCommand", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)] |
| 37 | + [OutputType(typeof(List<PSVirtualMachineRunCommand>))] |
| 38 | + public partial class AddAzVmssRunCommand : ComputeAutomationBaseCmdlet |
| 39 | + { |
| 40 | + public override void ExecuteCmdlet() |
| 41 | + { |
| 42 | + base.ExecuteCmdlet(); |
| 43 | + ExecuteClientAction(() => |
| 44 | + { |
| 45 | + if (ShouldProcess(this.VMScaleSetName, "Add")) |
| 46 | + { |
| 47 | + string resourceGroupName; |
| 48 | + string vmScaleSetName; |
| 49 | + switch (this.ParameterSetName) |
| 50 | + { |
| 51 | + case "ObjectParameter": |
| 52 | + resourceGroupName = GetResourceGroupName(this.VirtualMachineScaleSetVM.Id); |
| 53 | + vmScaleSetName = GetResourceName(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); |
| 54 | + break; |
| 55 | + default: |
| 56 | + resourceGroupName = this.ResourceGroupName; |
| 57 | + vmScaleSetName = this.VMScaleSetName; |
| 58 | + break; |
| 59 | + } |
| 60 | + VirtualMachineRunCommand vmruncommand; |
| 61 | + |
| 62 | + vmruncommand = new VirtualMachineRunCommand |
| 63 | + { |
| 64 | + OutputBlobUri = this.IsParameterBound(c => c.OutputBlobUri) ? this.OutputBlobUri : null, |
| 65 | + ErrorBlobUri = this.IsParameterBound(c => c.ErrorBlobUri) ? this.ErrorBlobUri : null, |
| 66 | + RunAsPassword = this.IsParameterBound(c => c.RunAsPassword) ? this.RunAsPassword.ToString() : null, |
| 67 | + RunAsUser = this.IsParameterBound(c => c.RunAsUser) ? this.RunAsUser : null, |
| 68 | + TimeoutInSeconds = this.IsParameterBound(c => c.TimeOutInSeconds) ? Convert.ToInt32(this.TimeOutInSeconds) : (int?)null, |
| 69 | + Location = this.IsParameterBound(c => c.Location) ? this.Location : null, |
| 70 | + AsyncExecution = this.IsParameterBound(c => c.AsyncExecution) ? this.AsyncExecution : null |
| 71 | + }; |
| 72 | + |
| 73 | + |
| 74 | + if (this.IsParameterBound(c => c.ScriptUri)) { |
| 75 | + vmruncommand.Source = new VirtualMachineRunCommandScriptSource |
| 76 | + { |
| 77 | + Script = this.IsParameterBound(c => c.Script) ? this.Script : null, |
| 78 | + ScriptUri = this.IsParameterBound(c => c.ScriptUri) ? this.ScriptUri : null, |
| 79 | + CommandId = this.IsParameterBound(c => c.CommandId) ? this.CommandId : null |
| 80 | + }; |
| 81 | + } |
| 82 | + else if (this.ScriptPath != null && this.IsParameterBound(c => c.ScriptPath)) |
| 83 | + { |
| 84 | + List<string> Script = new List<string>(); |
| 85 | + PathIntrinsics currentPath = SessionState.Path; |
| 86 | + var filePath = new System.IO.FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(this.ScriptPath)); |
| 87 | + string fileContent = Commands.Common.Authentication.Abstractions.FileUtilities.DataStore.ReadFileAsText(filePath.FullName); |
| 88 | + Script = fileContent.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| 89 | + |
| 90 | + vmruncommand.Source = new VirtualMachineRunCommandScriptSource(this.Script, this.ScriptPath, this.CommandId); |
| 91 | + } |
| 92 | + |
| 93 | + if (this.Parameter != null) |
| 94 | + { |
| 95 | + var vParameter = new List<RunCommandInputParameter>(); |
| 96 | + foreach (var key in this.Parameter.Keys) |
| 97 | + { |
| 98 | + RunCommandInputParameter p = new RunCommandInputParameter(); |
| 99 | + |
| 100 | + p.Name = key.ToString(); |
| 101 | + p.Value = this.Parameter[key].ToString(); |
| 102 | + vParameter.Add(p); |
| 103 | + } |
| 104 | + vmruncommand.Parameters = vParameter; |
| 105 | + } |
| 106 | + else if (this.ProtectedParameter != null) |
| 107 | + { |
| 108 | + var vParameter = new List<RunCommandInputParameter>(); |
| 109 | + foreach (var key in this.ProtectedParameter.Keys) |
| 110 | + { |
| 111 | + RunCommandInputParameter p = new RunCommandInputParameter(); |
| 112 | + |
| 113 | + p.Name = key.ToString(); |
| 114 | + p.Value = this.ProtectedParameter[key].ToString(); |
| 115 | + vParameter.Add(p); |
| 116 | + } |
| 117 | + vmruncommand.ProtectedParameters = vParameter; |
| 118 | + } |
| 119 | + |
| 120 | + var expand = new Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM>(); |
| 121 | + expand.Expand = "instanceView"; |
| 122 | + var vmList = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName, expand); |
| 123 | + var resultList = vmList.ToList(); |
| 124 | + var nextPageLink = vmList.NextPageLink; |
| 125 | + while (!string.IsNullOrEmpty(nextPageLink)) |
| 126 | + { |
| 127 | + var pageResult = VirtualMachineScaleSetVMsClient.ListNext(nextPageLink); |
| 128 | + foreach (var pageItem in pageResult) |
| 129 | + { |
| 130 | + resultList.Add(pageItem); |
| 131 | + } |
| 132 | + nextPageLink = pageResult.NextPageLink; |
| 133 | + } |
| 134 | + List<VirtualMachineScaleSetVM> listOfVms = new List<VirtualMachineScaleSetVM>(resultList); |
| 135 | + List<PSVirtualMachineRunCommand> output = new List<PSVirtualMachineRunCommand>(); |
| 136 | + |
| 137 | + |
| 138 | + foreach (VirtualMachineScaleSetVM vm in listOfVms) |
| 139 | + { |
| 140 | + var resultOfRunCmd = VirtualMachineScaleSetVMRunCommandsClient.BeginCreateOrUpdateAsync(resourceGroupName, vmScaleSetName, vm.InstanceId, this.Name, vmruncommand); |
| 141 | + var Pstemp = new PSVirtualMachineRunCommand(); |
| 142 | + ComputeAutomationAutoMapperProfile.Mapper.Map<VirtualMachineRunCommand, PSVirtualMachineRunCommand>(resultOfRunCmd.Result, Pstemp); |
| 143 | + output.Add(Pstemp); |
| 144 | + } |
| 145 | + |
| 146 | + WriteObject(output); |
| 147 | + } |
| 148 | + }); |
| 149 | + } |
| 150 | + |
| 151 | + [Parameter( |
| 152 | + ParameterSetName = "DefaultParameter", |
| 153 | + Position = 0, |
| 154 | + Mandatory = true, |
| 155 | + ValueFromPipelineByPropertyName = true)] |
| 156 | + [ResourceGroupCompleter] |
| 157 | + public string ResourceGroupName { get; set; } |
| 158 | + |
| 159 | + [Parameter( |
| 160 | + ParameterSetName = "DefaultParameter", |
| 161 | + Position = 1, |
| 162 | + Mandatory = true, |
| 163 | + ValueFromPipelineByPropertyName = true)] |
| 164 | + [ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")] |
| 165 | + public string VMScaleSetName { get; set; } |
| 166 | + |
| 167 | + [Parameter( |
| 168 | + ParameterSetName = "DefaultParameter", |
| 169 | + Position = 2, |
| 170 | + Mandatory = true, |
| 171 | + ValueFromPipelineByPropertyName = true)] |
| 172 | + public string Location { get; set; } |
| 173 | + |
| 174 | + [Parameter( |
| 175 | + Mandatory = false)] |
| 176 | + [AllowNull] |
| 177 | + public string CommandId { get; set; } |
| 178 | + |
| 179 | + [Parameter( |
| 180 | + Mandatory = true)] |
| 181 | + [AllowNull] |
| 182 | + public string Name { get; set; } |
| 183 | + |
| 184 | + [Parameter( |
| 185 | + Mandatory = false)] |
| 186 | + [AllowNull] |
| 187 | + public string ScriptPath { get; set; } |
| 188 | + |
| 189 | + [Parameter( |
| 190 | + Mandatory = false)] |
| 191 | + [AllowNull] |
| 192 | + public string ScriptUri { get; set; } |
| 193 | + |
| 194 | + [Parameter( |
| 195 | + Mandatory = false)] |
| 196 | + [AllowNull] |
| 197 | + public string Script { get; set; } |
| 198 | + |
| 199 | + [Parameter( |
| 200 | + Mandatory = false)] |
| 201 | + [AllowNull] |
| 202 | + public string TimeOutInSeconds { get; set; } |
| 203 | + |
| 204 | + [Parameter( |
| 205 | + Mandatory = false)] |
| 206 | + [AllowNull] |
| 207 | + public string ErrorBlobUri { get; set; } |
| 208 | + |
| 209 | + [Parameter( |
| 210 | + Mandatory = false)] |
| 211 | + [AllowNull] |
| 212 | + public string OutputBlobUri { get; set; } |
| 213 | + |
| 214 | + [Parameter( |
| 215 | + Mandatory = false)] |
| 216 | + [AllowNull] |
| 217 | + public string RunAsUser { get; set; } |
| 218 | + |
| 219 | + [Parameter( |
| 220 | + Mandatory = false)] |
| 221 | + [AllowNull] |
| 222 | + public SecureString RunAsPassword { get; set; } |
| 223 | + |
| 224 | + [Parameter( |
| 225 | + Mandatory = false)] |
| 226 | + [AllowNull] |
| 227 | + public Hashtable Parameter { get; set; } |
| 228 | + |
| 229 | + [Parameter( |
| 230 | + Mandatory = false)] |
| 231 | + [AllowNull] |
| 232 | + public Hashtable ProtectedParameter { get; set; } |
| 233 | + |
| 234 | + [Parameter( |
| 235 | + Mandatory = false)] |
| 236 | + public Nullable<Boolean> AsyncExecution { get; set; } |
| 237 | + |
| 238 | + |
| 239 | + [Parameter( |
| 240 | + ParameterSetName = "ObjectParameter", |
| 241 | + Position = 0, |
| 242 | + Mandatory = true, |
| 243 | + ValueFromPipelineByPropertyName = true, |
| 244 | + ValueFromPipeline = true)] |
| 245 | + [ValidateNotNullOrEmpty] |
| 246 | + public PSVirtualMachineScaleSetVM VirtualMachineScaleSetVM { get; set; } |
| 247 | + |
| 248 | + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] |
| 249 | + public SwitchParameter AsJob { get; set; } |
| 250 | + } |
| 251 | +} |
0 commit comments