Commit 71932249 by Dudás Ádám

vm: moved shutdown confirmation to vmdriver

parent 50bc0a0e
...@@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals ...@@ -2,7 +2,6 @@ from __future__ import absolute_import, unicode_literals
from datetime import timedelta from datetime import timedelta
from logging import getLogger from logging import getLogger
from importlib import import_module from importlib import import_module
from Queue import Empty, Full, Queue
import string import string
import django.conf import django.conf
...@@ -210,7 +209,6 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -210,7 +209,6 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
"destruction.")) "destruction."))
objects = Manager() objects = Manager()
active = InstanceActiveManager() active = InstanceActiveManager()
libvirt_state_queue = Queue(maxsize=10)
class Meta: class Meta:
app_label = 'vm' app_label = 'vm'
...@@ -252,13 +250,6 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -252,13 +250,6 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
parts = [self.name, "(" + str(self.id) + ")"] parts = [self.name, "(" + str(self.id) + ")"]
return " ".join([s for s in parts if s != ""]) return " ".join([s for s in parts if s != ""])
def __clear_libvirt_state_queue(self):
while True:
try:
self.libvirt_state_queue.get_nowait()
except Empty:
break
@property @property
def state(self): def state(self):
"""State of the virtual machine instance. """State of the virtual machine instance.
...@@ -275,11 +266,8 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -275,11 +266,8 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
act = None act = None
return 'NOSTATE' if act is None else act.resultant_state return 'NOSTATE' if act is None else act.resultant_state
def state_changed(self, state): def vm_state_changed(self, new_state):
try: pass
self.libvirt_state_queue.put_nowait(state)
except Full:
pass
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
if self.time_of_delete is None: if self.time_of_delete is None:
...@@ -826,20 +814,8 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -826,20 +814,8 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
task_uuid=task_uuid, user=user): task_uuid=task_uuid, user=user):
queue_name = self.get_remote_queue_name('vm') queue_name = self.get_remote_queue_name('vm')
self.__clear_libvirt_state_queue()
vm_tasks.shutdown.apply_async(args=[self.vm_name], vm_tasks.shutdown.apply_async(args=[self.vm_name],
queue=queue_name).get() queue=queue_name).get()
i = 2
while i > 0:
try:
libvirt_state = self.libvirt_state_queue.get(True, 60)
except Empty:
raise TimeoutError()
else:
if libvirt_state == 'MISSING':
break
else:
i -= 1
def shutdown_async(self, user=None): def shutdown_async(self, user=None):
"""Execute shutdown asynchronously. """Execute shutdown asynchronously.
......
...@@ -170,7 +170,7 @@ class Node(TimeStampedModel): ...@@ -170,7 +170,7 @@ class Node(TimeStampedModel):
logger.info('Node %s update: instance %s state changed ' logger.info('Node %s update: instance %s state changed '
'(libvirt: %s, db: %s)', '(libvirt: %s, db: %s)',
self, i['id'], d, i['state']) self, i['id'], d, i['state'])
self.instance_set.get(id=i['id']).state_changed(d) self.instance_set.get(id=i['id']).vm_state_changed(d)
del domains[i['id']] del domains[i['id']]
for i in domains.keys(): for i in domains.keys():
......
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