From 27cde5283369866cd6629743d553e07875796afe Mon Sep 17 00:00:00 2001 From: Jayson Tai Date: Wed, 8 Apr 2026 17:06:14 +1000 Subject: [PATCH 1/4] {Compute} Remove unused gallery image version references and update argument contexts --- .../azure/cli/core/profiles/_shared.py | 1 - .../cli/command_modules/vm/_client_factory.py | 4 - .../azure/cli/command_modules/vm/_params.py | 11 +- .../azure/cli/command_modules/vm/commands.py | 9 +- .../azure/cli/command_modules/vm/custom.py | 176 +++++++++--------- 5 files changed, 91 insertions(+), 110 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/profiles/_shared.py b/src/azure-cli-core/azure/cli/core/profiles/_shared.py index fecc49e1e38..351a562fc07 100644 --- a/src/azure-cli-core/azure/cli/core/profiles/_shared.py +++ b/src/azure-cli-core/azure/cli/core/profiles/_shared.py @@ -165,7 +165,6 @@ def default_api_version(self): 'snapshots': '2023-10-02', 'galleries': '2021-10-01', 'gallery_images': '2021-10-01', - 'gallery_image_versions': '2024-03-03', 'gallery_applications': '2021-07-01', 'gallery_application_versions': '2022-01-03', 'shared_galleries': '2022-01-03', diff --git a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py index 9fe783b6de9..2e8716259d9 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py @@ -75,10 +75,6 @@ def cf_gallery_images(cli_ctx, _): return _compute_client_factory(cli_ctx).gallery_images -def cf_gallery_image_versions(cli_ctx, _): - return _compute_client_factory(cli_ctx).gallery_image_versions - - def cf_proximity_placement_groups(cli_ctx, _): return _compute_client_factory(cli_ctx).proximity_placement_groups diff --git a/src/azure-cli/azure/cli/command_modules/vm/_params.py b/src/azure-cli/azure/cli/command_modules/vm/_params.py index 3d15f0d3f0a..ad92e2e188c 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_params.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_params.py @@ -41,7 +41,6 @@ def load_arguments(self, _): OperatingSystemTypes = self.get_models('OperatingSystemTypes') HyperVGenerationTypes = self.get_models('HyperVGenerationTypes') DedicatedHostLicenseTypes = self.get_models('DedicatedHostLicenseTypes') - ReplicationMode = self.get_models('ReplicationMode', operation_group='gallery_image_versions') DiskControllerTypes = self.get_models('DiskControllerTypes', operation_group='virtual_machines') # REUSABLE ARGUMENT DEFINITIONS @@ -1386,11 +1385,11 @@ def load_arguments(self, _): 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. `..`') for scope in ['sig image-version create', 'sig image-version undelete']: - with self.argument_context(scope, resource_type=ResourceType.MGMT_COMPUTE, operation_group='gallery_image_versions') as c: + with self.argument_context(scope) as c: c.argument('gallery_image_version', options_list=['--gallery-image-version', '-e'], 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. `..`') - with self.argument_context('sig image-version create', resource_type=ResourceType.MGMT_COMPUTE, operation_group='gallery_image_versions') as c: + with self.argument_context('sig image-version create') as c: c.argument('description', help='the description of the gallery image version') c.argument('managed_image', help='image name(if in the same resource group) or resource id') c.argument('os_snapshot', help='Name or ID of OS disk snapshot') @@ -1408,7 +1407,7 @@ def load_arguments(self, _): c.argument('data_vhds_uris', nargs='+', help='Source VHD URIs (space-delimited) of data disks') c.argument('data_vhds_luns', nargs='+', help='Logical unit numbers (space-delimited) of source VHD URIs of data disks') 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') - 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.') + c.argument('replication_mode', min_api='2021-07-01', arg_type=get_enum_type(["Full", "Shallow"]), help='Optional parameter which specifies the mode to be used for replication. This property is not updatable.') c.argument('target_region_cvm_encryption', nargs='+', min_api='2021-10-01', help='Space-separated list of customer managed key for Confidential VM encrypting the OS disk in the gallery artifact for each region. Format for each region: `,`. The valid values for os_cvm_encryption_type are EncryptedVMGuestStateOnlyWithPmk, EncryptedWithPmk, EncryptedWithCmk.') c.argument('virtual_machine', help='Resource id of VM source') c.argument('image_version', help='Resource id of gallery image version source') @@ -1433,7 +1432,7 @@ def load_arguments(self, _): 'Format: `..`', id_part='child_name_3') for scope in ['sig image-version create', 'sig image-version update']: - with self.argument_context(scope, operation_group='gallery_image_versions') as c: + with self.argument_context(scope) as c: c.argument('target_regions', nargs='*', help='Space-separated list of regions and their replica counts. Use `[=][=]` to optionally set the replica count and/or storage account type for each region. ' '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') @@ -1447,7 +1446,7 @@ def load_arguments(self, _): help="Indicate whether or not the deletion is blocked for this gallery image version if its end of life has not expired") for scope in ['sig image-version create', 'sig image-version update', 'sig image-version undelete']: - with self.argument_context(scope, operation_group='gallery_image_versions') as c: + with self.argument_context(scope) as c: c.argument('allow_replicated_location_deletion', arg_type=get_three_state_flag(), min_api='2022-03-03', help='Indicate whether or not removing this gallery image version from replicated regions is allowed.') with self.argument_context('sig list-community') as c: diff --git a/src/azure-cli/azure/cli/command_modules/vm/commands.py b/src/azure-cli/azure/cli/command_modules/vm/commands.py index 0dd9c9d60bc..e9d384f3bde 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/commands.py @@ -7,7 +7,7 @@ cf_vm_ext, cf_vm_ext_image, cf_vm_image_term, cf_usage, cf_vmss, - cf_galleries, cf_gallery_images, cf_gallery_image_versions, + cf_galleries, cf_gallery_images, cf_proximity_placement_groups, cf_dedicated_hosts, cf_log_analytics_data_plane, @@ -111,11 +111,6 @@ def load_command_table(self, _): client_factory=cf_gallery_images, ) - compute_gallery_image_versions_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#GalleryImageVersionsOperations.{}', - client_factory=cf_gallery_image_versions, - ) - compute_gallery_application_profile = CliCommandType( operations_tmpl='azure.mgmt.compute.operations#GalleryApplicationsOperations.{}', ) @@ -467,7 +462,7 @@ def load_command_table(self, _): from .operations.sig_image_definition import SigImageDefinitionListShared self.command_table['sig image-definition list-shared'] = SigImageDefinitionListShared(loader=self) - with self.command_group('sig image-version', compute_gallery_image_versions_sdk, operation_group='gallery_image_versions', min_api='2018-06-01') as g: + with self.command_group('sig image-version') as g: g.custom_command('create', 'create_image_version', supports_no_wait=True, validator=process_image_version_create_namespace) g.custom_command('undelete', 'undelete_image_version', supports_no_wait=True, validator=process_image_version_undelete_namespace, is_preview=True) g.generic_update_command('update', getter_name='get_image_version_to_update', setter_arg_name='gallery_image_version', setter_name='update_image_version', setter_type=compute_custom, command_type=compute_custom, supports_no_wait=True, validator=process_image_version_update_namespace) diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index 01067b8a777..d3a592a5fa7 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -5680,102 +5680,94 @@ def create_image_version(cmd, resource_group_name, gallery_name, gallery_image_n if replication_mode is not None: profile["replication_mode"] = replication_mode - if not cmd.supported_api_version(min_api='2022-03-03', operation_group='gallery_image_versions'): - source = {"managed_image": {"id": managed_image}} - profile["source"] = source - - if cmd.supported_api_version(min_api='2019-07-01', operation_group='gallery_image_versions'): - if managed_image is None and os_snapshot is None and os_vhd_uri is None: - raise RequiredArgumentMissingError('usage error: Please provide --managed-image or --os-snapshot or --vhd') - - source = os_disk_image = data_disk_images = None - if virtual_machine is not None and cmd.supported_api_version(min_api='2023-07-03', - operation_group='gallery_image_versions'): - source = {"virtual_machine_id": virtual_machine} - elif managed_image is not None: - source = {"id": managed_image} - if os_snapshot is not None: - os_disk_image = {"source": {"id": os_snapshot}} - if data_snapshot_luns and not data_snapshots: - raise ArgumentUsageError('usage error: --data-snapshot-luns must be used together with --data-snapshots') - if data_snapshots: - if data_snapshot_luns and len(data_snapshots) != len(data_snapshot_luns): - raise ArgumentUsageError('usage error: Length of --data-snapshots and ' - '--data-snapshot-luns should be equal.') - if not data_snapshot_luns: - data_snapshot_luns = list(range(len(data_snapshots))) - data_disk_images = [] - for i, s in enumerate(data_snapshots): - data_disk_images.append({"source": {"id": s}, "lun": int(data_snapshot_luns[i])}) - # from vhd, only support os image now - if cmd.supported_api_version(min_api='2020-09-30', operation_group='gallery_image_versions'): - # OS disk - if os_vhd_uri and os_vhd_storage_account is None or os_vhd_uri is None and os_vhd_storage_account: - raise ArgumentUsageError('--os-vhd-uri and --os-vhd-storage-account should be used together.') - if os_vhd_uri and os_vhd_storage_account: - if not is_valid_resource_id(os_vhd_storage_account): - os_vhd_storage_account = resource_id( - subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, - namespace='Microsoft.Storage', type='storageAccounts', name=os_vhd_storage_account) - os_disk_image = { - "source": { - "storage_account_id": os_vhd_storage_account, - "uri": os_vhd_uri - } - } + source = {"managed_image": {"id": managed_image}} + profile["source"] = source + + if managed_image is None and os_snapshot is None and os_vhd_uri is None: + raise RequiredArgumentMissingError('usage error: Please provide --managed-image or --os-snapshot or --vhd') + + source = os_disk_image = data_disk_images = None + if virtual_machine is not None: + source = {"virtual_machine_id": virtual_machine} + elif managed_image is not None: + source = {"id": managed_image} + if os_snapshot is not None: + os_disk_image = {"source": {"id": os_snapshot}} + if data_snapshot_luns and not data_snapshots: + raise ArgumentUsageError('usage error: --data-snapshot-luns must be used together with --data-snapshots') + if data_snapshots: + if data_snapshot_luns and len(data_snapshots) != len(data_snapshot_luns): + raise ArgumentUsageError('usage error: Length of --data-snapshots and ' + '--data-snapshot-luns should be equal.') + if not data_snapshot_luns: + data_snapshot_luns = list(range(len(data_snapshots))) + data_disk_images = [] + for i, s in enumerate(data_snapshots): + data_disk_images.append({"source": {"id": s}, "lun": int(data_snapshot_luns[i])}) + # from vhd, only support os image now + # OS disk + if os_vhd_uri and os_vhd_storage_account is None or os_vhd_uri is None and os_vhd_storage_account: + raise ArgumentUsageError('--os-vhd-uri and --os-vhd-storage-account should be used together.') + if os_vhd_uri and os_vhd_storage_account: + if not is_valid_resource_id(os_vhd_storage_account): + os_vhd_storage_account = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, + namespace='Microsoft.Storage', type='storageAccounts', name=os_vhd_storage_account) + os_disk_image = { + "source": { + "storage_account_id": os_vhd_storage_account, + "uri": os_vhd_uri + } + } - # Data disks - if data_vhds_uris and data_vhds_storage_accounts is None or \ - data_vhds_uris is None and data_vhds_storage_accounts: - raise ArgumentUsageError('--data-vhds-uris and --data-vhds-storage-accounts should be used together.') - if data_vhds_luns and data_vhds_uris is None: - raise ArgumentUsageError('--data-vhds-luns must be used together with --data-vhds-uris') - if data_vhds_uris: - # Generate LUNs - if data_vhds_luns is None: - # 0, 1, 2, ... - data_vhds_luns = list(range(len(data_vhds_uris))) - # Check length - len_data_vhds_uris = len(data_vhds_uris) - len_data_vhds_luns = len(data_vhds_luns) - len_data_vhds_storage_accounts = len(data_vhds_storage_accounts) - if len_data_vhds_uris != len_data_vhds_luns or len_data_vhds_uris != len_data_vhds_storage_accounts: - raise ArgumentUsageError( - 'Length of --data-vhds-uris, --data-vhds-luns, --data-vhds-storage-accounts must be same.') - # Generate full storage account ID - for i, storage_account in enumerate(data_vhds_storage_accounts): - if not is_valid_resource_id(storage_account): - data_vhds_storage_accounts[i] = resource_id( - subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, - namespace='Microsoft.Storage', type='storageAccounts', name=storage_account) - if data_disk_images is None: - data_disk_images = [] - for uri, lun, account in zip(data_vhds_uris, data_vhds_luns, data_vhds_storage_accounts): - data_disk_images.append({ - "source": {"storage_account_id": account, "uri": uri}, - "lun": lun - }) + # Data disks + if data_vhds_uris and data_vhds_storage_accounts is None or \ + data_vhds_uris is None and data_vhds_storage_accounts: + raise ArgumentUsageError('--data-vhds-uris and --data-vhds-storage-accounts should be used together.') + if data_vhds_luns and data_vhds_uris is None: + raise ArgumentUsageError('--data-vhds-luns must be used together with --data-vhds-uris') + if data_vhds_uris: + # Generate LUNs + if data_vhds_luns is None: + # 0, 1, 2, ... + data_vhds_luns = list(range(len(data_vhds_uris))) + # Check length + len_data_vhds_uris = len(data_vhds_uris) + len_data_vhds_luns = len(data_vhds_luns) + len_data_vhds_storage_accounts = len(data_vhds_storage_accounts) + if len_data_vhds_uris != len_data_vhds_luns or len_data_vhds_uris != len_data_vhds_storage_accounts: + raise ArgumentUsageError( + 'Length of --data-vhds-uris, --data-vhds-luns, --data-vhds-storage-accounts must be same.') + # Generate full storage account ID + for i, storage_account in enumerate(data_vhds_storage_accounts): + if not is_valid_resource_id(storage_account): + data_vhds_storage_accounts[i] = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, + namespace='Microsoft.Storage', type='storageAccounts', name=storage_account) + if data_disk_images is None: + data_disk_images = [] + for uri, lun, account in zip(data_vhds_uris, data_vhds_luns, data_vhds_storage_accounts): + data_disk_images.append({ + "source": {"storage_account_id": account, "uri": uri}, + "lun": lun + }) - storage_profile = {"source": source, "os_disk_image": os_disk_image, "data_disk_images": data_disk_images} - args = { - "publishing_profile": profile, - "location": location, - "tags": tags or {}, - "storage_profile": storage_profile + storage_profile = {"source": source, "os_disk_image": os_disk_image, "data_disk_images": data_disk_images} + args = { + "publishing_profile": profile, + "location": location, + "tags": tags or {}, + "storage_profile": storage_profile + } + if allow_replicated_location_deletion is not None: + args["safety_profile"] = { + "allow_deletion_of_replicated_locations": allow_replicated_location_deletion } - if allow_replicated_location_deletion is not None: - args["safety_profile"] = { - "allow_deletion_of_replicated_locations": allow_replicated_location_deletion - } - if block_deletion_before_end_of_life is not None: - if "safety_profile" not in args: - args["safety_profile"] = {} + if block_deletion_before_end_of_life is not None: + if "safety_profile" not in args: + args["safety_profile"] = {} - args["safety_profile"]["block_deletion_before_end_of_life"] = block_deletion_before_end_of_life - else: - if managed_image is None: - raise RequiredArgumentMissingError('usage error: Please provide --managed-image') - args = {"publishing_profile": profile, "location": location, "tags": tags or {}} + args["safety_profile"]["block_deletion_before_end_of_life"] = block_deletion_before_end_of_life args["resource_group"] = resource_group_name args["gallery_name"] = gallery_name From 6231312cbb9496bb1b364fcfedfbb036740f6d55 Mon Sep 17 00:00:00 2001 From: Jayson Tai Date: Wed, 8 Apr 2026 17:06:14 +1000 Subject: [PATCH 2/4] {Compute} Remove unused gallery image version references and update argument contexts --- .../azure/cli/core/profiles/_shared.py | 1 - .../cli/command_modules/vm/_client_factory.py | 4 - .../azure/cli/command_modules/vm/_params.py | 11 +- .../azure/cli/command_modules/vm/commands.py | 9 +- .../azure/cli/command_modules/vm/custom.py | 176 +++++++++--------- 5 files changed, 91 insertions(+), 110 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/profiles/_shared.py b/src/azure-cli-core/azure/cli/core/profiles/_shared.py index fecc49e1e38..351a562fc07 100644 --- a/src/azure-cli-core/azure/cli/core/profiles/_shared.py +++ b/src/azure-cli-core/azure/cli/core/profiles/_shared.py @@ -165,7 +165,6 @@ def default_api_version(self): 'snapshots': '2023-10-02', 'galleries': '2021-10-01', 'gallery_images': '2021-10-01', - 'gallery_image_versions': '2024-03-03', 'gallery_applications': '2021-07-01', 'gallery_application_versions': '2022-01-03', 'shared_galleries': '2022-01-03', diff --git a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py index 9fe783b6de9..2e8716259d9 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py @@ -75,10 +75,6 @@ def cf_gallery_images(cli_ctx, _): return _compute_client_factory(cli_ctx).gallery_images -def cf_gallery_image_versions(cli_ctx, _): - return _compute_client_factory(cli_ctx).gallery_image_versions - - def cf_proximity_placement_groups(cli_ctx, _): return _compute_client_factory(cli_ctx).proximity_placement_groups diff --git a/src/azure-cli/azure/cli/command_modules/vm/_params.py b/src/azure-cli/azure/cli/command_modules/vm/_params.py index 3d15f0d3f0a..ad92e2e188c 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_params.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_params.py @@ -41,7 +41,6 @@ def load_arguments(self, _): OperatingSystemTypes = self.get_models('OperatingSystemTypes') HyperVGenerationTypes = self.get_models('HyperVGenerationTypes') DedicatedHostLicenseTypes = self.get_models('DedicatedHostLicenseTypes') - ReplicationMode = self.get_models('ReplicationMode', operation_group='gallery_image_versions') DiskControllerTypes = self.get_models('DiskControllerTypes', operation_group='virtual_machines') # REUSABLE ARGUMENT DEFINITIONS @@ -1386,11 +1385,11 @@ def load_arguments(self, _): 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. `..`') for scope in ['sig image-version create', 'sig image-version undelete']: - with self.argument_context(scope, resource_type=ResourceType.MGMT_COMPUTE, operation_group='gallery_image_versions') as c: + with self.argument_context(scope) as c: c.argument('gallery_image_version', options_list=['--gallery-image-version', '-e'], 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. `..`') - with self.argument_context('sig image-version create', resource_type=ResourceType.MGMT_COMPUTE, operation_group='gallery_image_versions') as c: + with self.argument_context('sig image-version create') as c: c.argument('description', help='the description of the gallery image version') c.argument('managed_image', help='image name(if in the same resource group) or resource id') c.argument('os_snapshot', help='Name or ID of OS disk snapshot') @@ -1408,7 +1407,7 @@ def load_arguments(self, _): c.argument('data_vhds_uris', nargs='+', help='Source VHD URIs (space-delimited) of data disks') c.argument('data_vhds_luns', nargs='+', help='Logical unit numbers (space-delimited) of source VHD URIs of data disks') 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') - 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.') + c.argument('replication_mode', min_api='2021-07-01', arg_type=get_enum_type(["Full", "Shallow"]), help='Optional parameter which specifies the mode to be used for replication. This property is not updatable.') c.argument('target_region_cvm_encryption', nargs='+', min_api='2021-10-01', help='Space-separated list of customer managed key for Confidential VM encrypting the OS disk in the gallery artifact for each region. Format for each region: `,`. The valid values for os_cvm_encryption_type are EncryptedVMGuestStateOnlyWithPmk, EncryptedWithPmk, EncryptedWithCmk.') c.argument('virtual_machine', help='Resource id of VM source') c.argument('image_version', help='Resource id of gallery image version source') @@ -1433,7 +1432,7 @@ def load_arguments(self, _): 'Format: `..`', id_part='child_name_3') for scope in ['sig image-version create', 'sig image-version update']: - with self.argument_context(scope, operation_group='gallery_image_versions') as c: + with self.argument_context(scope) as c: c.argument('target_regions', nargs='*', help='Space-separated list of regions and their replica counts. Use `[=][=]` to optionally set the replica count and/or storage account type for each region. ' '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') @@ -1447,7 +1446,7 @@ def load_arguments(self, _): help="Indicate whether or not the deletion is blocked for this gallery image version if its end of life has not expired") for scope in ['sig image-version create', 'sig image-version update', 'sig image-version undelete']: - with self.argument_context(scope, operation_group='gallery_image_versions') as c: + with self.argument_context(scope) as c: c.argument('allow_replicated_location_deletion', arg_type=get_three_state_flag(), min_api='2022-03-03', help='Indicate whether or not removing this gallery image version from replicated regions is allowed.') with self.argument_context('sig list-community') as c: diff --git a/src/azure-cli/azure/cli/command_modules/vm/commands.py b/src/azure-cli/azure/cli/command_modules/vm/commands.py index 0dd9c9d60bc..e9d384f3bde 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/commands.py @@ -7,7 +7,7 @@ cf_vm_ext, cf_vm_ext_image, cf_vm_image_term, cf_usage, cf_vmss, - cf_galleries, cf_gallery_images, cf_gallery_image_versions, + cf_galleries, cf_gallery_images, cf_proximity_placement_groups, cf_dedicated_hosts, cf_log_analytics_data_plane, @@ -111,11 +111,6 @@ def load_command_table(self, _): client_factory=cf_gallery_images, ) - compute_gallery_image_versions_sdk = CliCommandType( - operations_tmpl='azure.mgmt.compute.operations#GalleryImageVersionsOperations.{}', - client_factory=cf_gallery_image_versions, - ) - compute_gallery_application_profile = CliCommandType( operations_tmpl='azure.mgmt.compute.operations#GalleryApplicationsOperations.{}', ) @@ -467,7 +462,7 @@ def load_command_table(self, _): from .operations.sig_image_definition import SigImageDefinitionListShared self.command_table['sig image-definition list-shared'] = SigImageDefinitionListShared(loader=self) - with self.command_group('sig image-version', compute_gallery_image_versions_sdk, operation_group='gallery_image_versions', min_api='2018-06-01') as g: + with self.command_group('sig image-version') as g: g.custom_command('create', 'create_image_version', supports_no_wait=True, validator=process_image_version_create_namespace) g.custom_command('undelete', 'undelete_image_version', supports_no_wait=True, validator=process_image_version_undelete_namespace, is_preview=True) g.generic_update_command('update', getter_name='get_image_version_to_update', setter_arg_name='gallery_image_version', setter_name='update_image_version', setter_type=compute_custom, command_type=compute_custom, supports_no_wait=True, validator=process_image_version_update_namespace) diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index 01067b8a777..d3a592a5fa7 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -5680,102 +5680,94 @@ def create_image_version(cmd, resource_group_name, gallery_name, gallery_image_n if replication_mode is not None: profile["replication_mode"] = replication_mode - if not cmd.supported_api_version(min_api='2022-03-03', operation_group='gallery_image_versions'): - source = {"managed_image": {"id": managed_image}} - profile["source"] = source - - if cmd.supported_api_version(min_api='2019-07-01', operation_group='gallery_image_versions'): - if managed_image is None and os_snapshot is None and os_vhd_uri is None: - raise RequiredArgumentMissingError('usage error: Please provide --managed-image or --os-snapshot or --vhd') - - source = os_disk_image = data_disk_images = None - if virtual_machine is not None and cmd.supported_api_version(min_api='2023-07-03', - operation_group='gallery_image_versions'): - source = {"virtual_machine_id": virtual_machine} - elif managed_image is not None: - source = {"id": managed_image} - if os_snapshot is not None: - os_disk_image = {"source": {"id": os_snapshot}} - if data_snapshot_luns and not data_snapshots: - raise ArgumentUsageError('usage error: --data-snapshot-luns must be used together with --data-snapshots') - if data_snapshots: - if data_snapshot_luns and len(data_snapshots) != len(data_snapshot_luns): - raise ArgumentUsageError('usage error: Length of --data-snapshots and ' - '--data-snapshot-luns should be equal.') - if not data_snapshot_luns: - data_snapshot_luns = list(range(len(data_snapshots))) - data_disk_images = [] - for i, s in enumerate(data_snapshots): - data_disk_images.append({"source": {"id": s}, "lun": int(data_snapshot_luns[i])}) - # from vhd, only support os image now - if cmd.supported_api_version(min_api='2020-09-30', operation_group='gallery_image_versions'): - # OS disk - if os_vhd_uri and os_vhd_storage_account is None or os_vhd_uri is None and os_vhd_storage_account: - raise ArgumentUsageError('--os-vhd-uri and --os-vhd-storage-account should be used together.') - if os_vhd_uri and os_vhd_storage_account: - if not is_valid_resource_id(os_vhd_storage_account): - os_vhd_storage_account = resource_id( - subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, - namespace='Microsoft.Storage', type='storageAccounts', name=os_vhd_storage_account) - os_disk_image = { - "source": { - "storage_account_id": os_vhd_storage_account, - "uri": os_vhd_uri - } - } + source = {"managed_image": {"id": managed_image}} + profile["source"] = source + + if managed_image is None and os_snapshot is None and os_vhd_uri is None: + raise RequiredArgumentMissingError('usage error: Please provide --managed-image or --os-snapshot or --vhd') + + source = os_disk_image = data_disk_images = None + if virtual_machine is not None: + source = {"virtual_machine_id": virtual_machine} + elif managed_image is not None: + source = {"id": managed_image} + if os_snapshot is not None: + os_disk_image = {"source": {"id": os_snapshot}} + if data_snapshot_luns and not data_snapshots: + raise ArgumentUsageError('usage error: --data-snapshot-luns must be used together with --data-snapshots') + if data_snapshots: + if data_snapshot_luns and len(data_snapshots) != len(data_snapshot_luns): + raise ArgumentUsageError('usage error: Length of --data-snapshots and ' + '--data-snapshot-luns should be equal.') + if not data_snapshot_luns: + data_snapshot_luns = list(range(len(data_snapshots))) + data_disk_images = [] + for i, s in enumerate(data_snapshots): + data_disk_images.append({"source": {"id": s}, "lun": int(data_snapshot_luns[i])}) + # from vhd, only support os image now + # OS disk + if os_vhd_uri and os_vhd_storage_account is None or os_vhd_uri is None and os_vhd_storage_account: + raise ArgumentUsageError('--os-vhd-uri and --os-vhd-storage-account should be used together.') + if os_vhd_uri and os_vhd_storage_account: + if not is_valid_resource_id(os_vhd_storage_account): + os_vhd_storage_account = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, + namespace='Microsoft.Storage', type='storageAccounts', name=os_vhd_storage_account) + os_disk_image = { + "source": { + "storage_account_id": os_vhd_storage_account, + "uri": os_vhd_uri + } + } - # Data disks - if data_vhds_uris and data_vhds_storage_accounts is None or \ - data_vhds_uris is None and data_vhds_storage_accounts: - raise ArgumentUsageError('--data-vhds-uris and --data-vhds-storage-accounts should be used together.') - if data_vhds_luns and data_vhds_uris is None: - raise ArgumentUsageError('--data-vhds-luns must be used together with --data-vhds-uris') - if data_vhds_uris: - # Generate LUNs - if data_vhds_luns is None: - # 0, 1, 2, ... - data_vhds_luns = list(range(len(data_vhds_uris))) - # Check length - len_data_vhds_uris = len(data_vhds_uris) - len_data_vhds_luns = len(data_vhds_luns) - len_data_vhds_storage_accounts = len(data_vhds_storage_accounts) - if len_data_vhds_uris != len_data_vhds_luns or len_data_vhds_uris != len_data_vhds_storage_accounts: - raise ArgumentUsageError( - 'Length of --data-vhds-uris, --data-vhds-luns, --data-vhds-storage-accounts must be same.') - # Generate full storage account ID - for i, storage_account in enumerate(data_vhds_storage_accounts): - if not is_valid_resource_id(storage_account): - data_vhds_storage_accounts[i] = resource_id( - subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, - namespace='Microsoft.Storage', type='storageAccounts', name=storage_account) - if data_disk_images is None: - data_disk_images = [] - for uri, lun, account in zip(data_vhds_uris, data_vhds_luns, data_vhds_storage_accounts): - data_disk_images.append({ - "source": {"storage_account_id": account, "uri": uri}, - "lun": lun - }) + # Data disks + if data_vhds_uris and data_vhds_storage_accounts is None or \ + data_vhds_uris is None and data_vhds_storage_accounts: + raise ArgumentUsageError('--data-vhds-uris and --data-vhds-storage-accounts should be used together.') + if data_vhds_luns and data_vhds_uris is None: + raise ArgumentUsageError('--data-vhds-luns must be used together with --data-vhds-uris') + if data_vhds_uris: + # Generate LUNs + if data_vhds_luns is None: + # 0, 1, 2, ... + data_vhds_luns = list(range(len(data_vhds_uris))) + # Check length + len_data_vhds_uris = len(data_vhds_uris) + len_data_vhds_luns = len(data_vhds_luns) + len_data_vhds_storage_accounts = len(data_vhds_storage_accounts) + if len_data_vhds_uris != len_data_vhds_luns or len_data_vhds_uris != len_data_vhds_storage_accounts: + raise ArgumentUsageError( + 'Length of --data-vhds-uris, --data-vhds-luns, --data-vhds-storage-accounts must be same.') + # Generate full storage account ID + for i, storage_account in enumerate(data_vhds_storage_accounts): + if not is_valid_resource_id(storage_account): + data_vhds_storage_accounts[i] = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name, + namespace='Microsoft.Storage', type='storageAccounts', name=storage_account) + if data_disk_images is None: + data_disk_images = [] + for uri, lun, account in zip(data_vhds_uris, data_vhds_luns, data_vhds_storage_accounts): + data_disk_images.append({ + "source": {"storage_account_id": account, "uri": uri}, + "lun": lun + }) - storage_profile = {"source": source, "os_disk_image": os_disk_image, "data_disk_images": data_disk_images} - args = { - "publishing_profile": profile, - "location": location, - "tags": tags or {}, - "storage_profile": storage_profile + storage_profile = {"source": source, "os_disk_image": os_disk_image, "data_disk_images": data_disk_images} + args = { + "publishing_profile": profile, + "location": location, + "tags": tags or {}, + "storage_profile": storage_profile + } + if allow_replicated_location_deletion is not None: + args["safety_profile"] = { + "allow_deletion_of_replicated_locations": allow_replicated_location_deletion } - if allow_replicated_location_deletion is not None: - args["safety_profile"] = { - "allow_deletion_of_replicated_locations": allow_replicated_location_deletion - } - if block_deletion_before_end_of_life is not None: - if "safety_profile" not in args: - args["safety_profile"] = {} + if block_deletion_before_end_of_life is not None: + if "safety_profile" not in args: + args["safety_profile"] = {} - args["safety_profile"]["block_deletion_before_end_of_life"] = block_deletion_before_end_of_life - else: - if managed_image is None: - raise RequiredArgumentMissingError('usage error: Please provide --managed-image') - args = {"publishing_profile": profile, "location": location, "tags": tags or {}} + args["safety_profile"]["block_deletion_before_end_of_life"] = block_deletion_before_end_of_life args["resource_group"] = resource_group_name args["gallery_name"] = gallery_name From 845f3b8ad62c4982f8fccc9038dd74f356cdc1a9 Mon Sep 17 00:00:00 2001 From: Jayson Tai Date: Thu, 9 Apr 2026 09:56:01 +1000 Subject: [PATCH 3/4] Remove unused import of _compute_client_factory from _actions.py --- src/azure-cli/azure/cli/command_modules/vm/_actions.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/_actions.py b/src/azure-cli/azure/cli/command_modules/vm/_actions.py index 9cdec570c03..b73a7183749 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_actions.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_actions.py @@ -19,8 +19,6 @@ from azure.cli.core.commands.parameters import get_one_of_subscription_locations from azure.cli.core.commands.arm import resource_exists -from ._client_factory import _compute_client_factory - from .generated.action import * # noqa: F403, pylint: disable=unused-wildcard-import,wildcard-import try: from .manual.action import * # noqa: F403, pylint: disable=unused-wildcard-import,wildcard-import From d40c1a6b3cc51937c9f2dd9bb91177007a2428c0 Mon Sep 17 00:00:00 2001 From: Jayson Tai Date: Thu, 9 Apr 2026 17:11:44 +1000 Subject: [PATCH 4/4] Remove unnecessary logic for old API support --- src/azure-cli/azure/cli/command_modules/vm/custom.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index d3a592a5fa7..725f68c6741 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -5680,8 +5680,6 @@ def create_image_version(cmd, resource_group_name, gallery_name, gallery_image_n if replication_mode is not None: profile["replication_mode"] = replication_mode - source = {"managed_image": {"id": managed_image}} - profile["source"] = source if managed_image is None and os_snapshot is None and os_vhd_uri is None: raise RequiredArgumentMissingError('usage error: Please provide --managed-image or --os-snapshot or --vhd')