public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.VMScaleSetName, VerbsCommon.Set)) { string resourceGroupName = this.ResourceGroupName; string vmScaleSetName = this.VMScaleSetName; System.Collections.Generic.IList <string> instanceIds = this.InstanceId; Rest.Azure.AzureOperationResponse result = null; if (this.ParameterSetName.Equals("FriendMethod")) { result = VirtualMachineScaleSetsClient.ReimageAllWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceIds).GetAwaiter().GetResult(); } else if (this.ParameterSetName.Equals("RedeployMethodParameter")) { result = VirtualMachineScaleSetsClient.RedeployWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceIds).GetAwaiter().GetResult(); } else if (this.ParameterSetName.Equals("PerformMaintenanceMethodParameter")) { result = VirtualMachineScaleSetsClient.PerformMaintenanceWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceIds).GetAwaiter().GetResult(); } else { var vmScaleSetReimageInput = new VirtualMachineScaleSetReimageParameters(); vmScaleSetReimageInput.InstanceIds = instanceIds; vmScaleSetReimageInput.TempDisk = this.TempDisk.IsPresent; result = VirtualMachineScaleSetsClient.ReimageWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, vmScaleSetReimageInput).GetAwaiter().GetResult(); } PSOperationStatusResponse output = new PSOperationStatusResponse { StartTime = this.StartTime, EndTime = DateTime.Now }; if (result != null && result.Request != null && result.Request.RequestUri != null) { output.Name = GetOperationIdFromUrlString(result.Request.RequestUri.ToString()); } WriteObject(output); } }); }
public async Task TestVMScaleSetBatchOperations() { EnsureClientsInitialized(DefaultLocation); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage : true); // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking( rgName : rgName, vmssName : vmssName, storageAccount : storageAccountOutput, imageRef : imageRef, createWithManagedDisks : true, vmScaleSetCustomizer : (virtualMachineScaleSet) => virtualMachineScaleSet.UpgradePolicy = new UpgradePolicy { Mode = UpgradeMode.Manual } ); VirtualMachineScaleSet vmScaleSet = getTwoVirtualMachineScaleSet.Item1; inputVMScaleSet = getTwoVirtualMachineScaleSet.Item2; var virtualMachineScaleSetInstanceIDs = new VirtualMachineScaleSetVMInstanceIDs(new List <string>() { "0", "1" }); var virtualMachineScaleSetInstanceID = new List <string>() { "0", "1" }; var virtualMachineScaleSetRequ = new VirtualMachineScaleSetVMInstanceRequiredIDs(new List <string>() { "0", "1" }); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartStartAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs)); virtualMachineScaleSetInstanceIDs = new VirtualMachineScaleSetVMInstanceIDs(new List <string>() { "0" }); VirtualMachineScaleSetReimageParameters virtualMachineScaleSetReimageParameters = new VirtualMachineScaleSetReimageParameters { InstanceIds = virtualMachineScaleSetInstanceID }; await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartReimageAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetReimageParameters)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartReimageAllAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartPowerOffAsync(rgName, vmScaleSet.Name, null, virtualMachineScaleSetInstanceIDs)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartUpdateInstancesAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetRequ)); virtualMachineScaleSetInstanceID = new List <string>() { "1" }; await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartRestartAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeallocateAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs)); await WaitForCompletionAsync(await VirtualMachineScaleSetsOperations.StartDeleteInstancesAsync(rgName, vmScaleSet.Name, virtualMachineScaleSetRequ)); passed = true; Assert.True(passed); }
public void TestVMScaleSetBatchOperations() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true); // Create resource group string rgName = TestUtilities.GenerateName(TestPrefix) + 1; var vmssName = TestUtilities.GenerateName("vmss"); string storageAccountName = TestUtilities.GenerateName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; try { var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName); VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking( rgName: rgName, vmssName: vmssName, storageAccount: storageAccountOutput, imageRef: imageRef, inputVMScaleSet: out inputVMScaleSet, createWithManagedDisks: true, vmScaleSetCustomizer: (virtualMachineScaleSet) => virtualMachineScaleSet.UpgradePolicy = new UpgradePolicy { Mode = UpgradeMode.Manual } ); var virtualMachineScaleSetInstanceIDs = new List <string>() { "0", "1" }; m_CrpClient.VirtualMachineScaleSets.Start(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs); virtualMachineScaleSetInstanceIDs = new List <string>() { "0" }; VirtualMachineScaleSetReimageParameters virtualMachineScaleSetReimageParameters = new VirtualMachineScaleSetReimageParameters { InstanceIds = virtualMachineScaleSetInstanceIDs }; m_CrpClient.VirtualMachineScaleSets.Reimage(rgName, vmScaleSet.Name, virtualMachineScaleSetReimageParameters); m_CrpClient.VirtualMachineScaleSets.ReimageAll(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs); m_CrpClient.VirtualMachineScaleSets.PowerOff(rgName, vmScaleSet.Name, null, virtualMachineScaleSetInstanceIDs); m_CrpClient.VirtualMachineScaleSets.UpdateInstances(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs); virtualMachineScaleSetInstanceIDs = new List <string>() { "1" }; m_CrpClient.VirtualMachineScaleSets.Restart(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs); m_CrpClient.VirtualMachineScaleSets.Deallocate(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs); m_CrpClient.VirtualMachineScaleSets.DeleteInstances(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs); passed = true; } finally { m_ResourcesClient.ResourceGroups.DeleteIfExists(rgName); } Assert.True(passed); } }