From 16613d900e3cd1b3046f5ab5de4ef3d20f2e4f30 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Thu, 31 May 2018 22:55:44 -0400 Subject: [PATCH] Fix up creating empty node entry --- NodeInstance.py | 4 ++-- pvcd.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index 55c58ef8..31bd9d5a 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -40,7 +40,7 @@ class NodeInstance(threading.Thread): least_mem = node_freemem least_host = node.getname() - self.zk.set('/domains/' + domain + '/state', b'migrate') + self.zk.set('/domains/' + domain + '/state', 'flush'.encode('ascii')) self.zk.set('/domains/' + domain + '/hypervisor', least_host.encode('ascii')) def run(self): @@ -60,7 +60,7 @@ class NodeInstance(threading.Thread): # Gather data about hypervisor self.name = conn.getHostname() self.cpucount = conn.getCPUMap()[0] - self.zk.set(self.zkey + '/state', self.name.encode('ascii')) + self.zk.set(self.zkey + '/state', 'start'.encode('ascii')) self.zk.set(self.zkey + '/cpucount', str(self.cpucount).encode('ascii')) print("Node hostname: %s" % self.name) print("CPUs: %s" % self.cpucount) diff --git a/pvcd.py b/pvcd.py index f2c62d13..b7c74d4f 100755 --- a/pvcd.py +++ b/pvcd.py @@ -48,6 +48,17 @@ def cleanup(): atexit.register(cleanup) +# Check if our node exists in Zookeeper, and create it if not +mynodestring = '/nodes/%s' % myhostname +if not zk.exists('%s' + mynodestring): + zk.create('%s' % mynodestring, 'hypervisor'.encode('ascii')) + zk.create('%s/state' % mynodestring, 'stop'.encode('ascii')) + zk.create('%s/cpucount' % mynodestring, '0'.encode('ascii')) + zk.create('%s/memfree' % mynodestring, '0'.encode('ascii')) + zk.create('%s/cpuload' % mynodestring, '0.0'.encode('ascii')) + +time.sleep(1) + node_list = zk.get_children('/nodes') print(node_list) @@ -62,6 +73,8 @@ for node in node_list: if t_node[node].name == myhostname: t_node[node].start() +time.sleep(1) + for domain in domain_list: s_domain[domain] = VMInstance.VMInstance(domain, zk, t_node[myhostname]);