Skip to content

Commit d0a24c7

Browse files
authored
[Compute] az vmss create: Add new parameter --enable-automatic-repairs to support setting automatic repairs policy (#31722)
1 parent 6b1c304 commit d0a24c7

File tree

7 files changed

+2849
-181
lines changed

7 files changed

+2849
-181
lines changed

src/azure-cli/azure/cli/command_modules/resource/tests/latest/recordings/test_create_deployment_stack_subscription_with_bicep.yaml

Lines changed: 276 additions & 178 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ def load_arguments(self, _):
742742
c.argument('orchestration_mode', help='Choose how virtual machines are managed by the scale set. In Uniform mode, you define a virtual machine model and Azure will generate identical instances based on that model.',
743743
arg_type=get_enum_type(['Uniform']), default='Uniform', max_api='2020-09-30')
744744
c.argument('scale_in_policy', scale_in_policy_type)
745+
c.argument('enable_automatic_repairs', options_list=['--enable-automatic-repairs', '--enable-auto-repairs'], min_api='2021-11-01', arg_type=get_three_state_flag(), help='Enable automatic repairs')
745746
c.argument('automatic_repairs_grace_period', min_api='2018-10-01',
746747
help='The amount of time (in minutes, between 30 and 90) for which automatic repairs are suspended due to a state change on VM.')
747748
c.argument('automatic_repairs_action', arg_type=get_enum_type(['Replace', 'Restart', 'Reimage']), min_api='2021-11-01', help='Type of repair action that will be used for repairing unhealthy virtual machines in the scale set.')

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
10441044
security_posture_reference_is_overridable=None, zone_balance=None, wire_server_mode=None,
10451045
imds_mode=None, wire_server_access_control_profile_reference_id=None,
10461046
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
1047-
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None):
1047+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None,
1048+
enable_automatic_repairs=None):
10481049

10491050
# Build IP configuration
10501051
ip_configuration = {}
@@ -1541,6 +1542,9 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
15411542
automatic_zone_rebalancing_policy = {}
15421543
if enable_automatic_zone_balancing is not None:
15431544
automatic_zone_rebalancing_policy['enabled'] = enable_automatic_zone_balancing
1545+
if enable_automatic_zone_balancing is True and enable_automatic_repairs is not None:
1546+
automatic_repairs_policy = {'enabled': enable_automatic_repairs}
1547+
vmss_properties['automaticRepairsPolicy'] = automatic_repairs_policy
15441548

15451549
if automatic_zone_balancing_strategy is not None:
15461550
automatic_zone_rebalancing_policy['rebalanceStrategy'] = automatic_zone_balancing_strategy

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,9 @@ def _validate_vmss_create_automatic_repairs(cmd, namespace): # pylint: disable=
25322532
if namespace.load_balancer is None or namespace.health_probe is None:
25332533
raise ArgumentUsageError("usage error: --load-balancer and --health-probe are required "
25342534
"when creating vmss with automatic repairs")
2535+
if namespace.enable_automatic_repairs is not None and namespace.enable_automatic_repairs is False:
2536+
raise ArgumentUsageError("usage error: --enable-automatic-repairs cannot be false when "
2537+
"--automatic-repairs-action or --automatic-repairs-grace-period are used")
25352538
_validate_vmss_automatic_repairs(cmd, namespace)
25362539

25372540

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,7 +3306,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None,
33063306
security_posture_reference_is_overridable=None, zone_balance=None, wire_server_mode=None,
33073307
imds_mode=None, wire_server_access_control_profile_reference_id=None,
33083308
imds_access_control_profile_reference_id=None, enable_automatic_zone_balancing=None,
3309-
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None):
3309+
automatic_zone_balancing_strategy=None, automatic_zone_balancing_behavior=None,
3310+
enable_automatic_repairs=None):
33103311
from azure.cli.core.commands.client_factory import get_subscription_id
33113312
from azure.cli.core.util import random_string, hash_string
33123313
from azure.cli.core.commands.arm import ArmTemplateBuilder
@@ -3628,7 +3629,8 @@ def _get_public_ip_address_allocation(value, sku):
36283629
imds_access_control_profile_reference_id=imds_access_control_profile_reference_id,
36293630
enable_automatic_zone_balancing=enable_automatic_zone_balancing,
36303631
automatic_zone_balancing_strategy=automatic_zone_balancing_strategy,
3631-
automatic_zone_balancing_behavior=automatic_zone_balancing_behavior)
3632+
automatic_zone_balancing_behavior=automatic_zone_balancing_behavior,
3633+
enable_automatic_repairs=enable_automatic_repairs)
36323634

36333635
vmss_resource['dependsOn'] = vmss_dependencies
36343636

0 commit comments

Comments
 (0)