Replace complicated ifs with a number of passes; this is pass 1 (are we doing somethin already)

This commit is contained in:
Joshua Boniface 2018-06-11 18:53:07 -04:00
parent 768dcdd480
commit ec26fb4849
1 changed files with 10 additions and 6 deletions

View File

@ -247,24 +247,28 @@ class VMInstance:
except: except:
running = libvirt.VIR_DOMAIN_NOSTATE running = libvirt.VIR_DOMAIN_NOSTATE
# Conditional pass one - If we're already doing something, bail out
if self.instart == True or self.instop == True or self.inshutdown == True or self.inmigrate == True or self.inreceive == True:
return 0
# VM should be stopped # VM should be stopped
if running == libvirt.VIR_DOMAIN_RUNNING and self.state == "stop" and self.hypervisor == self.thishypervisor.name and self.instop == False: if running == libvirt.VIR_DOMAIN_RUNNING and self.state == "stop" and self.hypervisor == self.thishypervisor.name:
self.stop_vm() self.stop_vm()
# VM should be shut down # VM should be shut down
elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "shutdown" and self.hypervisor == self.thishypervisor.name and self.inshutdown == False: elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "shutdown" and self.hypervisor == self.thishypervisor.name:
self.shutdown_vm() self.shutdown_vm()
# VM should be migrated to this hypervisor # VM should be migrated to this hypervisor
elif running != libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor == self.thishypervisor.name and self.inreceive == False: elif running != libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor == self.thishypervisor.name:
self.receive_migrate() self.receive_migrate()
# VM should be migrated away from this hypervisor # VM should be migrated away from this hypervisor
elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor != self.thishypervisor.name and self.inmigrate == False and self.inreceive == False: elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "migrate" and self.hypervisor != self.thishypervisor.name:
self.migrate_vm() self.migrate_vm()
# VM should be running but not on this hypervisor # VM should be running but not on this hypervisor
elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor != self.thishypervisor.name and self.inmigrate == False and self.inreceive == False: elif running == libvirt.VIR_DOMAIN_RUNNING and self.state == "start" and self.hypervisor != self.thishypervisor.name:
self.terminate_vm() self.terminate_vm()
# VM is already running and should be # VM is already running and should be
@ -279,7 +283,7 @@ class VMInstance:
self.thishypervisor.domain_list.append(self.domuuid) self.thishypervisor.domain_list.append(self.domuuid)
# 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:
# Grab the domain information from Zookeeper # Grab the domain information from Zookeeper
domxml, domxmlstat = self.zk.get('/domains/{}/xml'.format(self.domuuid)) domxml, domxmlstat = self.zk.get('/domains/{}/xml'.format(self.domuuid))
domxml = str(domxml.decode('ascii')) domxml = str(domxml.decode('ascii'))