This commit is contained in:
Joshua Boniface 2018-06-01 00:51:20 -04:00
parent 177ec4f862
commit 54d40f117b
1 changed files with 21 additions and 36 deletions

View File

@ -54,8 +54,27 @@ class NodeInstance(threading.Thread):
def run(self): def run(self):
if self.name == socket.gethostname(): if self.name == socket.gethostname():
self.setup_local_node() 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): def setup_local_node(self):
# Connect to libvirt # Connect to libvirt
@ -91,37 +110,3 @@ class NodeInstance(threading.Thread):
if self.stop_thread.is_set(): if self.stop_thread.is_set():
return 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))