Skip to content

Commit 9c827a5

Browse files
authored
[Compute] az sig image-version create/update: Add new parameter --block-deletion-before-end-of-life to support blocking deletion if the end of life has not expired (#31013)
1 parent cb5335b commit 9c827a5

42 files changed

Lines changed: 32176 additions & 23911 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/azure-cli-core/azure/cli/core/profiles/_shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def default_api_version(self):
165165
'snapshots': '2023-10-02',
166166
'galleries': '2021-10-01',
167167
'gallery_images': '2021-10-01',
168-
'gallery_image_versions': '2023-07-03',
168+
'gallery_image_versions': '2024-03-03',
169169
'gallery_applications': '2021-07-01',
170170
'gallery_application_versions': '2022-01-03',
171171
'shared_galleries': '2022-01-03',

src/azure-cli/azure/cli/command_modules/vm/_params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,9 @@ def load_arguments(self, _):
13781378
help='Space-separated list of regions, edge zones, replica counts and storage types. Use `<region>=<edge zone>[=<replica count>][=<storage account type>]` to optionally set the replica count and/or storage account type for each region. '
13791379
'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. '
13801380
'If "--target-edge-zones None" is specified, the target extended locations will be cleared.')
1381+
c.argument('block_deletion_before_end_of_life', arg_type=get_three_state_flag(), min_api='2024-03-03',
1382+
options_list=['--block-deletion-before-end-of-life', '--block-deletion'],
1383+
help="Indicate whether or not the deletion is blocked for this gallery image version if its end of life has not expired")
13811384

13821385
for scope in ['sig image-version create', 'sig image-version update', 'sig image-version undelete']:
13831386
with self.argument_context(scope, operation_group='gallery_image_versions') as c:

src/azure-cli/azure/cli/command_modules/vm/_validators.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,30 @@ def _validate_vm_create_storage_profile(cmd, namespace, for_scale_set=False):
514514
namespace.os_type = image_info.os_type
515515
gallery_image_version = res.get('child_name_2', '')
516516
if gallery_image_version.lower() in ['latest', '']:
517-
image_version_infos = compute_client.gallery_image_versions.list_by_gallery_image(
518-
resource_group_name=res['resource_group'], gallery_name=res['name'],
519-
gallery_image_name=res['child_name_1'])
520-
image_version_infos = [x for x in image_version_infos if not x.publishing_profile.exclude_from_latest]
517+
from .aaz.latest.sig.image_version import List as _SigImageVersionList
518+
image_version_infos = _SigImageVersionList(cli_ctx=cmd.cli_ctx)(command_args={
519+
"resource_group": res['resource_group'],
520+
"gallery_name": res['name'],
521+
"gallery_image_definition": res['child_name_1']
522+
})
523+
image_version_infos = [x for x in image_version_infos
524+
if not x.get("publishingProfile", {}).get("excludeFromLatest", None)]
521525
if not image_version_infos:
522526
raise CLIError('There is no latest image version exists for "{}"'.format(namespace.image))
523-
image_version_info = sorted(image_version_infos, key=lambda x: x.publishing_profile.published_date)[-1]
527+
image_version_info = sorted(image_version_infos,
528+
key=lambda x: x["publishingProfile"]["publishedDate"])[-1]
529+
image_data_disks = image_version_info.get("storageProfile", {}).get("dataDiskImages", []) or []
530+
image_data_disks = [{'lun': disk["lun"]} for disk in image_data_disks]
524531
else:
525-
image_version_info = compute_client.gallery_image_versions.get(
526-
resource_group_name=res['resource_group'], gallery_name=res['name'],
527-
gallery_image_name=res['child_name_1'], gallery_image_version_name=res['child_name_2'])
528-
image_data_disks = image_version_info.storage_profile.data_disk_images or []
529-
image_data_disks = [{'lun': disk.lun} for disk in image_data_disks]
532+
from .aaz.latest.sig.image_version import Show as _SigImageVersionShow
533+
image_version_info = _SigImageVersionShow(cli_ctx=cmd.cli_ctx)(command_args={
534+
"resource_group": res['resource_group'],
535+
"gallery_name": res['name'],
536+
"gallery_image_definition": res['child_name_1'],
537+
"gallery_image_version_name": res['child_name_2'],
538+
})
539+
image_data_disks = image_version_info.get("storageProfile", {}).get("dataDiskImages", []) or []
540+
image_data_disks = [{'lun': disk["lun"]} for disk in image_data_disks]
530541

531542
else:
532543
raise CLIError('usage error: unrecognized image information "{}"'.format(namespace.image))

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/image_version/_create.py

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Create(AAZCommand):
1616
"""
1717

1818
_aaz_info = {
19-
"version": "2023-07-03",
19+
"version": "2024-03-03",
2020
"resources": [
21-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/galleries/{}/images/{}/versions/{}", "2023-07-03"],
21+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/galleries/{}/images/{}/versions/{}", "2024-03-03"],
2222
]
2323
}
2424

@@ -86,6 +86,11 @@ def _build_arguments_schema(cls, *args, **kwargs):
8686
arg_group="Properties",
8787
help="The publishing profile of a gallery image Version.",
8888
)
89+
_args_schema.restore = AAZBoolArg(
90+
options=["--restore"],
91+
arg_group="Properties",
92+
help="Indicates if this is a soft-delete resource restoration request.",
93+
)
8994
_args_schema.safety_profile = AAZObjectArg(
9095
options=["--safety-profile"],
9196
arg_group="Properties",
@@ -123,7 +128,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
123128
publishing_profile.storage_account_type = AAZStrArg(
124129
options=["storage-account-type"],
125130
help="Specifies the storage account type to be used to store the image. This property is not updatable.",
126-
enum={"Premium_LRS": "Premium_LRS", "Standard_LRS": "Standard_LRS", "Standard_ZRS": "Standard_ZRS"},
131+
enum={"PremiumV2_LRS": "PremiumV2_LRS", "Premium_LRS": "Premium_LRS", "Standard_LRS": "Standard_LRS", "Standard_ZRS": "Standard_ZRS"},
127132
)
128133
publishing_profile.target_extended_locations = AAZListArg(
129134
options=["target-extended-locations"],
@@ -174,6 +179,10 @@ def _build_arguments_schema(cls, *args, **kwargs):
174179
target_regions.Element = AAZObjectArg()
175180

176181
_element = cls._args_schema.publishing_profile.target_regions.Element
182+
_element.additional_replica_sets = AAZListArg(
183+
options=["additional-replica-sets"],
184+
help="List of storage sku with replica count to create direct drive replicas.",
185+
)
177186
_element.encryption = AAZObjectArg(
178187
options=["encryption"],
179188
help="Optional. Allows users to provide customer managed keys for encrypting the OS and data disks in the gallery artifact.",
@@ -195,14 +204,32 @@ def _build_arguments_schema(cls, *args, **kwargs):
195204
_element.storage_account_type = AAZStrArg(
196205
options=["storage-account-type"],
197206
help="Specifies the storage account type to be used to store the image. This property is not updatable.",
198-
enum={"Premium_LRS": "Premium_LRS", "Standard_LRS": "Standard_LRS", "Standard_ZRS": "Standard_ZRS"},
207+
enum={"PremiumV2_LRS": "PremiumV2_LRS", "Premium_LRS": "Premium_LRS", "Standard_LRS": "Standard_LRS", "Standard_ZRS": "Standard_ZRS"},
208+
)
209+
210+
additional_replica_sets = cls._args_schema.publishing_profile.target_regions.Element.additional_replica_sets
211+
additional_replica_sets.Element = AAZObjectArg()
212+
213+
_element = cls._args_schema.publishing_profile.target_regions.Element.additional_replica_sets.Element
214+
_element.regional_replica_count = AAZIntArg(
215+
options=["regional-replica-count"],
216+
help="The number of direct drive replicas of the Image Version to be created.This Property is updatable",
217+
)
218+
_element.storage_account_type = AAZStrArg(
219+
options=["storage-account-type"],
220+
help="Specifies the storage account type to be used to create the direct drive replicas",
221+
enum={"PremiumV2_LRS": "PremiumV2_LRS", "Premium_LRS": "Premium_LRS", "Standard_LRS": "Standard_LRS", "Standard_ZRS": "Standard_ZRS"},
199222
)
200223

201224
safety_profile = cls._args_schema.safety_profile
202225
safety_profile.allow_deletion_of_replicated_locations = AAZBoolArg(
203226
options=["allow-deletion-of-replicated-locations"],
204227
help="Indicates whether or not removing this Gallery Image Version from replicated regions is allowed.",
205228
)
229+
safety_profile.block_deletion_before_end_of_life = AAZBoolArg(
230+
options=["block-deletion-before-end-of-life"],
231+
help="Indicates whether or not the deletion is blocked for this Gallery Image Version if its End Of Life has not expired.",
232+
)
206233

207234
security_profile = cls._args_schema.security_profile
208235
security_profile.uefi_settings = AAZObjectArg(
@@ -522,7 +549,7 @@ def url_parameters(self):
522549
def query_parameters(self):
523550
parameters = {
524551
**self.serialize_query_param(
525-
"api-version", "2023-07-03",
552+
"api-version", "2024-03-03",
526553
required=True,
527554
),
528555
}
@@ -554,6 +581,7 @@ def content(self):
554581
properties = _builder.get(".properties")
555582
if properties is not None:
556583
properties.set_prop("publishingProfile", AAZObjectType, ".publishing_profile")
584+
properties.set_prop("restore", AAZBoolType, ".restore")
557585
properties.set_prop("safetyProfile", AAZObjectType, ".safety_profile")
558586
properties.set_prop("securityProfile", AAZObjectType, ".security_profile")
559587
properties.set_prop("storageProfile", AAZObjectType, ".storage_profile", typ_kwargs={"flags": {"required": True}})
@@ -591,15 +619,26 @@ def content(self):
591619

592620
_elements = _builder.get(".properties.publishingProfile.targetRegions[]")
593621
if _elements is not None:
622+
_elements.set_prop("additionalReplicaSets", AAZListType, ".additional_replica_sets")
594623
_CreateHelper._build_schema_encryption_images_create(_elements.set_prop("encryption", AAZObjectType, ".encryption"))
595624
_elements.set_prop("excludeFromLatest", AAZBoolType, ".exclude_from_latest")
596625
_elements.set_prop("name", AAZStrType, ".name", typ_kwargs={"flags": {"required": True}})
597626
_elements.set_prop("regionalReplicaCount", AAZIntType, ".regional_replica_count")
598627
_elements.set_prop("storageAccountType", AAZStrType, ".storage_account_type")
599628

629+
additional_replica_sets = _builder.get(".properties.publishingProfile.targetRegions[].additionalReplicaSets")
630+
if additional_replica_sets is not None:
631+
additional_replica_sets.set_elements(AAZObjectType, ".")
632+
633+
_elements = _builder.get(".properties.publishingProfile.targetRegions[].additionalReplicaSets[]")
634+
if _elements is not None:
635+
_elements.set_prop("regionalReplicaCount", AAZIntType, ".regional_replica_count")
636+
_elements.set_prop("storageAccountType", AAZStrType, ".storage_account_type")
637+
600638
safety_profile = _builder.get(".properties.safetyProfile")
601639
if safety_profile is not None:
602640
safety_profile.set_prop("allowDeletionOfReplicatedLocations", AAZBoolType, ".allow_deletion_of_replicated_locations")
641+
safety_profile.set_prop("blockDeletionBeforeEndOfLife", AAZBoolType, ".block_deletion_before_end_of_life")
603642

604643
security_profile = _builder.get(".properties.securityProfile")
605644
if security_profile is not None:
@@ -852,6 +891,7 @@ def _build_schema_gallery_image_version_read(cls, _schema):
852891
serialized_name="replicationStatus",
853892
flags={"read_only": True},
854893
)
894+
properties.restore = AAZBoolType()
855895
properties.safety_profile = AAZObjectType(
856896
serialized_name="safetyProfile",
857897
)
@@ -862,6 +902,10 @@ def _build_schema_gallery_image_version_read(cls, _schema):
862902
serialized_name="storageProfile",
863903
flags={"required": True},
864904
)
905+
properties.validations_profile = AAZObjectType(
906+
serialized_name="validationsProfile",
907+
flags={"read_only": True},
908+
)
865909

866910
publishing_profile = _schema_gallery_image_version_read.properties.publishing_profile
867911
publishing_profile.end_of_life_date = AAZStrType(
@@ -915,6 +959,9 @@ def _build_schema_gallery_image_version_read(cls, _schema):
915959
target_regions.Element = AAZObjectType()
916960

917961
_element = _schema_gallery_image_version_read.properties.publishing_profile.target_regions.Element
962+
_element.additional_replica_sets = AAZListType(
963+
serialized_name="additionalReplicaSets",
964+
)
918965
_element.encryption = AAZObjectType()
919966
cls._build_schema_encryption_images_read(_element.encryption)
920967
_element.exclude_from_latest = AAZBoolType(
@@ -930,6 +977,17 @@ def _build_schema_gallery_image_version_read(cls, _schema):
930977
serialized_name="storageAccountType",
931978
)
932979

980+
additional_replica_sets = _schema_gallery_image_version_read.properties.publishing_profile.target_regions.Element.additional_replica_sets
981+
additional_replica_sets.Element = AAZObjectType()
982+
983+
_element = _schema_gallery_image_version_read.properties.publishing_profile.target_regions.Element.additional_replica_sets.Element
984+
_element.regional_replica_count = AAZIntType(
985+
serialized_name="regionalReplicaCount",
986+
)
987+
_element.storage_account_type = AAZStrType(
988+
serialized_name="storageAccountType",
989+
)
990+
933991
replication_status = _schema_gallery_image_version_read.properties.replication_status
934992
replication_status.aggregated_state = AAZStrType(
935993
serialized_name="aggregatedState",
@@ -960,6 +1018,9 @@ def _build_schema_gallery_image_version_read(cls, _schema):
9601018
safety_profile.allow_deletion_of_replicated_locations = AAZBoolType(
9611019
serialized_name="allowDeletionOfReplicatedLocations",
9621020
)
1021+
safety_profile.block_deletion_before_end_of_life = AAZBoolType(
1022+
serialized_name="blockDeletionBeforeEndOfLife",
1023+
)
9631024
safety_profile.policy_violations = AAZListType(
9641025
serialized_name="policyViolations",
9651026
flags={"read_only": True},
@@ -1057,6 +1118,39 @@ def _build_schema_gallery_image_version_read(cls, _schema):
10571118
serialized_name="virtualMachineId",
10581119
)
10591120

1121+
validations_profile = _schema_gallery_image_version_read.properties.validations_profile
1122+
validations_profile.executed_validations = AAZListType(
1123+
serialized_name="executedValidations",
1124+
)
1125+
validations_profile.platform_attributes = AAZListType(
1126+
serialized_name="platformAttributes",
1127+
)
1128+
validations_profile.validation_etag = AAZStrType(
1129+
serialized_name="validationEtag",
1130+
)
1131+
1132+
executed_validations = _schema_gallery_image_version_read.properties.validations_profile.executed_validations
1133+
executed_validations.Element = AAZObjectType()
1134+
1135+
_element = _schema_gallery_image_version_read.properties.validations_profile.executed_validations.Element
1136+
_element.execution_time = AAZStrType(
1137+
serialized_name="executionTime",
1138+
)
1139+
_element.status = AAZStrType()
1140+
_element.type = AAZStrType()
1141+
_element.version = AAZStrType()
1142+
1143+
platform_attributes = _schema_gallery_image_version_read.properties.validations_profile.platform_attributes
1144+
platform_attributes.Element = AAZObjectType()
1145+
1146+
_element = _schema_gallery_image_version_read.properties.validations_profile.platform_attributes.Element
1147+
_element.name = AAZStrType(
1148+
flags={"read_only": True},
1149+
)
1150+
_element.value = AAZStrType(
1151+
flags={"read_only": True},
1152+
)
1153+
10601154
tags = _schema_gallery_image_version_read.tags
10611155
tags.Element = AAZStrType()
10621156

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/sig/image_version/_delete.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Delete(AAZCommand):
1919
"""
2020

2121
_aaz_info = {
22-
"version": "2023-07-03",
22+
"version": "2024-03-03",
2323
"resources": [
24-
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/galleries/{}/images/{}/versions/{}", "2023-07-03"],
24+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/galleries/{}/images/{}/versions/{}", "2024-03-03"],
2525
]
2626
}
2727

@@ -159,7 +159,7 @@ def url_parameters(self):
159159
def query_parameters(self):
160160
parameters = {
161161
**self.serialize_query_param(
162-
"api-version", "2023-07-03",
162+
"api-version", "2024-03-03",
163163
required=True,
164164
),
165165
}

0 commit comments

Comments
 (0)