Skip to content

Commit

Permalink
[Compute] az vmss create/update: Add --skuprofile-vmsizes and `--…
Browse files Browse the repository at this point in the history
…skuprofile-allocation-strategy` for Instance Mix (Azure#29906)
  • Loading branch information
msdorahu authored Oct 14, 2024
1 parent 8d82dce commit 238493c
Show file tree
Hide file tree
Showing 6 changed files with 1,688 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ def load_arguments(self, _):
options_list=['--security-posture-reference-exclude-extensions', '--exclude-extensions'],
help='List of virtual machine extensions to exclude when applying the Security Posture. Either a Json string or a file path is acceptable. '
'Please refer to https://docs.microsoft.com/rest/api/compute/virtualmachinescalesets/get#virtualmachineextension for the data format.')
c.argument('skuprofile_vmsizes', nargs='+', min_api='2024-07-01', help='A list of VM sizes in the scale set. See https://azure.microsoft.com/pricing/details/virtual-machines/ for size info.')
c.argument('skuprofile_allostrat', options_list=['--skuprofile-allocation-strategy', '--sku-allocat-strat'], arg_type=get_enum_type(['LowestPrice', 'CapacityOptimized']), min_api='2024-07-01', help='Allocation strategy for vm sizes in SKU profile.')

with self.argument_context('vmss create', arg_group='Network Balancer') as c:
c.argument('application_gateway', help='Name to use when creating a new application gateway (default) or referencing an existing one. Can also reference an existing application gateway by ID or specify "" for none.', options_list=['--app-gateway'])
Expand Down Expand Up @@ -838,6 +840,8 @@ def load_arguments(self, _):
c.argument('ephemeral_os_disk', arg_type=get_three_state_flag(), min_api='2024-03-01', help='Allow you to specify the ephemeral disk settings for the operating system disk. Specify it to false to set ephemeral disk setting as empty and migrate it to non ephemeral')
c.argument('ephemeral_os_disk_option', options_list=['--ephemeral-os-disk-option', '--ephemeral-option'], arg_type=get_enum_type(self.get_models('DiffDiskOptions')), min_api='2024-03-01', help='Specify the ephemeral disk settings for operating system disk.')
c.argument('zones', zones_type, min_api='2023-03-01')
c.argument('skuprofile_vmsizes', nargs='+', min_api='2024-07-01', help='A list of VM sizes in the scale set. See https://azure.microsoft.com/pricing/details/virtual-machines/ for size info.')
c.argument('skuprofile_allostrat', options_list=['--skuprofile-allocation-strategy', '--sku-allocat-strat'], arg_type=get_enum_type(['LowestPrice', 'CapacityOptimized']), min_api='2024-07-01', help='Allocation strategy for vm sizes in SKU profile.')

with self.argument_context('vmss update', min_api='2018-10-01', arg_group='Automatic Repairs') as c:

Expand Down
16 changes: 15 additions & 1 deletion src/azure-cli/azure/cli/command_modules/vm/_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
security_posture_reference_id=None, security_posture_reference_exclude_extensions=None,
enable_resilient_vm_creation=None, enable_resilient_vm_deletion=None,
additional_scheduled_events=None, enable_user_reboot_scheduled_events=None,
enable_user_redeploy_scheduled_events=None):
enable_user_redeploy_scheduled_events=None,
skuprofile_vmsizes=None, skuprofile_allostrat=None):

# Build IP configuration
ip_configuration = {}
Expand Down Expand Up @@ -1530,6 +1531,19 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
vmss_properties['additionalCapabilities'] = {}
vmss_properties['additionalCapabilities']['hibernationEnabled'] = enable_hibernation

if skuprofile_vmsizes:
sku_profile_vmsizes_list = []
for vm_size in skuprofile_vmsizes:
vmsize_obj = {
'name': vm_size
}
sku_profile_vmsizes_list.append(vmsize_obj)
sku_profile = {
'vmSizes': sku_profile_vmsizes_list,
'allocationStrategy': skuprofile_allostrat
}
vmss_properties['skuProfile'] = sku_profile

vmss = {
'type': 'Microsoft.Compute/virtualMachineScaleSets',
'name': name,
Expand Down
24 changes: 21 additions & 3 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3182,7 +3182,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None,
security_posture_reference_id=None, security_posture_reference_exclude_extensions=None,
enable_resilient_creation=None, enable_resilient_deletion=None,
additional_scheduled_events=None, enable_user_reboot_scheduled_events=None,
enable_user_redeploy_scheduled_events=None):
enable_user_redeploy_scheduled_events=None,
skuprofile_vmsizes=None, skuprofile_allostrat=None):
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.util import random_string, hash_string
from azure.cli.core.commands.arm import ArmTemplateBuilder
Expand Down Expand Up @@ -3495,7 +3496,9 @@ def _get_public_ip_address_allocation(value, sku):
enable_resilient_vm_deletion=enable_resilient_deletion,
additional_scheduled_events=additional_scheduled_events,
enable_user_reboot_scheduled_events=enable_user_reboot_scheduled_events,
enable_user_redeploy_scheduled_events=enable_user_redeploy_scheduled_events)
enable_user_redeploy_scheduled_events=enable_user_redeploy_scheduled_events,
skuprofile_vmsizes=skuprofile_vmsizes,
skuprofile_allostrat=skuprofile_allostrat)

vmss_resource['dependsOn'] = vmss_dependencies

Expand Down Expand Up @@ -3934,7 +3937,8 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
max_surge=None, enable_resilient_creation=None, enable_resilient_deletion=None,
ephemeral_os_disk=None, ephemeral_os_disk_option=None, zones=None, additional_scheduled_events=None,
enable_user_reboot_scheduled_events=None, enable_user_redeploy_scheduled_events=None,
upgrade_policy_mode=None, enable_auto_os_upgrade=None, **kwargs):
upgrade_policy_mode=None, enable_auto_os_upgrade=None,
skuprofile_vmsizes=None, skuprofile_allostrat=None, **kwargs):
vmss = kwargs['parameters']
aux_subscriptions = None
# pylint: disable=too-many-boolean-expressions
Expand Down Expand Up @@ -4170,6 +4174,20 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
else:
vmss.sku.name = vm_sku

sku_profile = dict()
if skuprofile_vmsizes is not None or skuprofile_allostrat is not None:
if skuprofile_vmsizes is not None:
sku_profile_vmsizes_list = []
for vm_size in skuprofile_vmsizes:
vmsize_obj = {
'name': vm_size
}
sku_profile_vmsizes_list.append(vmsize_obj)
sku_profile['vmSizes'] = sku_profile_vmsizes_list
if skuprofile_allostrat is not None:
sku_profile['allocationStrategy'] = skuprofile_allostrat
vmss.sku_profile = sku_profile

if ephemeral_os_disk_placement is not None or ephemeral_os_disk_option is not None:
if vmss.virtual_machine_profile.storage_profile.os_disk.diff_disk_settings is not None:
vmss.virtual_machine_profile.storage_profile.os_disk.diff_disk_settings.placement = \
Expand Down
Loading

0 comments on commit 238493c

Please sign in to comment.