Commit 1067a9ec by Dudás Ádám

vm: derive instance state from activity log

parent b478ebb0
......@@ -166,14 +166,6 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
* base resource configuration values
* owner and privilege information
STATES = [('NOSTATE', _('nostate')),
('RUNNING', _('running')),
('BLOCKED', _('blocked')),
('PAUSED', _('paused')),
('SHUTDOWN', _('shutdown')),
('SHUTOFF', _('shutoff')),
('CRASHED', _('crashed')),
('PMSUSPENDED', _('pmsuspended'))] # libvirt domain states
('user', _('user')), # see all details
('operator', _('operator')), # console, networking, change state
......@@ -204,7 +196,6 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
help_text=_("Current hypervisor of this instance."),
verbose_name=_('host node'))
state = CharField(choices=STATES, default='NOSTATE', max_length=20)
disks = ManyToManyField(Disk, related_name='instance_set',
help_text=_("Set of mounted disks."),
......@@ -258,6 +249,19 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
parts = [, "(" + str( + ")"]
return " ".join([s for s in parts if s != ""])
def state(self):
"""State of the virtual machine instance.
if self.activity_log.filter(activity_code__endswith='migrate',
return 'MIGRATING'
act = next(self.activity_log.filter(finished__isnull=False,
.order_by('-finished')[:1], None)
return 'NOSTATE' if act is None else act.resultant_state
def clean(self, *args, **kwargs):
if self.time_of_delete is None:
......@@ -914,6 +918,4 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):'Instance %s state change ignored: %s',
unicode(self), unicode(e))
self.state = new_state
post_state_changed.send(sender=self, new_state=new_state)
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