Skip to content

Commit ec4f0e8

Browse files
haaghaPSCmdAssistantdolauli
authored
PowerShell Support for ResiliencyPolicy (including ResilientVMCreationPolicy, ResilientVMDeletionPolicy) on VMSS (Azure#25928)
* Autogen code * Update ChangeLog.md * fixing autogenerated changes * adding test and help * More changes * changing help * changes with help * fixed test case * Adding static analysis suppression --------- Co-authored-by: PSCmdAssistant <pscmdassistant@microsoft.com> Co-authored-by: Xiaogang <xidi@microsoft.com>
1 parent 0a0f8d7 commit ec4f0e8

File tree

12 files changed

+1102
-60
lines changed

12 files changed

+1102
-60
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,12 @@ public void TestVirtualMachineScaleSetDefaultImgWhenStandard()
423423
{
424424
TestRunner.RunTestScript("Test-VirtualMachineScaleSetDefaultImgWhenStandard");
425425
}
426+
427+
[Fact]
428+
[Trait(Category.AcceptanceType, Category.CheckIn)]
429+
public void TestResiliencyPolicyVMSS()
430+
{
431+
TestRunner.RunTestScript("Test-ResiliencyPolicyVMSS");
432+
}
426433
}
427434
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5312,4 +5312,56 @@ function Test-VirtualMachineScaleSetDefaultImgWhenStandard
53125312
# Cleanup
53135313
Clean-ResourceGroup $rgname;
53145314
}
5315-
}
5315+
}
5316+
5317+
<#
5318+
.SYNOPSIS
5319+
Create a VMSS using New-Azvmssconfig
5320+
Update the Resiliency policies of VMSS using Update-Azvmss
5321+
Test ResilientVMCreationPolicy and ResilientVMDeletionPolicy
5322+
#>
5323+
function Test-ResiliencyPolicyVMSS
5324+
{
5325+
# Setup
5326+
$rgname = Get-ComputeTestResourceName
5327+
5328+
try
5329+
{
5330+
# Common
5331+
$loc = Get-ComputeVMLocation;
5332+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
5333+
5334+
# New VMSS Parameters
5335+
$vmssName = 'vmssResiliencyPolicy' + $rgname;
5336+
5337+
$adminUsername = Get-ComputeTestResourceName;
5338+
$adminPassword = $PLACEHOLDER;
5339+
$securePassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force;
5340+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $securePassword);
5341+
5342+
$vmssConfig = new-azvmssconfig -Location $loc -EnableResilientVMCreate -EnableResilientVMDelete;
5343+
$vmss = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig;
5344+
5345+
# Asserts
5346+
# check ResilientVMCreationPolicy
5347+
Assert-True { $vmssConfig.ResiliencyPolicy.ResilientVMCreationPolicy.Enabled };
5348+
# check ResilientVMDeletionPolicy
5349+
Assert-True { $vmssConfig.ResiliencyPolicy.ResilientVMDeletionPolicy.Enabled };
5350+
5351+
Update-azvmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -EnableResilientVMDelete $false -EnableResilientVMCreate $false
5352+
$updatedVmss = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
5353+
5354+
# Asserts
5355+
# check ResilientVMCreationPolicy
5356+
Assert-False { $updatedVmss.ResiliencyPolicy.ResilientVMCreationPolicy.Enabled };
5357+
# check ResilientVMDeletionPolicy
5358+
Assert-False { $updatedVmss.ResiliencyPolicy.ResilientVMDeletionPolicy.Enabled };
5359+
5360+
5361+
}
5362+
finally
5363+
{
5364+
# Cleanup
5365+
Clean-ResourceGroup $rgname
5366+
}
5367+
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestResiliencyPolicyVMSS.json

Lines changed: 814 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added `EnableResilientVMCreate` and `EnableResilientVMDelete` parameters to `Update-AzVmss` and `New-AzVmssConfig` cmdlets for enhanced VM resilience options.
2324

2425
## Version 8.3.0
2526
* Fixed secrets exposure in example documentation.

src/Compute/Compute/Compute.Automation.generated.format.ps1xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,11 @@
630630
<Label>ProvisioningState</Label>
631631
<Alignment>Right</Alignment>
632632
</TableColumnHeader>
633-
</TableHeaders>
633+
<TableColumnHeader>
634+
<Label>ResiliencyPolicy</Label>
635+
<Alignment>Right</Alignment>
636+
</TableColumnHeader>
637+
</TableHeaders>
634638
<TableRowEntries>
635639
<TableRowEntry>
636640
<TableColumnItems>
@@ -652,7 +656,10 @@
652656
<TableColumnItem>
653657
<ScriptBlock>$_.ProvisioningState</ScriptBlock>
654658
</TableColumnItem>
655-
</TableColumnItems>
659+
<TableColumnItem>
660+
<ScriptBlock>$_.ResiliencyPolicy.ResilientVMCreationPolicy</ScriptBlock>
661+
</TableColumnItem>
662+
</TableColumnItems>
656663
</TableRowEntry>
657664
</TableRowEntries>
658665
</TableControl>

src/Compute/Compute/Generated/Models/PSVirtualMachineScaleSet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,7 @@ public string ResourceGroupName
7474
// api-version: 2022-03-01.
7575
public DateTime? TimeCreated { get; private set; }
7676
public string Etag { get; private set; }
77+
78+
public ResiliencyPolicy ResiliencyPolicy { get; set; }
7779
}
7880
}

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
347347
Mandatory = false)]
348348
public bool? EnableSecureBoot { get; set; } = null;
349349

350+
[Parameter(
351+
Mandatory = false,
352+
HelpMessage = "Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.")]
353+
public SwitchParameter EnableResilientVMCreate { get; set; }
354+
355+
[Parameter(
356+
Mandatory = false,
357+
HelpMessage = "Specifies whether resilient VM deletion should be enabled on the virtual machine scale set. The default value is false.")]
358+
public SwitchParameter EnableResilientVMDelete { get; set; }
359+
350360
protected override void ProcessRecord()
351361
{
352362
if (ShouldProcess("VirtualMachineScaleSet", "New"))
@@ -390,6 +400,9 @@ private void Run()
390400
// PriorityMix
391401
PriorityMixPolicy vPriorityMixPolicy = null;
392402

403+
//ResiliencyPolicy
404+
ResiliencyPolicy vResiliencyPolicy = null;
405+
393406
if (this.IsParameterBound(c => c.SkuName))
394407
{
395408
if (vSku == null)
@@ -399,6 +412,24 @@ private void Run()
399412
vSku.Name = this.SkuName;
400413
}
401414

415+
if (this.IsParameterBound(c => c.EnableResilientVMCreate))
416+
{
417+
if (vResiliencyPolicy == null)
418+
{
419+
vResiliencyPolicy = new ResiliencyPolicy();
420+
}
421+
vResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate.ToBool());
422+
}
423+
424+
if (this.IsParameterBound(c=> c.EnableResilientVMDelete))
425+
{
426+
if (vResiliencyPolicy == null)
427+
{
428+
vResiliencyPolicy = new ResiliencyPolicy();
429+
}
430+
vResiliencyPolicy.ResilientVMDeletionPolicy = new ResilientVMDeletionPolicy(this.EnableResilientVMDelete.ToBool());
431+
}
432+
402433
if (this.IsParameterBound(c => c.SkuTier))
403434
{
404435
if (vSku == null)
@@ -915,6 +946,7 @@ private void Run()
915946
vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout = this.OSImageScheduledEventNotBeforeTimeoutInMinutes;
916947
}
917948

949+
918950
var vVirtualMachineScaleSet = new PSVirtualMachineScaleSet
919951
{
920952
Overprovision = this.IsParameterBound(c => c.Overprovision) ? this.Overprovision : (bool?)null,
@@ -937,11 +969,11 @@ private void Run()
937969
Identity = vIdentity,
938970
OrchestrationMode = this.IsParameterBound(c => c.OrchestrationMode) ? this.OrchestrationMode : null,
939971
SpotRestorePolicy = this.IsParameterBound(c => c.EnableSpotRestore) ? new SpotRestorePolicy(true, this.SpotRestoreTimeout) : null,
940-
PriorityMixPolicy = vPriorityMixPolicy
972+
PriorityMixPolicy = vPriorityMixPolicy,
973+
ResiliencyPolicy = vResiliencyPolicy
941974
};
942975

943976
WriteObject(vVirtualMachineScaleSet);
944977
}
945978
}
946-
}
947-
979+
}

src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetUpdateMethod.cs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) Microsoft and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -421,6 +421,16 @@ public override void ExecuteCmdlet()
421421
HelpMessage = "Used to make a request conditional for the GET and HEAD methods. The server will only return the requested resources if none of the listed ETag values match the current entity. Used to make a request conditional for the GET and HEAD methods. The server will only return the requested resources if none of the listed ETag values match the current entity. Set to '*' to allow a new record set to be created, but to prevent updating an existing record set. Other values will result in error from server as they are not supported.")]
422422
public string IfNoneMatch { get; set; }
423423

424+
[Parameter(
425+
Mandatory = false,
426+
HelpMessage = "Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.")]
427+
public bool EnableResilientVMCreate { get; set; }
428+
429+
[Parameter(
430+
Mandatory = false,
431+
HelpMessage = "Specifies whether resilient VM deletion should be enabled on the virtual machine scale set. The default value is false.")]
432+
public bool EnableResilientVMDelete { get; set; }
433+
424434
private void BuildPatchObject()
425435
{
426436
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
@@ -1404,8 +1414,35 @@ private void BuildPatchObject()
14041414
{
14051415
throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
14061416
}
1407-
}
14081417

1418+
// New Feature Implementation
1419+
if (this.IsParameterBound(c => c.EnableResilientVMCreate))
1420+
{
1421+
if (this.VirtualMachineScaleSetUpdate == null)
1422+
{
1423+
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
1424+
}
1425+
if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy == null)
1426+
{
1427+
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy = new ResiliencyPolicy();
1428+
}
1429+
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate);
1430+
}
1431+
1432+
if (this.IsParameterBound(c => c.EnableResilientVMDelete))
1433+
{
1434+
if (this.VirtualMachineScaleSetUpdate == null)
1435+
{
1436+
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
1437+
}
1438+
if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy == null)
1439+
{
1440+
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy = new ResiliencyPolicy();
1441+
}
1442+
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ResilientVMDeletionPolicy = new ResilientVMDeletionPolicy(this.EnableResilientVMDelete);
1443+
}
1444+
}
1445+
14091446
private void BuildPutObject()
14101447
{
14111448
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
@@ -1455,7 +1492,7 @@ private void BuildPutObject()
14551492
this.VirtualMachineScaleSet.VirtualMachineProfile.DiagnosticsProfile.BootDiagnostics.StorageUri = this.BootDiagnosticsStorageUri;
14561493
}
14571494

1458-
if (this.IsParameterBound(c=> c.CapacityReservationGroupId))
1495+
if (this.IsParameterBound(c => c.CapacityReservationGroupId))
14591496
{
14601497
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
14611498
{
@@ -2173,6 +2210,31 @@ private void BuildPutObject()
21732210
throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
21742211
}
21752212

2213+
if (this.IsParameterBound(c => c.EnableResilientVMCreate))
2214+
{
2215+
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
2216+
{
2217+
this.VirtualMachineScaleSet.VirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
2218+
}
2219+
if (this.VirtualMachineScaleSet.ResiliencyPolicy == null)
2220+
{
2221+
this.VirtualMachineScaleSet.ResiliencyPolicy = new ResiliencyPolicy();
2222+
}
2223+
this.VirtualMachineScaleSet.ResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate);
2224+
}
2225+
2226+
if (this.IsParameterBound(c => c.EnableResilientVMDelete))
2227+
{
2228+
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
2229+
{
2230+
this.VirtualMachineScaleSet.VirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
2231+
}
2232+
if (this.VirtualMachineScaleSet.ResiliencyPolicy == null)
2233+
{
2234+
this.VirtualMachineScaleSet.ResiliencyPolicy = new ResiliencyPolicy();
2235+
}
2236+
this.VirtualMachineScaleSet.ResiliencyPolicy.ResilientVMDeletionPolicy = new ResilientVMDeletionPolicy(this.EnableResilientVMDelete);
2237+
}
21762238
}
21772239
}
21782240
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
//
1+
//
22
// Copyright (c) Microsoft and contributors. All rights reserved.
3-
//
3+
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
66
// You may obtain a copy of the License at
77
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
8+
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
//
12+
//
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
//
15+
//
1616

1717
// Warning: This code was generated by a tool.
18-
//
18+
//
1919
// Changes to this file may cause incorrect behavior and will be lost if the
2020
// code is regenerated.
2121

@@ -27,4 +27,4 @@ public partial class PSVirtualMachineScaleSet
2727
public string FullyQualifiedDomainName { get; set; }
2828

2929
}
30-
}
30+
}

src/Compute/Compute/help/New-AzVmssConfig.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ New-AzVmssConfig [[-Overprovision] <Boolean>] [[-Location] <String>] [-EdgeZone
3232
[-BaseRegularPriorityCount <Int32>] [-RegularPriorityPercentage <Int32>] [-ImageReferenceId <String>]
3333
[-SharedGalleryImageId <String>] [-OSImageScheduledEventEnabled]
3434
[-OSImageScheduledEventNotBeforeTimeoutInMinutes <String>] [-SecurityType <String>] [-EnableVtpm <Boolean>]
35-
[-EnableSecureBoot <Boolean>] [-DefaultProfile <IAzureContextContainer>]
36-
[-WhatIf] [-Confirm] [<CommonParameters>]
35+
[-EnableSecureBoot <Boolean>] [-EnableResilientVMCreate] [-EnableResilientVMDelete]
36+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
37+
[<CommonParameters>]
3738
```
3839

3940
### ExplicitIdentityParameterSet
@@ -55,8 +56,9 @@ New-AzVmssConfig [[-Overprovision] <Boolean>] [[-Location] <String>] [-EdgeZone
5556
[-AutomaticRepairAction <String>] [-BaseRegularPriorityCount <Int32>] [-RegularPriorityPercentage <Int32>]
5657
[-ImageReferenceId <String>] [-SharedGalleryImageId <String>] [-OSImageScheduledEventEnabled]
5758
[-OSImageScheduledEventNotBeforeTimeoutInMinutes <String>] [-SecurityType <String>] [-EnableVtpm <Boolean>]
58-
[-EnableSecureBoot <Boolean>] [-DefaultProfile <IAzureContextContainer>]
59-
[-WhatIf] [-Confirm] [<CommonParameters>]
59+
[-EnableSecureBoot <Boolean>] [-EnableResilientVMCreate] [-EnableResilientVMDelete]
60+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
61+
[<CommonParameters>]
6062
```
6163

6264
## DESCRIPTION
@@ -366,6 +368,36 @@ Accept pipeline input: True (ByPropertyName)
366368
Accept wildcard characters: False
367369
```
368370
371+
### -EnableResilientVMCreate
372+
Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.
373+
374+
```yaml
375+
Type: System.Management.Automation.SwitchParameter
376+
Parameter Sets: (All)
377+
Aliases:
378+
379+
Required: False
380+
Position: Named
381+
Default value: None
382+
Accept pipeline input: False
383+
Accept wildcard characters: False
384+
```
385+
386+
### -EnableResilientVMDelete
387+
Specifies whether resilient VM deletion should be enabled on the virtual machine scale set. The default value is false.
388+
389+
```yaml
390+
Type: System.Management.Automation.SwitchParameter
391+
Parameter Sets: (All)
392+
Aliases:
393+
394+
Required: False
395+
Position: Named
396+
Default value: None
397+
Accept pipeline input: False
398+
Accept wildcard characters: False
399+
```
400+
369401
### -EnableSecureBoot
370402
Specifies whether secure boot should be enabled on the virtual machine.
371403
@@ -773,6 +805,7 @@ Accept pipeline input: True (ByPropertyName)
773805
Accept wildcard characters: False
774806
```
775807
808+
776809
### -ProximityPlacementGroupId
777810
The resource id of the Proximity Placement Group to use with this scale set.
778811

0 commit comments

Comments
 (0)