Skip to content

Commit d13cea1

Browse files
committed
zone rebalance
1 parent bb273bf commit d13cea1

File tree

5 files changed

+4716
-10
lines changed

5 files changed

+4716
-10
lines changed

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
@@ -3246,7 +3246,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None,
32463246
enable_user_redeploy_scheduled_events=None, skuprofile_vmsizes=None, skuprofile_allostrat=None,
32473247
security_posture_reference_is_overridable=None, zone_balance=None, wire_server_mode=None,
32483248
imds_mode=None, wire_server_access_control_profile_reference_id=None,
3249-
imds_access_control_profile_reference_id=None):
3249+
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
3250+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None):
32503251
from azure.cli.core.commands.client_factory import get_subscription_id
32513252
from azure.cli.core.util import random_string, hash_string
32523253
from azure.cli.core.commands.arm import ArmTemplateBuilder
@@ -3564,7 +3565,10 @@ def _get_public_ip_address_allocation(value, sku):
35643565
security_posture_reference_is_overridable=security_posture_reference_is_overridable,
35653566
zone_balance=zone_balance, wire_server_mode=wire_server_mode, imds_mode=imds_mode,
35663567
wire_server_access_control_profile_reference_id=wire_server_access_control_profile_reference_id,
3567-
imds_access_control_profile_reference_id=imds_access_control_profile_reference_id)
3568+
imds_access_control_profile_reference_id=imds_access_control_profile_reference_id,
3569+
enable_automatic_zone_balancing=enable_automatic_zone_balancing,
3570+
automatic_zone_balancing_strategy=automatic_zone_balancing_strategy,
3571+
automatic_zone_balancing_behavior=automatic_zone_balancing_behavior)
35683572

35693573
vmss_resource['dependsOn'] = vmss_dependencies
35703574

@@ -4015,7 +4019,8 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
40154019
upgrade_policy_mode=None, enable_auto_os_upgrade=None, skuprofile_vmsizes=None,
40164020
skuprofile_allostrat=None, security_posture_reference_is_overridable=None, zone_balance=None,
40174021
wire_server_mode=None, imds_mode=None, wire_server_access_control_profile_reference_id=None,
4018-
imds_access_control_profile_reference_id=None, **kwargs):
4022+
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
4023+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None, **kwargs):
40194024
vmss = kwargs['parameters']
40204025
aux_subscriptions = None
40214026
# pylint: disable=too-many-boolean-expressions
@@ -4332,6 +4337,28 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
43324337
if enable_resilient_deletion is not None:
43334338
resiliency_policy.resilient_vm_deletion_policy = {'enabled': enable_resilient_deletion}
43344339

4340+
if enable_automatic_zone_balancing is not None or automatic_zone_balancing_strategy is not None or \
4341+
automatic_zone_balancing_behavior is not None:
4342+
resiliency_policy = vmss.resiliency_policy
4343+
if resiliency_policy is None:
4344+
ResiliencyPolicy = cmd.get_models('ResiliencyPolicy')
4345+
AutomaticZoneRebalancingPolicy = cmd.get_models('AutomaticZoneRebalancingPolicy')
4346+
resiliency_policy = ResiliencyPolicy()
4347+
resiliency_policy.automatic_zone_rebalancing_policy = AutomaticZoneRebalancingPolicy()
4348+
elif resiliency_policy.automatic_zone_rebalancing_policy is None:
4349+
AutomaticZoneRebalancingPolicy = cmd.get_models('AutomaticZoneRebalancingPolicy')
4350+
resiliency_policy.automatic_zone_rebalancing_policy = AutomaticZoneRebalancingPolicy()
4351+
4352+
if enable_automatic_zone_balancing is not None:
4353+
resiliency_policy.automatic_zone_rebalancing_policy.enabled = enable_automatic_zone_balancing
4354+
4355+
if automatic_zone_balancing_strategy is not None:
4356+
resiliency_policy.automatic_zone_rebalancing_policy.rebalance_strategy = automatic_zone_balancing_strategy
4357+
4358+
if automatic_zone_balancing_behavior is not None:
4359+
resiliency_policy.automatic_zone_rebalancing_policy.rebalance_behavior = automatic_zone_balancing_behavior
4360+
vmss.resiliency_policy = resiliency_policy
4361+
43354362
if zones is not None:
43364363
vmss.zones = zones
43374364

0 commit comments

Comments
 (0)