From 59410bf2d9a44cf81ecb0e902e74a83ce169c208 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Thu, 31 May 2018 23:28:26 -0400 Subject: [PATCH] More fixes --- NodeInstance.py | 1 - VMInstance.py | 18 +++++++++++------- pvcd.py | 33 ++++++++++++++++----------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index f9a7200e..b98de96d 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -75,7 +75,6 @@ class NodeInstance(threading.Thread): self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii')) print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload )) - print("Node list: %s" % self.node_list) print("Active domains: %s" % self.domainlist) for x in range(0,50): time.sleep(0.1) diff --git a/VMInstance.py b/VMInstance.py index d13c1017..e7c1c783 100644 --- a/VMInstance.py +++ b/VMInstance.py @@ -18,16 +18,16 @@ class VMInstance: # Watch for changes to the hypervisor field in Zookeeper @zk.DataWatch(self.zkey + '/hypervisor') def watch_hypervisor(data, stat): - self.hypervisor = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.hypervisor)) - self.manage_vm_state() + if self.hypervisor != data.decode('ascii'): + self.hypervisor = data.decode('ascii') + self.manage_vm_state() # Watch for changes to the state field in Zookeeper @zk.DataWatch(self.zkey + '/state') def watch_state(data, stat): - self.state = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.state)) - self.manage_vm_state() + if self.state != data.decode('ascii'): + self.state = data.decode('ascii') + self.manage_vm_state() # Start up the VM def start_vm(self, conn, xmlconfig): @@ -77,6 +77,7 @@ class VMInstance: self.zk.set(self.zkey + '/status', b'start') self.thishypervisor.domainlist.append(self.domuuid) break + # # Main function to manage a VM (taking only self) # @@ -91,7 +92,10 @@ class VMInstance: # Check the current state of the VM try: self.dom = conn.lookupByUUID(uuid.UUID(self.domuuid).bytes) - running = self.dom.state() + if self.dom != None: + running = self.dom.state() + else: + running = False except: running = False diff --git a/pvcd.py b/pvcd.py index 1b40ca3e..3e0560c5 100755 --- a/pvcd.py +++ b/pvcd.py @@ -59,26 +59,25 @@ else: zk.create('%s/memfree' % mynodestring, '0'.encode('ascii')) zk.create('%s/cpuload' % mynodestring, '0.0'.encode('ascii')) -time.sleep(1) - -def updatenodes(): - node_list = zk.get_children('/nodes') - print(node_list) - for node in node_list: - if t_node[node] is None: - t_node[node] = NodeInstance.NodeInstance(node, node_list, zk); - else: - t_node[node].updatenodelist(node_list) - -node_list = zk.get_children('/nodes') - -domain_list = zk.get_children('/domains') -print(domain_list) - t_node = dict() s_domain = dict() +node_list = [] -time.sleep(1) +@zk.ChildrenWatch('/nodes') +def updatenodes(new_node_list): + global node_list + node_list = new_node_list + print('Node list: %s' % node_list) + for node in node_list: + if node in t_node: + t_node[node].updatenodelist(node_list) + else: + t_node[node] = NodeInstance.NodeInstance(node, node_list, zk); + if t_node[node].name == myhostname: + t_node[node].start() + +domain_list = zk.get_children('/domains') +print('Domain list: %s' % domain_list) for domain in domain_list: s_domain[domain] = VMInstance.VMInstance(domain, zk, t_node[myhostname]);