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

New VMSS Instance Mix Flex Create and Update Parameters for Powershell #25980

Merged
merged 9 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -424,6 +424,13 @@ public void TestVirtualMachineScaleSetDefaultImgWhenStandard()
TestRunner.RunTestScript("Test-VirtualMachineScaleSetDefaultImgWhenStandard");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScaleSetSkuProfile()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetSkuProfile");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestResiliencyPolicyVMSS()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5314,6 +5314,158 @@ function Test-VirtualMachineScaleSetDefaultImgWhenStandard
}
}

<#
.SYNOPSIS
Test Virtual Machine Scale Set with SkuProfile
#>
function Test-VirtualMachineScaleSetSkuProfile
{
# Setup
$rgname = Get-ComputeTestResourceName
$loc = Get-ComputeVMLocation;

# Basic case
try
{
# Common
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$vmssName = 'vs' + $rgname;

$domainNameLabel1 = "d1" + $rgname;
$enable = $true;
$adminUsername = Get-ComputeTestResourceName;
$password = Get-PasswordForVM;
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);

$vmss = New-AzVmss -ResourceGroupName $rgname -Credential $cred -VMScaleSetName $vmssName -DomainNameLabel $domainNameLabel1 `
-VMSize "Mix" -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4");

Assert-AreEqual $vmss.OrchestrationMode "Flexible";
Assert-AreEqual $vmss.Sku.Name "Mix";
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "LowestPrice";
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}

# Changing allocation strategy
try
{
# Common
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$vmssName = 'vs' + $rgname;

$domainNameLabel1 = "d1" + $rgname;
$enable = $true;
$adminUsername = Get-ComputeTestResourceName;
$password = Get-PasswordForVM;
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);

$vmss = New-AzVmss -ResourceGroupName $rgname -Credential $cred -VMScaleSetName $vmssName -DomainNameLabel $domainNameLabel1 `
-SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4") -SkuProfileAllocationStrategy "CapacityOptimized";

Assert-AreEqual $vmss.OrchestrationMode "Flexible";
Assert-AreEqual $vmss.Sku.Name "Mix";
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "CapacityOptimized";
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}

# With azvmss config and update
try
{
# Common
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$vmssName = 'vs' + $rgname;

$domainNameLabel1 = "d1" + $rgname;
$enable = $true;
$adminUsername = Get-ComputeTestResourceName;
$password = Get-PasswordForVM;
$adminPassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);

$vmss = New-AzVmssConfig -Location $loc -Zone "1" -SkuCapacity 2 -SkuName 'Mix' -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4");

Assert-AreEqual $vmss.Sku.Name "Mix";
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "LowestPrice";
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";

$vmss = New-AzVmssConfig -Location $loc -Zone "1" -SkuCapacity 2 -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4") -SkuProfileAllocationStrategy "CapacityOptimized";

Assert-AreEqual $vmss.Sku.Name "Mix";
Assert-AreEqual $vmss.SkuProfile.AllocationStrategy "CapacityOptimized";
Assert-AreEqual $vmss.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
Assert-AreEqual $vmss.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";

$stnd = "Standard";
$ipName = Get-ComputeTestResourceName

# SRP
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;

# NRP
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;

# New VMSS Parameters
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);

$imgRef = Get-DefaultCRPImage -loc $loc -New $True;
$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId -PublicIPAddressConfigurationName $ipName -PublicIPAddressConfigurationIdleTimeoutInMinutes 10 -DnsSetting "testvmssdnscom" -PublicIPAddressVersion "IPv4";

$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -UpgradePolicyMode 'Manual' -EncryptionAtHost -SecurityType $stnd -SkuProfileVmSize @("Standard_D4s_v3", "Standard_D4s_v4") -SkuProfileAllocationStrategy "CapacityOptimized"`
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
| Set-AzVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion 'latest' `
-ImageReferencePublisher $imgRef.PublisherName;

# creating new-azvmss using New-VmssConfig
$vmssResult = New-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss

Assert-AreEqual $vmssResult.Sku.Name "Mix";
Assert-AreEqual $vmssResult.SkuProfile.AllocationStrategy "CapacityOptimized";
Assert-AreEqual $vmssResult.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
Assert-AreEqual $vmssResult.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";

# update vmss
$vmssUpdate = Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -SkuCapacity 3 -SkuProfileVmSize @($vmSize1, $vmSize2) -SkuProfileAllocationStrategy "CapacityOptimized";

$vmssGet = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;

Assert-AreEqual $vmssGet.Sku.Name "Mix";
Assert-AreEqual $vmssGet.SkuProfile.AllocationStrategy "CapacityOptimized";
Assert-AreEqual $vmssGet.SkuProfile.VMSizes[0].Name "Standard_D4s_v3";
Assert-AreEqual $vmssGet.SkuProfile.VMSizes[1].Name "Standard_D4s_v4";
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Create a VMSS using New-Azvmssconfig
Expand Down

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-->
## Upcoming Release
* Added `SkuProfileVmSize` and `SkuProfileAllocationStrategy` parameters to `New-AzVmss`, `New-AzVmssConfig`, and `Update-AzVmss` cmdlets for VMSS Instance Mix operations.
* 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).
* Added `EnableResilientVMCreate` and `EnableResilientVMDelete` parameters to `Update-AzVmss` and `New-AzVmssConfig` cmdlets for enhanced VM resilience options.

Expand Down Expand Up @@ -783,4 +784,4 @@
- The type of InstanceView property of PSVirtualMachineScaleSetVM object is changed from VirtualMachineInstanceView to VirtualMachineScaleSetVMInstanceView.
- AutoOSUpgradePolicy and AutomaticOSUpgrade properties are removed from UpgradePolicy property.
- The type of Sku property in PSSnapshotUpdate object is changed from DiskSku to SnapshotSku.
- VmScaleSetVMParameterSet is removed from Add-AzVMDataDisk.
- VmScaleSetVMParameterSet is removed from Add-AzVMDataDisk.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public string ResourceGroupName
public PSVirtualMachineScaleSetVMProfile VirtualMachineProfile { get; set; }
public string OrchestrationMode { get; set; }
public PriorityMixPolicy PriorityMixPolicy { get; set; }
public SkuProfile SkuProfile { get; set; }
//
// Summary:
// Gets specifies the time at which the Virtual Machine Scale Set resource was created.&lt;br&gt;&lt;br&gt;Minimum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ namespace Microsoft.Azure.Commands.Compute.Automation
[OutputType(typeof(PSVirtualMachineScaleSet))]
public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
{

private const string ExplicitIdentityParameterSet = "ExplicitIdentityParameterSet",
DefaultParameterSetName = "DefaultParameterSet";
DefaultParameterSetName = "DefaultParameterSet",
VmSizeMix = "Mix";
[Parameter(
Mandatory = false,
Position = 0,
Expand Down Expand Up @@ -274,13 +275,13 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
HelpMessage = "Specifies the orchestration mode for the virtual machine scale set.")]
[PSArgumentCompleter("Uniform", "Flexible")]
public string OrchestrationMode { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Id of the capacity reservation Group that is used to allocate.")]
[ResourceIdCompleter("Microsoft.Compute/capacityReservationGroups")]
public string CapacityReservationGroupId { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "UserData for the VM, which will be Base64 encoded. Customer should not pass any secrets in here.",
Expand Down Expand Up @@ -316,7 +317,7 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
Mandatory = false,
HelpMessage = "Specified the shared gallery image unique id for vm deployment. This can be fetched from shared gallery image GET call.")]
public string SharedGalleryImageId { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Specifies whether the OS Image Scheduled event is enabled or disabled.")]
Expand Down Expand Up @@ -347,6 +348,17 @@ public partial class NewAzureRmVmssConfigCommand : Microsoft.Azure.Commands.Reso
Mandatory = false)]
public bool? EnableSecureBoot { get; set; } = null;

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
public string[] SkuProfileVmSize { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
[PSArgumentCompleter("LowestPrice", "CapacityOptimized")]
public string SkuProfileAllocationStrategy { 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.")]
Expand Down Expand Up @@ -400,6 +412,9 @@ private void Run()
// PriorityMix
PriorityMixPolicy vPriorityMixPolicy = null;

// SkuProfile
SkuProfile vSkuProfile = null;

//ResiliencyPolicy
ResiliencyPolicy vResiliencyPolicy = null;

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

if (this.IsParameterBound(c=> c.EnableResilientVMDelete))
if (this.IsParameterBound(c => c.EnableResilientVMDelete))
{
if (vResiliencyPolicy == null)
{
Expand Down Expand Up @@ -501,7 +516,7 @@ private void Run()
}
vUpgradePolicy.RollingUpgradePolicy = this.RollingUpgradePolicy;
}

if (this.EnableAutomaticOSUpgrade.IsPresent)
{
if (vUpgradePolicy == null)
Expand Down Expand Up @@ -537,7 +552,7 @@ private void Run()
vVirtualMachineProfile.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost;
}

if (this.IsParameterBound(c=> c.CapacityReservationGroupId))
if (this.IsParameterBound(c => c.CapacityReservationGroupId))
{
if (vVirtualMachineProfile == null)
{
Expand Down Expand Up @@ -831,7 +846,7 @@ private void Run()
{
vExtendedLocation = new CM.PSExtendedLocation(this.EdgeZone);
}

if (this.IsParameterBound(c => c.UserData))
{
if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData))
Expand Down Expand Up @@ -874,6 +889,40 @@ private void Run()
vPriorityMixPolicy.RegularPriorityPercentageAboveBase = this.RegularPriorityPercentage;
}

if (this.IsParameterBound(c => c.SkuProfileVmSize))
{
if (vSkuProfile == null)
{
vSkuProfile = new SkuProfile();
vSkuProfile.VmSizes = new List<SkuProfileVMSize>();
}
foreach (string vmSize in this.SkuProfileVmSize)
{
vSkuProfile.VmSizes.Add(new SkuProfileVMSize()
{
Name = vmSize,
});
}

if (this.IsParameterBound(c => c.SkuProfileAllocationStrategy))
{
vSkuProfile.AllocationStrategy = this.SkuProfileAllocationStrategy;
}
else
{
vSkuProfile.AllocationStrategy = "LowestPrice";
haagha marked this conversation as resolved.
Show resolved Hide resolved
}

if (!this.IsParameterBound(c => c.SkuName))
{
if (vSku == null)
{
vSku = new Sku();
}
vSku.Name = VmSizeMix;
msdorahu marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (this.IsParameterBound(c => c.ImageReferenceId))
{
if (vVirtualMachineProfile == null)
Expand Down Expand Up @@ -970,6 +1019,7 @@ private void Run()
OrchestrationMode = this.IsParameterBound(c => c.OrchestrationMode) ? this.OrchestrationMode : null,
SpotRestorePolicy = this.IsParameterBound(c => c.EnableSpotRestore) ? new SpotRestorePolicy(true, this.SpotRestoreTimeout) : null,
PriorityMixPolicy = vPriorityMixPolicy,
SkuProfile = vSkuProfile,
ResiliencyPolicy = vResiliencyPolicy
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public override void ExecuteCmdlet()

flexibleOrchestrationModeDefaultParameters(parameters);
checkFlexibleOrchestrationModeParamsDefaultParamSet(parameters);
}
}

if (parameters.VirtualMachineProfile?.SecurityProfile?.SecurityType?.ToLower() == ConstantValues.TrustedLaunchSecurityType || parameters.VirtualMachineProfile?.SecurityProfile?.SecurityType?.ToLower() == ConstantValues.ConfidentialVMSecurityType)
{
if (parameters.VirtualMachineProfile?.SecurityProfile?.UefiSettings != null)
Expand Down Expand Up @@ -419,5 +419,4 @@ private int convertAPIVersionToInt(string networkAPIVersion)
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; }
}
}

}
Loading