From 0a8faac2aa008598466988d132df3da25f3a7fdc Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 1 Jun 2018 01:00:55 -0400 Subject: [PATCH] Fix --- NodeInstance.py | 50 ++++++++++++++++++++++++++++--------------------- pvcd.py | 1 - 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index 8f412135..7850d02a 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -9,7 +9,7 @@ class NodeInstance(threading.Thread): self.zkey = '/nodes/%s' % name self.zk = zk self.name = name - #self.state = 'stop' + self.state = 'stop' self.stop_thread = threading.Event() self.node_list = node_list self.domainlist = [] @@ -53,25 +53,9 @@ class NodeInstance(threading.Thread): def run(self): if self.name == socket.gethostname(): - conn = self.setup_local_node() - - while True: - if self.name == socket.gethostname(): - self.memfree = conn.getFreeMemory() - self.cpuload = os.getloadavg()[0] - try: - self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) - self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii')) - except: - if self.stop_thread.is_set(): - return - print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload )) - print("Active domains: %s" % self.domainlist) - - for x in range(0,100): - time.sleep(0.1) - if self.stop_thread.is_set(): - return + self.setup_local_node() + else: + self.setup_remote_node() @zk.DataWatch(self.zkey + '/state') def watch_state(data, stat): @@ -111,4 +95,28 @@ class NodeInstance(threading.Thread): print("Node hostname: %s" % self.name) print("CPUs: %s" % self.cpucount) - return conn + while True: + self.memfree = conn.getFreeMemory() + self.cpuload = os.getloadavg()[0] + try: + self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) + self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii')) + except: + if self.stop_thread.is_set(): + return + + print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload )) + print("Active domains: %s" % self.domainlist) + for x in range(0,100): + time.sleep(0.1) + if self.stop_thread.is_set(): + return + + def setup_remote_node(self): + while True: + for x in range(0,100): + time.sleep(0.1) + if self.stop_thread.is_set(): + return + + diff --git a/pvcd.py b/pvcd.py index 1d499dcb..50c2b259 100755 --- a/pvcd.py +++ b/pvcd.py @@ -79,7 +79,6 @@ def updatenodes(new_node_list): else: t_node[node] = NodeInstance.NodeInstance(node, node_list, zk); t_node[node].start() - time.sleep(0.1) node_state = t_node[node].getstate() print(node_state)