Commit b0db4153 by Őry Máté

vm: fix more legacy 'state' field uses

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