From 0794cc854c85582ff8460c02eedcb88b46322793 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Wed, 6 Jun 2018 14:53:28 -0400 Subject: [PATCH] Improve handling of keepalive and message printing --- NodeInstance.py | 28 ++++++++++++++-------------- pvcd.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index d71df573..48391bab 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -143,14 +143,7 @@ class NodeInstance(): conn = libvirt.open(libvirt_name) if conn == None: print('>>> Failed to open connection to %s' % libvirt_name) - exit(1) - - # Gather data about hypervisor - self.name = conn.getHostname() - self.cpucount = conn.getCPUMap()[0] - self.zk.set(self.zkey + '/cpucount', str(self.cpucount).encode('ascii')) - print("Node hostname: %s" % self.name) - print("CPUs: %s" % self.cpucount) + return # Get past state and update if needed past_state = self.zk.get(self.zkey + '/state')[0].decode('ascii') @@ -182,18 +175,23 @@ class NodeInstance(): pass # Set our information in zookeeper + self.name = conn.getHostname() + self.cpucount = conn.getCPUMap()[0] self.memfree = conn.getFreeMemory() self.cpuload = os.getloadavg()[0] try: + self.zk.set(self.zkey + '/cpucount', str(self.cpucount).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 + '/runningdomains', ' '.join(self.domain_list).encode('ascii')) except: return - print(">>> %s - Free memory: %s | Load: %s" % ( time.strftime("%d/%m/%Y %H:%M:%S"), self.memfree, self.cpuload )) - print("Active domains: %s" % self.domain_list) - + # Display node information to the terminal + print('>>> {} - {} keepalive'.format(time.strftime('%d/%m/%Y %H:%M:%S'), self.name)) + print(' CPUs: {} | Free memory: {} | Load: {}'.format(self.cpucount, self.memfree, self.cpuload)) + print(' Active domains: {}'.format(' '.join(self.domain_list))) + # Update our local node lists for node_name in self.t_node: try: @@ -233,6 +231,8 @@ class NodeInstance(): except ValueError: pass - print('Active nodes: %s' % self.active_node_list) - print('Flushed nodes: %s' % self.flushed_node_list) - print('Inactive nodes: %s' % self.inactive_node_list) + # Display cluster information to the terminal + print('>>> {} - Cluster status'.format(time.strftime('%d/%m/%Y %H:%M:%S'))) + print(' Active nodes: {}'.format(' '.join(self.active_node_list))) + print(' Flushed nodes: {}'.format(' '.join(self.flushed_node_list))) + print(' Inactive nodes: {}'.format(' '.join(self.inactive_node_list))) diff --git a/pvcd.py b/pvcd.py index 88f86aaa..2f4691e8 100755 --- a/pvcd.py +++ b/pvcd.py @@ -119,7 +119,7 @@ update_zookeeper = this_node.update_zookeeper # Create timer to update this node in Zookeeper update_timer = apscheduler.schedulers.background.BackgroundScheduler() -update_timer.add_job(update_zookeeper, 'interval', seconds=2) +update_timer.add_job(update_zookeeper, 'interval', seconds=5) update_timer.start() # Tick loop