Skip to content

Commit 9e76255

Browse files
authored
[Compute] az vmss create/update: Add new parameters --enable-automatic-zone-balancing to support setting automatic zone rebalancing policy (#31377)
1 parent db712c8 commit 9e76255

5 files changed

Lines changed: 4716 additions & 10 deletions

File tree

src/azure-cli/azure/cli/command_modules/vm/_params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ def load_arguments(self, _):
863863
c.argument('zone_balance', arg_type=get_three_state_flag(), min_api='2017-12-01', help='Whether to force strictly even Virtual Machine distribution cross x-zones in case there is zone outage.')
864864
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch", "Standard", "ConfidentialVM"], default=None),
865865
help='Specify the security type of the virtual machine scale set. The value Standard can be used if subscription has feature flag UseStandardSecurityType registered under Microsoft.Compute namespace. Refer to https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/preview-features for steps to enable required feature.')
866+
c.argument('enable_automatic_zone_balancing', arg_type=get_three_state_flag(), options_list=['--enable-automatic-zone-balancing', '--enable-zone-balancing'], min_api='2024-11-01', help='Specify whether automatic AZ balancing should be enabled on the virtualmachine scale set.')
867+
c.argument('automatic_zone_balancing_strategy', arg_type=get_enum_type(self.get_models('RebalanceStrategy')), options_list=['--automatic-zone-balancing-strategy', '--balancing-strategy'], min_api='2024-11-01', help='Type of rebalance strategy that will be used for rebalancing virtualmachines in the scale set across availability zones.')
868+
c.argument('automatic_zone_balancing_behavior', arg_type=get_enum_type(self.get_models('RebalanceBehavior')), options_list=['--automatic-zone-balancing-behavior', '--balancing-behavior'], min_api='2024-11-01', help='Type of rebalance behavior that will be used for recreating virtualmachines in the scale set across availability zones.')
866869

867870
with self.argument_context('vmss update') as c:
868871
c.argument('instance_id', id_part='child_name_1', help="Update the VM instance with this ID. If missing, update the VMSS.")

src/azure-cli/azure/cli/command_modules/vm/_template_builder.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,8 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
10421042
enable_user_redeploy_scheduled_events=None, skuprofile_vmsizes=None, skuprofile_allostrat=None,
10431043
security_posture_reference_is_overridable=None, zone_balance=None, wire_server_mode=None,
10441044
imds_mode=None, wire_server_access_control_profile_reference_id=None,
1045-
imds_access_control_profile_reference_id=None):
1045+
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
1046+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None):
10461047

10471048
# Build IP configuration
10481049
ip_configuration = {}
@@ -1530,12 +1531,26 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
15301531
if scale_in_policy:
15311532
vmss_properties['scaleInPolicy'] = {'rules': scale_in_policy}
15321533

1533-
if enable_resilient_vm_creation is not None or enable_resilient_vm_deletion is not None:
1534-
resiliency_policy = {}
1535-
if enable_resilient_vm_creation is not None:
1536-
resiliency_policy['resilientVMCreationPolicy'] = {'enabled': enable_resilient_vm_creation}
1537-
if enable_resilient_vm_deletion is not None:
1538-
resiliency_policy['resilientVMDeletionPolicy'] = {'enabled': enable_resilient_vm_deletion}
1534+
resiliency_policy = {}
1535+
if enable_resilient_vm_creation is not None:
1536+
resiliency_policy['resilientVMCreationPolicy'] = {'enabled': enable_resilient_vm_creation}
1537+
if enable_resilient_vm_deletion is not None:
1538+
resiliency_policy['resilientVMDeletionPolicy'] = {'enabled': enable_resilient_vm_deletion}
1539+
1540+
automatic_zone_rebalancing_policy = {}
1541+
if enable_automatic_zone_balancing is not None:
1542+
automatic_zone_rebalancing_policy['enabled'] = enable_automatic_zone_balancing
1543+
1544+
if automatic_zone_balancing_strategy is not None:
1545+
automatic_zone_rebalancing_policy['rebalanceStrategy'] = automatic_zone_balancing_strategy
1546+
1547+
if automatic_zone_balancing_behavior is not None:
1548+
automatic_zone_rebalancing_policy['rebalanceBehavior'] = automatic_zone_balancing_behavior
1549+
1550+
if automatic_zone_rebalancing_policy:
1551+
resiliency_policy['automaticZoneRebalancingPolicy'] = automatic_zone_rebalancing_policy
1552+
1553+
if resiliency_policy:
15391554
vmss_properties['resiliencyPolicy'] = resiliency_policy
15401555

15411556
security_profile = {}

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,7 +3250,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None,
32503250
enable_user_redeploy_scheduled_events=None, skuprofile_vmsizes=None, skuprofile_allostrat=None,
32513251
security_posture_reference_is_overridable=None, zone_balance=None, wire_server_mode=None,
32523252
imds_mode=None, wire_server_access_control_profile_reference_id=None,
3253-
imds_access_control_profile_reference_id=None):
3253+
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
3254+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None):
32543255
from azure.cli.core.commands.client_factory import get_subscription_id
32553256
from azure.cli.core.util import random_string, hash_string
32563257
from azure.cli.core.commands.arm import ArmTemplateBuilder
@@ -3568,7 +3569,10 @@ def _get_public_ip_address_allocation(value, sku):
35683569
security_posture_reference_is_overridable=security_posture_reference_is_overridable,
35693570
zone_balance=zone_balance, wire_server_mode=wire_server_mode, imds_mode=imds_mode,
35703571
wire_server_access_control_profile_reference_id=wire_server_access_control_profile_reference_id,
3571-
imds_access_control_profile_reference_id=imds_access_control_profile_reference_id)
3572+
imds_access_control_profile_reference_id=imds_access_control_profile_reference_id,
3573+
enable_automatic_zone_balancing=enable_automatic_zone_balancing,
3574+
automatic_zone_balancing_strategy=automatic_zone_balancing_strategy,
3575+
automatic_zone_balancing_behavior=automatic_zone_balancing_behavior)
35723576

35733577
vmss_resource['dependsOn'] = vmss_dependencies
35743578

@@ -4019,7 +4023,8 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
40194023
upgrade_policy_mode=None, enable_auto_os_upgrade=None, skuprofile_vmsizes=None,
40204024
skuprofile_allostrat=None, security_posture_reference_is_overridable=None, zone_balance=None,
40214025
wire_server_mode=None, imds_mode=None, wire_server_access_control_profile_reference_id=None,
4022-
imds_access_control_profile_reference_id=None, **kwargs):
4026+
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
4027+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None, **kwargs):
40234028
vmss = kwargs['parameters']
40244029
aux_subscriptions = None
40254030
# pylint: disable=too-many-boolean-expressions
@@ -4336,6 +4341,28 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
43364341
if enable_resilient_deletion is not None:
43374342
resiliency_policy.resilient_vm_deletion_policy = {'enabled': enable_resilient_deletion}
43384343

4344+
if enable_automatic_zone_balancing is not None or automatic_zone_balancing_strategy is not None or \
4345+
automatic_zone_balancing_behavior is not None:
4346+
resiliency_policy = vmss.resiliency_policy
4347+
if resiliency_policy is None:
4348+
ResiliencyPolicy = cmd.get_models('ResiliencyPolicy')
4349+
AutomaticZoneRebalancingPolicy = cmd.get_models('AutomaticZoneRebalancingPolicy')
4350+
resiliency_policy = ResiliencyPolicy()
4351+
resiliency_policy.automatic_zone_rebalancing_policy = AutomaticZoneRebalancingPolicy()
4352+
elif resiliency_policy.automatic_zone_rebalancing_policy is None:
4353+
AutomaticZoneRebalancingPolicy = cmd.get_models('AutomaticZoneRebalancingPolicy')
4354+
resiliency_policy.automatic_zone_rebalancing_policy = AutomaticZoneRebalancingPolicy()
4355+
4356+
if enable_automatic_zone_balancing is not None:
4357+
resiliency_policy.automatic_zone_rebalancing_policy.enabled = enable_automatic_zone_balancing
4358+
4359+
if automatic_zone_balancing_strategy is not None:
4360+
resiliency_policy.automatic_zone_rebalancing_policy.rebalance_strategy = automatic_zone_balancing_strategy
4361+
4362+
if automatic_zone_balancing_behavior is not None:
4363+
resiliency_policy.automatic_zone_rebalancing_policy.rebalance_behavior = automatic_zone_balancing_behavior
4364+
vmss.resiliency_policy = resiliency_policy
4365+
43394366
if zones is not None:
43404367
vmss.zones = zones
43414368

0 commit comments

Comments
 (0)