From 5279c019d2adcd35147d8bdfcb1333d279c20dc6 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Tue, 19 Jun 2018 19:52:03 -0400 Subject: [PATCH] Revert "Remove any updates of hypervisor domain_list from the VMInstance; this is all handled during node keepalive" This reverts commit 79e61184117ceb81c5b37a68b99f33a5dc395302. --- pvcd/VMInstance.py | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/pvcd/VMInstance.py b/pvcd/VMInstance.py index ae7161fb..f0d0f17c 100644 --- a/pvcd/VMInstance.py +++ b/pvcd/VMInstance.py @@ -81,6 +81,9 @@ class VMInstance: # Grab the domain information from Zookeeper xmlconfig = self.zk_conn.get('/domains/{}/xml'.format(self.domuuid))[0].decode('ascii') dom = lv_conn.createXML(xmlconfig, 0) + if not self.domuuid in self.thishypervisor.domain_list: + self.thishypervisor.domain_list.append(self.domuuid) + ansiiprint.echo('Successfully started VM', '{}:'.format(self.domuuid), 'o') self.dom = dom except libvirt.libvirtError as e: @@ -123,6 +126,11 @@ class VMInstance: self.dom.destroy() except AttributeError: ansiiprint.echo('Failed to terminate VM', '{}:'.format(self.domuuid), 'e') + if self.domuuid in self.thishypervisor.domain_list: + try: + self.thishypervisor.domain_list.remove(self.domuuid) + except ValueError: + pass ansiiprint.echo('Successfully terminated VM', '{}:'.format(self.domuuid), 'o') self.dom = None self.instop = False @@ -135,6 +143,11 @@ class VMInstance: self.dom.destroy() except AttributeError: ansiiprint.echo('Failed to stop VM', '{}:'.format(self.domuuid), 'e') + if self.domuuid in self.thishypervisor.domain_list: + try: + self.thishypervisor.domain_list.remove(self.domuuid) + except ValueError: + pass if self.inrestart == False: self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii')) @@ -162,6 +175,12 @@ class VMInstance: except: pass + if self.domuuid in self.thishypervisor.domain_list: + try: + self.thishypervisor.domain_list.remove(self.domuuid) + except ValueError: + pass + if self.inrestart == False: self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii')) @@ -200,6 +219,12 @@ class VMInstance: ansiiprint.echo('Could not live migrate VM; shutting down to migrate instead', '{}:'.format(self.domuuid), 'e') self.shutdown_vm() time.sleep(1) + else: + try: + self.thishypervisor.domain_list.remove(self.domuuid) + except ValueError: + pass + time.sleep(1) self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii')) self.inmigrate = False @@ -231,6 +256,8 @@ class VMInstance: dom_state = None if dom_state == libvirt.VIR_DOMAIN_RUNNING: + if not self.domuuid in self.thishypervisor.domain_list: + self.thishypervisor.domain_list.append(self.domuuid) ansiiprint.echo('Successfully received migrated VM', '{}:'.format(self.domuuid), 'o') else: ansiiprint.echo('Failed to receive migrated VM', '{}:'.format(self.domuuid), 'e') @@ -282,10 +309,13 @@ class VMInstance: if running == libvirt.VIR_DOMAIN_RUNNING: # VM is already running and should be if self.state == "start": - pass + if not self.domuuid in self.thishypervisor.domain_list: + self.thishypervisor.domain_list.append(self.domuuid) # VM is already running and should be but stuck in migrate state elif self.state == "migrate": self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii')) + if not self.domuuid in self.thishypervisor.domain_list: + self.thishypervisor.domain_list.append(self.domuuid) # VM should be restarted elif self.state == "restart": self.restart_vm() @@ -305,12 +335,15 @@ class VMInstance: # VM should be restarted (i.e. started since it isn't running) if self.state == "restart": self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii')) - # VM should be shut down + # VM should be shut down; ensure it's gone from this node's domain_list elif self.state == "shutdown": - pass - # VM should be stoped + if self.domuuid in self.thishypervisor.domain_list: + self.thishypervisor.domain_list.remove(self.domuuid) + # VM should be stoped; ensure it's gone from this node's domain_list elif self.state == "stop": - pass + if self.domuuid in self.thishypervisor.domain_list: + self.thishypervisor.domain_list.remove(self.domuuid) + else: # Conditional pass three - Is this VM currently running on this hypervisor if running == libvirt.VIR_DOMAIN_RUNNING: