From 74b95c704f3233921b4d9d183c834a21bfdf6973 Mon Sep 17 00:00:00 2001 From: Dmitry Galkin Date: Thu, 24 Mar 2016 10:12:17 +0100 Subject: [PATCH] Added function to decide which node is running on (Compute/Network) --- openvswitch.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/openvswitch.py b/openvswitch.py index 0442f31..eaa2bf6 100644 --- a/openvswitch.py +++ b/openvswitch.py @@ -26,11 +26,11 @@ def determine_node_role(): """ Runs virsh list as a simple check if that's a compute or network node. """ - cmd = Popen(("virsh", "list"), - stdout=PIPE, stderr=PIPE, close_fds=True) - cmd.communicate() - - if cmd.returncode != 0: + try: + cmd = Popen(("virsh", "list"), + stdout=PIPE, stderr=PIPE, close_fds=True) + cmd.communicate() + except OSError: global is_network_node is_network_node = True @@ -226,9 +226,12 @@ def send_data_to_collectd(ovs_data, cpu_usage, vms_running, vxlan_count): # CPU use; number of VMs; VXLAN count: dispatch_to_collectd("cpu_usage", (cpu_usage,)) - dispatch_to_collectd("running_vms", (vms_running,)) dispatch_to_collectd("total_vxlans", (vxlan_count,)) + if not is_network_node: + # compute node -> report amount of VMs + dispatch_to_collectd("running_vms", (vms_running,)) + def read_openvswitch_stats(): """ A callback method used by collectd.