Improve dom handling

This commit is contained in:
Joshua Boniface 2018-06-02 15:52:50 -04:00
parent 76e99b6e87
commit 2349e56fc1
1 changed files with 11 additions and 5 deletions

View File

@ -49,7 +49,7 @@ class VMInstance:
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)
return dom self.dom = dom
# Stop the VM forcibly # Stop the VM forcibly
def stop_vm(self): def stop_vm(self):
@ -61,6 +61,8 @@ class VMInstance:
except ValueError: except ValueError:
pass pass
self.dom = None
# Shutdown the VM gracefully # Shutdown the VM gracefully
def shutdown_vm(self): def shutdown_vm(self):
print("Stopping VM %s" % self.domuuid) print("Stopping VM %s" % self.domuuid)
@ -71,6 +73,8 @@ class VMInstance:
except ValueError: except ValueError:
pass pass
self.dom = None
# Migrate the VM to a target host # Migrate the VM to a target host
def migrate_vm(self): def migrate_vm(self):
print(self.zkey) print(self.zkey)
@ -102,7 +106,10 @@ class VMInstance:
def receive_migrate(self): def receive_migrate(self):
while True: while True:
if self.dom == None or self.dom.state() != libvirt.VIR_DOMAIN_RUNNING: if self.dom == None or self.dom.state() != libvirt.VIR_DOMAIN_RUNNING:
continue try:
self.dom = conn.lookupByUUID(uuid.UUID(self.domuuid).bytes)
except:
pass
else: else:
self.zk.set(self.zkey + '/status', b'start') self.zk.set(self.zkey + '/status', b'start')
if not self.domuuid in self.thishypervisor.domain_list: if not self.domuuid in self.thishypervisor.domain_list:
@ -122,11 +129,10 @@ class VMInstance:
# Check the current state of the VM # Check the current state of the VM
try: try:
self.dom = conn.lookupByUUID(uuid.UUID(self.domuuid).bytes)
if self.dom != None: if self.dom != None:
running, reason = self.dom.state() running, reason = self.dom.state()
else: else:
running = libvirt.VIR_DOMAIN_NOSTATE raise
except: except:
running = libvirt.VIR_DOMAIN_NOSTATE running = libvirt.VIR_DOMAIN_NOSTATE
@ -151,7 +157,7 @@ class VMInstance:
# 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(self.zkey + '/xml')
domxml = str(domxml.decode('ascii')) domxml = str(domxml.decode('ascii'))
self.dom = self.start_vm(conn, domxml) self.start_vm(conn, domxml)
# VM is already running and should be # VM is already running and should be
elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor == self.thishypervisor.name: elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor == self.thishypervisor.name: