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] Fix #22995: az image-version create: Unbind the usage of --target-region-encryption and --target-region-cvm-encryption #23147

Merged
merged 7 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,8 @@ def process_gallery_image_version_namespace(cmd, namespace):

# Parse target region encryption, example: ['des1,0,des2,1,des3', 'null', 'des4']
encryption = None
os_disk_image = None
data_disk_images = None
if hasattr(namespace, 'target_region_encryption') and namespace.target_region_encryption:
terms = namespace.target_region_encryption[i].split(',')
# OS disk
Expand All @@ -2061,29 +2063,7 @@ def process_gallery_image_version_namespace(cmd, namespace):
else:
des_id = _disk_encryption_set_format(cmd, namespace, os_disk_image)
security_profile = None
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
if hasattr(namespace, 'target_region_cvm_encryption') and namespace.target_region_cvm_encryption:
cvm_terms = namespace.target_region_cvm_encryption[i].split(',')
if not cvm_terms or len(cvm_terms) != 2:
Jing-song marked this conversation as resolved.
Show resolved Hide resolved
raise ArgumentUsageError(
"usage error: {} is an invalid target region cvm encryption. "
"Both os_cvm_encryption_type and os_cvm_des parameters are required.".format(cvm_terms))

storage_profile_types = [profile_type.value for profile_type in ConfidentialVMEncryptionType]
storage_profile_types_str = ", ".join(storage_profile_types)
if cvm_terms[0] not in storage_profile_types:
raise ArgumentUsageError(
"usage error: {} is an invalid os_cvm_encryption_type. "
"The valid values for os_cvm_encryption_type are {}".format(
cvm_terms, storage_profile_types_str))
if cvm_terms[1]:
cvm_des_id = _disk_encryption_set_format(cmd, namespace, cvm_terms[1])
else:
cvm_des_id = None
security_profile = OSDiskImageSecurityProfile(confidential_vm_encryption_type=cvm_terms[0],
secure_vm_disk_encryption_set_id=cvm_des_id)

os_disk_image = OSDiskImageEncryption(disk_encryption_set_id=des_id,
security_profile=security_profile)
os_disk_image = OSDiskImageEncryption(disk_encryption_set_id=des_id)
# Data disk
if len(terms) > 1:
data_disk_images = terms[1:]
Expand All @@ -2100,8 +2080,31 @@ def process_gallery_image_version_namespace(cmd, namespace):
data_disk_image_encryption_list.append(DataDiskImageEncryption(
lun=lun, disk_encryption_set_id=des_id))
data_disk_images = data_disk_image_encryption_list

if hasattr(namespace, 'target_region_cvm_encryption') and namespace.target_region_cvm_encryption:
cvm_terms = namespace.target_region_cvm_encryption[i].split(',')
if not cvm_terms or len(cvm_terms) != 2:
raise ArgumentUsageError(
"usage error: {} is an invalid target region cvm encryption. "
"Both os_cvm_encryption_type and os_cvm_des parameters are required.".format(cvm_terms))
storage_profile_types = [profile_type.value for profile_type in ConfidentialVMEncryptionType]
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved
storage_profile_types_str = ", ".join(storage_profile_types)
if cvm_terms[0] not in storage_profile_types:
raise ArgumentUsageError(
"usage error: {} is an invalid os_cvm_encryption_type. "
"The valid values for os_cvm_encryption_type are {}".format(
cvm_terms, storage_profile_types_str))
cvm_des_id = None
if cvm_terms[1]:
cvm_des_id = _disk_encryption_set_format(cmd, namespace, cvm_terms[1])
security_profile = OSDiskImageSecurityProfile(confidential_vm_encryption_type=cvm_terms[0],
secure_vm_disk_encryption_set_id=cvm_des_id)
if os_disk_image:
os_disk_image.security_profile = security_profile
else:
data_disk_images = None
os_disk_image = OSDiskImageEncryption(security_profile=security_profile)

if os_disk_image or data_disk_images:
encryption = EncryptionImages(os_disk_image=os_disk_image, data_disk_images=data_disk_images)
zhoxing-ms marked this conversation as resolved.
Show resolved Hide resolved

# At least the region is specified
Expand Down
Loading