Skip to content
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

New Start-AzVmssRollingExtensionUpgrade cmdlet #13479

Merged
merged 22 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,12 @@ public void TestVirtualMachineScaleSetAssignedHost()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetAssignedHost");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is LiveOnly because it requires some manual setup.

public void TestVirtualMachineScaleSetExtRollingUpgrade()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetExtRollingUpgrade");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2650,3 +2650,35 @@ function Test-VirtualMachineScaleSetAssignedHost
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test the VMSS Extension rolling upgrade cmdlet.
This is a LiveOnly test and requires some manual setup due to test resources deleting themselves
before the extension upgrade can complete.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test requires some manual setup because the test framework does not create healthy VMs when creating a VMSS. The VMs start deleting themselves immediately, and the upgrade will fail.

#>
function Test-VirtualMachineScaleSetExtRollingUpgrade
{

try
{
# create a VM scale set manually in Azure Portal, use its default values.
# Provide the Location, ResourceGroupName, and VM scale set name below.

# Common
[string]$loc = "eastus";
$rgname = "adamvmssupdate";
$vmssname = "windowsvmss";
$vmss = Get-Azvmss -ResourceGroupName $rgname -VMScaleSetName $vmssname;

Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name "testExtension" -Publisher Microsoft.CPlat.Core -Type "NullWindows" -TypeHandlerVersion "3.0" -AutoUpgradeMinorVersion $True -Setting "";

$job = Start-AzVmssRollingExtensionUpgrade -ResourceGroupName $rgname -VMScaleSetName $vmssname -AsJob;
$result = $job | Wait-Job;
Assert-AreEqual "Completed" $result.State;
}
finally
{

}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Compute/Compute/Az.Compute.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
'Set-AzVmssOrchestrationServiceState', 'New-AzDiskAccess',
'Remove-AzDiskAccess', 'Get-AzDiskAccess',
'Invoke-AzVmPatchAssessment',
'Get-AzDiskEncryptionSetAssociatedResource'
'Get-AzDiskEncryptionSetAssociatedResource', 'Start-AzVmssRollingExtensionUpgrade'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-->
## Upcoming Release
* New cmdlet `Start-AzVmssRollingExtensionUpgrade`.

## Version 4.6.0
* Added `-VmssId` parameter to `New-AzVm`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Automation.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;

namespace Microsoft.Azure.Commands.Compute.Automation
{
[Cmdlet(VerbsLifecycle.Start, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VmssRollingExtensionUpgrade", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)]
[OutputType(typeof(PSOperationStatusResponse))]
public partial class VirtualMachineScaleSetRollingExtensionStartUpgrade : ComputeAutomationBaseCmdlet
{
private const string ByResourceIdParamSet = "ByResourceId",
ByInputObjectParamSet = "ByInputObject", DefaultParameterSetName = "DefaultParameter";
Sandido marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(
ParameterSetName = DefaultParameterSetName,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[ResourceGroupCompleter]
public string ResourceGroupName { get; set; }

[Parameter(
ParameterSetName = DefaultParameterSetName,
Mandatory = true,
ValueFromPipelineByPropertyName = true)]
[ResourceNameCompleter("Microsoft.Compute/virtualMachineScaleSets", "ResourceGroupName")]
[Alias("Name")]
public string VMScaleSetName { get; set; }

[Parameter(
ParameterSetName = ByInputObjectParamSet,
Mandatory = true,
ValueFromPipeline = true)]
public PSVirtualMachineScaleSet VirtualMachineScaleSet { get; set; }

[Parameter(
ParameterSetName = ByResourceIdParamSet,
Mandatory = true,
ValueFromPipeline = true)]
public string ResourceId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void ExecuteCmdlet()
{

base.ExecuteCmdlet();
switch (ParameterSetName)
{

case ByInputObjectParamSet:
ExecuteClientAction(() =>
{
this.StartRollingUpdate(this.VirtualMachineScaleSet.ResourceGroupName, this.VirtualMachineScaleSet.Name);
});
break;

case ByResourceIdParamSet:

ResourceIdentifier identifier = new ResourceIdentifier(this.ResourceId);

ExecuteClientAction(() =>
{
this.StartRollingUpdate(identifier.ResourceGroupName, identifier.ResourceName);
});

break;

default:

ExecuteClientAction(() =>
{
this.StartRollingUpdate(this.ResourceGroupName, this.VMScaleSetName);
});
break;
}
}

private void StartRollingUpdate(string ResourceGroup, string vmssName)
{
if (ShouldProcess(vmssName, VerbsLifecycle.Start))
{

var result = VirtualMachineScaleSetRollingUpgradesClient.StartExtensionUpgradeWithHttpMessagesAsync(ResourceGroup, vmssName).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);
}
}
}
}
186 changes: 186 additions & 0 deletions src/Compute/Compute/help/Start-AzVmssRollingExtensionUpgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
external help file: Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml
Module Name: Az.Compute
online version: https://docs.microsoft.com/en-us/powershell/module/az.compute/start-azvmssrollingextensionupgrade
schema: 2.0.0
---

# Start-AzVmssRollingExtensionUpgrade

## SYNOPSIS
This cmdlet starts a rolling upgrade for all extensions on the given Virtual Machine Scale Set to the latest available version.

## SYNTAX

### DefaultParameter
```
Start-AzVmssRollingExtensionUpgrade -ResourceGroupName <String> -VMScaleSetName <String> [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByInputObject
```
Start-AzVmssRollingExtensionUpgrade -VirtualMachineScaleSet <PSVirtualMachineScaleSet> [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByResourceId
```
Start-AzVmssRollingExtensionUpgrade -ResourceId <String> [-AsJob] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Starts a rolling upgrade to move all extensions on this virtual machine scale set to the latest available version.
Extensions which are already running the latest available version are not affected.

## EXAMPLES

### Example 1
```powershell
PS C:\> $vmss = Get-AzVM -ResourceGroupName "MyResourceGroupName" -VMScaleSetName "MyVmssName";
PS C:\> Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name "testExtension" -Publisher Microsoft.CPlat.Core -Type "NullWindows" -TypeHandlerVersion "3.0" -AutoUpgradeMinorVersion $True -Setting "";
PS C:\> Start-AzVmssRollingExtensionUpgrade -ResourceGroupName "MyResourceGroupName" -VMScaleSetName "MyVmssName";
```

This example gets the existing VM scale set "MyVmssName", and adds an extension to it. The final command runs the extension rolling upgrade process.

## PARAMETERS

### -AsJob
Run cmdlet in the background

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

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

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.

```yaml
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Parameter Sets: (All)
Aliases: AzContext, AzureRmContext, AzureCredential

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

### -ResourceGroupName
The name of the resource group.

```yaml
Type: System.String
Parameter Sets: DefaultParameter
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -ResourceId
The resource Id of the VM scale set object.

```yaml
Type: System.String
Parameter Sets: ByResourceId
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -VirtualMachineScaleSet
The VM scale set object.

```yaml
Type: Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet
Parameter Sets: ByInputObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -VMScaleSetName
The name of the VM scale set.

```yaml
Type: System.String
Parameter Sets: DefaultParameter
Aliases: Name

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

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

### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi

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

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### System.String

### Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet

## OUTPUTS

### Microsoft.Azure.Commands.Compute.Automation.Models.PSOperationStatusResponse

## NOTES

## RELATED LINKS