Skip to content

Commit 7bfca71

Browse files
authored
[Compute] Adding MaxSurge to Set-AzVmssRollingUpgrade And Changes to Get-AzVmImage (#20811)
* Changing Set-AzVmssRollingUpgrade * Adding help * Update changelog.md * resolve conflict * Supporting latest Version in Get-AzVMimage * removing extra line * fixing help * Updating to nullable
1 parent 63ca7b1 commit 7bfca71

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
## Upcoming Release
2323
* Added breaking change message for `New-AzVmss`.
2424
* Added `-PerformancePlus` parameter to `New-AzDiskConfig`
25+
* Added 'MaxSurge' to Set-AzVmssRollingUpgradePolicyCommand
26+
* Added support for 'latest' in 'Get-AzvmImage' '-Version' parameter
2527
* Added `CompletionPercent` property to PSDisk object.
2628

2729
## Version 5.4.0

src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/SetAzureRmVmssRollingUpgradePolicyCommand.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public partial class SetAzureRmVmssRollingUpgradePolicyCommand : Microsoft.Azure
7474
ValueFromPipelineByPropertyName = true)]
7575
public bool PrioritizeUnhealthyInstance { get; set; }
7676

77+
[Parameter(
78+
Mandatory = false,
79+
ValueFromPipelineByPropertyName = true,
80+
HelpMessage = "If enabled, VMSS will create new virtual machines to upgrade the scale set, rather than updating the existing virtual machines. Existing virtual machines will be deleted once the new virtual machines are created for each batch.")]
81+
public bool? MaxSurge { get; set; }
82+
83+
7784
protected override void ProcessRecord()
7885
{
7986
if (ShouldProcess("VirtualMachineScaleSet", "Set"))
@@ -174,6 +181,21 @@ private void Run()
174181
this.VirtualMachineScaleSet.UpgradePolicy.RollingUpgradePolicy.PrioritizeUnhealthyInstances = this.PrioritizeUnhealthyInstance;
175182
}
176183

184+
if (this.IsParameterBound(c => c.MaxSurge))
185+
{
186+
// UpgradePolicy
187+
if (this.VirtualMachineScaleSet.UpgradePolicy == null)
188+
{
189+
this.VirtualMachineScaleSet.UpgradePolicy = new UpgradePolicy();
190+
}
191+
// Rolling Upgrade
192+
if (this.VirtualMachineScaleSet.UpgradePolicy.RollingUpgradePolicy == null)
193+
{
194+
this.VirtualMachineScaleSet.UpgradePolicy.RollingUpgradePolicy = new RollingUpgradePolicy();
195+
}
196+
this.VirtualMachineScaleSet.UpgradePolicy.RollingUpgradePolicy.MaxSurge = this.MaxSurge;
197+
}
198+
177199
WriteObject(this.VirtualMachineScaleSet);
178200
}
179201
}

src/Compute/Compute/Images/GetAzureVMImageCommand.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public class GetAzureVMImageCommand : VirtualMachineImageBaseCmdlet
7979

8080
[Parameter(ParameterSetName = GetVMImageDetailParamSetName,
8181
Mandatory = true,
82-
ValueFromPipelineByPropertyName = true)]
82+
ValueFromPipelineByPropertyName = true,
83+
HelpMessage ="Specifies the version of the image. Use 'latest' to get the latest image")]
8384
[ValidateNotNullOrEmpty]
8485
[SupportsWildcards]
8586
public string Version { get; set; }
@@ -190,6 +191,32 @@ public override void ExecuteCmdlet()
190191

191192
WriteObject(SubResourceWildcardFilter(Version, images), true);
192193
}
194+
else if (this.ParameterSetName.Equals(GetVMImageDetailParamSetName) && this.Version.ToLower() == "latest")
195+
{
196+
var result = this.VirtualMachineImageClient.ListWithHttpMessagesAsync(
197+
this.Location.Canonicalize(),
198+
this.PublisherName,
199+
this.Offer,
200+
this.Skus,
201+
top: 1,
202+
orderby: "name desc"
203+
).GetAwaiter().GetResult();
204+
205+
var images = from r in result.Body
206+
select new PSVirtualMachineImage
207+
{
208+
RequestId = result.RequestId,
209+
StatusCode = result.Response.StatusCode,
210+
Id = r.Id,
211+
Location = r.Location,
212+
Version = r.Name,
213+
PublisherName = this.PublisherName,
214+
Offer = this.Offer,
215+
Skus = this.Skus
216+
};
217+
218+
WriteObject(images);
219+
}
193220
else
194221
{
195222
var response = this.VirtualMachineImageClient.GetWithHttpMessagesAsync(

src/Compute/Compute/help/Set-AzVmssRollingUpgradePolicy.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Sets the VMSS rolling upgrade policy properties.
1616
Set-AzVmssRollingUpgradePolicy [-VirtualMachineScaleSet] <PSVirtualMachineScaleSet>
1717
[[-MaxBatchInstancePercent] <Int32>] [[-MaxUnhealthyInstancePercent] <Int32>]
1818
[[-MaxUnhealthyUpgradedInstancePercent] <Int32>] [-PauseTimeBetweenBatches <String>]
19-
[-EnableCrossZoneUpgrade <Boolean>] [-PrioritizeUnhealthyInstance <Boolean>]
19+
[-EnableCrossZoneUpgrade <Boolean>] [-PrioritizeUnhealthyInstance <Boolean>] [-MaxSurge <Boolean>]
2020
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

@@ -81,6 +81,21 @@ Accept pipeline input: True (ByPropertyName)
8181
Accept wildcard characters: False
8282
```
8383
84+
### -MaxSurge
85+
If enabled, VMSS will create new virtual machines to upgrade the scale set, rather than updating the existing virtual machines. Existing virtual machines will be deleted once the new virtual machines are created for each batch.
86+
87+
```yaml
88+
Type: System.Boolean
89+
Parameter Sets: (All)
90+
Aliases:
91+
92+
Required: False
93+
Position: Named
94+
Default value: None
95+
Accept pipeline input: True (ByPropertyName)
96+
Accept wildcard characters: False
97+
```
98+
8499
### -MaxUnhealthyInstancePercent
85100
The maximum percentage of the total virtual machine instances in the scale set that can be simultaneously unhealthy, either as a result of being upgraded, or by being found in an unhealthy state by the virtual machine health checks before the rolling upgrade aborts.
86101
This constraint will be checked prior to starting any batch.

0 commit comments

Comments
 (0)