Commit f708f27e by Guba Sándor

vmdriver: modified shutdown method to accept interrupts

parent 90504bb9
...@@ -9,6 +9,7 @@ from decorator import decorator ...@@ -9,6 +9,7 @@ from decorator import decorator
from psutil import NUM_CPUS, virtual_memory, cpu_percent from psutil import NUM_CPUS, virtual_memory, cpu_percent
from celery.contrib.abortable import AbortableTask
from vm import VMInstance from vm import VMInstance
from vmcelery import celery, lib_connection from vmcelery import celery, lib_connection
...@@ -188,27 +189,35 @@ def create(vm_desc): ...@@ -188,27 +189,35 @@ def create(vm_desc):
return domain_info(vm.name) return domain_info(vm.name)
@celery.task(time_limit=120) class shutdown(AbortableTask):
@req_connection
def shutdown(name):
""" Shutdown virtual machine (need ACPI support). """ Shutdown virtual machine (need ACPI support).
Return When domain is missing. Return When domain is missiing.
This job is abortable:
AbortableAsyncResult(id="<<jobid>>").abort()
""" """
time_limit = 120
@req_connection
def run(self, **kwargs):
from time import sleep from time import sleep
name = kwargs['name']
try: try:
domain = lookupByName(name) domain = lookupByName(name)
domain.shutdown() domain.shutdown()
while True: while True:
try: try:
Connection.get().lookupByName(name) Connection.get().lookupByName(name)
except Exception as e: except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
return return
else: else:
raise raise
else: else:
if self.is_aborted(**kwargs):
logging.info("Shutdown aborted on vm: %s", name)
return
sleep(5) sleep(5)
except Exception as e: except libvirt.libvirtError as e:
new_e = Exception(e.get_error_message()) new_e = Exception(e.get_error_message())
new_e.libvirtError = True new_e.libvirtError = True
raise new_e raise new_e
......
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