Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
6 changes: 6 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,9 @@ vmss create:
automatic_repairs_grace_period:
rule_exclusions:
- option_length_too_long
automatic_repairs_action:
rule_exclusions:
- option_length_too_long
data_disk_encryption_sets:
rule_exclusions:
- option_length_too_long
Expand Down Expand Up @@ -3689,6 +3692,9 @@ vmss update:
enable_automatic_repairs:
rule_exclusions:
- option_length_too_long
automatic_repairs_action:
rule_exclusions:
- option_length_too_long
enable_terminate_notification:
rule_exclusions:
- option_length_too_long
Expand Down
3 changes: 3 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 @@ -657,6 +657,7 @@ def load_arguments(self, _):
c.argument('scale_in_policy', scale_in_policy_type)
c.argument('automatic_repairs_grace_period', min_api='2018-10-01',
help='The amount of time (in minutes, between 30 and 90) for which automatic repairs are suspended due to a state change on VM.')
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.')
c.argument('user_data', help='UserData for the virtual machines in the scale set. It can be passed in as file or string.', completer=FilesCompleter(), type=file_type, min_api='2021-03-01')
c.argument('network_api_version', min_api='2021-03-01',
help="Specify the Microsoft.Network API version used when creating networking resources in the Network "
Expand Down Expand Up @@ -710,11 +711,13 @@ def load_arguments(self, _):
help='Only applicable when used with `--vm-sku`. Allows you to choose the Ephemeral OS disk provisioning location.', is_preview=True)

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

c.argument('enable_automatic_repairs', arg_type=get_three_state_flag(), help='Enable automatic repairs')
c.argument(
'automatic_repairs_grace_period',
help='The amount of time (in minutes, between 30 and 90) for which automatic repairs are suspended due to a state change on VM.'
)
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.')

for scope in ['vmss create', 'vmss update']:
with self.argument_context(scope) as c:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
enable_cross_zone_upgrade=None, prioritize_unhealthy_instances=None, edge_zone=None,
orchestration_mode=None, user_data=None, network_api_version=None,
enable_spot_restore=None, spot_restore_timeout=None, capacity_reservation_group=None,
enable_auto_update=None, patch_mode=None, enable_agent=None):
enable_auto_update=None, patch_mode=None, enable_agent=None, automatic_repairs_action=None):

# Build IP configuration
ip_configuration = {}
Expand Down Expand Up @@ -1166,10 +1166,11 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
}
virtual_machine_profile['scheduledEventsProfile'] = scheduled_events_profile

if automatic_repairs_grace_period is not None:
if automatic_repairs_grace_period is not None or automatic_repairs_action is not None:
automatic_repairs_policy = {
'enabled': 'true',
'gracePeriod': automatic_repairs_grace_period
'gracePeriod': automatic_repairs_grace_period or 'PT10M',
'repairAction': automatic_repairs_action or 'Replace'
}
vmss_properties['automaticRepairsPolicy'] = automatic_repairs_policy

Expand Down
17 changes: 10 additions & 7 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1910,18 +1910,21 @@ def _validate_vmss_terminate_notification(cmd, namespace): # pylint: disable=un


def _validate_vmss_create_automatic_repairs(cmd, namespace): # pylint: disable=unused-argument
if namespace.automatic_repairs_grace_period is not None:
if namespace.automatic_repairs_grace_period is not None or namespace.automatic_repairs_action is not None:
if namespace.load_balancer is None or namespace.health_probe is None:
raise CLIError("usage error: --load-balancer and --health-probe are required "
"when creating vmss with automatic repairs")
raise ArgumentUsageError("usage error: --load-balancer and --health-probe are required "
"when creating vmss with automatic repairs")
_validate_vmss_automatic_repairs(cmd, namespace)


def _validate_vmss_update_automatic_repairs(cmd, namespace): # pylint: disable=unused-argument
if namespace.enable_automatic_repairs is False and namespace.automatic_repairs_grace_period is not None:
raise CLIError("usage error: please enable --enable-automatic-repairs")
if namespace.enable_automatic_repairs is True and namespace.automatic_repairs_grace_period is None:
raise CLIError("usage error: please set --automatic-repairs-grace-period")
if namespace.enable_automatic_repairs is False and \
(namespace.automatic_repairs_grace_period is not None or namespace.automatic_repairs_action is not None):
raise ArgumentUsageError("usage error: please enable --enable-automatic-repairs")
if namespace.enable_automatic_repairs is True and namespace.automatic_repairs_grace_period is None\
and namespace.automatic_repairs_action is None:
raise ArgumentUsageError("usage error: please set --automatic-repairs-grace-period or"
" --automatic-repairs-action")
_validate_vmss_automatic_repairs(cmd, namespace)


Expand Down
15 changes: 10 additions & 5 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None,
max_unhealthy_upgraded_instance_percent=None, pause_time_between_batches=None,
enable_cross_zone_upgrade=None, prioritize_unhealthy_instances=None, edge_zone=None,
user_data=None, network_api_version=None, enable_spot_restore=None, spot_restore_timeout=None,
capacity_reservation_group=None, enable_auto_update=None, patch_mode=None, enable_agent=None):
capacity_reservation_group=None, enable_auto_update=None, patch_mode=None, enable_agent=None,
automatic_repairs_action=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 @@ -3077,7 +3078,7 @@ def _get_public_ip_address_allocation(value, sku):
orchestration_mode=orchestration_mode, network_api_version=network_api_version,
enable_spot_restore=enable_spot_restore, spot_restore_timeout=spot_restore_timeout,
capacity_reservation_group=capacity_reservation_group, enable_auto_update=enable_auto_update,
patch_mode=patch_mode, enable_agent=enable_agent)
patch_mode=patch_mode, enable_agent=enable_agent, automatic_repairs_action=automatic_repairs_action)

vmss_resource['dependsOn'] = vmss_dependencies

Expand Down Expand Up @@ -3367,7 +3368,8 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
max_unhealthy_instance_percent=None, max_unhealthy_upgraded_instance_percent=None,
pause_time_between_batches=None, enable_cross_zone_upgrade=None, prioritize_unhealthy_instances=None,
user_data=None, enable_spot_restore=None, spot_restore_timeout=None, capacity_reservation_group=None,
vm_sku=None, ephemeral_os_disk_placement=None, force_deletion=None, **kwargs):
vm_sku=None, ephemeral_os_disk_placement=None, force_deletion=None, automatic_repairs_action=None,
**kwargs):
vmss = kwargs['parameters']
aux_subscriptions = None
# pylint: disable=too-many-boolean-expressions
Expand Down Expand Up @@ -3427,10 +3429,13 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
TerminateNotificationProfile(not_before_timeout=terminate_notification_time,
enable=enable_terminate_notification)

if enable_automatic_repairs is not None or automatic_repairs_grace_period is not None:
if enable_automatic_repairs is not None or \
automatic_repairs_grace_period is not None or automatic_repairs_action is not None:
AutomaticRepairsPolicy = cmd.get_models('AutomaticRepairsPolicy')
vmss.automatic_repairs_policy = \
AutomaticRepairsPolicy(enabled="true", grace_period=automatic_repairs_grace_period)
AutomaticRepairsPolicy(enabled=enable_automatic_repairs,
grace_period=automatic_repairs_grace_period,
repair_action=automatic_repairs_action)

if ultra_ssd_enabled is not None:
if cmd.supported_api_version(min_api='2019-03-01', operation_group='virtual_machine_scale_sets'):
Expand Down
Loading