Add tick counting during graceful shutdown to forcibly stop if blocked

This commit is contained in:
2018-06-02 16:28:18 -04:00
parent b199039453
commit ea97b51edb
2 changed files with 11 additions and 2 deletions

View File

@ -13,6 +13,7 @@ class VMInstance:
# These will all be set later
self.hypervisor = None
self.state = None
self.inshutdown = False
# Start up a new Libvirt connection
libvirt_name = "qemu:///system"
@ -79,8 +80,15 @@ class VMInstance:
print(">>> Stopping VM %s" % self.domuuid)
self.dom.shutdown()
try:
while self.dom.state()[0] == libvirt.VIR_DOMAIN_RUNNING:
self.inshutdown = True
tick = 0
while self.dom.state()[0] == libvirt.VIR_DOMAIN_RUNNING and tick < 60:
tick += 1
time.sleep(0.5)
if tick >= 60:
self.stop_vm()
return
except:
pass