Commit b0db4153 by Őry Máté

vm: fix more legacy 'state' field uses

parent 74bd1375
......@@ -95,11 +95,12 @@ class IndexView(LoginRequiredMixin, TemplateView):
}
})
running = [i for i in instances if i.state == 'RUNNING']
stopped = [i for i in instances if i.state not in ['RUNNING', 'NOSTATE']]
context.update({
'running_vms': instances.filter(state='RUNNING'),
'running_vm_num': instances.filter(state='RUNNING').count(),
'stopped_vm_num': instances.exclude(
state__in=['RUNNING', 'NOSTATE']).count()
'running_vms': running,
'running_vm_num': len(running),
'stopped_vm_num': len(stopped)
})
context['templates'] = InstanceTemplate.objects.all()[:5]
......
......@@ -117,7 +117,7 @@ class Disk(AclBase, TimeStampedModel):
}[self.type]
def is_in_use(self):
return self.instance_set.exclude(state='SHUTOFF').exists()
return any([i.state != 'SHUTOFF' for i in self.instance_set.all()])
def get_exclusive(self):
"""Get an instance of the disk for exclusive usage.
......
......@@ -267,12 +267,15 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
finished__isnull=True).exists():
return 'MIGRATING'
act = next(self.activity_log.filter(finished__isnull=False,
resultant_state__isnull=False)
.order_by('-finished')[:1], None)
try:
act = self.activity_log.filter(finished__isnull=False,
resultant_state__isnull=False
).order_by('-finished').all()[0]
except IndexError:
act = None
return 'NOSTATE' if act is None else act.resultant_state
def state_chaged(self, state):
def state_changed(self, state):
try:
self.libvirt_state_queue.put_nowait(state)
except Full:
......
......@@ -157,7 +157,8 @@ class Node(TimeStampedModel):
else:
domains[id] = i['state']
instances = self.instance_set.order_by('id').values('id', 'state')
instances = [{'id': i.id, 'state': i.state}
for i in self.instance_set.order_by('id').all()]
for i in instances:
try:
d = domains[i['id']]
......
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