1# --------------------------------------------------------------------------------------------
2# Copyright (c) Microsoft Corporation. All rights reserved.
3# Licensed under the MIT License. See License.txt in the project root for license information.
4# --------------------------------------------------------------------------------------------
5
6# pylint: disable=line-too-long, too-many-lines
7from argcomplete.completers import FilesCompleter
8
9from knack.arguments import CLIArgumentType
10
11from azure.cli.core.profiles import ResourceType
12from azure.cli.core.commands.parameters import get_datetime_type
13from azure.cli.core.commands.validators import (
14    get_default_location_from_resource_group, validate_file_or_dict)
15from azure.cli.core.commands.parameters import (
16    get_location_type, get_resource_name_completion_list, tags_type, get_three_state_flag,
17    file_type, get_enum_type, zone_type, zones_type)
18from azure.cli.command_modules.vm._actions import _resource_not_exists
19from azure.cli.command_modules.vm._completers import (
20    get_urn_aliases_completion_list, get_vm_size_completion_list, get_vm_run_command_completion_list)
21from azure.cli.command_modules.vm._validators import (
22    validate_nsg_name, validate_vm_nics, validate_vm_nic, validate_vm_disk, validate_vmss_disk,
23    validate_asg_names_or_ids, validate_keyvault, _validate_proximity_placement_group,
24    process_gallery_image_version_namespace, validate_vm_name_for_monitor_metrics)
25
26from azure.cli.command_modules.vm._vm_utils import MSI_LOCAL_ID
27from azure.cli.command_modules.vm._image_builder import ScriptType
28
29from azure.cli.command_modules.monitor.validators import validate_metric_dimension
30from azure.cli.command_modules.monitor.actions import get_period_type
31
32
33# pylint: disable=too-many-statements, too-many-branches, too-many-locals, too-many-lines
34def load_arguments(self, _):
35    # Model imports
36    StorageAccountTypes = self.get_models('StorageAccountTypes')
37    DiskStorageAccountTypes = self.get_models('DiskStorageAccountTypes,', operation_group='disks')
38    SnapshotStorageAccountTypes = self.get_models('SnapshotStorageAccountTypes', operation_group='snapshots')
39    UpgradeMode, CachingTypes, OperatingSystemTypes = self.get_models('UpgradeMode', 'CachingTypes', 'OperatingSystemTypes')
40    HyperVGenerationTypes, HyperVGeneration = self.get_models('HyperVGenerationTypes', 'HyperVGeneration')
41    DedicatedHostLicenseTypes = self.get_models('DedicatedHostLicenseTypes')
42    OrchestrationServiceNames, OrchestrationServiceStateAction = self.get_models('OrchestrationServiceNames', 'OrchestrationServiceStateAction', operation_group='virtual_machine_scale_sets')
43    RebootSetting, VMGuestPatchClassificationWindows, VMGuestPatchClassificationLinux = self.get_models('VMGuestPatchRebootSetting', 'VMGuestPatchClassificationWindows', 'VMGuestPatchClassificationLinux')
44    GallerySharingPermissionTypes = self.get_models('GallerySharingPermissionTypes', operation_group='shared_galleries')
45    ReplicationMode = self.get_models('ReplicationMode', operation_group='gallery_image_versions')
46
47    # REUSABLE ARGUMENT DEFINITIONS
48    name_arg_type = CLIArgumentType(options_list=['--name', '-n'], metavar='NAME')
49    multi_ids_type = CLIArgumentType(nargs='+')
50    existing_vm_name = CLIArgumentType(overrides=name_arg_type,
51                                       configured_default='vm',
52                                       help="The name of the Virtual Machine. You can configure the default using `az configure --defaults vm=<name>`",
53                                       completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines'), id_part='name')
54    existing_disk_name = CLIArgumentType(overrides=name_arg_type, help='The name of the managed disk', completer=get_resource_name_completion_list('Microsoft.Compute/disks'), id_part='name')
55    existing_snapshot_name = CLIArgumentType(overrides=name_arg_type, help='The name of the snapshot', completer=get_resource_name_completion_list('Microsoft.Compute/snapshots'), id_part='name')
56    vmss_name_type = CLIArgumentType(name_arg_type,
57                                     configured_default='vmss',
58                                     completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'),
59                                     help="Scale set name. You can configure the default using `az configure --defaults vmss=<name>`",
60                                     id_part='name')
61
62    extension_instance_name_type = CLIArgumentType(help="Name of extension instance, which can be customized. Default: name of the extension.")
63    image_template_name_type = CLIArgumentType(overrides=name_arg_type, id_part='name')
64    disk_encryption_set_name = CLIArgumentType(overrides=name_arg_type, help='Name of disk encryption set.', id_part='name')
65
66    # StorageAccountTypes renamed to DiskStorageAccountTypes in 2018_06_01 of azure-mgmt-compute
67    DiskStorageAccountTypes = DiskStorageAccountTypes or StorageAccountTypes
68
69    if DiskStorageAccountTypes:
70        disk_sku = CLIArgumentType(arg_type=get_enum_type(DiskStorageAccountTypes))
71    else:
72        # StorageAccountTypes introduced in api version 2016_04_30_preview of Resource.MGMT.Compute package..
73        # However, 2017-03-09-profile targets version 2016-03-30 of compute package.
74        disk_sku = CLIArgumentType(arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS']))
75
76    if SnapshotStorageAccountTypes:
77        snapshot_sku = CLIArgumentType(arg_type=get_enum_type(SnapshotStorageAccountTypes))
78    else:
79        # SnapshotStorageAccountTypes introduced in api version 2018_04_01 of Resource.MGMT.Compute package..
80        # However, 2017-03-09-profile targets version 2016-03-30 of compute package.
81        snapshot_sku = CLIArgumentType(arg_type=get_enum_type(['Premium_LRS', 'Standard_LRS']))
82
83    # special case for `network nic scale-set list` command alias
84    with self.argument_context('network nic scale-set list') as c:
85        c.argument('virtual_machine_scale_set_name', options_list=['--vmss-name'], completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), id_part='name')
86
87    HyperVGenerationTypes = HyperVGenerationTypes or HyperVGeneration
88    if HyperVGenerationTypes:
89        hyper_v_gen_sku = CLIArgumentType(arg_type=get_enum_type(HyperVGenerationTypes, default="V1"))
90    else:
91        hyper_v_gen_sku = CLIArgumentType(arg_type=get_enum_type(["V1", "V2"], default="V1"))
92
93    ultra_ssd_enabled_type = CLIArgumentType(
94        arg_type=get_three_state_flag(), min_api='2018-06-01',
95        help='Enables or disables the capability to have 1 or more managed data disks with UltraSSD_LRS storage account')
96
97    scale_in_policy_type = CLIArgumentType(
98        nargs='+', arg_type=get_enum_type(self.get_models('VirtualMachineScaleSetScaleInRules')),
99        help='Specify the scale-in policy (space delimited) that decides which virtual machines are chosen for removal when a Virtual Machine Scale Set is scaled-in.'
100    )
101
102    edge_zone_type = CLIArgumentType(
103        help='The name of edge zone.',
104        min_api='2020-12-01',
105        is_preview=True
106    )
107
108    t_shared_to = self.get_models('SharedToValues', operation_group='shared_galleries')
109    shared_to_type = CLIArgumentType(
110        arg_type=get_enum_type(t_shared_to),
111        help='The query parameter to decide what shared galleries to fetch when doing listing operations. '
112             'If not specified, list by subscription id.'
113    )
114
115    # region MixedScopes
116    for scope in ['vm', 'disk', 'snapshot', 'image', 'sig']:
117        with self.argument_context(scope) as c:
118            c.argument('tags', tags_type)
119
120    for scope in ['disk', 'snapshot']:
121        with self.argument_context(scope) as c:
122            c.ignore('source_blob_uri', 'source_disk', 'source_snapshot')
123            c.argument('source_storage_account_id', help='used when source blob is in a different subscription')
124            c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
125            c.argument('duration_in_seconds', help='Time duration in seconds until the SAS access expires', type=int)
126            if self.supported_api_version(min_api='2018-09-30', operation_group='disks'):
127                c.argument('access_level', arg_type=get_enum_type(['Read', 'Write']), default='Read', help='access level')
128                c.argument('for_upload', arg_type=get_three_state_flag(),
129                           help='Create the {0} for uploading blobs later on through storage commands. Run "az {0} grant-access --access-level Write" to retrieve the {0}\'s SAS token.'.format(scope))
130                c.argument('hyper_v_generation', arg_type=hyper_v_gen_sku, help='The hypervisor generation of the Virtual Machine. Applicable to OS disks only.')
131            else:
132                c.ignore('access_level', 'for_upload', 'hyper_v_generation')
133            c.argument('encryption_type', min_api='2019-07-01', arg_type=get_enum_type(self.get_models('EncryptionType')),
134                       help='Encryption type. EncryptionAtRestWithPlatformKey: Disk is encrypted with XStore managed key at rest. It is the default encryption type. EncryptionAtRestWithCustomerKey: Disk is encrypted with Customer managed key at rest.')
135            c.argument('disk_encryption_set', min_api='2019-07-01', help='Name or ID of disk encryption set that is used to encrypt the disk.')
136            c.argument('location', help='Location. Values from: `az account list-locations`. You can configure the default location using `az configure --defaults location=<location>`. If location is not specified and no default location specified, location will be automatically set as same as the resource group.')
137            operation_group = 'disks' if scope == 'disk' else 'snapshots'
138            c.argument('network_access_policy', min_api='2020-05-01', help='Policy for accessing the disk via network.', arg_type=get_enum_type(self.get_models('NetworkAccessPolicy', operation_group=operation_group)))
139            c.argument('disk_access', min_api='2020-05-01', help='Name or ID of the disk access resource for using private endpoints on disks.')
140            c.argument('enable_bursting', arg_type=get_three_state_flag(), help='Enable bursting beyond the provisioned performance target of the disk. Bursting is disabled by default, and it does not apply to Ultra disks.')
141
142    for scope in ['disk create', 'snapshot create']:
143        with self.argument_context(scope) as c:
144            c.argument('source', help='source to create the disk/snapshot from, including unmanaged blob uri, managed disk id or name, or snapshot id or name')
145    # endregion
146
147    # region Disks
148    with self.argument_context('disk') as c:
149        c.argument('zone', zone_type, min_api='2017-03-30', options_list=['--zone'])  # TODO: --size-gb currently has claimed -z. We can do a breaking change later if we want to.
150        c.argument('disk_name', existing_disk_name, completer=get_resource_name_completion_list('Microsoft.Compute/disks'))
151        c.argument('name', arg_type=name_arg_type)
152        c.argument('sku', arg_type=disk_sku, help='Underlying storage SKU')
153        c.argument('os_type', arg_type=get_enum_type(OperatingSystemTypes), help='The Operating System type of the Disk.')
154        c.argument('disk_iops_read_write', type=int, min_api='2018-06-01', help='The number of IOPS allowed for this disk. Only settable for UltraSSD disks. One operation can transfer between 4k and 256k bytes')
155        c.argument('disk_mbps_read_write', type=int, min_api='2018-06-01', help="The bandwidth allowed for this disk. Only settable for UltraSSD disks. MBps means millions of bytes per second with ISO notation of powers of 10")
156        c.argument('upload_size_bytes', type=int, min_api='2019-03-01',
157                   help='The size (in bytes) of the contents of the upload including the VHD footer. Min value: 20972032. Max value: 35183298347520')
158        c.argument('max_shares', type=int, help='The maximum number of VMs that can attach to the disk at the same time. Value greater than one indicates a disk that can be mounted on multiple VMs at the same time')
159        c.argument('disk_iops_read_only', type=int, help='The total number of IOPS that will be allowed across all VMs mounting the shared disk as ReadOnly. One operation can transfer between 4k and 256k bytes')
160        c.argument('disk_mbps_read_only', type=int, help='The total throughput (MBps) that will be allowed across all VMs mounting the shared disk as ReadOnly. MBps means millions of bytes per second - MB here uses the ISO notation, of powers of 10')
161        c.argument('image_reference', help='ID or URN (publisher:offer:sku:version) of the image from which to create a disk')
162        c.argument('image_reference_lun', type=int, help='If the disk is created from an image\'s data disk, this is an index that indicates which of the data disks in the image to use. For OS disks, this field is null')
163        c.argument('gallery_image_reference', help='ID of the shared galley image version from which to create a disk')
164        c.argument('gallery_image_reference_lun', type=int, help='If the disk is created from an image\'s data disk, this is an index that indicates which of the data disks in the image to use. For OS disks, this field is null')
165        c.argument('logical_sector_size', type=int, help='Logical sector size in bytes for Ultra disks. Supported values are 512 ad 4096. 4096 is the default.')
166        c.argument('tier', help='Performance tier of the disk (e.g, P4, S10) as described here: https://azure.microsoft.com/pricing/details/managed-disks/. Does not apply to Ultra disks.')
167        c.argument('edge_zone', edge_zone_type)
168        c.argument('security_type', choices=['TrustedLaunch'], help='The security type of the VM. Applicable for OS disks only.', min_api='2020-12-01')
169        c.argument('support_hibernation', arg_type=get_three_state_flag(), help='Indicate the OS on a disk supports hibernation.', min_api='2020-12-01')
170    # endregion
171
172    # region Snapshots
173    with self.argument_context('snapshot', resource_type=ResourceType.MGMT_COMPUTE, operation_group='snapshots') as c:
174        c.argument('snapshot_name', existing_snapshot_name, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/snapshots'))
175        c.argument('name', arg_type=name_arg_type)
176        c.argument('sku', arg_type=snapshot_sku)
177        c.argument('incremental', arg_type=get_three_state_flag(), min_api='2019-03-01',
178                   help='Whether a snapshot is incremental. Incremental snapshots on the same disk occupy less space than full snapshots and can be diffed')
179        c.argument('edge_zone', edge_zone_type)
180    # endregion
181
182    # region Images
183    with self.argument_context('image') as c:
184        c.argument('os_type', arg_type=get_enum_type(['Windows', 'Linux']))
185        c.argument('image_name', arg_type=name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/images'))
186        c.argument('tags', tags_type)
187
188    with self.argument_context('image create') as c:
189        # here we collpase all difference image sources to under 2 common arguments --os-disk-source --data-disk-sources
190        c.argument('name', arg_type=name_arg_type, help='new image name')
191        c.argument('source', help='OS disk source from the same region, including a virtual machine ID or name, OS disk blob URI, managed OS disk ID or name, or OS snapshot ID or name')
192        c.argument('data_disk_sources', nargs='+', help='Space-separated list of data disk sources, including unmanaged blob URI, managed disk ID or name, or snapshot ID or name')
193        c.argument('zone_resilient', min_api='2017-12-01', arg_type=get_three_state_flag(), help='Specifies whether an image is zone resilient or not. '
194                   'Default is false. Zone resilient images can be created only in regions that provide Zone Redundant Storage')
195        c.argument('storage_sku', arg_type=disk_sku, help='The SKU of the storage account with which to create the VM image. Unused if source VM is specified.')
196        c.argument('os_disk_caching', arg_type=get_enum_type(CachingTypes), help="Storage caching type for the image's OS disk.")
197        c.argument('data_disk_caching', arg_type=get_enum_type(CachingTypes),
198                   help="Storage caching type for the image's data disk.")
199        c.argument('hyper_v_generation', arg_type=hyper_v_gen_sku, min_api="2019-03-01", help='The hypervisor generation of the Virtual Machine created from the image.')
200        c.ignore('source_virtual_machine', 'os_blob_uri', 'os_disk', 'os_snapshot', 'data_blob_uris', 'data_disks', 'data_snapshots')
201        c.argument('edge_zone', edge_zone_type, )
202    # endregion
203
204    # region Image Templates
205    with self.argument_context('image builder') as c:
206        ib_output_name_help = "Name of the image builder run output."
207
208        c.argument('location', get_location_type(self.cli_ctx))
209        c.argument('scripts', nargs='+', help="Space-separated list of shell or powershell scripts to customize the image with. Each script must be a publicly accessible URL."
210                                              " Infers type of script from file extension ('.sh' or'.ps1') or from source type. More more customizer options and flexibility, see: 'az image template customizer add'")
211        c.argument('source', options_list=["--image-source", "-i"], help="The base image to customize. Must be a valid platform image URN, platform image alias, Red Hat ISO image URI, managed image name/ID, or shared image version ID.")
212        c.argument('image_template_name', image_template_name_type, help="The name of the image template.")
213        c.argument('checksum', help="The SHA256 checksum of the Red Hat ISO image")
214        c.argument('managed_image_destinations', nargs='+', help='Managed image output distributor information. Space-separated list of key-value pairs. E.g "image_1=westus2 image_2=westus". Each key is the name or resource ID of the managed image to be created. Each value is the location of the image.')
215        c.argument('shared_image_destinations', nargs='+', help='Shared image gallery (sig) output distributor information. Space-separated list of key-value pairs. E.g "my_gallery_1/image_def_1=eastus,westus  my_gallery_2/image_def_2=uksouth,canadaeast,francesouth." '
216                                                                'Each key is the sig image definition ID or sig gallery name and sig image definition delimited by a "/". Each value is a comma-delimited list of replica locations.')
217        c.argument('output_name', help=ib_output_name_help)
218        c.ignore('destinations_lists', 'scripts_list', 'source_dict')
219
220    with self.argument_context('image builder create') as c:
221        ib_source_type = CLIArgumentType(arg_group="Image Source")
222        ib_customizer_type = CLIArgumentType(arg_group="Customizer")
223        ib_cutput_type = CLIArgumentType(arg_group="Output")
224
225        c.argument('build_timeout', type=int, help="The Maximum duration to wait while building the image template, in minutes. Default is 60.")
226        c.argument('image_template', help='Local path or URL to an image template file. When using --image-template, all other parameters are ignored except -g and -n. Reference: https://docs.microsoft.com/azure/virtual-machines/linux/image-builder-json')
227        c.argument('identity', nargs='+', help='List of user assigned identities (name or ID, space delimited) of the image template.')
228
229        # VM profile
230        c.argument('vm_size', help='Size of the virtual machine used to build, customize and capture images. Omit or specify empty string to use the default (Standard_D1_v2)')
231        c.argument('os_disk_size', type=int, help='Size of the OS disk in GB. Omit or specify 0 to use Azure\'s default OS disk size')
232        c.argument('vnet', help='Name of VNET to deploy the build virtual machine. You should only specify it when subnet is a name')
233        c.argument('subnet', help='Name or ID of subnet to deploy the build virtual machine')
234
235        # Image Source Arguments
236        c.argument('source', arg_type=ib_source_type)
237        c.argument('checksum', arg_type=ib_source_type)
238        c.argument('', arg_type=ib_source_type)
239
240        # Image Customizer Arguments
241        c.argument('scripts', arg_type=ib_customizer_type)
242        c.argument('', arg_type=ib_customizer_type)
243        c.argument('', arg_type=ib_customizer_type)
244
245        # Image Output Arguments
246        c.argument('managed_image_destinations', arg_type=ib_cutput_type)
247        c.argument('shared_image_destinations', arg_type=ib_cutput_type)
248        c.argument('output_name', arg_type=ib_cutput_type)
249
250    with self.argument_context('image builder output') as c:
251        ib_sig_regions_help = "Space-separated list of regions to replicate the image version into."
252        ib_img_location_help = "Location where the customized image will be created."
253
254        c.argument('gallery_image_definition', arg_group="Shared Image Gallery", help="Name or ID of the existing SIG image definition to create the customized image version with.")
255        c.argument('gallery_name', arg_group="Shared Image Gallery", help="Shared image gallery name, if image definition name and not ID was provided.")
256        c.argument('gallery_replication_regions', arg_group="Shared Image Gallery", nargs='+', help=ib_sig_regions_help)
257        c.argument('managed_image', arg_group="Managed Image", help="Name or ID of the customized managed image to be created.")
258        c.argument('managed_image_location', arg_group="Managed Image", help=ib_img_location_help)
259
260    with self.argument_context('image builder output add') as c:
261        ib_artifact_tags_help = "Tags that will be applied to the output artifact once it has been created by the distributor. " + tags_type.settings['help']
262        ib_artifact_tags_type = CLIArgumentType(overrides=tags_type, help=ib_artifact_tags_help, options_list=["--artifact-tags"])
263        ib_default_loc_help = " Defaults to resource group's location."
264
265        c.argument('output_name', help=ib_output_name_help + " Defaults to the name of the managed image or sig image definition.")
266        c.argument('gallery_replication_regions', arg_group="Shared Image Gallery", nargs='+', help=ib_sig_regions_help + ib_default_loc_help)
267        c.argument('managed_image_location', arg_group="Managed Image", help=ib_img_location_help + ib_default_loc_help)
268        c.argument('is_vhd', arg_group="VHD", help="The output is a VHD distributor.", action='store_true')
269        c.argument('tags', arg_type=ib_artifact_tags_type)
270        c.ignore('location')
271
272    with self.argument_context('image builder customizer') as c:
273        ib_win_restart_type = CLIArgumentType(arg_group="Windows Restart")
274        ib_win_update_type = CLIArgumentType(arg_group="Windows Update")
275        ib_script_type = CLIArgumentType(arg_group="Shell and Powershell")
276        ib_powershell_type = CLIArgumentType(arg_group="Powershell")
277        ib_file_customizer_type = CLIArgumentType(arg_group="File")
278
279        c.argument('customizer_name', help="Name of the customizer.")
280        c.argument('customizer_type', options_list=['--type', '-t'], help="Type of customizer to be added to the image template.", arg_type=get_enum_type(ScriptType))
281
282        # Script Args
283        c.argument('script_url', arg_type=ib_script_type, help="URL of script to customize the image with. The URL must be publicly accessible.")
284        c.argument('inline_script', arg_type=ib_script_type, nargs='+', help="Space-separated list of inline script lines to customize the image with.")
285
286        # Powershell Specific Args
287        c.argument('valid_exit_codes', options_list=['--exit-codes', '-e'], arg_type=ib_powershell_type, nargs='+', help="Space-separated list of valid exit codes, as integers")
288
289        # Windows Restart Specific Args
290        c.argument('restart_command', arg_type=ib_win_restart_type, help="Command to execute the restart operation.")
291        c.argument('restart_check_command', arg_type=ib_win_restart_type, help="Command to verify that restart succeeded.")
292        c.argument('restart_timeout', arg_type=ib_win_restart_type, help="Restart timeout specified as a string consisting of a magnitude and unit, e.g. '5m' (5 minutes) or '2h' (2 hours)", default="5m")
293
294        # Windows Update Specific Args
295        c.argument('search_criteria', arg_type=ib_win_update_type, help='Criteria to search updates. Omit or specify empty string to use the default (search all). Refer to above link for examples and detailed description of this field.')
296        c.argument('filters', arg_type=ib_win_update_type, nargs='+', help='Space delimited filters to select updates to apply. Omit or specify empty array to use the default (no filter)')
297        c.argument('update_limit', arg_type=ib_win_update_type, help='Maximum number of updates to apply at a time. Omit or specify 0 to use the default (1000)')
298
299        # File Args
300        c.argument('file_source', arg_type=ib_file_customizer_type, help="The URI of the file to be downloaded into the image. It can be a github link, SAS URI for Azure Storage, etc.")
301        c.argument('dest_path', arg_type=ib_file_customizer_type, help="The absolute destination path where the file specified in --file-source will be downloaded to in the image")
302
303    # endregion
304
305    # region AvailabilitySets
306    with self.argument_context('vm availability-set') as c:
307        c.argument('availability_set_name', name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/availabilitySets'), help='Name of the availability set')
308
309    with self.argument_context('vm availability-set create') as c:
310        c.argument('availability_set_name', name_arg_type, validator=get_default_location_from_resource_group, help='Name of the availability set')
311        c.argument('platform_update_domain_count', type=int, help='Update Domain count. If unspecified, the server will pick the most optimal number like 5.')
312        c.argument('platform_fault_domain_count', type=int, help='Fault Domain count.')
313        c.argument('validate', help='Generate and validate the ARM template without creating any resources.', action='store_true')
314        c.argument('unmanaged', action='store_true', min_api='2016-04-30-preview', help='contained VMs should use unmanaged disks')
315
316    with self.argument_context('vm availability-set update') as c:
317        if self.supported_api_version(max_api='2016-04-30-preview', operation_group='virtual_machines'):
318            c.argument('name', name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Compute/availabilitySets'), help='Name of the availability set')
319            c.argument('availability_set_name', options_list=['--availability-set-name'])
320    # endregion
321
322    # region VirtualMachines
323    with self.argument_context('vm') as c:
324        c.argument('vm_name', existing_vm_name)
325        c.argument('size', completer=get_vm_size_completion_list)
326        c.argument('name', arg_type=name_arg_type)
327        c.argument('zone', zone_type, min_api='2017-03-30')
328        c.argument('caching', help='Disk caching policy', arg_type=get_enum_type(CachingTypes))
329        c.argument('nsg', help='The name to use when creating a new Network Security Group (default) or referencing an existing one. Can also reference an existing NSG by ID or specify "" for none.', arg_group='Network')
330        c.argument('nsg_rule', help='NSG rule to create when creating a new NSG. Defaults to open ports for allowing RDP on Windows and allowing SSH on Linux.', arg_group='Network', arg_type=get_enum_type(['RDP', 'SSH']))
331        c.argument('application_security_groups', min_api='2017-09-01', nargs='+', options_list=['--asgs'], help='Space-separated list of existing application security groups to associate with the VM.', arg_group='Network')
332        c.argument('workspace', is_preview=True, arg_group='Monitor', help='Name or ID of Log Analytics Workspace. If you specify the workspace through its name, the workspace should be in the same resource group with the vm, otherwise a new workspace will be created.')
333    with self.argument_context('vm capture') as c:
334        c.argument('overwrite', action='store_true')
335
336    with self.argument_context('vm update') as c:
337        c.argument('os_disk', min_api='2017-12-01', help="Managed OS disk ID or name to swap to")
338        c.argument('write_accelerator', nargs='*', min_api='2017-12-01',
339                   help="enable/disable disk write accelerator. Use singular value 'true/false' to apply across, or specify individual disks, e.g.'os=true 1=true 2=true' for os disk and data disks with lun of 1 & 2")
340        c.argument('disk_caching', nargs='*', help="Use singular value to apply across, or specify individual disks, e.g. 'os=ReadWrite 0=None 1=ReadOnly' should enable update os disk and 2 data disks")
341        c.argument('ultra_ssd_enabled', ultra_ssd_enabled_type)
342        c.argument('enable_secure_boot', arg_type=get_three_state_flag(), min_api='2020-12-01',
343                   help='Enable secure boot.')
344        c.argument('enable_vtpm', arg_type=get_three_state_flag(), min_api='2020-12-01',
345                   help='Enable vTPM.')
346
347    with self.argument_context('vm create') as c:
348        c.argument('name', name_arg_type, validator=_resource_not_exists(self.cli_ctx, 'Microsoft.Compute/virtualMachines'))
349        c.argument('vm_name', name_arg_type, id_part=None, help='Name of the virtual machine.', completer=None)
350        c.argument('os_disk_size_gb', type=int, help='the size of the os disk in GB', arg_group='Storage')
351        c.argument('availability_set', help='Name or ID of an existing availability set to add the VM to. None by default.')
352        c.argument('vmss', help='Name or ID of an existing virtual machine scale set that the virtual machine should be assigned to. None by default.')
353        c.argument('nsg', help='The name to use when creating a new Network Security Group (default) or referencing an existing one. Can also reference an existing NSG by ID or specify "" for none (\'""\' in Azure CLI using PowerShell or --% operator).', arg_group='Network')
354        c.argument('nsg_rule', help='NSG rule to create when creating a new NSG. Defaults to open ports for allowing RDP on Windows and allowing SSH on Linux. NONE represents no NSG rule', arg_group='Network', arg_type=get_enum_type(['RDP', 'SSH', 'NONE']))
355        c.argument('application_security_groups', resource_type=ResourceType.MGMT_NETWORK, min_api='2017-09-01', nargs='+', options_list=['--asgs'], help='Space-separated list of existing application security groups to associate with the VM.', arg_group='Network', validator=validate_asg_names_or_ids)
356        c.argument('boot_diagnostics_storage',
357                   help='pre-existing storage account name or its blob uri to capture boot diagnostics. Its sku should be one of Standard_GRS, Standard_LRS and Standard_RAGRS')
358        c.argument('accelerated_networking', resource_type=ResourceType.MGMT_NETWORK, min_api='2016-09-01', arg_type=get_three_state_flag(), arg_group='Network',
359                   help="enable accelerated networking. Unless specified, CLI will enable it based on machine image and size")
360        if self.supported_api_version(min_api='2019-03-01', resource_type=ResourceType.MGMT_COMPUTE):
361            VirtualMachineEvictionPolicyTypes = self.get_models('VirtualMachineEvictionPolicyTypes', resource_type=ResourceType.MGMT_COMPUTE)
362            c.argument('eviction_policy', resource_type=ResourceType.MGMT_COMPUTE, min_api='2019-03-01',
363                       arg_type=get_enum_type(VirtualMachineEvictionPolicyTypes, default=None),
364                       help="The eviction policy for the Spot priority virtual machine. Default eviction policy is Deallocate for a Spot priority virtual machine")
365        c.argument('enable_agent', arg_type=get_three_state_flag(), min_api='2018-06-01',
366                   help='Indicates whether virtual machine agent should be provisioned on the virtual machine. When this property is not specified, default behavior is to set it to true. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later')
367        c.argument('enable_auto_update', arg_type=get_three_state_flag(), min_api='2020-06-01',
368                   help='Indicate whether Automatic Updates is enabled for the Windows virtual machine')
369        c.argument('patch_mode', arg_type=get_enum_type(['AutomaticByOS', 'AutomaticByPlatform', 'Manual', 'ImageDefault']), min_api='2020-12-01',
370                   help='Mode of in-guest patching to IaaS virtual machine. Allowed values for Windows VM: AutomaticByOS, AutomaticByPlatform, Manual. Allowed values for Linux VM: AutomaticByPlatform, ImageDefault. Manual - You control the application of patches to a virtual machine. You do this by applying patches manually inside the VM. In this mode, automatic updates are disabled; the paramater --enable-auto-update must be false. AutomaticByOS - The virtual machine will automatically be updated by the OS. The parameter --enable-auto-update must be true. AutomaticByPlatform - the virtual machine will automatically updated by the OS. ImageDefault - The virtual machine\'s default patching configuration is used. The parameter --enable-agent and --enable-auto-update must be true')
371        c.argument('ssh_key_name', help='Use it as public key in virtual machine. It should be an existing SSH key resource in Azure.')
372        c.argument('enable_hotpatching', arg_type=get_three_state_flag(), help='Patch VMs without requiring a reboot. --enable-agent must be set and --patch-mode must be set to AutomaticByPlatform', min_api='2020-12-01')
373        c.argument('platform_fault_domain', min_api='2020-06-01',
374                   help='Specify the scale set logical fault domain into which the virtual machine will be created. By default, the virtual machine will be automatically assigned to a fault domain that best maintains balance across available fault domains. This is applicable only if the virtualMachineScaleSet property of this virtual machine is set. The virtual machine scale set that is referenced, must have platform fault domain count. This property cannot be updated once the virtual machine is created. Fault domain assignment can be viewed in the virtual machine instance view')
375        c.argument('count', type=int, is_preview=True,
376                   help='Number of virtual machines to create. Value range is [2, 250], inclusive. Don\'t specify this parameter if you want to create a normal single VM. The VMs are created in parallel. The output of this command is an array of VMs instead of one single VM. Each VM has its own public IP, NIC. VNET and NSG are shared. It is recommended that no existing public IP, NIC, VNET and NSG are in resource group. When --count is specified, --attach-data-disks, --attach-os-disk, --boot-diagnostics-storage, --computer-name, --host, --host-group, --nics, --os-disk-name, --private-ip-address, --public-ip-address, --public-ip-address-dns-name, --storage-account, --storage-container-name, --subnet, --use-unmanaged-disk, --vnet-name are not allowed.')
377        c.argument('security_type', arg_type=get_enum_type(['TrustedLaunch']), min_api='2020-12-01',
378                   help='Specify if the VM is Trusted Launch enabled. See https://docs.microsoft.com/azure/virtual-machines/trusted-launch.')
379        c.argument('enable_secure_boot', arg_type=get_three_state_flag(), min_api='2020-12-01',
380                   help='Enable secure boot. It is part of trusted launch.')
381        c.argument('enable_vtpm', arg_type=get_three_state_flag(), min_api='2020-12-01',
382                   help='Enable vTPM. It is part of trusted launch.')
383        c.argument('user_data', help='UserData for the VM. It can be passed in as file or string.', completer=FilesCompleter(), type=file_type, min_api='2021-03-01')
384
385    with self.argument_context('vm create', arg_group='Storage') as c:
386        c.argument('attach_os_disk', help='Attach an existing OS disk to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.')
387        c.argument('attach_data_disks', nargs='+', help='Attach existing data disks to the VM. Can use the name or ID of a managed disk or the URI to an unmanaged disk VHD.')
388
389    with self.argument_context('vm create', arg_group='Dedicated Host', min_api='2019-03-01') as c:
390        c.argument('dedicated_host_group', options_list=['--host-group'], is_preview=True, help="Name or ID of the dedicated host group that the VM will reside in. --host and --host-group can't be used together.")
391        c.argument('dedicated_host', options_list=['--host'], is_preview=True, help="ID of the dedicated host that the VM will reside in. --host and --host-group can't be used together.")
392
393    with self.argument_context('vm open-port') as c:
394        c.argument('vm_name', name_arg_type, help='The name of the virtual machine to open inbound traffic on.')
395        c.argument('network_security_group_name', options_list=('--nsg-name',), help='The name of the network security group to create if one does not exist. Ignored if an NSG already exists.', validator=validate_nsg_name)
396        c.argument('apply_to_subnet', help='Allow inbound traffic on the subnet instead of the NIC', action='store_true')
397        c.argument('port', help="The port or port range (ex: 80-100) to open inbound traffic to. Use '*' to allow traffic to all ports. Use comma separated values to specify more than one port or port range.")
398        c.argument('priority', help='Rule priority, between 100 (highest priority) and 4096 (lowest priority). Must be unique for each rule in the collection.', type=int)
399
400    for scope in ['vm show', 'vm list']:
401        with self.argument_context(scope) as c:
402            c.argument('show_details', action='store_true', options_list=['--show-details', '-d'], help='show public ip address, FQDN, and power states. command will run slow')
403
404    for scope in ['vm show', 'vmss show']:
405        with self.argument_context(scope) as c:
406            c.argument('include_user_data', action='store_true', options_list=['--include-user-data', '-u'], help='Include the user data properties in the query result.', min_api='2021-03-01')
407
408    for scope in ['vm get-instance-view', 'vm wait', 'vmss wait']:
409        with self.argument_context(scope) as c:
410            c.ignore('include_user_data')
411
412    with self.argument_context('vm diagnostics') as c:
413        c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'])
414
415    with self.argument_context('vm diagnostics set') as c:
416        c.argument('storage_account', completer=get_resource_name_completion_list('Microsoft.Storage/storageAccounts'))
417
418    with self.argument_context('vm install-patches') as c:
419        c.argument('maximum_duration', type=str, help='Specify the maximum amount of time that the operation will run. It must be an ISO 8601-compliant duration string such as PT4H (4 hours)')
420        c.argument('reboot_setting', arg_type=get_enum_type(RebootSetting), help='Define when it is acceptable to reboot a VM during a software update operation.')
421        c.argument('classifications_to_include_win', nargs='+', arg_type=get_enum_type(VMGuestPatchClassificationWindows), help='Space-separated list of classifications to include for Windows VM.')
422        c.argument('classifications_to_include_linux', nargs='+', arg_type=get_enum_type(VMGuestPatchClassificationLinux), help='Space-separated list of classifications to include for Linux VM.')
423        c.argument('kb_numbers_to_include', nargs='+', help='Space-separated list of KBs to include in the patch operation. Applicable to Windows VM only')
424        c.argument('kb_numbers_to_exclude', nargs='+', help='Space-separated list of KBs to exclude in the patch operation. Applicable to Windows VM only')
425        c.argument('exclude_kbs_requiring_reboot', arg_type=get_three_state_flag(), help="Filter out KBs that don't have a reboot behavior of 'NeverReboots' when this is set. Applicable to Windows VM only")
426        c.argument('package_name_masks_to_include', nargs='+', help='Space-separated list of packages to include in the patch operation. Format: packageName_packageVersion. Applicable to Linux VM only')
427        c.argument('package_name_masks_to_exclude', nargs='+', help='Space-separated list of packages to exclude in the patch operation. Format: packageName_packageVersion. Applicable to Linux VM only')
428
429    with self.argument_context('vm disk') as c:
430        c.argument('vm_name', options_list=['--vm-name'], id_part=None, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines'))
431        c.argument('new', action='store_true', help='create a new disk')
432        c.argument('sku', arg_type=disk_sku, help='Underlying storage SKU')
433        c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
434        c.argument('lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virtual Machine size.')
435
436    with self.argument_context('vm disk attach') as c:
437        c.argument('enable_write_accelerator', min_api='2017-12-01', action='store_true', help='enable write accelerator')
438        c.argument('disk', options_list=['--name', '-n', c.deprecate(target='--disk', redirect='--name', hide=True)],
439                   help="The name or ID of the managed disk", validator=validate_vm_disk, id_part='name',
440                   completer=get_resource_name_completion_list('Microsoft.Compute/disks'))
441
442    with self.argument_context('vm disk detach') as c:
443        c.argument('disk_name', arg_type=name_arg_type, help='The data disk name.')
444
445    with self.argument_context('vm encryption enable') as c:
446        c.argument('encrypt_format_all', action='store_true', help='Encrypts-formats data disks instead of encrypting them. Encrypt-formatting is a lot faster than in-place encryption but wipes out the partition getting encrypt-formatted.')
447        # Place aad arguments in their own group
448        aad_arguments = 'Azure Active Directory'
449        c.argument('aad_client_id', arg_group=aad_arguments)
450        c.argument('aad_client_secret', arg_group=aad_arguments)
451        c.argument('aad_client_cert_thumbprint', arg_group=aad_arguments)
452
453    with self.argument_context('vm extension') as c:
454        c.argument('vm_extension_name', name_arg_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines/extensions'), help='Name of the extension.', id_part='child_name_1')
455        c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'], id_part='name')
456        c.argument('expand', deprecate_info=c.deprecate(expiration='3.0.0', hide=True))
457
458    with self.argument_context('vm extension list') as c:
459        c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'], id_part=None)
460
461    with self.argument_context('vm secret') as c:
462        c.argument('secrets', multi_ids_type, options_list=['--secrets', '-s'], help='Space-separated list of key vault secret URIs. Perhaps, produced by \'az keyvault secret list-versions --vault-name vaultname -n cert1 --query "[?attributes.enabled].id" -o tsv\'')
463        c.argument('keyvault', help='Name or ID of the key vault.', validator=validate_keyvault)
464        c.argument('certificate', help='key vault certificate name or its full secret URL')
465        c.argument('certificate_store', help='Windows certificate store names. Default: My')
466
467    with self.argument_context('vm secret list') as c:
468        c.argument('vm_name', arg_type=existing_vm_name, id_part=None)
469
470    with self.argument_context('vm image') as c:
471        c.argument('publisher_name', options_list=['--publisher', '-p'], help='image publisher')
472        c.argument('publisher', options_list=['--publisher', '-p'], help='image publisher')
473        c.argument('offer', options_list=['--offer', '-f'], help='image offer')
474        c.argument('plan', help='image billing plan')
475        c.argument('sku', options_list=['--sku', '-s'], help='image sku')
476        c.argument('version', help="image sku's version")
477        c.argument('urn', help="URN, in format of 'publisher:offer:sku:version' or 'publisher:offer:sku:edge_zone:version'. If specified, other argument values can be omitted")
478
479    with self.argument_context('vm image list') as c:
480        c.argument('image_location', get_location_type(self.cli_ctx))
481        c.argument('edge_zone', edge_zone_type)
482
483    with self.argument_context('vm image list-offers') as c:
484        c.argument('edge_zone', edge_zone_type)
485
486    with self.argument_context('vm image list-skus') as c:
487        c.argument('edge_zone', edge_zone_type)
488
489    with self.argument_context('vm image list-publishers') as c:
490        c.argument('edge_zone', edge_zone_type)
491
492    with self.argument_context('vm image show') as c:
493        c.argument('skus', options_list=['--sku', '-s'])
494        c.argument('edge_zone', edge_zone_type)
495
496    with self.argument_context('vm image terms') as c:
497        c.argument('urn', help='URN, in the format of \'publisher:offer:sku:version\'. If specified, other argument values can be omitted')
498        c.argument('publisher', help='Image publisher')
499        c.argument('offer', help='Image offer')
500        c.argument('plan', help='Image billing plan')
501
502    with self.argument_context('vm nic') as c:
503        c.argument('vm_name', existing_vm_name, options_list=['--vm-name'], id_part=None)
504        c.argument('nics', nargs='+', help='Names or IDs of NICs.', validator=validate_vm_nics)
505        c.argument('primary_nic', help='Name or ID of the primary NIC. If missing, the first NIC in the list will be the primary.')
506
507    with self.argument_context('vm nic show') as c:
508        c.argument('nic', help='NIC name or ID.', validator=validate_vm_nic)
509
510    with self.argument_context('vm unmanaged-disk') as c:
511        c.argument('new', action='store_true', help='Create a new disk.')
512        c.argument('lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virtual Machine size.')
513        c.argument('vhd_uri', help="Virtual hard disk URI. For example: https://mystorage.blob.core.windows.net/vhds/d1.vhd")
514
515    with self.argument_context('vm unmanaged-disk attach') as c:
516        c.argument('disk_name', options_list=['--name', '-n'], help='The data disk name.')
517        c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
518
519    with self.argument_context('vm unmanaged-disk detach') as c:
520        c.argument('disk_name', options_list=['--name', '-n'], help='The data disk name.')
521
522    for scope in ['vm unmanaged-disk attach', 'vm unmanaged-disk detach']:
523        with self.argument_context(scope) as c:
524            c.argument('vm_name', arg_type=existing_vm_name, options_list=['--vm-name'], id_part=None)
525
526    with self.argument_context('vm unmanaged-disk list') as c:
527        c.argument('vm_name', options_list=['--vm-name', '--name', '-n'], arg_type=existing_vm_name, id_part=None)
528
529    with self.argument_context('vm user') as c:
530        c.argument('username', options_list=['--username', '-u'], help='The user name')
531        c.argument('password', options_list=['--password', '-p'], help='The user password')
532
533    with self.argument_context('vm list-skus') as c:
534        c.argument('size', options_list=['--size', '-s'], help="size name, partial name is accepted")
535        c.argument('zone', options_list=['--zone', '-z'], arg_type=get_three_state_flag(), help="show skus supporting availability zones")
536        c.argument('show_all', options_list=['--all'], arg_type=get_three_state_flag(),
537                   help="show all information including vm sizes not available under the current subscription")
538        c.argument('resource_type', options_list=['--resource-type', '-r'], help='resource types e.g. "availabilitySets", "snapshots", "disks", etc')
539
540    with self.argument_context('vm restart') as c:
541        c.argument('force', action='store_true', help='Force the VM to restart by redeploying it. Use if the VM is unresponsive.')
542
543    with self.argument_context('vm host') as c:
544        c.argument('host_group_name', options_list=['--host-group'], id_part='name', help="Name of the Dedicated Host Group")
545        c.argument('host_name', name_arg_type, id_part='child_name_1', help="Name of the Dedicated Host")
546        c.ignore('expand')
547
548    with self.argument_context('vm host create') as c:
549        c.argument('platform_fault_domain', options_list=['--platform-fault-domain', '-d'], type=int,
550                   help="Fault domain of the host within a group. Allowed values: 0, 1, 2")
551        c.argument('auto_replace_on_failure', options_list=['--auto-replace'], arg_type=get_three_state_flag(),
552                   help="Replace the host automatically if a failure occurs")
553        c.argument('license_type', arg_type=get_enum_type(DedicatedHostLicenseTypes),
554                   help="The software license type that will be applied to the VMs deployed on the dedicated host.")
555        c.argument('sku', help="SKU of the dedicated host. Available SKUs: https://azure.microsoft.com/pricing/details/virtual-machines/dedicated-host/")
556
557    with self.argument_context('vm host list') as c:
558        c.argument('host_group_name', id_part=None)
559
560    with self.argument_context('vm host group') as c:
561        c.argument('host_group_name', name_arg_type, id_part='name', help="Name of the Dedicated Host Group")
562        c.argument('automatic_placement', arg_type=get_three_state_flag(), min_api='2020-06-01',
563                   help='Specify whether virtual machines or virtual machine scale sets can be placed automatically '
564                        'on the dedicated host group. Automatic placement means resources are allocated on dedicated '
565                        'hosts, that are chosen by Azure, under the dedicated host group. The value is defaulted to '
566                        'false when not provided.')
567
568    with self.argument_context('vm host group create') as c:
569        c.argument('platform_fault_domain_count', options_list=["--platform-fault-domain-count", "-c"], type=int,
570                   help="Number of fault domains that the host group can span.")
571        c.argument('zones', zone_type)
572
573    for scope in ["vm host", "vm host group"]:
574        with self.argument_context("{} create".format(scope)) as c:
575            location_type = get_location_type(self.cli_ctx)
576            custom_location_msg = " Otherwise, location will default to the resource group's location"
577            custom_location_type = CLIArgumentType(overrides=location_type,
578                                                   help=location_type.settings["help"] + custom_location_msg)
579            c.argument('location', arg_type=custom_location_type)
580    # endregion
581
582    # region VMSS
583    scaleset_name_aliases = ['vm_scale_set_name', 'virtual_machine_scale_set_name', 'name']
584
585    with self.argument_context('vmss') as c:
586        c.argument('zones', zones_type, min_api='2017-03-30')
587        c.argument('instance_id', id_part='child_name_1')
588        c.argument('instance_ids', multi_ids_type, help='Space-separated list of IDs (ex: 1 2 3 ...) or * for all instances. If not provided, the action will be applied on the scaleset itself')
589        c.argument('tags', tags_type)
590        c.argument('caching', help='Disk caching policy', arg_type=get_enum_type(CachingTypes))
591        for dest in scaleset_name_aliases:
592            c.argument(dest, vmss_name_type)
593        c.argument('host_group', min_api='2020-06-01',
594                   help='Name or ID of dedicated host group that the virtual machine scale set resides in')
595
596    for scope in ['vmss deallocate', 'vmss delete-instances', 'vmss restart', 'vmss start', 'vmss stop', 'vmss show', 'vmss update-instances', 'vmss simulate-eviction']:
597        with self.argument_context(scope) as c:
598            for dest in scaleset_name_aliases:
599                c.argument(dest, vmss_name_type, id_part=None)  # due to instance-ids parameter
600
601    with self.argument_context('vmss create', operation_group='virtual_machine_scale_sets') as c:
602        VirtualMachineEvictionPolicyTypes = self.get_models('VirtualMachineEvictionPolicyTypes', resource_type=ResourceType.MGMT_COMPUTE)
603
604        c.argument('name', name_arg_type)
605        c.argument('nat_backend_port', default=None, help='Backend port to open with NAT rules. Defaults to 22 on Linux and 3389 on Windows.')
606        c.argument('single_placement_group', arg_type=get_three_state_flag(), help="Limit the scale set to a single placement group."
607                   " See https://docs.microsoft.com/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-placement-groups for details.")
608        c.argument('platform_fault_domain_count', type=int, help='Fault Domain count for each placement group in the availability zone', min_api='2017-12-01')
609        c.argument('vmss_name', name_arg_type, id_part=None, help='Name of the virtual machine scale set.')
610        c.argument('instance_count', help='Number of VMs in the scale set.', type=int)
611        c.argument('disable_overprovision', help='Overprovision option (see https://azure.microsoft.com/documentation/articles/virtual-machine-scale-sets-overview/ for details).', action='store_true')
612        c.argument('upgrade_policy_mode', help=None, arg_type=get_enum_type(UpgradeMode))
613        c.argument('health_probe', help='Probe name from the existing load balancer, mainly used for rolling upgrade or automatic repairs')
614        c.argument('vm_sku', help='Size of VMs in the scale set. Default to "Standard_DS1_v2". See https://azure.microsoft.com/pricing/details/virtual-machines/ for size info.')
615        c.argument('nsg', help='Name or ID of an existing Network Security Group.', arg_group='Network')
616        c.argument('eviction_policy', resource_type=ResourceType.MGMT_COMPUTE, min_api='2017-12-01', arg_type=get_enum_type(VirtualMachineEvictionPolicyTypes, default=None),
617                   help="The eviction policy for virtual machines in a Spot priority scale set. Default eviction policy is Deallocate for a Spot priority scale set")
618        c.argument('application_security_groups', resource_type=ResourceType.MGMT_COMPUTE, min_api='2018-06-01', nargs='+', options_list=['--asgs'], help='Space-separated list of existing application security groups to associate with the VM.', arg_group='Network', validator=validate_asg_names_or_ids)
619        c.argument('computer_name_prefix', help='Computer name prefix for all of the virtual machines in the scale set. Computer name prefixes must be 1 to 15 characters long')
620        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. In Flexible mode, you manually create and add a virtual machine of any configuration to the scale set or generate identical instances based on virtual machine model defined for the scale set.',
621                   arg_type=get_enum_type(['Uniform', 'Flexible']))
622        c.argument('scale_in_policy', scale_in_policy_type)
623        c.argument('automatic_repairs_grace_period', min_api='2018-10-01',
624                   help='The amount of time (in minutes, between 30 and 90) for which automatic repairs are suspended due to a state change on VM.')
625        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')
626        c.argument('network_api_version', min_api='2021-03-01',
627                   help="Specify the Microsoft.Network API version used when creating networking resources in the Network "
628                        "Interface Configurations for Virtual Machine Scale Set with orchestration mode 'Flexible'. Default "
629                        "value is 2020-11-01.")
630        c.argument('enable_spot_restore', arg_type=get_three_state_flag(), min_api='2021-04-01', help='Enable the Spot-Try-Restore feature where evicted VMSS SPOT instances will be tried to be restored opportunistically based on capacity availability and pricing constraints')
631        c.argument('spot_restore_timeout', min_api='2021-04-01', help='Timeout value expressed as an ISO 8601 time duration after which the platform will not try to restore the VMSS SPOT instances')
632
633    with self.argument_context('vmss create', arg_group='Network Balancer') as c:
634        LoadBalancerSkuName = self.get_models('LoadBalancerSkuName', resource_type=ResourceType.MGMT_NETWORK)
635        c.argument('application_gateway', help='Name to use when creating a new application gateway (default) or referencing an existing one. Can also reference an existing application gateway by ID or specify "" for none.', options_list=['--app-gateway'])
636        c.argument('app_gateway_capacity', help='The number of instances to use when creating a new application gateway.')
637        c.argument('app_gateway_sku', help='SKU when creating a new application gateway.')
638        c.argument('app_gateway_subnet_address_prefix', help='The subnet IP address prefix to use when creating a new application gateway in CIDR format.')
639        c.argument('backend_pool_name', help='Name to use for the backend pool when creating a new load balancer or application gateway.')
640        c.argument('backend_port', help='When creating a new load balancer, backend port to open with NAT rules (Defaults to 22 on Linux and 3389 on Windows). When creating an application gateway, the backend port to use for the backend HTTP settings.', type=int)
641        c.argument('load_balancer', help='Name to use when creating a new load balancer (default) or referencing an existing one. Can also reference an existing load balancer by ID or specify "" for none.', options_list=['--load-balancer', '--lb'])
642        c.argument('load_balancer_sku', resource_type=ResourceType.MGMT_NETWORK, min_api='2017-08-01', options_list=['--lb-sku'], arg_type=get_enum_type(LoadBalancerSkuName),
643                   help="Sku of the Load Balancer to create. Default to 'Standard' when single placement group is turned off; otherwise, default to 'Basic'. The public IP is supported to be created on edge zone only when it is 'Standard'")
644        c.argument('nat_pool_name', help='Name to use for the NAT pool when creating a new load balancer.', options_list=['--lb-nat-pool-name', '--nat-pool-name'])
645
646    with self.argument_context('vmss create', min_api='2017-03-30', arg_group='Network') as c:
647        c.argument('public_ip_per_vm', action='store_true', help="Each VM instance will have a public ip. For security, you can use '--nsg' to apply appropriate rules")
648        c.argument('vm_domain_name', help="domain name of VM instances, once configured, the FQDN is `vm<vm-index>.<vm-domain-name>.<..rest..>`")
649        c.argument('dns_servers', nargs='+', help="space-separated IP addresses of DNS servers, e.g. 10.0.0.5 10.0.0.6")
650        c.argument('accelerated_networking', arg_type=get_three_state_flag(),
651                   help="enable accelerated networking. Unless specified, CLI will enable it based on machine image and size")
652
653    with self.argument_context('vmss update') as c:
654        protection_policy_type = CLIArgumentType(overrides=get_three_state_flag(), arg_group="Protection Policy", min_api='2019-03-01')
655        c.argument('protect_from_scale_in', arg_type=protection_policy_type, help="Protect the VM instance from scale-in operations.")
656        c.argument('protect_from_scale_set_actions', arg_type=protection_policy_type, help="Protect the VM instance from scale set actions (including scale-in).")
657        c.argument('enable_terminate_notification', min_api='2019-03-01', arg_type=get_three_state_flag(),
658                   help='Enable terminate notification')
659        c.argument('ultra_ssd_enabled', ultra_ssd_enabled_type)
660        c.argument('scale_in_policy', scale_in_policy_type)
661        c.argument('user_data', help='UserData for the virtual machines in the scale set. It can be passed in as file or string. If empty string is passed in, the existing value will be deleted.', completer=FilesCompleter(), type=file_type, min_api='2021-03-01')
662        c.argument('enable_spot_restore', arg_type=get_three_state_flag(), min_api='2021-04-01',
663                   help='Enable the Spot-Try-Restore feature where evicted VMSS SPOT instances will be tried to be restored opportunistically based on capacity availability and pricing constraints')
664        c.argument('spot_restore_timeout', min_api='2021-04-01',
665                   help='Timeout value expressed as an ISO 8601 time duration after which the platform will not try to restore the VMSS SPOT instances')
666
667    with self.argument_context('vmss update', min_api='2018-10-01', arg_group='Automatic Repairs') as c:
668        c.argument('enable_automatic_repairs', arg_type=get_three_state_flag(), help='Enable automatic repairs')
669        c.argument(
670            'automatic_repairs_grace_period',
671            help='The amount of time (in minutes, between 30 and 90) for which automatic repairs are suspended due to a state change on VM.'
672        )
673
674    for scope in ['vmss create', 'vmss update']:
675        with self.argument_context(scope) as c:
676            c.argument('terminate_notification_time', min_api='2019-03-01',
677                       help='Length of time (in minutes, between 5 and 15) a notification to be sent to the VM on the instance metadata server till the VM gets deleted')
678            c.argument('max_batch_instance_percent', type=int, min_api='2020-12-01',
679                       help='The maximum percent of total virtual machine instances that will be upgraded simultaneously by the rolling upgrade in one batch. Default: 20%')
680            c.argument('max_unhealthy_instance_percent', type=int, min_api='2020-12-01',
681                       help='The maximum percentage of the total virtual machine instances in the scale set that can be simultaneously unhealthy. Default: 20%')
682            c.argument('max_unhealthy_upgraded_instance_percent', type=int, min_api='2020-12-01',
683                       help='The maximum percentage of upgraded virtual machine instances that can be found to be in an unhealthy state. Default: 20%')
684            c.argument('pause_time_between_batches', min_api='2020-12-01',
685                       help='The wait time between completing the update for all virtual machines in one batch and starting the next batch. Default: 0 seconds')
686            c.argument('enable_cross_zone_upgrade', arg_type=get_three_state_flag(), min_api='2020-12-01',
687                       help='Set this Boolean property will allow VMSS to ignore AZ boundaries when constructing upgrade batches, and only consider Update Domain and maxBatchInstancePercent to determine the batch size')
688            c.argument('prioritize_unhealthy_instances', arg_type=get_three_state_flag(), min_api='2020-12-01',
689                       help='Set this Boolean property will lead to all unhealthy instances in a scale set getting upgraded before any healthy instances')
690
691    for scope, help_prefix in [('vmss update', 'Update the'), ('vmss wait', 'Wait on the')]:
692        with self.argument_context(scope) as c:
693            c.argument('instance_id', id_part='child_name_1', help="{0} VM instance with this ID. If missing, {0} VMSS.".format(help_prefix))
694
695    for scope in ['vmss update-instances', 'vmss delete-instances']:
696        with self.argument_context(scope) as c:
697            c.argument('instance_ids', multi_ids_type, help='Space-separated list of IDs (ex: 1 2 3 ...) or * for all instances.')
698
699    with self.argument_context('vmss diagnostics') as c:
700        c.argument('vmss_name', id_part=None, help='Scale set name')
701
702    with self.argument_context('vmss disk') as c:
703        options_list = ['--vmss-name'] + [c.deprecate(target=opt, redirect='--vmss-name', hide=True)for opt in name_arg_type.settings['options_list']]
704        new_vmss_name_type = CLIArgumentType(overrides=vmss_name_type, options_list=options_list)
705
706        c.argument('lun', type=int, help='0-based logical unit number (LUN). Max value depends on the Virtual Machine instance size.')
707        c.argument('size_gb', options_list=['--size-gb', '-z'], help='size in GB. Max size: 4095 GB (certain preview disks can be larger).', type=int)
708        c.argument('vmss_name', new_vmss_name_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'))
709        c.argument('disk', validator=validate_vmss_disk, help='existing disk name or ID to attach or detach from VM instances',
710                   min_api='2017-12-01', completer=get_resource_name_completion_list('Microsoft.Compute/disks'))
711        c.argument('instance_id', help='Scale set VM instance id', min_api='2017-12-01')
712        c.argument('sku', arg_type=disk_sku, help='Underlying storage SKU')
713
714    with self.argument_context('vmss encryption') as c:
715        c.argument('vmss_name', vmss_name_type, completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'))
716
717    with self.argument_context('vmss extension') as c:
718        c.argument('extension_name', name_arg_type, help='Name of the extension.')
719        c.argument('vmss_name', vmss_name_type, options_list=['--vmss-name'], id_part=None)
720
721    with self.argument_context('vmss nic') as c:
722        c.argument('virtual_machine_scale_set_name', options_list=['--vmss-name'], help='Scale set name.', completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachineScaleSets'), id_part='name')
723        c.argument('virtualmachine_index', options_list=['--instance-id'], id_part='child_name_1')
724        c.argument('network_interface_name', options_list=['--name', '-n'], metavar='NIC_NAME', help='The network interface (NIC).', completer=get_resource_name_completion_list('Microsoft.Network/networkInterfaces'), id_part='child_name_2')
725
726    with self.argument_context('vmss nic list') as c:
727        c.argument('virtual_machine_scale_set_name', arg_type=vmss_name_type, options_list=['--vmss-name'], id_part=None)
728
729    with self.argument_context('vmss set-orchestration-service-state') as c:
730        c.argument('service_name', arg_type=get_enum_type(OrchestrationServiceNames), help='The name of the orchestration service.')
731        c.argument('action', arg_type=get_enum_type(OrchestrationServiceStateAction), help='The action to be performed.')
732    # endregion
733
734    # region VM & VMSS Shared
735    for scope in ['vm', 'vmss']:
736        with self.argument_context(scope) as c:
737            c.argument('no_auto_upgrade',
738                       options_list=['--no-auto-upgrade-minor-version', c.deprecate(target='--no-auto-upgrade', redirect='--no-auto-upgrade-minor-version')],
739                       arg_type=get_three_state_flag(),
740                       help='If set, the extension service will not automatically pick or upgrade to the latest minor version, even if the extension is redeployed.')
741
742        with self.argument_context('{} run-command'.format(scope)) as c:
743            c.argument('command_id', completer=get_vm_run_command_completion_list, help="The command id. Use 'az {} run-command list' to get the list".format(scope))
744            if scope == 'vmss':
745                c.argument('vmss_name', vmss_name_type)
746
747        with self.argument_context('{} run-command invoke'.format(scope)) as c:
748            c.argument('parameters', nargs='+', help="space-separated parameters in the format of '[name=]value'")
749            c.argument('scripts', nargs='+', help="Space-separated script lines. Use @{file} to load script from a file")
750
751        with self.argument_context('{} stop'.format(scope)) as c:
752            c.argument('skip_shutdown', action='store_true', help='Skip shutdown and power-off immediately.', min_api='2019-03-01')
753
754    for scope in ['vm identity assign', 'vmss identity assign']:
755        with self.argument_context(scope) as c:
756            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))
757            c.argument('vm_name', existing_vm_name)
758            c.argument('vmss_name', vmss_name_type)
759
760    for scope in ['vm identity remove', 'vmss identity remove']:
761        with self.argument_context(scope) as c:
762            c.argument('identities', nargs='+', help="Space-separated identities to remove. Use '{0}' to refer to the system assigned identity. Default: '{0}'".format(MSI_LOCAL_ID))
763            c.argument('vm_name', existing_vm_name)
764            c.argument('vmss_name', vmss_name_type)
765
766    for scope in ['vm identity show', 'vmss identity show']:
767        with self.argument_context(scope) as c:
768            c.argument('vm_name', existing_vm_name)
769            c.argument('vmss_name', vmss_name_type)
770
771    for scope in ['vm create', 'vmss create']:
772        with self.argument_context(scope) as c:
773            c.argument('location', get_location_type(self.cli_ctx), help='Location in which to create VM and related resources. If default location is not configured, will default to the resource group\'s location')
774            c.argument('tags', tags_type)
775            c.argument('no_wait', help='Do not wait for the long-running operation to finish.')
776            c.argument('validate', options_list=['--validate'], help='Generate and validate the ARM template without creating any resources.', action='store_true')
777            c.argument('size', help='The VM size to be created. See https://azure.microsoft.com/pricing/details/virtual-machines/ for size info.')
778            c.argument('image', completer=get_urn_aliases_completion_list)
779            c.argument('custom_data', help='Custom init script file or text (cloud-init, cloud-config, etc..)', completer=FilesCompleter(), type=file_type)
780            c.argument('secrets', multi_ids_type, help='One or many Key Vault secrets as JSON strings or files via `@{path}` containing `[{ "sourceVault": { "id": "value" }, "vaultCertificates": [{ "certificateUrl": "value", "certificateStore": "cert store name (only on windows)"}] }]`', type=file_type, completer=FilesCompleter())
781            c.argument('assign_identity', nargs='*', arg_group='Managed Service Identity', help="accept system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity, or a resource id to refer user assigned identity. Check out help for more examples")
782            c.ignore('aux_subscriptions')
783            c.argument('edge_zone', edge_zone_type)
784
785        with self.argument_context(scope, arg_group='Authentication') as c:
786            c.argument('generate_ssh_keys', action='store_true', help='Generate SSH public and private key files if missing. The keys will be stored in the ~/.ssh directory')
787            c.argument('admin_username', help='Username for the VM. Default value is current username of OS. If the default value is system reserved, then default value will be set to azureuser. Please refer to https://docs.microsoft.com/rest/api/compute/virtualmachines/createorupdate#osprofile to get a full list of reserved values.')
788            c.argument('admin_password', help="Password for the VM if authentication type is 'Password'.")
789            c.argument('ssh_key_value', options_list=['--ssh-key-values'], completer=FilesCompleter(), type=file_type, nargs='+')
790            c.argument('ssh_dest_key_path', help='Destination file path on the VM for the SSH key. If the file already exists, the specified key(s) are appended to the file. Destination path for SSH public keys is currently limited to its default value "/home/username/.ssh/authorized_keys" due to a known issue in Linux provisioning agent.')
791            c.argument('authentication_type', help='Type of authentication to use with the VM. Defaults to password for Windows and SSH public key for Linux. "all" enables both ssh and password authentication. ', arg_type=get_enum_type(['ssh', 'password', 'all']))
792
793        with self.argument_context(scope, arg_group='Storage') as c:
794            if DiskStorageAccountTypes:
795                allowed_values = ", ".join([sku.value for sku in DiskStorageAccountTypes])
796            else:
797                allowed_values = ", ".join(['Premium_LRS', 'Standard_LRS'])
798
799            usage = 'Usage: [--storage-sku SKU | --storage-sku ID=SKU ID=SKU ID=SKU...], where each ID is "os" or a 0-indexed lun.'
800            allowed_values = 'Allowed values: {}.'.format(allowed_values)
801            storage_sku_help = 'The SKU of the storage account with which to persist VM. Use a singular sku that would be applied across all disks, ' \
802                               'or specify individual disks. {} {}'.format(usage, allowed_values)
803
804            c.argument('os_disk_name', help='The name of the new VM OS disk.')
805            c.argument('os_type', help='Type of OS installed on a custom VHD. Do not use when specifying an URN or URN alias.', arg_type=get_enum_type(['windows', 'linux']))
806            c.argument('storage_account', help="Only applicable when used with `--use-unmanaged-disk`. The name to use when creating a new storage account or referencing an existing one. If omitted, an appropriate storage account in the same resource group and location will be used, or a new one will be created.")
807            c.argument('storage_sku', nargs='+', help=storage_sku_help)
808            c.argument('storage_container_name', help="Only applicable when used with `--use-unmanaged-disk`. Name of the storage container for the VM OS disk. Default: vhds")
809            c.ignore('os_publisher', 'os_offer', 'os_sku', 'os_version', 'storage_profile')
810            c.argument('use_unmanaged_disk', action='store_true', help='Do not use managed disk to persist VM')
811            c.argument('os_disk_size_gb', type=int, help='OS disk size in GB to create.')
812            c.argument('data_disk_sizes_gb', nargs='+', type=int, help='space-separated empty managed data disk sizes in GB to create')
813            c.ignore('disk_info', 'storage_account_type', 'public_ip_address_type', 'nsg_type', 'nic_type', 'vnet_type', 'load_balancer_type', 'app_gateway_type')
814            c.argument('os_caching', options_list=[self.deprecate(target='--storage-caching', redirect='--os-disk-caching', hide=True), '--os-disk-caching'], help='Storage caching type for the VM OS disk. Default: ReadWrite', arg_type=get_enum_type(CachingTypes))
815            c.argument('data_caching', options_list=['--data-disk-caching'], nargs='+',
816                       help="storage caching type for data disk(s), including 'None', 'ReadOnly', 'ReadWrite', etc. Use a singular value to apply on all disks, or use `<lun>=<vaule1> <lun>=<value2>` to configure individual disk")
817            c.argument('ultra_ssd_enabled', ultra_ssd_enabled_type)
818            c.argument('ephemeral_os_disk', arg_type=get_three_state_flag(), min_api='2018-06-01',
819                       help='Allows you to create an OS disk directly on the host node, providing local disk performance and faster VM/VMSS reimage time.', is_preview=True)
820            c.argument('os_disk_encryption_set', min_api='2019-07-01', help='Name or ID of disk encryption set for OS disk.')
821            c.argument('data_disk_encryption_sets', nargs='+', min_api='2019-07-01',
822                       help='Names or IDs (space delimited) of disk encryption sets for data disks.')
823            c.argument('data_disk_iops', min_api='2019-07-01', nargs='+', type=int, help='Specify the Read-Write IOPS (space delimited) for the managed disk. Should be used only when StorageAccountType is UltraSSD_LRS. If not specified, a default value would be assigned based on diskSizeGB.')
824            c.argument('data_disk_mbps', min_api='2019-07-01', nargs='+', type=int, help='Specify the bandwidth in MB per second (space delimited) for the managed disk. Should be used only when StorageAccountType is UltraSSD_LRS. If not specified, a default value would be assigned based on diskSizeGB.')
825            c.argument('specialized', arg_type=get_three_state_flag(), help='Indicate whether the source image is specialized.')
826            c.argument('encryption_at_host', arg_type=get_three_state_flag(), help='Enable Host Encryption for the VM or VMSS. This will enable the encryption for all the disks including Resource/Temp disk at host itself.')
827            c.argument('os_disk_delete_option', arg_type=get_enum_type(self.get_models('DiskDeleteOptionTypes')), min_api='2021-03-01',
828                       help='Specify the behavior of the managed disk when the VM gets deleted i.e whether the managed disk is deleted or detached.')
829            c.argument('data_disk_delete_option', options_list=['--data-disk-delete-option', self.deprecate(target='--data-delete-option', redirect='--data-disk-delete-option', hide=True)],
830                       nargs='+', min_api='2021-03-01',
831                       help='Specify whether data disk should be deleted or detached upon VM deletion.')
832
833        with self.argument_context(scope, arg_group='Network') as c:
834            c.argument('vnet_name', help='Name of the virtual network when creating a new one or referencing an existing one.')
835            c.argument('vnet_address_prefix', help='The IP address prefix to use when creating a new VNet in CIDR format.')
836            c.argument('subnet', help='The name of the subnet when creating a new VNet or referencing an existing one. Can also reference an existing subnet by ID. If both vnet-name and subnet are omitted, an appropriate VNet and subnet will be selected automatically, or a new one will be created.')
837            c.argument('subnet_address_prefix', help='The subnet IP address prefix to use when creating a new VNet in CIDR format.')
838            c.argument('nics', nargs='+', help='Names or IDs of existing NICs to attach to the VM. The first NIC will be designated as primary. If omitted, a new NIC will be created. If an existing NIC is specified, do not specify subnet, VNet, public IP or NSG.')
839            c.argument('private_ip_address', help='Static private IP address (e.g. 10.0.0.5).')
840            c.argument('public_ip_address', help='Name of the public IP address when creating one (default) or referencing an existing one. Can also reference an existing public IP by ID or specify "" for None (\'""\' in Azure CLI using PowerShell or --% operator).')
841            c.argument('public_ip_address_allocation', help=None, default=None, arg_type=get_enum_type(['dynamic', 'static']))
842            c.argument('public_ip_address_dns_name', help='Globally unique DNS name for a newly created public IP.')
843            if self.supported_api_version(min_api='2017-08-01', resource_type=ResourceType.MGMT_NETWORK):
844                PublicIPAddressSkuName = self.get_models('PublicIPAddressSkuName', resource_type=ResourceType.MGMT_NETWORK)
845                c.argument('public_ip_sku', help='Public IP SKU. It is set to Basic by default. The public IP is supported to be created on edge zone only when it is \'Standard\'',
846                           default=None, arg_type=get_enum_type(PublicIPAddressSkuName))
847            c.argument('nic_delete_option', nargs='+', min_api='2021-03-01',
848                       help='Specify what happens to the network interface when the VM is deleted. Use a singular '
849                       'value to apply on all resources, or use <Name>=<Value> to configure '
850                       'the delete behavior for individual resources. Possible options are Delete and Detach.')
851
852        with self.argument_context(scope, arg_group='Marketplace Image Plan') as c:
853            c.argument('plan_name', help='plan name')
854            c.argument('plan_product', help='plan product')
855            c.argument('plan_publisher', help='plan publisher')
856            c.argument('plan_promotion_code', help='plan promotion code')
857
858    for scope in ['vm create', 'vmss create', 'vm identity assign', 'vmss identity assign']:
859        with self.argument_context(scope) as c:
860            arg_group = 'Managed Service Identity' if scope.split()[-1] == 'create' else None
861            c.argument('identity_scope', options_list=['--scope'], arg_group=arg_group, help="Scope that the system assigned identity can access")
862            c.argument('identity_role', options_list=['--role'], arg_group=arg_group, help="Role name or id the system assigned identity will have")
863            c.ignore('identity_role_id')
864
865    with self.argument_context('vm auto-shutdown') as c:
866        c.argument('off', action='store_true', help='Turn off auto-shutdown for VM. Configuration will be cleared.')
867        c.argument('email', help='The email recipient to send notifications to (can be a list of semi-colon separated email addresses)')
868        c.argument('time', help='The UTC time of day the schedule will occur every day. Format: hhmm. Example: 1730')
869        c.argument('webhook', help='The webhook URL to which the notification will be sent')
870        c.argument('location', validator=get_default_location_from_resource_group)
871
872    for scope in ['vm diagnostics', 'vmss diagnostics']:
873        with self.argument_context(scope) as c:
874            c.argument('version', help='version of the diagnostics extension. Will use the latest if not specfied')
875            c.argument('settings', help='json string or a file path, which defines data to be collected.', type=validate_file_or_dict, completer=FilesCompleter())
876            c.argument('protected_settings', help='json string or a file path containing private configurations such as storage account keys, etc.', type=validate_file_or_dict, completer=FilesCompleter())
877            c.argument('is_windows_os', action='store_true', help='for Windows VMs')
878
879    for scope in ['vm encryption', 'vmss encryption']:
880        with self.argument_context(scope) as c:
881            c.argument('volume_type', help='Type of volume that the encryption operation is performed on', arg_type=get_enum_type(['DATA', 'OS', 'ALL']))
882            c.argument('force', action='store_true', help='continue by ignoring client side validation errors')
883            c.argument('disk_encryption_keyvault', help='Name or ID of the key vault where the generated encryption key will be placed.')
884            c.argument('key_encryption_key', help='Key vault key name or URL used to encrypt the disk encryption key.')
885            c.argument('key_encryption_keyvault', help='Name or ID of the key vault containing the key encryption key used to encrypt the disk encryption key. If missing, CLI will use `--disk-encryption-keyvault`.')
886
887    for scope in ['vm extension', 'vmss extension']:
888        with self.argument_context(scope) as c:
889            c.argument('publisher', help='The name of the extension publisher.')
890            c.argument('settings', type=validate_file_or_dict, help='Extension settings in JSON format. A JSON file path is also accepted.')
891            c.argument('protected_settings', type=validate_file_or_dict, help='Protected settings in JSON format for sensitive information like credentials. A JSON file path is also accepted.')
892            c.argument('version', help='The version of the extension. To pin extension version to this value, please specify --no-auto-upgrade-minor-version.')
893            c.argument('enable_auto_upgrade', arg_type=get_three_state_flag(),
894                       help='Indicate the extension should be automatically upgraded by the platform if there is a newer version of the extension available.')
895
896    with self.argument_context('vm extension set') as c:
897        c.argument('vm_extension_name', name_arg_type,
898                   completer=get_resource_name_completion_list('Microsoft.Compute/virtualMachines/extensions'),
899                   help='Name of the extension.', id_part=None)
900        c.argument('force_update', action='store_true', help='force to update even if the extension configuration has not changed.')
901        c.argument('extension_instance_name', extension_instance_name_type)
902
903    with self.argument_context('vmss extension set', min_api='2017-12-01') as c:
904        c.argument('force_update', action='store_true', help='force to update even if the extension configuration has not changed.')
905        c.argument('extension_instance_name', extension_instance_name_type)
906        c.argument('provision_after_extensions', nargs='+', help='Space-separated list of extension names after which this extension should be provisioned. These extensions must already be set on the vm.')
907
908    for scope in ['vm extension image', 'vmss extension image']:
909        with self.argument_context(scope) as c:
910            c.argument('image_location', options_list=['--location', '-l'], help='Image location.')
911            c.argument('name', help='Image name', id_part=None)
912            c.argument('publisher_name', options_list=['--publisher', '-p'], help='Image publisher name')
913            c.argument('type', options_list=['--name', '-n'], help='Name of the extension')
914            c.argument('latest', action='store_true', help='Show the latest version only.')
915            c.argument('version', help='Extension version')
916            c.argument('orderby', help="the $orderby odata query option")
917            c.argument('top', help='the $top odata query option')
918
919    for scope in ['vm create', 'vm update', 'vmss create', 'vmss update']:
920        with self.argument_context(scope) as c:
921            license_msg = "Specifies that the Windows image or disk was licensed on-premises. " \
922                          "To enable Azure Hybrid Benefit for Windows Server, use 'Windows_Server'. " \
923                          "To enable Multitenant Hosting Rights for Windows 10, use 'Windows_Client'. " \
924                          "For more information see the Azure Windows VM online docs."
925            c.argument('license_type', help=license_msg, arg_type=get_enum_type(['Windows_Server', 'Windows_Client', 'RHEL_BYOS', 'SLES_BYOS', 'None']))
926            c.argument('priority', resource_type=ResourceType.MGMT_COMPUTE, min_api='2019-03-01',
927                       arg_type=get_enum_type(self.get_models('VirtualMachinePriorityTypes'), default=None),
928                       help="Priority. Use 'Spot' to run short-lived workloads in a cost-effective way. 'Low' enum will be deprecated in the future. Please use 'Spot' to deploy Azure spot VM and/or VMSS. Default to Regular.")
929            c.argument('max_price', min_api='2019-03-01', type=float, is_preview=True,
930                       help='The maximum price (in US Dollars) you are willing to pay for a Spot VM/VMSS. -1 indicates that the Spot VM/VMSS should not be evicted for price reasons')
931            c.argument('capacity_reservation_group', options_list=['--capacity-reservation-group', '--crg'],
932                       help='The ID or name of the capacity reservation group that is used to allocate. Pass in "None" to disassociate the capacity reservation group. Please note that if you want to delete a VM/VMSS that has been associated with capacity reservation group, you need to disassociate the capacity reservation group first.',
933                       min_api='2021-04-01', is_preview=True)
934
935    with self.argument_context('vm update') as c:
936        c.argument('license_type', help=license_msg, arg_type=get_enum_type(
937            ['Windows_Server', 'Windows_Client', 'RHEL_BYOS', 'SLES_BYOS', 'RHEL_ELS_6', 'None']))
938        c.argument('user_data', help='UserData for the VM. It can be passed in as file or string. If empty string is passed in, the existing value will be deleted.', completer=FilesCompleter(), type=file_type, min_api='2021-03-01')
939
940    with self.argument_context('vmss create') as c:
941        c.argument('priority', resource_type=ResourceType.MGMT_COMPUTE, min_api='2017-12-01',
942                   arg_type=get_enum_type(self.get_models('VirtualMachinePriorityTypes'), default=None),
943                   help="Priority. Use 'Spot' to run short-lived workloads in a cost-effective way. 'Low' enum will be deprecated in the future. Please use 'Spot' to deploy Azure spot VM and/or VMSS. Default to Regular.")
944
945    with self.argument_context('sig') as c:
946        c.argument('gallery_name', options_list=['--gallery-name', '-r'], help='gallery name')
947        c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], help='gallery image definition')
948        c.argument('gallery_image_version', options_list=['--gallery-image-version', '-e'], help='gallery image version')
949
950    for scope in ['sig show', 'sig image-definition show', 'sig image-definition delete']:
951        with self.argument_context(scope) as c:
952            c.argument('gallery_name', options_list=['--gallery-name', '-r'], id_part='name', help='gallery name')
953            c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], id_part='child_name_1', help='gallery image definition')
954
955    with self.argument_context('sig list-shared') as c:
956        c.argument('location', arg_type=get_location_type(self.cli_ctx))
957        c.argument('shared_to', shared_to_type)
958
959    with self.argument_context('sig show-shared') as c:
960        c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
961        c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
962                   id_part='child_name_1')
963
964    for scope in ['sig share add', 'sig share remove']:
965        with self.argument_context(scope) as c:
966            c.argument('gallery_name', type=str, help='The name of the Shared Image Gallery.', id_part='name')
967            c.argument('subscription_ids', nargs='+', help='A list of subscription ids to share the gallery.')
968            c.argument('tenant_ids', nargs='+', help='A list of tenant ids to share the gallery.')
969
970    with self.argument_context('sig share add') as c:
971        c.argument('op_type', default='Add', deprecate_info=c.deprecate(hide=True),
972                   help='distinguish add operation and remove operation')
973
974    with self.argument_context('sig share remove') as c:
975        c.argument('op_type', default='Remove', deprecate_info=c.deprecate(hide=True),
976                   help='distinguish add operation and remove operation')
977
978    with self.argument_context('sig share reset') as c:
979        c.argument('gallery_name', type=str, help='The name of the Shared Image Gallery.', id_part='name')
980
981    with self.argument_context('sig image-definition create') as c:
982        c.argument('offer', options_list=['--offer', '-f'], help='image offer')
983        c.argument('sku', options_list=['--sku', '-s'], help='image sku')
984        c.argument('publisher', options_list=['--publisher', '-p'], help='image publisher')
985        c.argument('os_type', arg_type=get_enum_type(['Windows', 'Linux']), help='the type of the OS that is included in the disk if creating a VM from user-image or a specialized VHD')
986        c.argument('os_state', arg_type=get_enum_type(self.get_models('OperatingSystemStateTypes')), help="This property allows the user to specify whether the virtual machines created under this image are 'Generalized' or 'Specialized'.")
987        c.argument('hyper_v_generation', arg_type=get_enum_type(self.get_models('HyperVGenerationTypes')), help='The hypervisor generation of the Virtual Machine. Applicable to OS disks only.')
988        c.argument('minimum_cpu_core', type=int, arg_group='Recommendation', help='minimum cpu cores')
989        c.argument('maximum_cpu_core', type=int, arg_group='Recommendation', help='maximum cpu cores')
990        c.argument('minimum_memory', type=int, arg_group='Recommendation', help='minimum memory in MB')
991        c.argument('maximum_memory', type=int, arg_group='Recommendation', help='maximum memory in MB')
992
993        c.argument('plan_publisher', help='plan publisher', arg_group='Purchase plan')
994        c.argument('plan_name', help='plan name', arg_group='Purchase plan')
995        c.argument('plan_product', help='plan product', arg_group='Purchase plan')
996
997        c.argument('eula', help='The Eula agreement for the gallery image')
998        c.argument('privacy_statement_uri', help='The privacy statement uri')
999        c.argument('release_note_uri', help='The release note uri')
1000        c.argument('end_of_life_date', help="the end of life date, e.g. '2020-12-31'")
1001        c.argument('disallowed_disk_types', nargs='*', help='disk types which would not work with the image, e.g., Standard_LRS')
1002        c.argument('features', help='A list of gallery image features. E.g. "IsSecureBootSupported=true IsMeasuredBootSupported=false"')
1003
1004    with self.argument_context('sig image-definition list-shared') as c:
1005        c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
1006        c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
1007                   id_part='child_name_1')
1008        c.argument('shared_to', shared_to_type)
1009
1010    with self.argument_context('sig image-definition show-shared') as c:
1011        c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
1012        c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
1013                   id_part='child_name_1')
1014        c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], type=str, help='The name '
1015                   'of the Shared Gallery Image Definition from which the Image Versions are to be listed.',
1016                   id_part='child_name_2')
1017
1018    with self.argument_context('sig create') as c:
1019        c.argument('description', help='the description of the gallery')
1020        c.argument('permissions', arg_type=get_enum_type(GallerySharingPermissionTypes), arg_group='Sharing Profile',
1021                   min_api='2020-09-30', is_experimental=True,
1022                   help='This property allows you to specify the permission of sharing gallery.')
1023        c.argument('soft_delete', arg_type=get_three_state_flag(), min_api='2021-03-01', is_preview=True,
1024                   help='Enable soft-deletion for resources in this gallery, '
1025                        'allowing them to be recovered within retention time.')
1026    with self.argument_context('sig update') as c:
1027        c.ignore('gallery')
1028        c.argument('permissions', arg_type=get_enum_type(GallerySharingPermissionTypes), arg_group='Sharing Profile',
1029                   min_api='2020-09-30', is_experimental=True,
1030                   help='This property allows you to specify the permission of sharing gallery.')
1031        c.argument('soft_delete', arg_type=get_three_state_flag(), min_api='2021-03-01', is_preview=True,
1032                   help='Enable soft-deletion for resources in this gallery, '
1033                        'allowing them to be recovered within retention time.')
1034    with self.argument_context('sig image-definition create') as c:
1035        c.argument('description', help='the description of the gallery image definition')
1036    with self.argument_context('sig image-definition update') as c:
1037        c.ignore('gallery_image')
1038
1039    with self.argument_context('sig image-version') as c:
1040        deprecated_option = c.deprecate(target='--gallery-image-version-name', redirect='--gallery-image-version', hide=True, expiration="3.0.0")
1041        c.argument('gallery_image_version_name', options_list=['--gallery-image-version', '-e', deprecated_option],
1042                   help='Gallery image version in semantic version pattern. The allowed characters are digit and period. Digits must be within the range of a 32-bit integer, e.g. `<MajorVersion>.<MinorVersion>.<Patch>`')
1043
1044    with self.argument_context('sig image-version create', resource_type=ResourceType.MGMT_COMPUTE, operation_group='gallery_image_versions') as c:
1045        c.argument('gallery_image_version', options_list=['--gallery-image-version', '-e'],
1046                   help='Gallery image version in semantic version pattern. The allowed characters are digit and period. Digits must be within the range of a 32-bit integer, e.g. `<MajorVersion>.<MinorVersion>.<Patch>`')
1047        c.argument('description', help='the description of the gallery image version')
1048        c.argument('managed_image', help='image name(if in the same resource group) or resource id')
1049        c.argument('os_snapshot', help='Name or ID of OS disk snapshot')
1050        c.argument('data_snapshots', nargs='+', help='Names or IDs (space-delimited) of data disk snapshots')
1051        c.argument('data_snapshot_luns', nargs='+', help='Logical unit numbers (space-delimited) of data disk snapshots')
1052        c.argument('exclude_from_latest', arg_type=get_three_state_flag(), help='The flag means that if it is set to true, people deploying VMs with version omitted will not use this version.')
1053        c.argument('version', help='image version')
1054        c.argument('end_of_life_date', help="the end of life date, e.g. '2020-12-31'")
1055        c.argument('storage_account_type', help="The default storage account type to be used per region. To set regional storage account types, use --target-regions",
1056                   arg_type=get_enum_type(["Standard_LRS", "Standard_ZRS", "Premium_LRS"]), min_api='2019-03-01')
1057        c.argument('target_region_encryption', nargs='+',
1058                   help='Space-separated list of customer managed keys for encrypting the OS and data disks in the gallery artifact for each region. Format for each region: `<os_des>,<lun1>,<lun1_des>,<lun2>,<lun2_des>`. Use "null" as a placeholder.')
1059        c.argument('os_vhd_uri', help='Source VHD URI of OS disk')
1060        c.argument('os_vhd_storage_account', help='Name or ID of storage account of source VHD URI of OS disk')
1061        c.argument('data_vhds_uris', nargs='+', help='Source VHD URIs (space-delimited) of data disks')
1062        c.argument('data_vhds_luns', nargs='+', help='Logical unit numbers (space-delimited) of source VHD URIs of data disks')
1063        c.argument('data_vhds_storage_accounts', options_list=['--data-vhds-storage-accounts', '--data-vhds-sa'], nargs='+', help='Names or IDs (space-delimited) of storage accounts of source VHD URIs of data disks')
1064        c.argument('replication_mode', min_api='2021-07-01', arg_type=get_enum_type(ReplicationMode), help='Optional parameter which specifies the mode to be used for replication. This property is not updatable.')
1065
1066    with self.argument_context('sig image-version list-shared') as c:
1067        c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
1068        c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
1069                   id_part='child_name_1')
1070        c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], type=str, help='The name '
1071                   'of the Shared Gallery Image Definition from which the Image Versions are to be listed.',
1072                   id_part='child_name_2')
1073        c.argument('shared_to', shared_to_type)
1074
1075    with self.argument_context('sig image-version show') as c:
1076        c.argument('expand', help="The expand expression to apply on the operation, e.g. 'ReplicationStatus'")
1077
1078    with self.argument_context('sig image-version show-shared') as c:
1079        c.argument('location', arg_type=get_location_type(self.cli_ctx), id_part='name')
1080        c.argument('gallery_unique_name', type=str, help='The unique name of the Shared Gallery.',
1081                   id_part='child_name_1')
1082        c.argument('gallery_image_name', options_list=['--gallery-image-definition', '-i'], type=str, help='The name '
1083                   'of the Shared Gallery Image Definition from which the Image Versions are to be listed.',
1084                   id_part='child_name_2')
1085        c.argument('gallery_image_version_name', options_list=['--gallery-image-version', '-e'], type=str, help='The '
1086                   'name of the gallery image version to be created. Needs to follow semantic version name pattern: '
1087                   'The allowed characters are digit and period. Digits must be within the range of a 32-bit integer. '
1088                   'Format: <MajorVersion>.<MinorVersion>.<Patch>', id_part='child_name_3')
1089
1090    for scope in ['sig image-version create', 'sig image-version update']:
1091        with self.argument_context(scope) as c:
1092            c.argument('target_regions', nargs='*', validator=process_gallery_image_version_namespace,
1093                       help='Space-separated list of regions and their replica counts. Use `<region>[=<replica count>][=<storage account type>]` to optionally set the replica count and/or storage account type for each region. '
1094                            'If a replica count is not specified, the default replica count will be used. If a storage account type is not specified, the default storage account type will be used')
1095            c.argument('replica_count', help='The default number of replicas to be created per region. To set regional replication counts, use --target-regions', type=int)
1096    # endregion
1097
1098    # region Proximity Placement Group
1099    with self.argument_context('ppg', min_api='2018-04-01') as c:
1100        c.argument('proximity_placement_group_name', arg_type=name_arg_type, help="The name of the proximity placement group.")
1101
1102    with self.argument_context('ppg create', min_api='2018-04-01') as c:
1103        c.argument('ppg_type', options_list=['--type', '-t'], help="The type of the proximity placement group. Allowed values: Standard.")
1104        c.argument('tags', tags_type)
1105
1106    with self.argument_context('ppg show', min_api='2019-07-01') as c:
1107        c.argument('include_colocation_status', action='store_true', help='Enable fetching the colocation status of all the resources in the proximity placement group.')
1108
1109    for scope, item in [('vm create', 'VM'), ('vmss create', 'VMSS'),
1110                        ('vm availability-set create', 'availability set'),
1111                        ('vm update', 'VM'), ('vmss update', 'VMSS'),
1112                        ('vm availability-set update', 'availability set')]:
1113        with self.argument_context(scope, min_api='2018-04-01') as c:
1114            c.argument('proximity_placement_group', options_list=['--ppg'], help="The name or ID of the proximity placement group the {} should be associated with.".format(item),
1115                       validator=_validate_proximity_placement_group)    # only availability set does not have a command level validator, so this should be added.
1116    # endregion
1117
1118    # region VM Monitor
1119    with self.argument_context('vm monitor log show') as c:
1120        c.argument('analytics_query', options_list=['--analytics-query', '-q'], help="Query to execute over Log Analytics data.")
1121        c.argument('timespan', help="Timespan over which to query. Defaults to querying all available data.")
1122
1123    with self.argument_context('vm monitor metrics') as c:
1124        c.argument('metricnamespace', options_list=['--namespace'],
1125                   help='Namespace to query metric definitions for.')
1126
1127    with self.argument_context('vm monitor metrics tail') as c:
1128        from azure.mgmt.monitor.models import AggregationType
1129        c.extra('resource_group_name', required=True)
1130        c.argument('resource', arg_type=existing_vm_name, help='Name or ID of a virtual machine', validator=validate_vm_name_for_monitor_metrics, id_part=None)
1131        c.argument('metadata', action='store_true')
1132        c.argument('dimension', nargs='*', validator=validate_metric_dimension)
1133        c.argument('aggregation', arg_type=get_enum_type(t for t in AggregationType if t.name != 'none'), nargs='*')
1134        c.argument('metrics', nargs='*')
1135        c.argument('orderby',
1136                   help='Aggregation to use for sorting results and the direction of the sort. Only one order can be specificed. Examples: sum asc')
1137        c.argument('top', help='Max number of records to retrieve. Valid only if --filter used.')
1138        c.argument('filters', options_list=['--filter'])
1139        c.argument('metric_namespace', options_list=['--namespace'])
1140
1141    with self.argument_context('vm monitor metrics tail', arg_group='Time') as c:
1142        c.argument('start_time', arg_type=get_datetime_type(help='Start time of the query.'))
1143        c.argument('end_time', arg_type=get_datetime_type(help='End time of the query. Defaults to the current time.'))
1144        c.argument('offset', type=get_period_type(as_timedelta=True))
1145        c.argument('interval', arg_group='Time', type=get_period_type())
1146
1147    with self.argument_context('vm monitor metrics list-definitions') as c:
1148        c.extra('resource_group_name', required=True)
1149        c.argument('resource_uri', arg_type=existing_vm_name, help='Name or ID of a virtual machine', validator=validate_vm_name_for_monitor_metrics, id_part=None)
1150    # endregion
1151
1152    # region disk encryption set
1153    with self.argument_context('disk-encryption-set') as c:
1154        c.argument('disk_encryption_set_name', disk_encryption_set_name)
1155        c.argument('key_url', help='URL pointing to a key or secret in KeyVault.')
1156        c.argument('source_vault', help='Name or ID of the KeyVault containing the key or secret.')
1157        c.argument('encryption_type', arg_type=get_enum_type(['EncryptionAtRestWithPlatformKey', 'EncryptionAtRestWithCustomerKey', 'EncryptionAtRestWithPlatformAndCustomerKeys']),
1158                   help='The type of key used to encrypt the data of the disk. EncryptionAtRestWithPlatformKey: Disk is encrypted at rest with Platform managed key. It is the default encryption type. EncryptionAtRestWithCustomerKey: Disk is encrypted at rest with Customer managed key that can be changed and revoked by a customer. EncryptionAtRestWithPlatformAndCustomerKeys: Disk is encrypted at rest with 2 layers of encryption. One of the keys is Customer managed and the other key is Platform managed.')
1159        c.argument('location', validator=get_default_location_from_resource_group)
1160        c.argument('tags', tags_type)
1161        c.argument('enable_auto_key_rotation', arg_type=get_three_state_flag(), min_api='2020-12-01',
1162                   options_list=['--enable-auto-key-rotation', '--auto-rotation'],
1163                   help='Enable automatic rotation of keys.')
1164    # endregion
1165
1166    # region DiskAccess
1167    with self.argument_context('disk-access', resource_type=ResourceType.MGMT_COMPUTE, operation_group='disk_accesses') as c:
1168        c.argument('disk_access_name', arg_type=name_arg_type, help='Name of the disk access resource.', id_part='name')
1169        c.argument('location', validator=get_default_location_from_resource_group)
1170        c.argument('tags', tags_type)
1171    # endRegion
1172
1173    with self.argument_context('capacity reservation group') as c:
1174        c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
1175        c.argument('capacity_reservation_group_name', options_list=['--capacity-reservation-group', '-n'],
1176                   help='The name of the capacity reservation group.')
1177        c.argument('tags', tags_type)
1178
1179    with self.argument_context('capacity reservation group create') as c:
1180        c.argument('zones', zones_type, help='Availability Zones to use for this capacity reservation group. If not provided, the group supports only regional resources in the region. If provided, enforces each capacity reservation in the group to be in one of the zones.')
1181
1182    with self.argument_context('capacity reservation group show') as c:
1183        c.argument('instance_view', action='store_true', options_list=['--instance-view', '-i'], help='Retrieve the list of instance views of the capacity reservations under the capacity reservation group which is a snapshot of the runtime properties of a capacity reservation that is managed by the platform and can change outside of control plane operations.')
1184
1185    with self.argument_context('capacity reservation group list') as c:
1186        c.argument('vm_instance', action='store_true', help='Retrieve the Virtual Machine Instance which are associated to capacity reservation group in the response.')
1187        c.argument('vmss_instance', action='store_true', help='Retrieve the ScaleSet VM Instance which are associated to capacity reservation group in the response.')
1188
1189    with self.argument_context('capacity reservation') as c:
1190        c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
1191        c.argument('capacity_reservation_group_name', options_list=['--capacity-reservation-group', '-c'],
1192                   help='The name of the capacity reservation group.')
1193        c.argument('capacity_reservation_name', options_list=['--capacity-reservation-name', '-n'],
1194                   help='The name of the capacity reservation.')
1195        c.argument('capacity', type=int, help='Specify the number of virtual machines in the scale set.')
1196        c.argument('tags', tags_type)
1197
1198    with self.argument_context('capacity reservation create') as c:
1199        c.argument('zone', zone_type, help='Availability Zone to use for this capacity reservation. The zone has to be single value and also should be part for the list of zones specified during the capacity reservation group creation. If not provided, the reservation supports only non-zonal deployments. If provided, enforces VM/VMSS using this capacity reservation to be in same zone.')
1200        c.argument('sku_name', options_list=['--sku', '-s'], required=True, help='The SKU of the resource for which capacity needs be reserved. Currently VM Skus with the capability called "CapacityReservationSupported" set to true are supported. Refer to List Microsoft.Compute SKUs in a region (https://docs.microsoft.com/rest/api/compute/resourceskus/list) for supported values.')
1201
1202    with self.argument_context('capacity reservation show') as c:
1203        c.argument('instance_view', action='store_true', options_list=['--instance-view', '-i'], help='Retrieve a snapshot of the runtime properties of the capacity reservation that is managed by the platform and can change outside of control plane operations.')
1204