From 3b27a88128e71612eee33dd6dd66697b630f18f5 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 7 Aug 2019 10:57:19 -0400 Subject: [PATCH] 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 --- node-daemon/pvcd/VMInstance.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/node-daemon/pvcd/VMInstance.py b/node-daemon/pvcd/VMInstance.py index aa9f4d28..da23e4a7 100644 --- a/node-daemon/pvcd/VMInstance.py +++ b/node-daemon/pvcd/VMInstance.py @@ -229,12 +229,20 @@ class VMInstance(object): # Shutdown the VM gracefully def shutdown_vm(self): self.logger.out('Gracefully stopping VM', state='i', prefix='Domain {}:'.format(self.domuuid)) + is_aborted = False self.inshutdown = True self.dom.shutdown() tick = 0 while True: - tick += 1 - time.sleep(1) + tick += 2 + 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: lvdomstate = self.dom.state()[0] @@ -258,6 +266,9 @@ class VMInstance(object): self.inshutdown = False + if is_aborted: + self.manage_vm_state() + if self.inrestart: # Wait to prevent race conditions time.sleep(1)