Allow abort of shutdown state

Adds some logic to allow an active shutdown state to be aborted by
changing the VM to another state. Useful mostly if a VM is doing funky
things and not responding to the shutdown, but the administrator either
doesn't want to wait for the timer to expire (forcing an immediate
termination) or wishes to abort the shutdown attempt.

Fixes #49
This commit is contained in:
Joshua Boniface 2019-08-07 10:57:19 -04:00
parent e2ae58b62c
commit 3b27a88128
1 changed files with 13 additions and 2 deletions

View File

@ -229,12 +229,20 @@ class VMInstance(object):
# Shutdown the VM gracefully # Shutdown the VM gracefully
def shutdown_vm(self): def shutdown_vm(self):
self.logger.out('Gracefully stopping VM', state='i', prefix='Domain {}:'.format(self.domuuid)) self.logger.out('Gracefully stopping VM', state='i', prefix='Domain {}:'.format(self.domuuid))
is_aborted = False
self.inshutdown = True self.inshutdown = True
self.dom.shutdown() self.dom.shutdown()
tick = 0 tick = 0
while True: while True:
tick += 1 tick += 2
time.sleep(1) time.sleep(2)
# Abort shutdown if the state changes to start
current_state = zkhandler.readdata(self.zk_conn, '/domains/{}/state'.format(self.domuuid))
if current_state != 'shutdown':
self.logger.out('Aborting VM shutdown due to state change', state='i', prefix='Domain {}:'.format(self.domuuid))
is_aborted = True
break
try: try:
lvdomstate = self.dom.state()[0] lvdomstate = self.dom.state()[0]
@ -258,6 +266,9 @@ class VMInstance(object):
self.inshutdown = False self.inshutdown = False
if is_aborted:
self.manage_vm_state()
if self.inrestart: if self.inrestart:
# Wait to prevent race conditions # Wait to prevent race conditions
time.sleep(1) time.sleep(1)