forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Add-AzVmssRunCommand And Remove-AzVmssRunCommand (Azure#16318)
* Adding manual run commands * Adding Test and Recording * small changes and changelog.md * adding help * fixing help * change from parameters to parameter
- Loading branch information
Showing
11 changed files
with
4,032 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3,050 changes: 3,050 additions & 0 deletions
3,050
...mands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestAddAzVmssRunCommand.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
// | ||
// Copyright (c) Microsoft and contributors. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
|
||
// Warning: This code was generated by a tool. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if the | ||
// code is regenerated. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using Microsoft.Azure.Commands.Compute.Automation.Models; | ||
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||
using Microsoft.Azure.Management.Compute; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
using System.Security; | ||
|
||
namespace Microsoft.Azure.Commands.Compute.Automation | ||
{ | ||
[Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssRunCommand", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)] | ||
[OutputType(typeof(List<PSVirtualMachineRunCommand>))] | ||
public partial class AddAzVmssRunCommand : ComputeAutomationBaseCmdlet | ||
{ | ||
public override void ExecuteCmdlet() | ||
{ | ||
base.ExecuteCmdlet(); | ||
ExecuteClientAction(() => | ||
{ | ||
if (ShouldProcess(this.VMScaleSetName, "Add")) | ||
{ | ||
string resourceGroupName; | ||
string vmScaleSetName; | ||
switch (this.ParameterSetName) | ||
{ | ||
case "ObjectParameter": | ||
resourceGroupName = GetResourceGroupName(this.VirtualMachineScaleSetVM.Id); | ||
vmScaleSetName = GetResourceName(this.VirtualMachineScaleSetVM.Id, "Microsoft.Compute/virtualMachineScaleSets", "virtualMachines"); | ||
break; | ||
default: | ||
resourceGroupName = this.ResourceGroupName; | ||
vmScaleSetName = this.VMScaleSetName; | ||
break; | ||
} | ||
VirtualMachineRunCommand vmruncommand; | ||
|
||
vmruncommand = new VirtualMachineRunCommand | ||
{ | ||
OutputBlobUri = this.IsParameterBound(c => c.OutputBlobUri) ? this.OutputBlobUri : null, | ||
ErrorBlobUri = this.IsParameterBound(c => c.ErrorBlobUri) ? this.ErrorBlobUri : null, | ||
RunAsPassword = this.IsParameterBound(c => c.RunAsPassword) ? this.RunAsPassword.ToString() : null, | ||
RunAsUser = this.IsParameterBound(c => c.RunAsUser) ? this.RunAsUser : null, | ||
TimeoutInSeconds = this.IsParameterBound(c => c.TimeOutInSeconds) ? Convert.ToInt32(this.TimeOutInSeconds) : (int?)null, | ||
Location = this.IsParameterBound(c => c.Location) ? this.Location : null, | ||
AsyncExecution = this.IsParameterBound(c => c.AsyncExecution) ? this.AsyncExecution : null | ||
}; | ||
|
||
|
||
if (this.IsParameterBound(c => c.ScriptUri)) { | ||
vmruncommand.Source = new VirtualMachineRunCommandScriptSource | ||
{ | ||
Script = this.IsParameterBound(c => c.Script) ? this.Script : null, | ||
ScriptUri = this.IsParameterBound(c => c.ScriptUri) ? this.ScriptUri : null, | ||
CommandId = this.IsParameterBound(c => c.CommandId) ? this.CommandId : null | ||
}; | ||
} | ||
else if (this.ScriptPath != null && this.IsParameterBound(c => c.ScriptPath)) | ||
{ | ||
List<string> Script = new List<string>(); | ||
PathIntrinsics currentPath = SessionState.Path; | ||
var filePath = new System.IO.FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(this.ScriptPath)); | ||
string fileContent = Commands.Common.Authentication.Abstractions.FileUtilities.DataStore.ReadFileAsText(filePath.FullName); | ||
Script = fileContent.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries).ToList(); | ||
|
||
vmruncommand.Source = new VirtualMachineRunCommandScriptSource(this.Script, this.ScriptPath, this.CommandId); | ||
} | ||
|
||
if (this.Parameter != null) | ||
{ | ||
var vParameter = new List<RunCommandInputParameter>(); | ||
foreach (var key in this.Parameter.Keys) | ||
{ | ||
RunCommandInputParameter p = new RunCommandInputParameter(); | ||
|
||
p.Name = key.ToString(); | ||
p.Value = this.Parameter[key].ToString(); | ||
vParameter.Add(p); | ||
} | ||
vmruncommand.Parameters = vParameter; | ||
} | ||
else if (this.ProtectedParameter != null) | ||
{ | ||
var vParameter = new List<RunCommandInputParameter>(); | ||
foreach (var key in this.ProtectedParameter.Keys) | ||
{ | ||
RunCommandInputParameter p = new RunCommandInputParameter(); | ||
|
||
p.Name = key.ToString(); | ||
p.Value = this.ProtectedParameter[key].ToString(); | ||
vParameter.Add(p); | ||
} | ||
vmruncommand.ProtectedParameters = vParameter; | ||
} | ||
|
||
var expand = new Microsoft.Rest.Azure.OData.ODataQuery<VirtualMachineScaleSetVM>(); | ||
expand.Expand = "instanceView"; | ||
var vmList = VirtualMachineScaleSetVMsClient.List(resourceGroupName, vmScaleSetName, expand); | ||
var resultList = vmList.ToList(); | ||
var nextPageLink = vmList.NextPageLink; | ||
while (!string.IsNullOrEmpty(nextPageLink)) | ||
{ | ||
var pageResult = VirtualMachineScaleSetVMsClient.ListNext(nextPageLink); | ||
foreach (var pageItem in pageResult) | ||
{ | ||
resultList.Add(pageItem); | ||
} | ||
nextPageLink = pageResult.NextPageLink; | ||
} | ||
List<VirtualMachineScaleSetVM> listOfVms = new List<VirtualMachineScaleSetVM>(resultList); | ||
List<PSVirtualMachineRunCommand> output = new List<PSVirtualMachineRunCommand>(); | ||
|
||
|
||
foreach (VirtualMachineScaleSetVM vm in listOfVms) | ||
{ | ||
var resultOfRunCmd = VirtualMachineScaleSetVMRunCommandsClient.BeginCreateOrUpdateAsync(resourceGroupName, vmScaleSetName, vm.InstanceId, this.Name, vmruncommand); | ||
var Pstemp = new PSVirtualMachineRunCommand(); | ||
ComputeAutomationAutoMapperProfile.Mapper.Map<VirtualMachineRunCommand, PSVirtualMachineRunCommand>(resultOfRunCmd.Result, Pstemp); | ||
output.Add(Pstemp); | ||
} | ||
|
||
WriteObject(output); | ||
} | ||
}); | ||
} | ||
|
||
[Parameter( | ||
ParameterSetName = "DefaultParameter", | ||
Position = 0, | ||
Mandatory = true, | ||
ValueFromPipelineByPropertyName = true)] | ||
[ResourceGroupCompleter] | ||
public string ResourceGroupName { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = "DefaultParameter", | ||
Position = 1, | ||
Mandatory = true, | ||
ValueFromPipelineByPropertyName = true)] | ||
[ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")] | ||
public string VMScaleSetName { get; set; } | ||
|
||
[Parameter( | ||
ParameterSetName = "DefaultParameter", | ||
Position = 2, | ||
Mandatory = true, | ||
ValueFromPipelineByPropertyName = true)] | ||
public string Location { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string CommandId { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true)] | ||
[AllowNull] | ||
public string Name { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string ScriptPath { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string ScriptUri { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string Script { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string TimeOutInSeconds { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string ErrorBlobUri { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string OutputBlobUri { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public string RunAsUser { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public SecureString RunAsPassword { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public Hashtable Parameter { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
[AllowNull] | ||
public Hashtable ProtectedParameter { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false)] | ||
public Nullable<Boolean> AsyncExecution { get; set; } | ||
|
||
|
||
[Parameter( | ||
ParameterSetName = "ObjectParameter", | ||
Position = 0, | ||
Mandatory = true, | ||
ValueFromPipelineByPropertyName = true, | ||
ValueFromPipeline = true)] | ||
[ValidateNotNullOrEmpty] | ||
public PSVirtualMachineScaleSetVM VirtualMachineScaleSetVM { get; set; } | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] | ||
public SwitchParameter AsJob { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
| ||
using Microsoft.Rest.Serialization; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Azure.Management.Compute.Models | ||
{ | ||
|
||
public class PSVirtualMachineRunCommand : Resource | ||
{ | ||
public VirtualMachineRunCommandScriptSource Source { get; set; } | ||
public IList<RunCommandInputParameter> Parameters { get; set; } | ||
public IList<RunCommandInputParameter> ProtectedParameters { get; set; } | ||
public bool? AsyncExecution { get; set; } | ||
public string RunAsUser { get; set; } | ||
public string RunAsPassword { get; set; } | ||
public int? TimeoutInSeconds { get; set; } | ||
public string OutputBlobUri { get; set; } | ||
public string ErrorBlobUri { get; set; } | ||
public string ProvisioningState { get; } | ||
public VirtualMachineRunCommandInstanceView InstanceView { get; set; } | ||
} | ||
} |
Oops, something went wrong.