Revert "Remove any updates of hypervisor domain_list from the VMInstance; this is all handled during node keepalive"

This reverts commit 79e6118411.
This commit is contained in:
Joshua Boniface 2018-06-19 19:52:03 -04:00
parent 79e6118411
commit 5279c019d2
1 changed files with 38 additions and 5 deletions

View File

@ -81,6 +81,9 @@ class VMInstance:
# Grab the domain information from Zookeeper # Grab the domain information from Zookeeper
xmlconfig = self.zk_conn.get('/domains/{}/xml'.format(self.domuuid))[0].decode('ascii') xmlconfig = self.zk_conn.get('/domains/{}/xml'.format(self.domuuid))[0].decode('ascii')
dom = lv_conn.createXML(xmlconfig, 0) 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') ansiiprint.echo('Successfully started VM', '{}:'.format(self.domuuid), 'o')
self.dom = dom self.dom = dom
except libvirt.libvirtError as e: except libvirt.libvirtError as e:
@ -123,6 +126,11 @@ class VMInstance:
self.dom.destroy() self.dom.destroy()
except AttributeError: except AttributeError:
ansiiprint.echo('Failed to terminate VM', '{}:'.format(self.domuuid), 'e') 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') ansiiprint.echo('Successfully terminated VM', '{}:'.format(self.domuuid), 'o')
self.dom = None self.dom = None
self.instop = False self.instop = False
@ -135,6 +143,11 @@ class VMInstance:
self.dom.destroy() self.dom.destroy()
except AttributeError: except AttributeError:
ansiiprint.echo('Failed to stop VM', '{}:'.format(self.domuuid), 'e') 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: if self.inrestart == False:
self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii')) self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii'))
@ -162,6 +175,12 @@ class VMInstance:
except: except:
pass pass
if self.domuuid in self.thishypervisor.domain_list:
try:
self.thishypervisor.domain_list.remove(self.domuuid)
except ValueError:
pass
if self.inrestart == False: if self.inrestart == False:
self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii')) 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') ansiiprint.echo('Could not live migrate VM; shutting down to migrate instead', '{}:'.format(self.domuuid), 'e')
self.shutdown_vm() self.shutdown_vm()
time.sleep(1) 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.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii'))
self.inmigrate = False self.inmigrate = False
@ -231,6 +256,8 @@ class VMInstance:
dom_state = None dom_state = None
if dom_state == libvirt.VIR_DOMAIN_RUNNING: 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') ansiiprint.echo('Successfully received migrated VM', '{}:'.format(self.domuuid), 'o')
else: else:
ansiiprint.echo('Failed to receive migrated VM', '{}:'.format(self.domuuid), 'e') ansiiprint.echo('Failed to receive migrated VM', '{}:'.format(self.domuuid), 'e')
@ -282,10 +309,13 @@ class VMInstance:
if running == libvirt.VIR_DOMAIN_RUNNING: if running == libvirt.VIR_DOMAIN_RUNNING:
# VM is already running and should be # VM is already running and should be
if self.state == "start": 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 # VM is already running and should be but stuck in migrate state
elif self.state == "migrate": elif self.state == "migrate":
self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii')) 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 # VM should be restarted
elif self.state == "restart": elif self.state == "restart":
self.restart_vm() self.restart_vm()
@ -305,12 +335,15 @@ class VMInstance:
# VM should be restarted (i.e. started since it isn't running) # VM should be restarted (i.e. started since it isn't running)
if self.state == "restart": if self.state == "restart":
self.zk_conn.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii')) 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": elif self.state == "shutdown":
pass if self.domuuid in self.thishypervisor.domain_list:
# VM should be stoped 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": elif self.state == "stop":
pass if self.domuuid in self.thishypervisor.domain_list:
self.thishypervisor.domain_list.remove(self.domuuid)
else: else:
# Conditional pass three - Is this VM currently running on this hypervisor # Conditional pass three - Is this VM currently running on this hypervisor
if running == libvirt.VIR_DOMAIN_RUNNING: if running == libvirt.VIR_DOMAIN_RUNNING: