Remove zkey variable for better readability
This commit is contained in:
parent
f4bdc22602
commit
c124cae24b
|
@ -26,7 +26,6 @@ class VMInstance:
|
||||||
def __init__(self, domuuid, zk, thishypervisor):
|
def __init__(self, domuuid, zk, thishypervisor):
|
||||||
# Passed-in variables on creation
|
# Passed-in variables on creation
|
||||||
self.domuuid = domuuid
|
self.domuuid = domuuid
|
||||||
self.zkey = '/domains/{}'.format(domuuid)
|
|
||||||
self.zk = zk
|
self.zk = zk
|
||||||
self.thishypervisor = thishypervisor
|
self.thishypervisor = thishypervisor
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ class VMInstance:
|
||||||
self.dom = lookupByUUID(self.domuuid)
|
self.dom = lookupByUUID(self.domuuid)
|
||||||
|
|
||||||
# Watch for changes to the hypervisor field in Zookeeper
|
# Watch for changes to the hypervisor field in Zookeeper
|
||||||
@zk.DataWatch(self.zkey + '/hypervisor')
|
@zk.DataWatch('/domains/{}/hypervisor'.format(self.domuuid))
|
||||||
def watch_hypervisor(data, stat, event=""):
|
def watch_hypervisor(data, stat, event=""):
|
||||||
try:
|
try:
|
||||||
self.hypervisor = data.decode('ascii')
|
self.hypervisor = data.decode('ascii')
|
||||||
|
@ -51,7 +50,7 @@ class VMInstance:
|
||||||
self.manage_vm_state()
|
self.manage_vm_state()
|
||||||
|
|
||||||
# Watch for changes to the state field in Zookeeper
|
# Watch for changes to the state field in Zookeeper
|
||||||
@zk.DataWatch(self.zkey + '/state')
|
@zk.DataWatch('/domains/{}/state'.format(self.domuuid))
|
||||||
def watch_state(data, stat, event=""):
|
def watch_state(data, stat, event=""):
|
||||||
try:
|
try:
|
||||||
self.state = data.decode('ascii')
|
self.state = data.decode('ascii')
|
||||||
|
@ -83,7 +82,7 @@ class VMInstance:
|
||||||
dom = conn.createXML(xmlconfig, 0)
|
dom = conn.createXML(xmlconfig, 0)
|
||||||
except libvirt.libvirtError as e:
|
except libvirt.libvirtError as e:
|
||||||
print('>>> {} - Failed to create VM.'.format(self.domuuid))
|
print('>>> {} - Failed to create VM.'.format(self.domuuid))
|
||||||
self.zk.set(self.zkey + '/state', 'stop'.encode('ascii'))
|
self.zk.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii'))
|
||||||
|
|
||||||
if not self.domuuid in self.thishypervisor.domain_list:
|
if not self.domuuid in self.thishypervisor.domain_list:
|
||||||
self.thishypervisor.domain_list.append(self.domuuid)
|
self.thishypervisor.domain_list.append(self.domuuid)
|
||||||
|
@ -120,7 +119,7 @@ class VMInstance:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.zk.set(self.zkey + '/state', 'stop'.encode('ascii'))
|
self.zk.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii'))
|
||||||
self.dom = None
|
self.dom = None
|
||||||
self.instop = False
|
self.instop = False
|
||||||
|
|
||||||
|
@ -149,7 +148,7 @@ class VMInstance:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.zk.set(self.zkey + '/state', 'stop'.encode('ascii'))
|
self.zk.set('/domains/{}/state'.format(self.domuuid), 'stop'.encode('ascii'))
|
||||||
self.dom = None
|
self.dom = None
|
||||||
self.inshutdown = False
|
self.inshutdown = False
|
||||||
|
|
||||||
|
@ -184,7 +183,7 @@ class VMInstance:
|
||||||
print('>>> {} - Could not live migrate VM; shutting down to migrate instead.'.format(self.domuuid))
|
print('>>> {} - Could not live migrate VM; shutting down to migrate instead.'.format(self.domuuid))
|
||||||
self.shutdown_vm()
|
self.shutdown_vm()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
self.zk.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii'))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.thishypervisor.domain_list.remove(self.domuuid)
|
self.thishypervisor.domain_list.remove(self.domuuid)
|
||||||
|
@ -206,7 +205,7 @@ class VMInstance:
|
||||||
if self.dom.state()[0] == libvirt.VIR_DOMAIN_RUNNING:
|
if self.dom.state()[0] == libvirt.VIR_DOMAIN_RUNNING:
|
||||||
break
|
break
|
||||||
|
|
||||||
self.zk.set(self.zkey + '/state', 'start'.encode('ascii'))
|
self.zk.set('/domains/{}/state'.format(self.domuuid), 'start'.encode('ascii'))
|
||||||
if not self.domuuid in self.thishypervisor.domain_list:
|
if not self.domuuid in self.thishypervisor.domain_list:
|
||||||
self.thishypervisor.domain_list.append(self.domuuid)
|
self.thishypervisor.domain_list.append(self.domuuid)
|
||||||
|
|
||||||
|
@ -254,7 +253,7 @@ class VMInstance:
|
||||||
# VM should be started
|
# VM should be started
|
||||||
elif running != libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor == self.thishypervisor.name and self.instart == False:
|
elif running != libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor == self.thishypervisor.name and self.instart == False:
|
||||||
# Grab the domain information from Zookeeper
|
# Grab the domain information from Zookeeper
|
||||||
domxml, domxmlstat = self.zk.get(self.zkey + '/xml')
|
domxml, domxmlstat = self.zk.get('/domains/{}/xml'.format(self.domuuid))
|
||||||
domxml = str(domxml.decode('ascii'))
|
domxml = str(domxml.decode('ascii'))
|
||||||
self.start_vm(domxml)
|
self.start_vm(domxml)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue