Skip to content

Commit

Permalink
adding deletion code in try/catch to prevent interruption during exec…
Browse files Browse the repository at this point in the history
…ution
  • Loading branch information
eduardocerqueira committed Apr 30, 2021
1 parent ffd21f8 commit 898867f
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions janitor/module/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,36 @@ def run(self):
deleted = []
for vm in self.vm_list:
if vm['name'] not in to_keep_names:
if self.driver.delete_instance(vm):
print(vm['name'])
# deleted.append(vm)
else:
print(f"Could not delete vm {vm['name']}")
try:
if self.driver.delete_instance(vm):
deleted.append(vm)
else:
print(f"Could not delete vm {vm['name']}")
except Exception as ex:
print(ex)

# delete zoombies floating ips
ips_deleted = []
zoombies_ips = self.driver.get_zoombies_floating_ips()
for ip in zoombies_ips:
if self.driver.delete_floating_ip(ip['id']):
ips_deleted.append(ip)
else:
print(f"Could not delete ip {ip}")
zombie_ips = self.driver.get_zoombies_floating_ips()
try:
for ip in zombie_ips:
if self.driver.delete_floating_ip(ip['id']):
ips_deleted.append(ip)
else:
print(f"Could not delete ip {ip}")
except Exception as ex:
print(ex)

# delete volumes
vols_deleted = []
for vol in self.volumes:
# extra verification for not attached volumes
if len(vol.attachments) == 0:
self.driver.cinder.volumes.delete(vol.id)
vols_deleted.append(vol.id)
try:
if len(vol.attachments) == 0:
self.driver.cinder.volumes.delete(vol.id)
vols_deleted.append(vol.id)
except Exception as ex:
print(ex)

# history
history = History(to_keep, deleted, ips_deleted, vols_deleted)
Expand Down

0 comments on commit 898867f

Please sign in to comment.