Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -656,6 +656,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 @@ -714,11 +715,13 @@ def load_arguments(self, _):
c.argument('enable_vtpm', enable_vtpm_type)

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 @@ -848,7 +848,7 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
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, security_type=None,
enable_secure_boot=None, enable_vtpm=None,):
enable_secure_boot=None, enable_vtpm=None, automatic_repairs_action=None):

# Build IP configuration
ip_configuration = {}
Expand Down Expand Up @@ -1167,10 +1167,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 @@ -2816,7 +2816,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=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,
security_type=None, enable_secure_boot=None, enable_vtpm=None):
security_type=None, enable_secure_boot=None, enable_vtpm=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 @@ -3079,7 +3080,8 @@ def _get_public_ip_address_allocation(value, sku):
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, security_type=security_type,
enable_secure_boot=enable_secure_boot, enable_vtpm=enable_vtpm)
enable_secure_boot=enable_secure_boot, enable_vtpm=enable_vtpm,
automatic_repairs_action=automatic_repairs_action)

vmss_resource['dependsOn'] = vmss_dependencies

Expand Down Expand Up @@ -3370,7 +3372,7 @@ def update_vmss(cmd, resource_group_name, name, license_type=None, no_wait=False
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, enable_secure_boot=None,
enable_vtpm=None, **kwargs):
enable_vtpm=None, automatic_repairs_action=None, **kwargs):
vmss = kwargs['parameters']
aux_subscriptions = None
# pylint: disable=too-many-boolean-expressions
Expand Down Expand Up @@ -3430,10 +3432,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