Skip to content

Commit e5aa20f

Browse files
msdorahuPSCmdAssistanthaaghamsJinLei
authored
New VMSS Instance Mix Flex Create and Update Parameters for Powershell (#25980)
* Autogen code * Autogen code by build fixer * first pass * add tests * fix merge conflict * change to string * nit * Adding help --------- Co-authored-by: PSCmdAssistant <[email protected]> Co-authored-by: haagha <[email protected]> Co-authored-by: Jin Lei <[email protected]>
1 parent 4fb64ab commit e5aa20f

File tree

14 files changed

+9990
-71
lines changed

14 files changed

+9990
-71
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ public void TestVirtualMachineScaleSetDefaultImgWhenStandard()
424424
TestRunner.RunTestScript("Test-VirtualMachineScaleSetDefaultImgWhenStandard");
425425
}
426426

427+
[Fact]
428+
[Trait(Category.AcceptanceType, Category.CheckIn)]
429+
public void TestVirtualMachineScaleSetSkuProfile()
430+
{
431+
TestRunner.RunTestScript("Test-VirtualMachineScaleSetSkuProfile");
432+
}
433+
427434
[Fact]
428435
[Trait(Category.AcceptanceType, Category.CheckIn)]
429436
public void TestResiliencyPolicyVMSS()

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

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,6 +5314,158 @@ function Test-VirtualMachineScaleSetDefaultImgWhenStandard
53145314
}
53155315
}
53165316

5317+
<#
5318+
.SYNOPSIS
5319+
Test Virtual Machine Scale Set with SkuProfile
5320+
#>
5321+
function Test-VirtualMachineScaleSetSkuProfile
5322+
{
5323+
# Setup
5324+
$rgname = Get-ComputeTestResourceName
5325+
$loc = Get-ComputeVMLocation;
5326+
5327+
# Basic case
5328+
try
5329+
{
5330+
# Common
5331+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
5332+
5333+
$vmssName = 'vs' + $rgname;
5334+
5335+
$domainNameLabel1 = "d1" + $rgname;
5336+
$enable = $true;
5337+
$adminUsername = Get-ComputeTestResourceName;
5338+
$password = Get-PasswordForVM;
5339+
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
5340+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
5341+
5342+
$vmss = New-AzVmss -ResourceGroupName $rgname -Credential $cred -VMScaleSetName $vmssName -DomainNameLabel $domainNameLabel1 `
5343+
-VMSize "Mix" -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4");
5344+
5345+
Assert-AreEqual $vmss.OrchestrationMode "Flexible";
5346+
Assert-AreEqual $vmss.Sku.Name "Mix";
5347+
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "LowestPrice";
5348+
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
5349+
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
5350+
}
5351+
finally
5352+
{
5353+
# Cleanup
5354+
Clean-ResourceGroup $rgname
5355+
}
5356+
5357+
# Changing allocation strategy
5358+
try
5359+
{
5360+
# Common
5361+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
5362+
5363+
$vmssName = 'vs' + $rgname;
5364+
5365+
$domainNameLabel1 = "d1" + $rgname;
5366+
$enable = $true;
5367+
$adminUsername = Get-ComputeTestResourceName;
5368+
$password = Get-PasswordForVM;
5369+
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
5370+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
5371+
5372+
$vmss = New-AzVmss -ResourceGroupName $rgname -Credential $cred -VMScaleSetName $vmssName -DomainNameLabel $domainNameLabel1 `
5373+
-SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4") -SkuProfileAllocationStrategy "CapacityOptimized";
5374+
5375+
Assert-AreEqual $vmss.OrchestrationMode "Flexible";
5376+
Assert-AreEqual $vmss.Sku.Name "Mix";
5377+
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "CapacityOptimized";
5378+
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
5379+
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
5380+
}
5381+
finally
5382+
{
5383+
# Cleanup
5384+
Clean-ResourceGroup $rgname
5385+
}
5386+
5387+
# With azvmss config and update
5388+
try
5389+
{
5390+
# Common
5391+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
5392+
5393+
$vmssName = 'vs' + $rgname;
5394+
5395+
$domainNameLabel1 = "d1" + $rgname;
5396+
$enable = $true;
5397+
$adminUsername = Get-ComputeTestResourceName;
5398+
$password = Get-PasswordForVM;
5399+
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
5400+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
5401+
5402+
$vmss = New-AzVmssConfig -Location $loc -Zone "1" -SkuCapacity 2 -SkuName 'Mix' -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4");
5403+
5404+
Assert-AreEqual $vmss.Sku.Name "Mix";
5405+
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "LowestPrice";
5406+
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
5407+
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
5408+
5409+
$vmss = New-AzVmssConfig -Location $loc -Zone "1" -SkuCapacity 2 -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4") -SkuProfileAllocationStrategy "CapacityOptimized";
5410+
5411+
Assert-AreEqual $vmss.Sku.Name "Mix";
5412+
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "CapacityOptimized";
5413+
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
5414+
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
5415+
5416+
$stnd = "Standard";
5417+
$ipName = Get-ComputeTestResourceName
5418+
5419+
# SRP
5420+
$stoname = 'sto' + $rgname;
5421+
$stotype = 'Standard_GRS';
5422+
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
5423+
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;
5424+
5425+
# NRP
5426+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
5427+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
5428+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
5429+
$subnetId = $vnet.Subnets[0].Id;
5430+
5431+
# New VMSS Parameters
5432+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
5433+
5434+
$imgRef = Get-DefaultCRPImage -loc $loc -New $True;
5435+
$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId -PublicIPAddressConfigurationName $ipName -PublicIPAddressConfigurationIdleTimeoutInMinutes 10 -DnsSetting "testvmssdnscom" -PublicIPAddressVersion "IPv4";
5436+
5437+
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -UpgradePolicyMode 'Manual' -EncryptionAtHost -SecurityType $stnd -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4") -SkuProfileAllocationStrategy "CapacityOptimized"`
5438+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
5439+
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
5440+
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
5441+
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion 'latest' `
5442+
-ImageReferencePublisher $imgRef.PublisherName;
5443+
5444+
# creating new-azvmss using New-VmssConfig
5445+
$vmssResult = New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss
5446+
5447+
Assert-AreEqual $vmssResult.Sku.Name "Mix";
5448+
Assert-AreEqual $vmssResult.SkuProfile.AllocationStrategy "CapacityOptimized";
5449+
Assert-AreEqual $vmssResult.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
5450+
Assert-AreEqual $vmssResult.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
5451+
5452+
# update vmss
5453+
$vmssUpdate = Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -SkuCapacity 3 -SkuProfileVmSize @($vmSize1, $vmSize2) -SkuProfileAllocationStrategy "CapacityOptimized";
5454+
5455+
$vmssGet = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
5456+
5457+
Assert-AreEqual $vmssGet.Sku.Name "Mix";
5458+
Assert-AreEqual $vmssGet.SkuProfile.AllocationStrategy "CapacityOptimized";
5459+
Assert-AreEqual $vmssGet.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
5460+
Assert-AreEqual $vmssGet.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
5461+
}
5462+
finally
5463+
{
5464+
# Cleanup
5465+
Clean-ResourceGroup $rgname
5466+
}
5467+
}
5468+
53175469
<#
53185470
.SYNOPSIS
53195471
Create a VMSS using New-Azvmssconfig

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

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

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added `SkuProfileVmSize` and `SkuProfileAllocationStrategy` parameters to `New-AzVmss`, `New-AzVmssConfig`, and `Update-AzVmss` cmdlets for VMSS Instance Mix operations.
2324
* Added a new optional parameter `-GenerateSshKey-type` to the `New-AzVM` cmdlet, allowing users to specify the type of SSH key to generate (Ed25519 or RSA).
2425
* Added `EnableResilientVMCreate` and `EnableResilientVMDelete` parameters to `Update-AzVmss` and `New-AzVmssConfig` cmdlets for enhanced VM resilience options.
2526

@@ -783,4 +784,4 @@
783784
- The type of InstanceView property of PSVirtualMachineScaleSetVM object is changed from VirtualMachineInstanceView to VirtualMachineScaleSetVMInstanceView.
784785
- AutoOSUpgradePolicy and AutomaticOSUpgrade properties are removed from UpgradePolicy property.
785786
- The type of Sku property in PSSnapshotUpdate object is changed from DiskSku to SnapshotSku.
786-
- VmScaleSetVMParameterSet is removed from Add-AzVMDataDisk.
787+
- VmScaleSetVMParameterSet is removed from Add-AzVMDataDisk.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public string ResourceGroupName
6868
public PSVirtualMachineScaleSetVMProfile VirtualMachineProfile { get; set; }
6969
public string OrchestrationMode { get; set; }
7070
public PriorityMixPolicy PriorityMixPolicy { get; set; }
71+
public SkuProfile SkuProfile { get; set; }
7172
//
7273
// Summary:
7374
// Gets specifies the time at which the Virtual Machine Scale Set resource was created.&lt;br&gt;&lt;br&gt;Minimum

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

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ namespace Microsoft.Azure.Commands.Compute.Automation
3939
[OutputType(typeof(PSVirtualMachineScaleSet))]
4040
public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
4141
{
42-
42+
4343
private const string ExplicitIdentityParameterSet = "ExplicitIdentityParameterSet",
44-
DefaultParameterSetName = "DefaultParameterSet";
44+
DefaultParameterSetName = "DefaultParameterSet",
45+
VmSizeMix = "Mix";
4546
[Parameter(
4647
Mandatory = false,
4748
Position = 0,
@@ -274,13 +275,13 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
274275
HelpMessage = "Specifies the orchestration mode for the virtual machine scale set.")]
275276
[PSArgumentCompleter("Uniform", "Flexible")]
276277
public string OrchestrationMode { get; set; }
277-
278+
278279
[Parameter(
279280
Mandatory = false,
280281
HelpMessage = "Id of the capacity reservation Group that is used to allocate.")]
281282
[ResourceIdCompleter("Microsoft.Compute/capacityReservationGroups")]
282283
public string CapacityReservationGroupId { get; set; }
283-
284+
284285
[Parameter(
285286
Mandatory = false,
286287
HelpMessage = "UserData for the VM, which will be Base64 encoded. Customer should not pass any secrets in here.",
@@ -316,7 +317,7 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
316317
Mandatory = false,
317318
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
318319
public string SharedGalleryImageId { get; set; }
319-
320+
320321
[Parameter(
321322
Mandatory = false,
322323
HelpMessage = "Specifies whether the OS Image Scheduled event is enabled or disabled.")]
@@ -347,6 +348,17 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
347348
Mandatory = false)]
348349
public bool? EnableSecureBoot { get; set; } = null;
349350

351+
[Parameter(
352+
Mandatory = false,
353+
ValueFromPipelineByPropertyName = true)]
354+
public string[] SkuProfileVmSize { get; set; }
355+
356+
[Parameter(
357+
Mandatory = false,
358+
ValueFromPipelineByPropertyName = true)]
359+
[PSArgumentCompleter("LowestPrice", "CapacityOptimized")]
360+
public string SkuProfileAllocationStrategy { get; set; }
361+
350362
[Parameter(
351363
Mandatory = false,
352364
HelpMessage = "Specifies whether resilient VM creation should be enabled on the virtual machine scale set. The default value is false.")]
@@ -400,6 +412,9 @@ private void Run()
400412
// PriorityMix
401413
PriorityMixPolicy vPriorityMixPolicy = null;
402414

415+
// SkuProfile
416+
SkuProfile vSkuProfile = null;
417+
403418
//ResiliencyPolicy
404419
ResiliencyPolicy vResiliencyPolicy = null;
405420

@@ -421,7 +436,7 @@ private void Run()
421436
vResiliencyPolicy.ResilientVMCreationPolicy = new ResilientVMCreationPolicy(this.EnableResilientVMCreate.ToBool());
422437
}
423438

424-
if (this.IsParameterBound(c=> c.EnableResilientVMDelete))
439+
if (this.IsParameterBound(c => c.EnableResilientVMDelete))
425440
{
426441
if (vResiliencyPolicy == null)
427442
{
@@ -501,7 +516,7 @@ private void Run()
501516
}
502517
vUpgradePolicy.RollingUpgradePolicy = this.RollingUpgradePolicy;
503518
}
504-
519+
505520
if (this.EnableAutomaticOSUpgrade.IsPresent)
506521
{
507522
if (vUpgradePolicy == null)
@@ -537,7 +552,7 @@ private void Run()
537552
vVirtualMachineProfile.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost;
538553
}
539554

540-
if (this.IsParameterBound(c=> c.CapacityReservationGroupId))
555+
if (this.IsParameterBound(c => c.CapacityReservationGroupId))
541556
{
542557
if (vVirtualMachineProfile == null)
543558
{
@@ -831,7 +846,7 @@ private void Run()
831846
{
832847
vExtendedLocation = new CM.PSExtendedLocation(this.EdgeZone);
833848
}
834-
849+
835850
if (this.IsParameterBound(c => c.UserData))
836851
{
837852
if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData))
@@ -874,6 +889,40 @@ private void Run()
874889
vPriorityMixPolicy.RegularPriorityPercentageAboveBase = this.RegularPriorityPercentage;
875890
}
876891

892+
if (this.IsParameterBound(c => c.SkuProfileVmSize))
893+
{
894+
if (vSkuProfile == null)
895+
{
896+
vSkuProfile = new SkuProfile();
897+
vSkuProfile.VmSizes = new List<SkuProfileVMSize>();
898+
}
899+
foreach (string vmSize in this.SkuProfileVmSize)
900+
{
901+
vSkuProfile.VmSizes.Add(new SkuProfileVMSize()
902+
{
903+
Name = vmSize,
904+
});
905+
}
906+
907+
if (this.IsParameterBound(c => c.SkuProfileAllocationStrategy))
908+
{
909+
vSkuProfile.AllocationStrategy = this.SkuProfileAllocationStrategy;
910+
}
911+
else
912+
{
913+
vSkuProfile.AllocationStrategy = "LowestPrice";
914+
}
915+
916+
if (!this.IsParameterBound(c => c.SkuName))
917+
{
918+
if (vSku == null)
919+
{
920+
vSku = new Sku();
921+
}
922+
vSku.Name = VmSizeMix;
923+
}
924+
}
925+
877926
if (this.IsParameterBound(c => c.ImageReferenceId))
878927
{
879928
if (vVirtualMachineProfile == null)
@@ -970,6 +1019,7 @@ private void Run()
9701019
OrchestrationMode = this.IsParameterBound(c => c.OrchestrationMode) ? this.OrchestrationMode : null,
9711020
SpotRestorePolicy = this.IsParameterBound(c => c.EnableSpotRestore) ? new SpotRestorePolicy(true, this.SpotRestoreTimeout) : null,
9721021
PriorityMixPolicy = vPriorityMixPolicy,
1022+
SkuProfile = vSkuProfile,
9731023
ResiliencyPolicy = vResiliencyPolicy
9741024
};
9751025

src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetCreateOrUpdateMethod.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ public override void ExecuteCmdlet()
122122

123123
flexibleOrchestrationModeDefaultParameters(parameters);
124124
checkFlexibleOrchestrationModeParamsDefaultParamSet(parameters);
125-
}
126-
125+
}
126+
127127
if (parameters.VirtualMachineProfile?.SecurityProfile?.SecurityType?.ToLower() == ConstantValues.TrustedLaunchSecurityType || parameters.VirtualMachineProfile?.SecurityProfile?.SecurityType?.ToLower() == ConstantValues.ConfidentialVMSecurityType)
128128
{
129129
if (parameters.VirtualMachineProfile?.SecurityProfile?.UefiSettings != null)
@@ -419,5 +419,4 @@ private int convertAPIVersionToInt(string networkAPIVersion)
419419
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.")]
420420
public string IfNoneMatch { get; set; }
421421
}
422-
}
423-
422+
}

0 commit comments

Comments
 (0)