Skip to content

Commit a42daf6

Browse files
committed
[cloud] Separate snapshot deletion from image deletion for Alibaba Cloud
Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent 295f3be commit a42daf6

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

contrib/cloud/ali-import

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ def delete_image(clients, name):
390390
for image in rsp.body.images.image or ():
391391
logger.info("delete image %s %s (%s)" %
392392
(clients.region, image.image_name, image.image_id))
393+
# Unpublish image
394+
if image.is_public:
395+
req = ecs.models.ModifyImageSharePermissionRequest(
396+
region_id=clients.region,
397+
image_id=image.image_id,
398+
is_public=False,
399+
)
400+
rsp = clients.ecs.modify_image_share_permission_with_options(
401+
req, RUNTIME_OPTS
402+
)
393403
# Tag associated snapshots for deletion
394404
for disk in image.disk_device_mappings.disk_device_mapping or ():
395405
snapshot_id = disk.snapshot_id
@@ -404,23 +414,15 @@ def delete_image(clients, name):
404414
tag=[tag],
405415
)
406416
rsp = clients.ecs.tag_resources_with_options(req, RUNTIME_OPTS)
407-
# Unpublish image
408-
if image.is_public:
409-
req = ecs.models.ModifyImageSharePermissionRequest(
410-
region_id=clients.region,
411-
image_id=image.image_id,
412-
is_public=False,
413-
)
414-
rsp = clients.ecs.modify_image_share_permission_with_options(
415-
req, RUNTIME_OPTS
416-
)
417417
# Delete image
418418
req = ecs.models.DeleteImageRequest(
419419
region_id=clients.region,
420420
image_id=image.image_id
421421
)
422422
rsp = clients.ecs.delete_image_with_options(req, RUNTIME_OPTS)
423-
# Delete any snapshots tagged for deletion
423+
424+
def delete_snapshots(clients):
425+
"""Remove stale snapshots left behind by deleted images"""
424426
tag = ecs.models.ListTagResourcesRequestTag(
425427
key=IPXE_SNAPSHOT_DELETE_TAG,
426428
value=IPXE_SNAPSHOT_DELETE_TAG,
@@ -603,6 +605,13 @@ if args.overwrite:
603605
for region, image in imports}
604606
done = {futures[x]: x.result() for x in as_completed(futures)}
605607

608+
# Delete any stale snapshots from all regions
609+
with ThreadPoolExecutor(max_workers=workers) as executor:
610+
futures = {executor.submit(delete_snapshots,
611+
clients=clients[region]): region
612+
for region in regions}
613+
done = {futures[x]: x.result() for x in as_completed(futures)}
614+
606615
# Create temporary function in each censored region with usable FC
607616
with ThreadPoolExecutor(max_workers=workers) as executor:
608617
futures = {executor.submit(create_temp_function,

0 commit comments

Comments
 (0)