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

PowerShell Support for ResiliencyPolicy (including ResilientVMCreationPolicy, ResilientVMDeletionPolicy) on VMSS #25928

Merged
merged 10 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -423,5 +423,12 @@ public void TestVirtualMachineScaleSetDefaultImgWhenStandard()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetDefaultImgWhenStandard");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestResiliencyPolicyVMSS()
{
TestRunner.RunTestScript("Test-ResiliencyPolicyVMSS");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5312,4 +5312,56 @@ function Test-VirtualMachineScaleSetDefaultImgWhenStandard
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}

<#
.SYNOPSIS
Create a VMSS using New-Azvmssconfig
Update the Resiliency policies of VMSS using Update-Azvmss
Test ResilientVMCreationPolicy and ResilientVMDeletionPolicy
#>
function Test-ResiliencyPolicyVMSS
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-ComputeVMLocation;
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# New VMSS Parameters
$vmssName = 'vmssResiliencyPolicy' + $rgname;

$adminUsername = Get-ComputeTestResourceName;
$adminPassword = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $securePassword);

$vmssConfig = new-azvmssconfig -Location $loc -EnableResilientVMCreate -EnableResilientVMDelete;
$vmss = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig;

# Asserts
# check ResilientVMCreationPolicy
Assert-True { $vmssConfig.ResiliencyPolicy.ResilientVMCreationPolicy.Enabled };
# check ResilientVMDeletionPolicy
Assert-True { $vmssConfig.ResiliencyPolicy.ResilientVMDeletionPolicy.Enabled };

Update-azvmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -EnableResilientVMDelete $false -EnableResilientVMCreate $false
$updatedVmss = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;

# Asserts
# check ResilientVMCreationPolicy
Assert-False { $updatedVmss.ResiliencyPolicy.ResilientVMCreationPolicy.Enabled };
# check ResilientVMDeletionPolicy
Assert-False { $updatedVmss.ResiliencyPolicy.ResilientVMDeletionPolicy.Enabled };


}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

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
* Added `EnableResilientVMCreate` and `EnableResilientVMDelete` parameters to `Update-AzVmss` and `New-AzVmssConfig` cmdlets for enhanced VM resilience options.
* Fixed secrets exposure in example documentation.
* References are updated to use 2024-07-01 ComputeRP and 2024-03-02 DiskRP REST API calls.
* Added information on how to find VM Images when using `New-AzVM` with `-Image` parameter.
Expand Down
11 changes: 9 additions & 2 deletions src/Compute/Compute/Compute.Automation.generated.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,11 @@
<Label>ProvisioningState</Label>
<Alignment>Right</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableColumnHeader>
<Label>ResiliencyPolicy</Label>
<Alignment>Right</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
Expand All @@ -652,7 +656,10 @@
<TableColumnItem>
<ScriptBlock>$_.ProvisioningState</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.ResiliencyPolicy.ResilientVMCreationPolicy</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ public string ResourceGroupName
// api-version: 2022-03-01.
public DateTime? TimeCreated { get; private set; }
public string Etag { get; private set; }

public ResiliencyPolicy ResiliencyPolicy { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
Mandatory = false)]
public bool? EnableSecureBoot { get; set; } = null;

[Parameter(
Mandatory = false,
HelpMessage = "Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.")]
public SwitchParameter EnableResilientVMCreate { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Specifies whether resilient VM deletion should be enabled on the virtual machine scale set. The default value is false.")]
public SwitchParameter EnableResilientVMDelete { get; set; }

protected override void ProcessRecord()
{
if (ShouldProcess("VirtualMachineScaleSet", "New"))
Expand Down Expand Up @@ -390,6 +400,9 @@ private void Run()
// PriorityMix
PriorityMixPolicy vPriorityMixPolicy = null;

//ResiliencyPolicy
ResiliencyPolicy vResiliencyPolicy = null;

if (this.IsParameterBound(c => c.SkuName))
{
if (vSku == null)
Expand All @@ -399,6 +412,24 @@ private void Run()
vSku.Name = this.SkuName;
}

if (this.IsParameterBound(c => c.EnableResilientVMCreate))
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
{
if (vResiliencyPolicy == null)
{
vResiliencyPolicy = new ResiliencyPolicy();
}
vResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate.ToBool());
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
}

if (this.IsParameterBound(c=> c.EnableResilientVMDelete))
{
if (vResiliencyPolicy == null)
{
vResiliencyPolicy = new ResiliencyPolicy();
}
vResiliencyPolicy.ResilientVMDeletionPolicy = new ResilientVMDeletionPolicy(this.EnableResilientVMDelete.ToBool());
}

if (this.IsParameterBound(c => c.SkuTier))
{
if (vSku == null)
Expand Down Expand Up @@ -915,6 +946,7 @@ private void Run()
vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout = this.OSImageScheduledEventNotBeforeTimeoutInMinutes;
}


var vVirtualMachineScaleSet = new PSVirtualMachineScaleSet
{
Overprovision = this.IsParameterBound(c => c.Overprovision) ? this.Overprovision : (bool?)null,
Expand All @@ -937,11 +969,11 @@ private void Run()
Identity = vIdentity,
OrchestrationMode = this.IsParameterBound(c => c.OrchestrationMode) ? this.OrchestrationMode : null,
SpotRestorePolicy = this.IsParameterBound(c => c.EnableSpotRestore) ? new SpotRestorePolicy(true, this.SpotRestoreTimeout) : null,
PriorityMixPolicy = vPriorityMixPolicy
PriorityMixPolicy = vPriorityMixPolicy,
ResiliencyPolicy = vResiliencyPolicy
};

WriteObject(vVirtualMachineScaleSet);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -421,6 +421,16 @@ public override void ExecuteCmdlet()
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.")]
public string IfNoneMatch { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.")]
public bool EnableResilientVMCreate { get; set; }
haagha marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(
Mandatory = false,
HelpMessage = "Specifies whether resilient VM deletion should be enabled on the virtual machine scale set. The default value is false.")]
public bool EnableResilientVMDelete { get; set; }

private void BuildPatchObject()
{
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
Expand Down Expand Up @@ -1404,8 +1414,35 @@ private void BuildPatchObject()
{
throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
}
}

// New Feature Implementation
if (this.IsParameterBound(c => c.EnableResilientVMCreate))
{
if (this.VirtualMachineScaleSetUpdate == null)
{
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
}
if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy == null)
{
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy = new ResiliencyPolicy();
}
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate);
}

if (this.IsParameterBound(c => c.EnableResilientVMDelete))
{
if (this.VirtualMachineScaleSetUpdate == null)
{
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
}
if (this.VirtualMachineScaleSetUpdate.ResiliencyPolicy == null)
{
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy = new ResiliencyPolicy();
}
this.VirtualMachineScaleSetUpdate.ResiliencyPolicy.ResilientVMDeletionPolicy = new ResilientVMDeletionPolicy(this.EnableResilientVMDelete);
}
}

private void BuildPutObject()
{
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
Expand Down Expand Up @@ -1455,7 +1492,7 @@ private void BuildPutObject()
this.VirtualMachineScaleSet.VirtualMachineProfile.DiagnosticsProfile.BootDiagnostics.StorageUri = this.BootDiagnosticsStorageUri;
}

if (this.IsParameterBound(c=> c.CapacityReservationGroupId))
if (this.IsParameterBound(c => c.CapacityReservationGroupId))
{
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
{
Expand Down Expand Up @@ -2173,6 +2210,31 @@ private void BuildPutObject()
throw new ArgumentException(Microsoft.Azure.Commands.Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
}

if (this.IsParameterBound(c => c.EnableResilientVMCreate))
{
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
{
this.VirtualMachineScaleSet.VirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
}
if (this.VirtualMachineScaleSet.ResiliencyPolicy == null)
{
this.VirtualMachineScaleSet.ResiliencyPolicy = new ResiliencyPolicy();
}
this.VirtualMachineScaleSet.ResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate);
}

if (this.IsParameterBound(c => c.EnableResilientVMDelete))
{
if (this.VirtualMachineScaleSet.VirtualMachineProfile == null)
{
this.VirtualMachineScaleSet.VirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
}
if (this.VirtualMachineScaleSet.ResiliencyPolicy == null)
{
this.VirtualMachineScaleSet.ResiliencyPolicy = new ResiliencyPolicy();
}
this.VirtualMachineScaleSet.ResiliencyPolicy.ResilientVMDeletionPolicy = new ResilientVMDeletionPolicy(this.EnableResilientVMDelete);
}
}
}
}
14 changes: 7 additions & 7 deletions src/Compute/Compute/Manual/PSVirtualMachineScaleSet.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
grizzlytheodore marked this conversation as resolved.
Show resolved Hide resolved
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
//

// Warning: This code was generated by a tool.
//
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

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

}
}
}
41 changes: 37 additions & 4 deletions src/Compute/Compute/help/New-AzVmssConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ New-AzVmssConfig [[-Overprovision] <Boolean>] [[-Location] <String>] [-EdgeZone
[-BaseRegularPriorityCount <Int32>] [-RegularPriorityPercentage <Int32>] [-ImageReferenceId <String>]
[-SharedGalleryImageId <String>] [-OSImageScheduledEventEnabled]
[-OSImageScheduledEventNotBeforeTimeoutInMinutes <String>] [-SecurityType <String>] [-EnableVtpm <Boolean>]
[-EnableSecureBoot <Boolean>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-EnableSecureBoot <Boolean>] [-EnableResilientVMCreate] [-EnableResilientVMDelete]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

### ExplicitIdentityParameterSet
Expand All @@ -55,8 +56,9 @@ New-AzVmssConfig [[-Overprovision] <Boolean>] [[-Location] <String>] [-EdgeZone
[-AutomaticRepairAction <String>] [-BaseRegularPriorityCount <Int32>] [-RegularPriorityPercentage <Int32>]
[-ImageReferenceId <String>] [-SharedGalleryImageId <String>] [-OSImageScheduledEventEnabled]
[-OSImageScheduledEventNotBeforeTimeoutInMinutes <String>] [-SecurityType <String>] [-EnableVtpm <Boolean>]
[-EnableSecureBoot <Boolean>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-EnableSecureBoot <Boolean>] [-EnableResilientVMCreate] [-EnableResilientVMDelete]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -366,6 +368,36 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -EnableResilientVMCreate
Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.

```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
```

### -EnableResilientVMDelete
Specifies whether resilient VM deletion should be enabled on the virtual machine scale set. The default value is false.

```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
```

### -EnableSecureBoot
Specifies whether secure boot should be enabled on the virtual machine.

Expand Down Expand Up @@ -773,6 +805,7 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```


### -ProximityPlacementGroupId
The resource id of the Proximity Placement Group to use with this scale set.

Expand Down
Loading