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

Azure: Cleanup image definitions #361

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all 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
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
Loading