Functionlie the add/remove from domain list bits
This commit is contained in:
parent
8af0cddc50
commit
9627be498e
|
@ -64,6 +64,21 @@ class VMInstance:
|
||||||
def getdom(self):
|
def getdom(self):
|
||||||
return self.dom
|
return self.dom
|
||||||
|
|
||||||
|
# Manage local node domain_list
|
||||||
|
def addDomainToList(self):
|
||||||
|
if not self.domuuid in self.thishypervisor.domain_list:
|
||||||
|
try:
|
||||||
|
self.thishypervisor.domain_list.append(self.domuuid)
|
||||||
|
except Exception as e:
|
||||||
|
ansiiprint.echo('ERROR: {}'.format(e), '', 'c')
|
||||||
|
|
||||||
|
def removeDomainFromList(self):
|
||||||
|
if self.domuuid in self.thishypervisor.domain_list:
|
||||||
|
try:
|
||||||
|
self.thishypervisor.domain_list.remove(self.domuuid)
|
||||||
|
except Exception as e:
|
||||||
|
ansiiprint.echo('ERROR: {}'.format(e), '', 'c')
|
||||||
|
|
||||||
# Start up the VM
|
# Start up the VM
|
||||||
def start_vm(self):
|
def start_vm(self):
|
||||||
ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i')
|
ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i')
|
||||||
|
@ -81,9 +96,7 @@ 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.addDomainToList()
|
||||||
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:
|
||||||
|
@ -110,6 +123,7 @@ class VMInstance:
|
||||||
try:
|
try:
|
||||||
self.shutdown_vm()
|
self.shutdown_vm()
|
||||||
self.start_vm()
|
self.start_vm()
|
||||||
|
self.addDomainToList()
|
||||||
ansiiprint.echo('Successfully restarted VM', '{}:'.format(self.domuuid), 'o')
|
ansiiprint.echo('Successfully restarted VM', '{}:'.format(self.domuuid), 'o')
|
||||||
except libvirt.libvirtError as e:
|
except libvirt.libvirtError as e:
|
||||||
ansiiprint.echo('Failed to restart VM', '{}:'.format(self.domuuid), 'e')
|
ansiiprint.echo('Failed to restart VM', '{}:'.format(self.domuuid), 'e')
|
||||||
|
@ -126,11 +140,7 @@ 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:
|
self.removeDomainFromList()
|
||||||
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
|
||||||
|
@ -143,11 +153,7 @@ 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:
|
self.removeDomainFromList()
|
||||||
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'))
|
||||||
|
@ -175,11 +181,7 @@ class VMInstance:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.domuuid in self.thishypervisor.domain_list:
|
self.removeDomainFromList()
|
||||||
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'))
|
||||||
|
@ -220,10 +222,7 @@ class VMInstance:
|
||||||
self.shutdown_vm()
|
self.shutdown_vm()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
try:
|
self.removeDomainFromList()
|
||||||
self.thishypervisor.domain_list.remove(self.domuuid)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
time.sleep(1)
|
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'))
|
||||||
|
@ -256,8 +255,7 @@ 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.addDomainToList()
|
||||||
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')
|
||||||
|
@ -309,13 +307,11 @@ 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":
|
||||||
if not self.domuuid in self.thishypervisor.domain_list:
|
self.addDomainToList()
|
||||||
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.addDomainToList()
|
||||||
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()
|
||||||
|
@ -337,12 +333,10 @@ class VMInstance:
|
||||||
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; ensure it's gone from this node's domain_list
|
# VM should be shut down; ensure it's gone from this node's domain_list
|
||||||
elif self.state == "shutdown":
|
elif self.state == "shutdown":
|
||||||
if self.domuuid in self.thishypervisor.domain_list:
|
self.removeDomainFromList()
|
||||||
self.thishypervisor.domain_list.remove(self.domuuid)
|
|
||||||
# VM should be stoped; ensure it's gone from this node's domain_list
|
# VM should be stoped; ensure it's gone from this node's domain_list
|
||||||
elif self.state == "stop":
|
elif self.state == "stop":
|
||||||
if self.domuuid in self.thishypervisor.domain_list:
|
self.removeDomainFromList()
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue