Commit 9f60b684 by Dudás Ádám

vm: refactor and comment state property

parent 043a8ccf
...@@ -276,17 +276,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -276,17 +276,23 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
def state(self): def state(self):
"""State of the virtual machine instance. """State of the virtual machine instance.
""" """
# check special cases
if self.activity_log.filter(activity_code__endswith='migrate', if self.activity_log.filter(activity_code__endswith='migrate',
finished__isnull=True).exists(): finished__isnull=True).exists():
return 'MIGRATING' return 'MIGRATING'
# <<< add checks for special cases before this
# default case
acts = self.activity_log.filter(finished__isnull=False,
resultant_state__isnull=False
).order_by('-finished')[:1]
try: try:
act = self.activity_log.filter(finished__isnull=False, act = acts[0]
resultant_state__isnull=False
).order_by('-finished').all()[0]
except IndexError: except IndexError:
act = None return 'NOSTATE'
return 'NOSTATE' if act is None else act.resultant_state else:
return act.resultant_state
def is_console_available(self): def is_console_available(self):
return self.state in ('RUNNING', ) return self.state in ('RUNNING', )
......
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