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

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

View File

@ -40,17 +40,24 @@ class VMInstance:
self.inmigrate = 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
@zk.DataWatch('/domains/{}/hypervisor'.format(self.domuuid))
def watch_hypervisor(data, stat, event=""):
self.manage_vm_state()
self.dom = self.lookupByUUID(self.domuuid)
# Watch for changes to the state field in Zookeeper
@zk.DataWatch('/domains/{}/state'.format(self.domuuid))
def watch_state(data, stat, event=""):
self.manage_vm_state()
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()
# Get data functions
def getstate(self):
@ -59,6 +66,10 @@ class VMInstance:
def gethypervisor(self):
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
def start_vm(self, xmlconfig):
ansiiprint.echo('Starting VM', '{}:'.format(self.domuuid), 'i')
@ -286,7 +297,6 @@ class VMInstance:
domxml = str(domxml.decode('ascii'))
self.start_vm(domxml)
# This function is a wrapper for libvirt.lookupByUUID which fixes some problems
# 1. Takes a text UUID and handles converting it to bytes
# 2. Try's it and returns a sensible value if not