Fix up some more bugs

This commit is contained in:
Joshua Boniface 2018-06-01 00:35:39 -04:00
parent ae445d7770
commit 7bcb2e0b00
2 changed files with 14 additions and 8 deletions

View File

@ -77,11 +77,16 @@ class NodeInstance(threading.Thread):
while True: while True:
self.memfree = conn.getFreeMemory() self.memfree = conn.getFreeMemory()
self.cpuload = os.getloadavg()[0] self.cpuload = os.getloadavg()[0]
try:
self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii'))
self.zk.set(self.zkey + '/cpuload', str(self.cpuload).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("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload ))
print("Active domains: %s" % self.domainlist) print("Active domains: %s" % self.domainlist)
for x in range(0,50): for x in range(0,100):
time.sleep(0.1) time.sleep(0.1)
if self.stop_thread.is_set(): if self.stop_thread.is_set():
return return

11
pvcd.py
View File

@ -43,9 +43,11 @@ myhostname = socket.gethostname()
mynodestring = '/nodes/%s' % myhostname mynodestring = '/nodes/%s' % myhostname
def cleanup(): def cleanup():
zk.set('%s/state' % mynodestring, 'stop'.encode('ascii')) t_node[myhostname].stop()
for node in node_list: try:
t_node[node].stop() zk.set('/nodes/' + myhostname + '/state', 'stop'.encode('ascii'))
except:
pass
zk.stop() zk.stop()
atexit.register(cleanup) atexit.register(cleanup)
@ -76,9 +78,8 @@ def updatenodes(new_node_list):
t_node[node].updatenodelist(node_list) t_node[node].updatenodelist(node_list)
else: else:
t_node[node] = NodeInstance.NodeInstance(node, node_list, zk); t_node[node] = NodeInstance.NodeInstance(node, node_list, zk);
if t_node[node].name == myhostname: if node == myhostname:
t_node[node].start() t_node[node].start()
time.sleep(1)
node_state = t_node[node].getstate() node_state = t_node[node].getstate()
if node_state == 'start': if node_state == 'start':