Add some tweaks to prevent clobbering state changes happening at startup and during each keepalive cycle

This commit is contained in:
Joshua Boniface 2018-06-11 20:12:11 -04:00
parent f4493ed7c1
commit 5ad49d239e
2 changed files with 23 additions and 9 deletions

View File

@ -198,10 +198,12 @@ class NodeInstance():
else: else:
self.daemon_state = 'start' self.daemon_state = 'start'
# Toggle state management of all VMs and remove any non-running VMs # Toggle state management of dead VMs
for domain, instance in self.s_domain.items(): for domain, instance in self.s_domain.items():
if instance.inshutdown == False and domain in self.domain_list: if instance.inshutdown == False and domain in self.domain_list:
if instance.getstate() == 'start' and instance.gethypervisor() == self.name and instance.dom == None:
instance.manage_vm_state() instance.manage_vm_state()
if instance.dom == None: if instance.dom == None:
try: try:
self.domain_list.remove(domain) self.domain_list.remove(domain)
@ -218,6 +220,8 @@ class NodeInstance():
self.domain_list.remove(domain) self.domain_list.remove(domain)
except: except:
pass pass
else:
instance.setnoclobber()
# toggle state management of this node # toggle state management of this node
if self.domain_state == 'flush': if self.domain_state == 'flush':

View File

@ -40,16 +40,23 @@ class VMInstance:
self.inmigrate = False self.inmigrate = False
self.inreceive = False self.inreceive = False
self.dom = self.lookupByUUID(self.domuuid) # These stop a weird clobber at startup
self.noclobber = False
# Watch for changes to the hypervisor field in Zookeeper self.dom = self.lookupByUUID(self.domuuid)
@zk.DataWatch('/domains/{}/hypervisor'.format(self.domuuid))
def watch_hypervisor(data, stat, event=""):
self.manage_vm_state()
# Watch for changes to the state field in Zookeeper # Watch for changes to the state field in Zookeeper
@zk.DataWatch('/domains/{}/state'.format(self.domuuid)) @zk.DataWatch('/domains/{}/state'.format(self.domuuid))
def watch_state(data, stat, event=""): def watch_state(data, stat, event=""):
if self.noclobber == False:
self.noclobber = True
self.manage_vm_state()
# Watch for changes to the hypervisor field in Zookeeper
@zk.DataWatch('/domains/{}/hypervisor'.format(self.domuuid))
def watch_hypervisor(data, stat, event=""):
if self.noclobber == False:
self.noclobber = True
self.manage_vm_state() self.manage_vm_state()
# Get data functions # Get data functions
@ -59,6 +66,10 @@ class VMInstance:
def gethypervisor(self): def gethypervisor(self):
return self.hypervisor return self.hypervisor
# Allow the node to set the noclobber status once it performs its first keepalive
def setnoclobber(self):
self.noclobber = False
# Start up the VM # Start up the VM
def start_vm(self, xmlconfig): def start_vm(self, xmlconfig):
ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i') ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i')
@ -286,7 +297,6 @@ class VMInstance:
domxml = str(domxml.decode('ascii')) domxml = str(domxml.decode('ascii'))
self.start_vm(domxml) self.start_vm(domxml)
# This function is a wrapper for libvirt.lookupByUUID which fixes some problems # This function is a wrapper for libvirt.lookupByUUID which fixes some problems
# 1. Takes a text UUID and handles converting it to bytes # 1. Takes a text UUID and handles converting it to bytes
# 2. Try's it and returns a sensible value if not # 2. Try's it and returns a sensible value if not