Skip to content

Commit

Permalink
Azure: Cleanup image definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Mar 13, 2024
1 parent bce77d4 commit 8d96826
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ocw/lib/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ def cleanup_gallery_img_versions(self) -> None:
if Instance.TAG_IGNORE in image.tags:
self.log_info(f"Gallery {self.__gallery} image {image} has {Instance.TAG_IGNORE} tag")
continue
for version in self.compute_mgmt_client().gallery_image_versions.list_by_gallery_image(
self.__resource_group, gallery.name, image.name):
versions = list(self.compute_mgmt_client().gallery_image_versions.list_by_gallery_image(
self.__resource_group, gallery.name, image.name))
self.log_dbg(f"Image {image} in gallery {self.__gallery} has {len(versions)} versions")
for version in versions:
if version.tags is not None and Instance.TAG_IGNORE in version.tags:
self.log_info(f"Image version {version} for image {image} in gallery {self.__gallery} has {Instance.TAG_IGNORE} tag")
continue
Expand All @@ -206,6 +208,15 @@ def cleanup_gallery_img_versions(self) -> None:
self.compute_mgmt_client().gallery_image_versions.begin_delete(
self.__resource_group, gallery.name, image.name, version.name
)
# Delete image definition if all image versions were deleted
if not versions:
if self.dry_run:
self.log_info(f"Deletion of image {gallery.name}/{image.name} skipped due to dry run mode")
else:
self.log_info(f"Delete image '{gallery.name}/{image.name}'")
self.compute_mgmt_client().gallery_images.begin_delete(
self.__resource_group, gallery.name, image.name
)

def get_img_versions_count(self) -> int:
self.log_dbg("Call get_img_versions_count")
Expand Down

0 comments on commit 8d96826

Please sign in to comment.