Skip to content

Commit

Permalink
remove duplicated label logic
Browse files Browse the repository at this point in the history
  • Loading branch information
linguini-dev committed Feb 6, 2025
1 parent ec978be commit 189392e
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions ocw/lib/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,19 @@ def cleanup_disks(self) -> None:
self.log_dbg(f"{len(disks)} disks found")
for disk in disks:
if self.is_outdated(parse(disk["creationTimestamp"]).astimezone(timezone.utc)):
labels = disk.get('labels', [])
pcw_ignore_tag = 'pcw_ignore' in labels
if pcw_ignore_tag:
self.log_dbg(f"Ignoring {disk['name']} due to 'pcw_ignore' label set to '1'")
else:
self._delete_resource(
self.compute_client().disks, disk["name"], project=self.project, zone=zone, disk=disk["name"]
)
self._delete_resource(
self.compute_client().disks, disk["name"], project=self.project, zone=zone, disk=disk["name"]
)

def cleanup_images(self) -> None:
self.log_dbg("Images cleanup")
images = self._paginated(self.compute_client().images, project=self.project)
self.log_dbg(f"{len(images)} images found")
for image in images:
if self.is_outdated(parse(image["creationTimestamp"]).astimezone(timezone.utc)):
labels = image.get('labels', [])
pcw_ignore_tag = 'pcw_ignore' in labels
if pcw_ignore_tag:
self.log_dbg(f"Ignoring {image['name']} due to 'pcw_ignore' label set to '1'")
else:
self._delete_resource(
self.compute_client().images, image["name"], project=self.project, image=image["name"]
)
self._delete_resource(
self.compute_client().images, image["name"], project=self.project, image=image["name"]
)

def cleanup_firewalls(self) -> None:
self.log_dbg("Firewalls cleanup")
Expand Down

0 comments on commit 189392e

Please sign in to comment.