Skip to content

Commit 82d9d13

Browse files
SandidomsJinLei
andauthored
New-AzVmssConfig, Update-AzVmss, add OS Image Scheduled Events (#21268)
* dev and start test * test * test done * enabled edit * help doc * empty commit * cleanup * fix statics * changelog * Update ChangeLog.md * Update New-AzVmssConfig.md --------- Co-authored-by: Jin Lei <[email protected]>
1 parent bf25276 commit 82d9d13

File tree

8 files changed

+3659
-6
lines changed

8 files changed

+3659
-6
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,12 @@ public void TestVirtualMachineScaleSetConfidentialVMSecurityTypeDiskWithVMGuestS
311311
{
312312
TestRunner.RunTestScript("Test-VirtualMachineScaleSetConfidentialVMDiskWithVMGuestStateCMK");
313313
}
314+
315+
[Fact]
316+
[Trait(Category.AcceptanceType, Category.CheckIn)]
317+
public void TestVirtualMachineScaleSetOSImageScheduledEvents()
318+
{
319+
TestRunner.RunTestScript("Test-VirtualMachineScaleSetOSImageScheduledEvents");
320+
}
314321
}
315322
}

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

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4279,4 +4279,87 @@ function Test-VirtualMachineScaleSetConfidentialVMDiskWithVMGuestStateCMK
42794279
# Cleanup
42804280
Clean-ResourceGroup $rgname;
42814281
}
4282-
}
4282+
}
4283+
4284+
<#
4285+
.SYNOPSIS
4286+
Vmss Os Image Scheduled Events tests
4287+
#>
4288+
function Test-VirtualMachineScaleSetOSImageScheduledEvents
4289+
{
4290+
4291+
# Setup
4292+
$rgname = Get-ComputeTestResourceName;
4293+
$loc = Get-ComputeVMLocation;
4294+
4295+
try
4296+
{
4297+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
4298+
4299+
# Setup variables
4300+
$publisher = "MicrosoftWindowsServer";
4301+
$offer = "WindowsServer";
4302+
$imgSku = "2019-Datacenter";
4303+
$version = "latest";
4304+
$vmssName = 'vmss' + $rgname;
4305+
$vmssSku = "Standard_D2s_v3";
4306+
$vmssname = "vmss" + $rgname;
4307+
$domainNameLabel = "d" + $rgname;
4308+
$username = "admin01";
4309+
$password = Get-PasswordForVM;
4310+
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force
4311+
4312+
$credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword);
4313+
4314+
# SRP
4315+
$stoname = 'sto' + $rgname;
4316+
$stotype = 'Standard_GRS';
4317+
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
4318+
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;
4319+
4320+
# NRP
4321+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
4322+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
4323+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
4324+
$subnetId = $vnet.Subnets[0].Id;
4325+
4326+
# Create VMSS with managed disk
4327+
$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId;
4328+
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName $vmssSku -OSImageScheduledEventEnabled -OSImageScheduledEventNotBeforeTimeoutInMinutes "PT15M" -UpgradePolicy "Automatic" `
4329+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
4330+
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $username -AdminPassword $password `
4331+
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
4332+
-ImageReferenceOffer $offer -ImageReferenceSku $imgSku -ImageReferenceVersion $version `
4333+
-ImageReferencePublisher $publisher;
4334+
4335+
$result = New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;
4336+
4337+
$vmss = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
4338+
Assert-True {$vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.Enable};
4339+
Assert-AreEqual 'PT15M' $vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout;
4340+
4341+
4342+
# Update-AzVmss test
4343+
$vmssName2 = 'vs2' + $rgname;
4344+
$vmss2 = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName $vmssSku -UpgradePolicyMode "Automatic" `
4345+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test2' -Primary $true -IPConfiguration $ipCfg `
4346+
| Set-AzVmssOSProfile -ComputerNamePrefix 'test2' -AdminUsername $username -AdminPassword $password `
4347+
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
4348+
-ImageReferenceOffer $offer -ImageReferenceSku $imgSku -ImageReferenceVersion $version `
4349+
-ImageReferencePublisher $publisher;
4350+
$result = New-AzVmss -ResourceGroupName $rgname -Name $vmssName2 -VirtualMachineScaleSet $vmss2;
4351+
$vmss = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName2;
4352+
Assert-False {$vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.Enable};
4353+
Assert-Null $vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout;
4354+
4355+
Update-AzVmss -VMScaleSetName $vmssName2 -ResourceGroupName $rgname -OSImageScheduledEventEnabled -OSImageScheduledEventNotBeforeTimeoutInMinutes "PT15M";
4356+
$vmss = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName2;
4357+
Assert-True {$vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.Enable};
4358+
Assert-AreEqual 'PT15M' $vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout;
4359+
}
4360+
finally
4361+
{
4362+
# Cleanup
4363+
Clean-ResourceGroup $rgname;
4364+
}
4365+
}

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

Lines changed: 3356 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 new switch parameter `OSImageScheduledEventEnabled` and string parameter `OSImageScheduledEventNotBeforeTimeoutInMinutes` to the cmdlets `New-AzVmssConfig` and `Update-AzVmss`.
2324

2425
## Version 5.7.1
2526
* Added a breaking change warning to the `Get-AzVM` cmdlet to show that the `NextLink` parameter and parameter set will be removed in June 2023. The parameter has been non-functional for a long time.

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
315315
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
316316
public string SharedGalleryImageId { get; set; }
317317

318+
[Parameter(
319+
Mandatory = false,
320+
HelpMessage = "Specifies whether the OS Image Scheduled event is enabled or disabled.")]
321+
public SwitchParameter OSImageScheduledEventEnabled { get; set; }
322+
323+
[Parameter(
324+
Mandatory = false,
325+
HelpMessage = "The length of time a virtual machine being reimaged or having its OS upgraded will have to potentially approve the OS Image Scheduled Event before the event is auto approved (timed out). The configuration is specified in ISO 8601 format, with the value set to 15 minutes (PT15M).")]
326+
public string OSImageScheduledEventNotBeforeTimeoutInMinutes { get; set; }
327+
318328
protected override void ProcessRecord()
319329
{
320330
if (ShouldProcess("VirtualMachineScaleSet", "New"))
@@ -793,6 +803,40 @@ private void Run()
793803
vVirtualMachineProfile.StorageProfile.ImageReference.SharedGalleryImageId = this.SharedGalleryImageId;
794804
}
795805

806+
if (this.IsParameterBound(c => c.OSImageScheduledEventEnabled))
807+
{
808+
if (vVirtualMachineProfile == null)
809+
{
810+
vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
811+
}
812+
if (vVirtualMachineProfile.ScheduledEventsProfile == null)
813+
{
814+
vVirtualMachineProfile.ScheduledEventsProfile = new ScheduledEventsProfile();
815+
}
816+
if (vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile == null)
817+
{
818+
vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile = new OSImageNotificationProfile();
819+
}
820+
vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.Enable = this.OSImageScheduledEventEnabled;
821+
}
822+
823+
if (this.IsParameterBound(c => c.OSImageScheduledEventNotBeforeTimeoutInMinutes))
824+
{
825+
if (vVirtualMachineProfile == null)
826+
{
827+
vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile();
828+
}
829+
if (vVirtualMachineProfile.ScheduledEventsProfile == null)
830+
{
831+
vVirtualMachineProfile.ScheduledEventsProfile = new ScheduledEventsProfile();
832+
}
833+
if (vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile == null)
834+
{
835+
vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile = new OSImageNotificationProfile();
836+
}
837+
vVirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout = this.OSImageScheduledEventNotBeforeTimeoutInMinutes;
838+
}
839+
796840
var vVirtualMachineScaleSet = new PSVirtualMachineScaleSet
797841
{
798842
Overprovision = this.IsParameterBound(c => c.Overprovision) ? this.Overprovision : (bool?)null,

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ public override void ExecuteCmdlet()
376376
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
377377
public string SharedGalleryImageId { get; set; }
378378

379+
[Parameter(
380+
Mandatory = false,
381+
HelpMessage = "Specifies whether the OS Image Scheduled event is enabled or disabled.")]
382+
public SwitchParameter OSImageScheduledEventEnabled { get; set; }
383+
384+
[Parameter(
385+
Mandatory = false,
386+
HelpMessage = "The length of time a virtual machine being reimaged or having its OS upgraded will have to potentially approve the OS Image Scheduled Event before the event is auto approved (timed out). The configuration is specified in ISO 8601 format, with the value set to 15 minutes (PT15M).")]
387+
public string OSImageScheduledEventNotBeforeTimeoutInMinutes { get; set; }
388+
379389
private void BuildPatchObject()
380390
{
381391
if (this.IsParameterBound(c => c.AutomaticOSUpgrade))
@@ -1227,6 +1237,48 @@ private void BuildPatchObject()
12271237
this.VirtualMachineScaleSet.VirtualMachineProfile.UserData = this.UserData;
12281238
}
12291239

1240+
if (this.IsParameterBound(c => c.OSImageScheduledEventEnabled))
1241+
{
1242+
if (this.VirtualMachineScaleSetUpdate == null)
1243+
{
1244+
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
1245+
}
1246+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile == null)
1247+
{
1248+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile();
1249+
}
1250+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile == null)
1251+
{
1252+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile = new ScheduledEventsProfile();
1253+
}
1254+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile == null)
1255+
{
1256+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile = new OSImageNotificationProfile();
1257+
}
1258+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.Enable = this.OSImageScheduledEventEnabled;
1259+
}
1260+
1261+
if (this.IsParameterBound(c => c.OSImageScheduledEventNotBeforeTimeoutInMinutes))
1262+
{
1263+
if (this.VirtualMachineScaleSetUpdate == null)
1264+
{
1265+
this.VirtualMachineScaleSetUpdate = new VirtualMachineScaleSetUpdate();
1266+
}
1267+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile == null)
1268+
{
1269+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile = new VirtualMachineScaleSetUpdateVMProfile();
1270+
}
1271+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile == null)
1272+
{
1273+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile = new ScheduledEventsProfile();
1274+
}
1275+
if (this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile == null)
1276+
{
1277+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile = new OSImageNotificationProfile();
1278+
}
1279+
this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout = this.OSImageScheduledEventNotBeforeTimeoutInMinutes;
1280+
}
1281+
12301282
if (this.VirtualMachineScaleSetUpdate != null
12311283
&& this.VirtualMachineScaleSetUpdate.VirtualMachineProfile != null
12321284
&& this.VirtualMachineScaleSetUpdate.VirtualMachineProfile.OsProfile != null

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

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ New-AzVmssConfig [[-Overprovision] <Boolean>] [[-Location] <String>] [-EdgeZone
3030
[-ScaleInPolicy <String[]>] [-EncryptionAtHost] [-OrchestrationMode <String>]
3131
[-CapacityReservationGroupId <String>] [-UserData <String>] [-AutomaticRepairAction <String>]
3232
[-BaseRegularPriorityCount <Int32>] [-RegularPriorityPercentage <Int32>] [-ImageReferenceId <String>]
33-
[-SharedGalleryImageId <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
34-
[<CommonParameters>]
33+
[-SharedGalleryImageId <String>] [-OSImageScheduledEventEnabled]
34+
[-OSImageScheduledEventNotBeforeTimeoutInMinutes <String>] [-DefaultProfile <IAzureContextContainer>]
35+
[-WhatIf] [-Confirm] [<CommonParameters>]
3536
```
3637

3738
### ExplicitIdentityParameterSet
@@ -51,7 +52,8 @@ New-AzVmssConfig [[-Overprovision] <Boolean>] [[-Location] <String>] [-EdgeZone
5152
[-ScaleInPolicy <String[]>] -IdentityType <ResourceIdentityType> [-IdentityId <String[]>] [-EncryptionAtHost]
5253
[-OrchestrationMode <String>] [-CapacityReservationGroupId <String>] [-UserData <String>]
5354
[-AutomaticRepairAction <String>] [-BaseRegularPriorityCount <Int32>] [-RegularPriorityPercentage <Int32>]
54-
[-ImageReferenceId <String>] [-SharedGalleryImageId <String>] [-DefaultProfile <IAzureContextContainer>]
55+
[-ImageReferenceId <String>] [-SharedGalleryImageId <String>] [-OSImageScheduledEventEnabled]
56+
[-OSImageScheduledEventNotBeforeTimeoutInMinutes <String>] [-DefaultProfile <IAzureContextContainer>]
5557
[-WhatIf] [-Confirm] [<CommonParameters>]
5658
```
5759

@@ -111,6 +113,52 @@ Creates a VMSS configuration object. (autogenerated)
111113
New-AzVmssConfig -Location <String> -SkuCapacity 2 -SkuName 'Standard_A0' -UpgradePolicyMode Automatic -IdentityType SystemAssigned;
112114
```
113115

116+
### Example 4: Create a VMSS with the OS Image Scheduled Events enabled
117+
```powershell
118+
$publisher = "MicrosoftWindowsServer";
119+
$offer = "WindowsServer";
120+
$imgSku = "2019-Datacenter";
121+
$version = "latest";
122+
$vmssName = 'vmss' + $rgname;
123+
$vmssSku = "Standard_D2s_v3";
124+
$vmssname = "vmss" + $rgname;
125+
$domainNameLabel = "d" + $rgname;
126+
$username = <Username>;
127+
$password = <Password>;
128+
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force
129+
130+
$credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword);
131+
132+
# SRP
133+
$stoname = 'sto' + $rgname;
134+
$stotype = 'Standard_GRS';
135+
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
136+
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;
137+
138+
# NRP
139+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
140+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
141+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
142+
$subnetId = $vnet.Subnets[0].Id;
143+
144+
# Create VMSS with managed disk
145+
$timeoutValue = 'PT15M';
146+
$ipCfg = New-AzVmssIpConfig -Name 'test' -SubnetId $subnetId;
147+
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName $vmssSku -OSImageScheduledEventEnabled -OSImageScheduledEventNotBeforeTimeoutInMinutes $timeoutValue -UpgradePolicyMode "Automatic" `
148+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
149+
| Set-AzVmssOsProfile -ComputerNamePrefix 'test' -AdminUsername $username -AdminPassword $password `
150+
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
151+
-ImageReferenceOffer $offer -ImageReferenceSku $imgSku -ImageReferenceVersion $version `
152+
-ImageReferencePublisher $publisher;
153+
154+
$result = New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;
155+
156+
$vmss = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
157+
# $vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.Enable is the OSImageScheduledEventEnabled flag.
158+
# $vmss.VirtualMachineProfile.ScheduledEventsProfile.OsImageNotificationProfile.NotBeforeTimeout is the timeout value 'PT15M'.
159+
160+
```
161+
114162
## PARAMETERS
115163

116164
### -AutomaticRepairAction
@@ -486,6 +534,36 @@ Accept pipeline input: True (ByPropertyName)
486534
Accept wildcard characters: False
487535
```
488536
537+
### -OSImageScheduledEventEnabled
538+
Specifies whether the OS Image Scheduled event is enabled or disabled.
539+
540+
```yaml
541+
Type: System.Management.Automation.SwitchParameter
542+
Parameter Sets: (All)
543+
Aliases:
544+
545+
Required: False
546+
Position: Named
547+
Default value: None
548+
Accept pipeline input: False
549+
Accept wildcard characters: False
550+
```
551+
552+
### -OSImageScheduledEventNotBeforeTimeoutInMinutes
553+
The length of time a virtual machine being reimaged or having its OS upgraded will have to potentially approve the OS Image Scheduled Event before the event is auto approved (timed out). The configuration is specified in ISO 8601 format, with the value set to 15 minutes (PT15M).
554+
555+
```yaml
556+
Type: System.String
557+
Parameter Sets: (All)
558+
Aliases:
559+
560+
Required: False
561+
Position: Named
562+
Default value: None
563+
Accept pipeline input: False
564+
Accept wildcard characters: False
565+
```
566+
489567
### -OsProfile
490568
Specifies the operating system profile object that contains the operating system properties for the VMSS configuration.
491569
You can use the **Set-AzVmssOsProfile** cmdlet to set this object.

0 commit comments

Comments
 (0)