Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compute] az vmss create: Add new parameters --os-disk-delete-option and --data-disk-delete-option to support configuring whether the VMSS Flex VM OS/Data Disks will be deleted or detached upon VM deletion #23200

Merged
merged 7 commits into from
Jul 20, 2022
9 changes: 4 additions & 5 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ def load_arguments(self, _):
with self.argument_context('vm create', arg_group='Storage') as c:
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.')
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.')
c.argument('os_disk_delete_option', arg_type=get_enum_type(self.get_models('DiskDeleteOptionTypes')), min_api='2021-03-01', help='Specify the behavior of the managed disk when the VM gets deleted i.e whether the managed disk is deleted or detached.')
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)], nargs='+', min_api='2021-03-01', help='Specify whether data disk should be deleted or detached upon VM deletion. If a single data disk is attached, the allowed values are Delete and Detach. For multiple data disks are attached, please use "<data_disk>=Delete <data_disk2>=Detach" to configure each disk')

with self.argument_context('vm create', arg_group='Dedicated Host', min_api='2019-03-01') as c:
c.argument('dedicated_host_group', options_list=['--host-group'], is_preview=True, help="Name or resource ID of the dedicated host group that the VM will reside in. --host and --host-group can't be used together.")
Expand Down Expand Up @@ -701,6 +703,8 @@ def load_arguments(self, _):
c.argument('security_type', security_type)
c.argument('enable_secure_boot', enable_secure_boot_type)
c.argument('enable_vtpm', enable_vtpm_type)
c.argument('os_disk_delete_option', arg_type=get_enum_type(self.get_models('DiskDeleteOptionTypes')), min_api='2022-03-01', arg_group='Storage', help='Specify whether OS disk should be deleted or detached upon VMSS Flex deletion (This feature is only for VMSS with flexible orchestration mode).')
c.argument('data_disk_delete_option', arg_type=get_enum_type(self.get_models('DiskDeleteOptionTypes')), min_api='2022-03-01', arg_group='Storage', help='Specify whether data disk should be deleted or detached upon VMSS Flex deletion (This feature is only for VMSS with flexible orchestration mode)')

with self.argument_context('vmss create', arg_group='Network Balancer') as c:
LoadBalancerSkuName = self.get_models('LoadBalancerSkuName', resource_type=ResourceType.MGMT_NETWORK)
Expand Down Expand Up @@ -1018,11 +1022,6 @@ def load_arguments(self, _):
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.')
c.argument('specialized', arg_type=get_three_state_flag(), help='Indicate whether the source image is specialized.')
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.')
c.argument('os_disk_delete_option', arg_type=get_enum_type(self.get_models('DiskDeleteOptionTypes')), min_api='2021-03-01',
help='Specify the behavior of the managed disk when the VM gets deleted i.e whether the managed disk is deleted or detached.')
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)],
nargs='+', min_api='2021-03-01',
help='Specify whether data disk should be deleted or detached upon VM deletion. If a single data disk is attached, the allowed values are Delete and Detach. For multiple data disks are attached, please use "<data_disk>=Delete <data_disk2>=Detach" to configure each disk')

with self.argument_context(scope, arg_group='Network') as c:
c.argument('vnet_name', help='Name of the virtual network when creating a new one or referencing an existing one.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
enable_auto_update=None, patch_mode=None, enable_agent=None, security_type=None,
enable_secure_boot=None, enable_vtpm=None, automatic_repairs_action=None, v_cpus_available=None,
v_cpus_per_core=None, os_disk_security_encryption_type=None,
os_disk_secure_vm_disk_encryption_set=None):
os_disk_secure_vm_disk_encryption_set=None, os_disk_delete_option=None):

# Build IP configuration
ip_configuration = {}
Expand Down Expand Up @@ -978,6 +978,9 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro

if os_disk_size_gb is not None:
storage_properties['osDisk']['diskSizeGB'] = os_disk_size_gb
if os_disk_delete_option is not None:
storage_properties['osDisk']['deleteOption'] = os_disk_delete_option

elif storage_profile in [StorageProfile.ManagedPirImage, StorageProfile.ManagedCustomImage]:
storage_properties['osDisk'] = {
'createOption': 'FromImage',
Expand Down Expand Up @@ -1005,6 +1008,8 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro

if os_disk_size_gb is not None:
storage_properties['osDisk']['diskSizeGB'] = os_disk_size_gb
if os_disk_delete_option is not None:
storage_properties['osDisk']['deleteOption'] = os_disk_delete_option

if storage_profile in [StorageProfile.SAPirImage, StorageProfile.ManagedPirImage]:
storage_properties['imageReference'] = {
Expand Down Expand Up @@ -1043,6 +1048,8 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
'id': os_disk_secure_vm_disk_encryption_set
}
})
if os_disk_delete_option is not None:
storage_properties['osDisk']['deleteOption'] = os_disk_delete_option
if storage_profile == StorageProfile.CommunityGalleryImage:
storage_properties['osDisk'] = {
'caching': os_caching,
Expand All @@ -1069,6 +1076,8 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
'id': os_disk_secure_vm_disk_encryption_set
}
})
if os_disk_delete_option is not None:
storage_properties['osDisk']['deleteOption'] = os_disk_delete_option

if disk_info:
data_disks = [v for k, v in disk_info.items() if k != 'os']
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,12 @@ def process_vmss_create_namespace(cmd, namespace):
from azure.cli.core.azclierror import InvalidArgumentValueError
# uniform_str = 'Uniform'
flexible_str = 'Flexible'

if namespace.os_disk_delete_option is not None or namespace.data_disk_delete_option is not None:
if namespace.orchestration_mode.lower() != flexible_str.lower():
raise InvalidArgumentValueError('usage error: --os-disk-delete-option/--data-disk-delete-option is only'
' available for VMSS with flexible orchestration mode')

if namespace.orchestration_mode.lower() == flexible_str.lower():

# The commentted parameters are also forbidden, but they have default values.
Expand Down
6 changes: 4 additions & 2 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,8 @@ def create_vmss(cmd, vmss_name, resource_group_name, image=None,
capacity_reservation_group=None, enable_auto_update=None, patch_mode=None, enable_agent=None,
security_type=None, enable_secure_boot=None, enable_vtpm=None, automatic_repairs_action=None,
v_cpus_available=None, v_cpus_per_core=None, accept_term=None, disable_integrity_monitoring=False,
os_disk_security_encryption_type=None, os_disk_secure_vm_disk_encryption_set=None):
os_disk_security_encryption_type=None, os_disk_secure_vm_disk_encryption_set=None,
os_disk_delete_option=None, data_disk_delete_option=None):

from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.util import random_string, hash_string
Expand Down Expand Up @@ -3257,7 +3258,8 @@ def _get_public_ip_address_allocation(value, sku):
enable_secure_boot=enable_secure_boot, enable_vtpm=enable_vtpm,
automatic_repairs_action=automatic_repairs_action, v_cpus_available=v_cpus_available,
v_cpus_per_core=v_cpus_per_core, os_disk_security_encryption_type=os_disk_security_encryption_type,
os_disk_secure_vm_disk_encryption_set=os_disk_secure_vm_disk_encryption_set)
os_disk_secure_vm_disk_encryption_set=os_disk_secure_vm_disk_encryption_set,
os_disk_delete_option=os_disk_delete_option)

vmss_resource['dependsOn'] = vmss_dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ vmss create:
os_disk_secure_vm_disk_encryption_set:
rule_exclusions:
- option_length_too_long
data_disk_delete_option:
rule_exclusions:
- option_length_too_long
vmss update:
parameters:
enable_cross_zone_upgrade:
Expand Down
Loading