Skip to content
1 change: 0 additions & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,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

Expand Down
11 changes: 5 additions & 6 deletions src/azure-cli/azure/cli/command_modules/vm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1390,11 +1389,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. `<MajorVersion>.<MinorVersion>.<Patch>`')

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. `<MajorVersion>.<MinorVersion>.<Patch>`')

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')
Expand All @@ -1412,7 +1411,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: `<os_cvm_encryption_type>,<os_cvm_des>`. 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')
Expand All @@ -1437,7 +1436,7 @@ def load_arguments(self, _):
'Format: `<MajorVersion>.<MinorVersion>.<Patch>`', 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 `<region>[=<replica count>][=<storage account type>]` 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')
Expand All @@ -1451,7 +1450,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:
Expand Down
9 changes: 2 additions & 7 deletions src/azure-cli/azure/cli/command_modules/vm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
cf_vm_ext, cf_vm_ext_image,
cf_vm_image_term,
cf_vmss,
cf_gallery_images, cf_gallery_image_versions,
cf_gallery_images,
cf_proximity_placement_groups,
cf_log_analytics_data_plane,
cf_capacity_reservations,
Expand Down Expand Up @@ -100,11 +100,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.{}',
)
Expand Down Expand Up @@ -445,7 +440,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)
Expand Down
174 changes: 82 additions & 92 deletions src/azure-cli/azure/cli/command_modules/vm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5772,102 +5772,92 @@ 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
Comment on lines -5775 to -5777

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement checks whether the API version is earlier than 2022-03-03, and executes the code if it is.
I think we can safely remove these lines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, I have removed it now.


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
}
}

# 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
})
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
}
}

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
# 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
}
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
Expand Down
Loading