Skip to content
Open
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
84 changes: 84 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2746,6 +2746,53 @@
"myResourceGroup" --run-command-name "myRunCommand" --vmss-name "myVMSS"
"""

helps['vmss lifecycle-hook'] = """
type: group
short-summary: Manage lifecycle hooks on a Virtual Machine Scale Set (preview).
"""

helps['vmss lifecycle-hook add'] = """
type: command
short-summary: Add a lifecycle hook to a VMSS.
examples:
- name: Add an UpgradeAutoOSScheduling hook with an 8 hour wait.
text: az vmss lifecycle-hook add -g MyRg --vmss-name MyVmss --type UpgradeAutoOSScheduling --wait-duration PT8H
"""

helps['vmss lifecycle-hook update'] = """
type: command
short-summary: Update an existing lifecycle hook on a VMSS.
examples:
- name: Change the wait duration of a hook.
text: az vmss lifecycle-hook update -g MyRg --vmss-name MyVmss --type UpgradeAutoOSScheduling --wait-duration PT2H
"""

helps['vmss lifecycle-hook remove'] = """
type: command
short-summary: Remove one lifecycle hook (--type) or all lifecycle hooks (--all) from a VMSS.
examples:
- name: Remove one hook type.
text: az vmss lifecycle-hook remove -g MyRg --vmss-name MyVmss --type UpgradeAutoOSScheduling
- name: Remove all hooks.
text: az vmss lifecycle-hook remove -g MyRg --vmss-name MyVmss --all
"""

helps['vmss lifecycle-hook show'] = """
type: command
short-summary: Show the details of a lifecycle hook on a VMSS.
examples:
- name: Show a hook by type.
text: az vmss lifecycle-hook show -g MyRg --vmss-name MyVmss --type UpgradeAutoOSScheduling
"""

helps['vmss lifecycle-hook list'] = """
type: command
short-summary: List all lifecycle hooks on a VMSS.
examples:
- name: List hooks.
text: az vmss lifecycle-hook list -g MyRg --vmss-name MyVmss
"""

helps['vmss scale'] = """
type: command
short-summary: Change the number of VMs within a VMSS.
Expand Down Expand Up @@ -3028,3 +3075,40 @@
text: |-
az restore-point collection show --resource-group "myResourceGroup" --collection-name "rpcName"
"""

helps['vmss lifecycle-hook-event'] = """
type: group
short-summary: Manage virtual machine scale set lifecycle hook events.
"""

helps['vmss lifecycle-hook-event update'] = """
type: command
short-summary: Update a virtual machine scale set lifecycle hook event.
examples:
- name: Approve all target resources of a lifecycle hook event.
text: az vmss lifecycle-hook-event update --vmss-name MyVmss -g MyRg --name {eventGuid} --action-state Approved
- name: Approve a subset of target resources (Uniform decimal instance ids or Flex VM names).
text: az vmss lifecycle-hook-event update --vmss-name MyVmss -g MyRg --name {eventGuid} --instance-ids 0 1 2 --action-state Approved
- name: Delay the event deadline.
text: az vmss lifecycle-hook-event update --vmss-name MyVmss -g MyRg --name {eventGuid} --wait-until "2026-05-08T11:00:00Z"
"""

helps['vmss lifecycle-hook-event approve'] = """
type: command
short-summary: Approve a virtual machine scale set lifecycle hook event.
examples:
- name: Approve all target resources of a lifecycle hook event.
text: az vmss lifecycle-hook-event approve --vmss-name MyVmss -g MyRg --name {eventGuid}
- name: Approve a subset of target resources.
text: az vmss lifecycle-hook-event approve --vmss-name MyVmss -g MyRg --name {eventGuid} --instance-ids 0 1 2
"""

helps['vmss lifecycle-hook-event reject'] = """
type: command
short-summary: Reject a virtual machine scale set lifecycle hook event.
examples:
- name: Reject all target resources of a lifecycle hook event.
text: az vmss lifecycle-hook-event reject --vmss-name MyVmss -g MyRg --name {eventGuid}
- name: Reject a subset of target resources.
text: az vmss lifecycle-hook-event reject --vmss-name MyVmss -g MyRg --name {eventGuid} --instance-ids 0 1 2
"""
43 changes: 43 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 @@ -59,6 +59,9 @@ def load_arguments(self, _):
EvictionPolicy = ['Deallocate', 'Delete']
HyperVGenerationTypes = ['V1', 'V2']
LicenseType = ['Windows_Server', 'Windows_Client', 'RHEL_BYOS', 'SLES_BYOS', 'RHEL_BASE', 'RHEL_SAPAPPS', 'RHEL_SAPHA', 'RHEL_EUS', 'RHEL_BASESAPAPPS', 'RHEL_BASESAPHA', 'SLES_STANDARD', 'SLES', 'SLES_SAP', 'SLES_HPC', 'None', 'RHEL_ELS_6', 'UBUNTU_PRO', 'UBUNTU']
LifecycleHookActionState = ['Approved', 'Rejected']
LifecycleHookDefaultAction = ['Approve', 'Reject']
LifecycleHookType = ['UpgradeAutoOSScheduling', 'UpgradeAutoOSRollingBatchStarting']
LoadBalancerSkuName = ['Basic', 'Standard', 'Gateway']
NetworkAccessPolicy = ['AllowAll', 'AllowPrivate', 'DenyAll']
NsgRule = ['RDP', 'SSH']
Expand Down Expand Up @@ -1147,6 +1150,46 @@ def load_arguments(self, _):
c.argument('expand', help='The expand expression to apply on the operation.', deprecate_info=c.deprecate(hide=True))
c.argument('instance_view', action='store_true', help='The instance view of a run command.')

with self.argument_context('vmss lifecycle-hook') as c:
c.argument('vmss_name', help='The name of the VM scale set.', id_part=None)
c.argument('type', arg_type=get_enum_type(LifecycleHookType), help='Specifies the type of the lifecycle hook.')
c.argument('wait_duration',
help='Specifies the time duration a virtual machine scale set lifecycle hook event sent to the customer waits for a response from the customer. It should be in ISO 8601 format.')
c.argument('default_action', arg_type=get_enum_type(LifecycleHookDefaultAction),
help='Specifies the action that will be applied to a target resource in the virtual machine scale set lifecycle hook event if the platform does not receive a response from the customer for the target resource before waitUntil.')

with self.argument_context('vmss lifecycle-hook remove') as c:
c.argument('type', arg_type=get_enum_type(LifecycleHookType),
help='Specifies the type of the lifecycle hook. Mutually exclusive with --all.')
c.argument('remove_all', options_list=['--all'], action='store_true',
help='Remove all lifecycle hooks. Mutually exclusive with --type.')

with self.argument_context('vmss lifecycle-hook-event') as c:
c.argument('vmss_name', help='The name of the VM scale set.', id_part='name')
c.argument('lifecycle_hook_event_name', options_list=['--name', '-n'], id_part='child_name_1',
help='The name of the VMScaleSetLifecycleHookEvent.')
c.argument('instance_ids', nargs='+',
help='Space-separated list of target resources to act on. For Uniform scale sets use decimal '
'instance ids (e.g. 0 1 2); for Flexible scale sets use VM names. When omitted, the action '
'is applied to all target resources of the event.')
c.ignore('target_resource_ids')

with self.argument_context('vmss lifecycle-hook-event update') as c:
c.argument('action_state', arg_type=get_enum_type(LifecycleHookActionState),
help="State of the lifecycle hook for the target resource. The customer can patch this property to "
"move the lifecycle hook to a terminal state.")
c.argument('wait_until',
help='Specifies the exact UTC timestamp in ISO 8601 format till which the event would remain in '
'the current lifecycle state waiting for an action from the customer. Beyond this timestamp, '
'the platform will apply the defaultAction for the event.')

for scope in ['vmss lifecycle-hook-event approve', 'vmss lifecycle-hook-event reject']:
with self.argument_context(scope) as c:
c.ignore('target_resource_ids')

with self.argument_context('vmss lifecycle-hook-event list') as c:
c.ignore('lifecycle_hook_event_name')

for scope in ['vm identity assign', 'vmss identity assign']:
with self.argument_context(scope) as c:
c.argument('assign_identity', options_list=['--identities'], nargs='*', help="Space-separated identities to assign. Use '{0}' to refer to the system assigned identity. Default: '{0}'".format(MSI_LOCAL_ID))
Expand Down
62 changes: 62 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2885,3 +2885,65 @@ def _validate_community_gallery_legal_agreement_acceptance(cmd, namespace):
if not prompt_y_n(msg, default="y"):
import sys
sys.exit(0)


def process_vmss_lifecycle_hook_remove(cmd, namespace): # pylint: disable=unused-argument
if namespace.remove_all and namespace.type:
raise MutuallyExclusiveArgumentError("Specify exactly one of --type or --all.")

if not namespace.remove_all and not namespace.type:
raise RequiredArgumentMissingError("Specify exactly one of --type or --all.")


def process_vmss_lifecycle_hook_event_update(cmd, namespace): # pylint: disable=unused-argument
if namespace.instance_ids is not None and not namespace.action_state:
raise RequiredArgumentMissingError("--instance-ids requires --action-state.")

if namespace.action_state is None and namespace.wait_until is None:
raise RequiredArgumentMissingError("Specify at least one of --action-state or --wait-until.")

if namespace.action_state is not None:
_resolve_vmss_lifecycle_hook_event_target_resources(cmd, namespace)


def process_vmss_lifecycle_hook_event_action(cmd, namespace): # pylint: disable=unused-argument
_resolve_vmss_lifecycle_hook_event_target_resources(cmd, namespace)


def _resolve_vmss_lifecycle_hook_event_target_resources(cmd, namespace):
from azure.cli.core.azclierror import InvalidArgumentValueError
from .aaz.latest.vmss.lifecycle_hook_event import Show as _lifecycleHookEventShow

event = _lifecycleHookEventShow(cli_ctx=cmd.cli_ctx)(command_args={
'lifecycle_hook_event_name': namespace.lifecycle_hook_event_name,
'resource_group': namespace.resource_group_name,
'vmss_name': namespace.vmss_name,
})

target_resources = event.get('properties', {}).get('targetResources') or []

identifier_to_id = {}
for target in target_resources:
resource_id = target.get('resource', {}).get('id')
if resource_id:
identifier_to_id[resource_id.rsplit('/', 1)[-1].lower()] = resource_id

if not namespace.instance_ids:
namespace.target_resource_ids = list(identifier_to_id.values())
return

resolved_ids = []
unknown_ids = []
for instance_id in namespace.instance_ids:
resource_id = identifier_to_id.get(instance_id.lower())
if resource_id is None:
unknown_ids.append(instance_id)
else:
resolved_ids.append(resource_id)

if unknown_ids:
raise InvalidArgumentValueError("The following instance ids were not found among the target resources of "
"lifecycle hook event '{}': {}"
.format(namespace.lifecycle_hook_event_name, ", ".join(unknown_ids)))

namespace.target_resource_ids = resolved_ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"vmss lifecycle-hook-event",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage Lifecycle Hook Event
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._list import *
from ._show import *
from ._update import *
Loading
Loading