Commit b8eff33b by Őry Máté

storage: refactor Disk.is_deletable

parent 8703382d
...@@ -133,21 +133,20 @@ class Disk(AclBase, TimeStampedModel): ...@@ -133,21 +133,20 @@ class Disk(AclBase, TimeStampedModel):
}[self.type] }[self.type]
def is_deletable(self): def is_deletable(self):
"""Returns True if no child and disk is destroyed.""" """Returns whether the file can be deleted.
time_before = - timedelta(days=1)
if self.destroyed > time_before or self.has_active_child(): Checks if all children and the disk itself is destroyed.
return False """
return True yesterday = - timedelta(days=1)
return (self.destroyed is not None
and self.destroyed < yesterday) and not self.has_active_child()
def has_active_child(self): def has_active_child(self):
"""Returns True if disk have iactive childs.""" """Returns if disk has children that are not destroyed.
time_before = - timedelta(days=1) """
for child in self.derivatives.all():
if child.destroyed > time_before or None: return any((not i.is_deletable() for i in self.derivatives.all()))
return True
return False
def is_in_use(self): def is_in_use(self):
"""Returns True if disc is attached to an active VM else False""" """Returns True if disc is attached to an active VM else False"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment