From 54d40f117bb23deb26bf2196412b0421ed8c3512 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 1 Jun 2018 00:51:20 -0400 Subject: [PATCH] More fix --- NodeInstance.py | 57 ++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index fe21a201..b0c34de9 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -54,8 +54,27 @@ class NodeInstance(threading.Thread): def run(self): if self.name == socket.gethostname(): self.setup_local_node() - else: - self.setup_remote_node() + + @zk.DataWatch(self.zkey + '/state') + def watch_state(data, stat): + self.state = data.decode('ascii') + print("Version: %s, data: %s" % (stat.version, self.state)) + + @zk.DataWatch(self.zkey + '/cpucount') + def watch_cpucount(data, stat): + self.cpucount = data.decode('ascii') + print("Version: %s, data: %s" % (stat.version, self.cpucount)) + + @zk.DataWatch(self.zkey + '/cpuload') + def watch_cpuload(data, stat): + self.cpuload = data.decode('ascii') + print("Version: %s, data: %s" % (stat.version, self.cpuload)) + + @zk.DataWatch(self.zkey + '/memfree') + def watch_memfree(data, stat): + self.memfree = data.decode('ascii') + print("Version: %s, data: %s" % (stat.version, self.memfree)) + def setup_local_node(self): # Connect to libvirt @@ -91,37 +110,3 @@ class NodeInstance(threading.Thread): if self.stop_thread.is_set(): return - @zk.DataWatch(self.zkey + '/state') - def watch_state(data, stat): - self.state = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.state)) - if self.state == 'flush': - self.flush() - - def setup_remote_node(self): - while True: - for x in range(0,100): - time.sleep(0.1) - if self.stop_thread.is_set(): - return - - @zk.DataWatch(self.zkey + '/state') - def watch_state(data, stat): - self.state = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.state)) - - @zk.DataWatch(self.zkey + '/cpucount') - def watch_cpucount(data, stat): - self.cpucount = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.cpucount)) - - @zk.DataWatch(self.zkey + '/cpuload') - def watch_cpuload(data, stat): - self.cpuload = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.cpuload)) - - @zk.DataWatch(self.zkey + '/memfree') - def watch_memfree(data, stat): - self.memfree = data.decode('ascii') - print("Version: %s, data: %s" % (stat.version, self.memfree)) -