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
7 changes: 7 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 @@ -2599,6 +2599,13 @@
crafted: true
"""

helps['vmss list-instances'] = """
type: command
short-summary: List all virtual machines in a VM scale sets.
long-summary: Return a list of virtual machines managed by VMSS. For VMSS in Flexible Orchestration mode,
please use "az vm list" to get full details.
"""

helps['vmss reimage'] = """
type: command
short-summary: Reimage VMs within a VMSS.
Expand Down
14 changes: 14 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 @@ -910,6 +910,20 @@ def load_arguments(self, _):
with self.argument_context('vmss set-orchestration-service-state') as c:
c.argument('service_name', arg_type=get_enum_type(OrchestrationServiceNames), help='The name of the orchestration service.')
c.argument('action', arg_type=get_enum_type(OrchestrationServiceStateAction), help='The action to be performed.')

with self.argument_context('vmss list-instances') as c:
c.argument('virtual_machine_scale_set_name', id_part='virtual_machine_scale_set_name', required=True, options_list=["-n", "--name", "--virtual-machine-scale-set-name"],
help='The name of the VM scale set.')
c.argument('expand', help="The expand expression to apply to the operation. Allowed values are 'instanceView'.")
c.argument('filter', help="The filter to apply to the operation. Allowed values are 'startswith(instanceView/statuses/code, 'PowerState') eq true', 'properties/latestModelApplied eq true', 'properties/latestModelApplied eq false'.")
c.argument('select', help="The list parameters. Allowed values are 'instanceView', 'instanceView/statuses'.")
c.argument('resiliency_view', action='store_true', help="Show resiliency status of each instance.")
c.argument('pagination_limit', options_list=['--max-items'], type=int, arg_group="Pagination",
help="Total number of items to return in the command's output. If the total number of items available is "
"more than the value specified, a token is provided in the command's output. To resume pagination, "
"provide the token value in `--next-token` argument of a subsequent command.")
c.argument('pagination_token', options_list=['--next-token'], arg_group="Pagination",
help="Token to specify where to start paginating. This is the token value from a previously truncated response.")
# endregion

# region VM & VMSS Shared
Expand Down
5 changes: 3 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def load_command_table(self, _):
g.custom_command('get-instance-view', 'get_vmss_instance_view', table_transformer='{ProvisioningState:statuses[0].displayStatus, PowerState:statuses[1].displayStatus}')
g.custom_command('list-instance-connection-info', 'list_vmss_instance_connection_info')
g.custom_command('list-instance-public-ips', 'list_vmss_instance_public_ips')
g.custom_command('list-instances', 'get_instances_list')
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True, min_api='2017-03-30')
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
Expand All @@ -432,8 +433,8 @@ def load_command_table(self, _):
self.command_table['vmss list'] = VMSSList(loader=self,
table_transformer=transform_vmss_list_with_zones_table_output)

from .operations.vmss import VMSSListInstances
self.command_table['vmss list-instances'] = VMSSListInstances(loader=self)
from .operations.vmss_vms import VMSSGetResiliencyView
self.command_table['vmss get-resiliency-view'] = VMSSGetResiliencyView(loader=self)

with self.command_group('vmss diagnostics', compute_vmss_sdk) as g:
g.custom_command('set', 'set_vmss_diagnostics_extension')
Expand Down
27 changes: 27 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4109,6 +4109,33 @@ def get_vmss_modified_by_aaz(cmd, resource_group_name, name, instance_id=None, s
return vmss


def get_instances_list(cmd, resource_group_name, virtual_machine_scale_set_name, expand=None, filter=None,
select=None, pagination_limit=None, pagination_token=None, resiliency_view=False, **kwargs):
get_list_args = kwargs
get_list_args['resource_group'] = resource_group_name
get_list_args['virtual_machine_scale_set_name'] = virtual_machine_scale_set_name
get_list_args['expand'] = expand
get_list_args['filter'] = filter
get_list_args['select'] = select
get_list_args['pagination_limit'] = pagination_limit
get_list_args['pagination_token'] = pagination_token

from .operations.vmss import VMSSListInstances
instances = VMSSListInstances(cli_ctx=cmd.cli_ctx)(command_args=get_list_args)

if not resiliency_view:
return instances

instances_id = [instance['instanceId'] for instance in instances]

from .operations.vmss_vms import VMSSGetResiliencyView
return [VMSSGetResiliencyView(cli_ctx=cmd.cli_ctx)(command_args={
'instance_id': instance_id,
'resource_group': resource_group_name,
'vm_scale_set_name': virtual_machine_scale_set_name,
}) for instance_id in instances_id]


def get_vmss_instance_view(cmd, resource_group_name, vm_scale_set_name, instance_id=None):
client = _compute_client_factory(cmd.cli_ctx)
if instance_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pylint: disable=no-self-use, line-too-long, protected-access, too-few-public-methods, unused-argument, too-many-statements, too-many-branches, too-many-locals
from knack.log import get_logger

from azure.cli.core.aaz import AAZUndefined, has_value
from azure.cli.core.aaz import AAZUndefined, has_value, register_command
from ..aaz.latest.vmss.vms import Create as _VMSSVMSCreate, Show as _VMSSVMSShow

logger = get_logger(__name__)
Expand Down Expand Up @@ -66,6 +66,27 @@ def _output(self, *args, **kwargs):
return result


@register_command(
"vmss get-resiliency-view",
)
class VMSSGetResiliencyView(_VMSSVMSShow):
"""View the resiliency status of a VMSS instance

:example: View the resiliency status of a VMSS instance.
az vmss get-resiliency-view --name MyScaleSet --resource-group MyResourceGroup --instance MyInstanceId
"""
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
args_schema = super()._build_arguments_schema(*args, **kwargs)
args_schema.instance_id._options = ["--instance"]
args_schema.vm_scale_set_name._options = ["-n", "--name"]
args_schema.expand._registered = False
return args_schema

def pre_operations(self):
self.ctx.args.expand = 'resiliencyView'


def convert_show_result_to_snake_case(result):
new_result = {}
if "instanceId" in result:
Expand Down
Loading