From bf1afbd7eb7e25f70d0a132d57037d9a437ad124 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 1 Jun 2018 01:26:21 -0400 Subject: [PATCH] Finally get this working --- NodeInstance.py | 42 ++++++++++++++++++++---------------------- pvcd.py | 16 ---------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index f84b107a..31f15d30 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -14,27 +14,6 @@ class NodeInstance(threading.Thread): self.node_list = node_list self.domainlist = [] - @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)) - - # Get value functions def getfreemem(self): return self.memfree @@ -105,8 +84,27 @@ class NodeInstance(threading.Thread): if self.stop_thread.is_set(): return - print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload )) + print("%s - Free memory: %s | Load: %s" % ( time.strftime("%d/%m/%Y %H:%M:%S"), self.memfree, self.cpuload )) print("Active domains: %s" % self.domainlist) + active_node_list = [] + flushed_node_list = [] + inactive_node_list = [] + + for node in self.node_list: + #node_state = t_node[node].getstate() + state, stat = self.zk.get('/nodes/%s/state' % node) + node_state = state.decode('ascii') + if node_state == 'start': + active_node_list.append(node) + elif node_state == 'flush': + flushed_node_list.append(node) + else: + inactive_node_list.append(node) + + print('Active nodes: %s' % active_node_list) + print('Flushed nodes: %s' % flushed_node_list) + print('Inactive nodes: %s' % inactive_node_list) + for x in range(0,100): time.sleep(0.1) if self.stop_thread.is_set(): diff --git a/pvcd.py b/pvcd.py index 48279091..896ed16d 100755 --- a/pvcd.py +++ b/pvcd.py @@ -69,9 +69,6 @@ node_list = [] @zk.ChildrenWatch('/nodes') def updatenodes(new_node_list): node_list = new_node_list - active_node_list = [] - flushed_node_list = [] - inactive_node_list = [] print('Node list: %s' % node_list) for node in node_list: if node in t_node: @@ -82,19 +79,6 @@ def updatenodes(new_node_list): t_node[node].start() time.sleep(0.5) - node_state = t_node[node].getstate() - print(node_state) - if node_state == 'start': - active_node_list.append(t_node[node].getname()) - elif node_state == 'flush': - flushed_node_list.append(t_node[node].getname()) - else: - inactive_node_list.append(t_node[node].getname()) - - print('Active nodes: %s' % active_node_list) - print('Flushed nodes: %s' % flushed_node_list) - print('Inactive nodes: %s' % inactive_node_list) - domain_list = zk.get_children('/domains') print('Domain list: %s' % domain_list)