diff --git a/ocw/lib/azure.py b/ocw/lib/azure.py index 35376797..b02bf760 100644 --- a/ocw/lib/azure.py +++ b/ocw/lib/azure.py @@ -206,6 +206,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 ) + properties = self.get_resource_properties(image.id) + if self.is_outdated(parse(properties['publishingProfile']['publishedDate'])): + 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")