Skip to content

[Compute] VMSS Redeploy and PerformMaintenance feature #5992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ResourceManager/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Current Release
* VMSS Redeploy and PerformMaintenance feature
- Add new switch parameter -Redeploy and -PerformMaintenance to `Set-AzureRmVmss` and `Set-AzureRmVmssVM`
* Add DisableVMAgent switch parameter to `Set-AzureRmVMOperatingSystem` cmdlet
* `New-AzureRmVm` and `New-AzureRmVmss` (simple parameter set) support a `Win10` image.
* `Repair-AzureRmVmssServiceFabricUpdateDomain` cmdlet is added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,12 @@ public void TestVirtualMachineScaleSetForceUDWalk()
{
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineScaleSetForceUDWalk");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScaleSetRedeploy()
{
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineScaleSetRedeploy");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1590,3 +1590,129 @@ function Test-VirtualMachineScaleSetForceUDWalk
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Virtual Machine Scale Set Redeploy and PerformMaintenance
#>
function Test-VirtualMachineScaleSetRedeploy
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-Location "Microsoft.Compute" "virtualMachines" "East US 2";
New-AzureRMResourceGroup -Name $rgname -Location $loc -Force;

# SRP
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzureRMStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
$stoaccount = Get-AzureRMStorageAccount -ResourceGroupName $rgname -Name $stoname;

# NRP
$subnet = New-AzureRMVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzureRMVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzureRMVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;

# New VMSS Parameters
$vmssName = 'vmss' + $rgname;
$vmssType = 'Microsoft.Compute/virtualMachineScaleSets';

$adminUsername = 'Foo12';
$adminPassword = $PLACEHOLDER;

$imgRef = Get-DefaultCRPImage -loc $loc;
$vhdContainer = "https://" + $stoname + ".blob.core.windows.net/" + $vmssName;

$ipCfg = New-AzureRmVmssIPConfig -Name 'test' -SubnetId $subnetId;
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_A1_v2' -UpgradePolicyMode 'Automatic' `
| Add-AzureRmVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
| Set-AzureRmVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
| Set-AzureRmVmssStorageProfile -Name 'test' -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion $imgRef.Version `
-ImageReferencePublisher $imgRef.PublisherName -VhdContainer $vhdContainer;

$result = New-AzureRmVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;

Assert-AreEqual $loc.ToLowerInvariant().Replace(" ", "") $result.Location;
Assert-AreEqual 2 $result.Sku.Capacity;
Assert-AreEqual 'Standard_A1_v2' $result.Sku.Name;
Assert-AreEqual 'Automatic' $result.UpgradePolicy.Mode;

# Validate Network Profile
Assert-AreEqual 'test' $result.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].Name;
Assert-AreEqual $true $result.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].Primary;
Assert-AreEqual $subnetId `
$result.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Subnet.Id;

# Validate OS Profile
Assert-AreEqual 'test' $result.VirtualMachineProfile.OsProfile.ComputerNamePrefix;
Assert-AreEqual $adminUsername $result.VirtualMachineProfile.OsProfile.AdminUsername;
Assert-Null $result.VirtualMachineProfile.OsProfile.AdminPassword;

# Validate Storage Profile
Assert-AreEqual 'test' $result.VirtualMachineProfile.StorageProfile.OsDisk.Name;
Assert-AreEqual 'FromImage' $result.VirtualMachineProfile.StorageProfile.OsDisk.CreateOption;
Assert-AreEqual 'None' $result.VirtualMachineProfile.StorageProfile.OsDisk.Caching;
Assert-AreEqual $vhdContainer $result.VirtualMachineProfile.StorageProfile.OsDisk.VhdContainers[0];
Assert-AreEqual $imgRef.Offer $result.VirtualMachineProfile.StorageProfile.ImageReference.Offer;
Assert-AreEqual $imgRef.Skus $result.VirtualMachineProfile.StorageProfile.ImageReference.Sku;
Assert-AreEqual $imgRef.Version $result.VirtualMachineProfile.StorageProfile.ImageReference.Version;
Assert-AreEqual $imgRef.PublisherName $result.VirtualMachineProfile.StorageProfile.ImageReference.Publisher;

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$id = $vmssVMs[0].InstanceId;

# Redeploy operation
Set-AzureRmVmss -Redeploy -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual "Succeeded" $vmss.ProvisioningState;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual "Succeeded" $vmssVMs[0].ProvisioningState;
Assert-AreEqual "Succeeded" $vmssVMs[1].ProvisioningState;

Set-AzureRmVmss -Redeploy -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceId $id;
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual "Succeeded" $vmss.ProvisioningState;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual "Succeeded" $vmssVMs[0].ProvisioningState;
Assert-AreEqual "Succeeded" $vmssVMs[1].ProvisioningState;

Set-AzureRmVmssVM -Redeploy -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceId $id;
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual "Succeeded" $vmss.ProvisioningState;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual "Succeeded" $vmssVMs[0].ProvisioningState;
Assert-AreEqual "Succeeded" $vmssVMs[1].ProvisioningState;

# PerformMaintenance operation
# Note that PerformMaintenace operation can only be performed when VMSS requires a maintenance
# and after the given subscription gets a permission for the operation due to the required maintenance.
Assert-ThrowsContains { Set-AzureRmVmss -PerformMaintenance -ResourceGroupName $rgname -VMScaleSetName $vmssName; } `
"since the Subscription of this VM is not eligible";

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;

Assert-ThrowsContains { Set-AzureRmVmss -PerformMaintenance -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceId $id; } `
"since the Subscription of this VM is not eligible";

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;

Assert-ThrowsContains { Set-AzureRmVmssVM -PerformMaintenance -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceId $id; } `
"since the Subscription of this VM is not eligible";
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public override void ExecuteCmdlet()
{
ExecuteClientAction(() =>
{
string location = this.Location;
string location = this.Location.Canonicalize();
string commandId = this.CommandId;

if (!string.IsNullOrEmpty(location) && !string.IsNullOrEmpty(commandId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private void Run()
{
Overprovision = this.MyInvocation.BoundParameters.ContainsKey("Overprovision") ? this.Overprovision : (bool?) null,
SinglePlacementGroup = this.MyInvocation.BoundParameters.ContainsKey("SinglePlacementGroup") ? this.SinglePlacementGroup : (bool?) null,
ZoneBalance = this.ZoneBalance.IsPresent,
ZoneBalance = this.ZoneBalance.IsPresent ? true : (bool?) null,
PlatformFaultDomainCount = this.MyInvocation.BoundParameters.ContainsKey("PlatformFaultDomainCount") ? this.PlatformFaultDomainCount : (int?) null,
Zones = this.MyInvocation.BoundParameters.ContainsKey("Zone") ? this.Zone : null,
Location = this.MyInvocation.BoundParameters.ContainsKey("Location") ? this.Location : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void Run()
}

// PublicIPAddressConfigurationIdleTimeoutInMinutes
if (this.PublicIPAddressConfigurationIdleTimeoutInMinutes != null)
if (this.MyInvocation.BoundParameters.ContainsKey("PublicIPAddressConfigurationIdleTimeoutInMinutes"))
{
if (vIpConfigurations.PublicIPAddressConfiguration == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public override void ExecuteCmdlet()
ComputeAutomationAutoMapperProfile.Mapper.Map<Azure.Management.Compute.Models.OperationStatusResponse, PSOperationStatusResponse>(result, psObject);
WriteObject(psObject);
}
else if (this.ParameterSetName.Equals("RedeployMethodParameter"))
{
var result = VirtualMachineScaleSetsClient.Redeploy(resourceGroupName, vmScaleSetName, instanceIds);
var psObject = new PSOperationStatusResponse();
ComputeAutomationAutoMapperProfile.Mapper.Map<Azure.Management.Compute.Models.OperationStatusResponse, PSOperationStatusResponse>(result, psObject);
WriteObject(psObject);
}
else if (this.ParameterSetName.Equals("PerformMaintenanceMethodParameter"))
{
var result = VirtualMachineScaleSetsClient.PerformMaintenance(resourceGroupName, vmScaleSetName, instanceIds);
var psObject = new PSOperationStatusResponse();
ComputeAutomationAutoMapperProfile.Mapper.Map<Azure.Management.Compute.Models.OperationStatusResponse, PSOperationStatusResponse>(result, psObject);
WriteObject(psObject);
}
else
{
var result = VirtualMachineScaleSetsClient.Reimage(resourceGroupName, vmScaleSetName, instanceIds);
Expand All @@ -150,37 +164,20 @@ public override void ExecuteCmdlet()
}

[Parameter(
ParameterSetName = "DefaultParameter",
Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Parameter(
ParameterSetName = "FriendMethod",
Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[ResourceManager.Common.ArgumentCompleters.ResourceGroupCompleter()]
public string ResourceGroupName { get; set; }

[Parameter(
ParameterSetName = "DefaultParameter",
Position = 2,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Parameter(
ParameterSetName = "FriendMethod",
Position = 2,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Alias("Name")]
public string VMScaleSetName { get; set; }

[Parameter(
ParameterSetName = "DefaultParameter",
Position = 3,
ValueFromPipelineByPropertyName = true)]
[Parameter(
ParameterSetName = "FriendMethod",
Position = 3,
ValueFromPipelineByPropertyName = true)]
public string [] InstanceId { get; set; }
Expand All @@ -195,6 +192,16 @@ public override void ExecuteCmdlet()
Mandatory = true)]
public SwitchParameter ReimageAll { get; set; }

[Parameter(
ParameterSetName = "RedeployMethodParameter",
Mandatory = true)]
public SwitchParameter Redeploy { get; set; }

[Parameter(
ParameterSetName = "PerformMaintenanceMethodParameter",
Mandatory = true)]
public SwitchParameter PerformMaintenance { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ public override void ExecuteCmdlet()
ComputeAutomationAutoMapperProfile.Mapper.Map<Azure.Management.Compute.Models.OperationStatusResponse, PSOperationStatusResponse>(result, psObject);
WriteObject(psObject);
}
else if (this.ParameterSetName.Equals("RedeployMethodParameter"))
{
var result = VirtualMachineScaleSetVMsClient.Redeploy(resourceGroupName, vmScaleSetName, instanceId);
var psObject = new PSOperationStatusResponse();
ComputeAutomationAutoMapperProfile.Mapper.Map<Azure.Management.Compute.Models.OperationStatusResponse, PSOperationStatusResponse>(result, psObject);
WriteObject(psObject);
}
else if (this.ParameterSetName.Equals("PerformMaintenanceMethodParameter"))
{
var result = VirtualMachineScaleSetVMsClient.PerformMaintenance(resourceGroupName, vmScaleSetName, instanceId);
var psObject = new PSOperationStatusResponse();
ComputeAutomationAutoMapperProfile.Mapper.Map<Azure.Management.Compute.Models.OperationStatusResponse, PSOperationStatusResponse>(result, psObject);
WriteObject(psObject);
}
else
{
var result = VirtualMachineScaleSetVMsClient.Reimage(resourceGroupName, vmScaleSetName, instanceId);
Expand All @@ -145,38 +159,20 @@ public override void ExecuteCmdlet()
}

[Parameter(
ParameterSetName = "DefaultParameter",
Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Parameter(
ParameterSetName = "FriendMethod",
Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[ResourceManager.Common.ArgumentCompleters.ResourceGroupCompleter()]
public string ResourceGroupName { get; set; }

[Parameter(
ParameterSetName = "DefaultParameter",
Position = 2,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Parameter(
ParameterSetName = "FriendMethod",
Position = 2,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Alias("Name")]
public string VMScaleSetName { get; set; }

[Parameter(
ParameterSetName = "DefaultParameter",
Position = 3,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[Parameter(
ParameterSetName = "FriendMethod",
Position = 3,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
Expand All @@ -192,6 +188,16 @@ public override void ExecuteCmdlet()
Mandatory = true)]
public SwitchParameter ReimageAll { get; set; }

[Parameter(
ParameterSetName = "RedeployMethodParameter",
Mandatory = true)]
public SwitchParameter Redeploy { get; set; }

[Parameter(
ParameterSetName = "PerformMaintenanceMethodParameter",
Mandatory = true)]
public SwitchParameter PerformMaintenance { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }
}
Expand Down
20 changes: 16 additions & 4 deletions src/ResourceManager/Compute/Commands.Compute/help/New-AzureRmVM.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
external help file: Microsoft.Azure.Commands.Compute.dll-Help.xml
Module Name: AzureRM.Compute
ms.assetid: 05E6155D-4F0E-406B-9312-77AD97EF66EE
Expand All @@ -15,8 +15,8 @@ Creates a virtual machine.

### SimpleParameterSet (Default)
```
New-AzureRmVM [[-ResourceGroupName] <String>] [[-Location] <String>] -Name <String> -Credential <PSCredential>
[-VirtualNetworkName <String>] [-AddressPrefix <String>] [-SubnetName <String>]
New-AzureRmVM [[-ResourceGroupName] <String>] [[-Location] <String>] [[-Zone] <String[]>] -Name <String>
-Credential <PSCredential> [-VirtualNetworkName <String>] [-AddressPrefix <String>] [-SubnetName <String>]
[-SubnetAddressPrefix <String>] [-PublicIpAddressName <String>] [-DomainNameLabel <String>]
[-AllocationMethod <String>] [-SecurityGroupName <String>] [-OpenPorts <Int32[]>] [-ImageName <String>]
[-Size <String>] [-AvailabilitySetName <String>] [-AsJob] [-DataDiskSizeInGb <Int32[]>]
Expand Down Expand Up @@ -549,6 +549,18 @@ Accept wildcard characters: False
### -Zone
Specifies the zone list of the virtual machine.

```yaml
Type: String[]
Parameter Sets: SimpleParameterSet
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

```yaml
Type: String[]
Parameter Sets: DefaultParameterSet
Expand All @@ -557,7 +569,7 @@ Aliases:
Required: False
Position: 3
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept pipeline input: False
Accept wildcard characters: False
```

Expand Down
Loading