From 6a63df5a724a5debbfabf6723d62ffd72f2cb531 Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 00:09:27 -0700 Subject: [PATCH 1/7] Initial commit of openstack_vms.py This patch provides an module for tracking the number of active and non-active VMs in a given openstack cluster. When non-"ACTIVE" VMs are above a given threshold, the text will (by default) change to red, thus indicating an issue. Otherwise, the text will be green. --- i3pystatus/openstack_vms.py | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 i3pystatus/openstack_vms.py diff --git a/i3pystatus/openstack_vms.py b/i3pystatus/openstack_vms.py new file mode 100644 index 0000000..c22a5b5 --- /dev/null +++ b/i3pystatus/openstack_vms.py @@ -0,0 +1,69 @@ +from i3pystatus import IntervalModule +from .core.util import round_dict +# requires python-novaclient +from novaclient.v2 import client +import webbrowser + + +class Openstack_vms(IntervalModule): + """ + Displays the number of VMs in an openstack cluster in ACTIVE and + non-ACTIVE states. + """ + + settings = ( + ("auth_url", "OpenStack cluster authentication URL (OS_AUTH_URL)"), + ("username", "Username for OpenStack authentication (OS_USERNAME)"), + ("password", "Password for Openstack authentication (OS_PASSWORD)"), + ("tenant_name", "Tenant/Project name to view (OS_TENANT_NAME)"), + ("color", "Display color when non-active VMs are =< `threshold` " + "(default: #00FF00"), + ("crit_color", "Display color when non-active VMs are => `threshold` " + "(default: #FF0000"), + ("threshold", "Set critical indicators when non-active VM pass this " + "number (default: 0)"), + ("horizon_url", "When clicked, open this URL in a browser") + ) + required = ("auth_url", "password", "tenant_name", "username") + color = "#00FF00" + crit_color = "#FF0000" + threshold = 0 + horizon_url = None + format = "{tenant_name}: {active_servers} active, {nonactive_servers} non-active" + + on_leftclick = "openurl" + + def run(self): + nclient = client.Client( + self.username, + self.password, + self.tenant_name, + self.auth_url + ) + + active_servers = 0 + nonactive_servers = 0 + server_list = nclient.servers.list() + for server in server_list: + if server.status == 'ACTIVE': + active_servers = active_servers + 1 + else: + nonactive_servers = nonactive_servers + 1 + + if nonactive_servers > self.threshold: + display_color = self.crit_color + else: + display_color = self.color + cdict = { + "tenant_name": self.tenant_name, + "active_servers": active_servers, + "nonactive_servers": nonactive_servers, + } + + self.output = { + "full_text": self.format.format(**cdict), + "color": display_color + } + + def openurl(self): + webbrowser.open_new_tab(self.horizon_url) From 9134880d55f814354d6b79b3ac91ad226d41381f Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 07:32:55 -0700 Subject: [PATCH 2/7] pep8 compliance for openstacK_vms.py --- i3pystatus/openstack_vms.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/i3pystatus/openstack_vms.py b/i3pystatus/openstack_vms.py index c22a5b5..d8da803 100644 --- a/i3pystatus/openstack_vms.py +++ b/i3pystatus/openstack_vms.py @@ -17,11 +17,11 @@ class Openstack_vms(IntervalModule): ("password", "Password for Openstack authentication (OS_PASSWORD)"), ("tenant_name", "Tenant/Project name to view (OS_TENANT_NAME)"), ("color", "Display color when non-active VMs are =< `threshold` " - "(default: #00FF00"), + "(default: #00FF00"), ("crit_color", "Display color when non-active VMs are => `threshold` " - "(default: #FF0000"), + "(default: #FF0000"), ("threshold", "Set critical indicators when non-active VM pass this " - "number (default: 0)"), + "number (default: 0)"), ("horizon_url", "When clicked, open this URL in a browser") ) required = ("auth_url", "password", "tenant_name", "username") @@ -29,7 +29,8 @@ class Openstack_vms(IntervalModule): crit_color = "#FF0000" threshold = 0 horizon_url = None - format = "{tenant_name}: {active_servers} active, {nonactive_servers} non-active" + format = "{tenant_name}: {active_servers} active, "\ + "{nonactive_servers} non-active" on_leftclick = "openurl" From 8b299233ccc450805bfbe5331f708fa6fac2f6bb Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 07:35:28 -0700 Subject: [PATCH 3/7] Add mock module and additional documentation This patch updates conf.py's mock_modules to include the required python-novaclient module to ensure we have green tests. This patch also updates the openstack_vms.py description to be more explicit about it's requirements. --- docs/conf.py | 3 ++- i3pystatus/openstack_vms.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index c29cb33..6705bdb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,7 +30,8 @@ MOCK_MODULES = [ "i3pystatus.pulseaudio.pulse", "notmuch", "requests", - "bs4" + "bs4", + "python-novaclient" ] for mod_name in MOCK_MODULES: diff --git a/i3pystatus/openstack_vms.py b/i3pystatus/openstack_vms.py index d8da803..52d7bad 100644 --- a/i3pystatus/openstack_vms.py +++ b/i3pystatus/openstack_vms.py @@ -9,6 +9,7 @@ class Openstack_vms(IntervalModule): """ Displays the number of VMs in an openstack cluster in ACTIVE and non-ACTIVE states. + Requires: python-novaclient """ settings = ( From ba711a745c973a06ab7f919a23bf27db3c028bea Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 08:01:53 -0700 Subject: [PATCH 4/7] Use proper module name for mock_modules --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 6705bdb..1f7754a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -31,7 +31,7 @@ MOCK_MODULES = [ "notmuch", "requests", "bs4", - "python-novaclient" + "novaclient.v2" ] for mod_name in MOCK_MODULES: From 31b8d423b4bde96f0590553071185a99cf412ec8 Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 09:46:19 -0700 Subject: [PATCH 5/7] Remove defaults documentation, as they are auto-gen --- i3pystatus/openstack_vms.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/i3pystatus/openstack_vms.py b/i3pystatus/openstack_vms.py index 52d7bad..faa866b 100644 --- a/i3pystatus/openstack_vms.py +++ b/i3pystatus/openstack_vms.py @@ -17,12 +17,10 @@ class Openstack_vms(IntervalModule): ("username", "Username for OpenStack authentication (OS_USERNAME)"), ("password", "Password for Openstack authentication (OS_PASSWORD)"), ("tenant_name", "Tenant/Project name to view (OS_TENANT_NAME)"), - ("color", "Display color when non-active VMs are =< `threshold` " - "(default: #00FF00"), - ("crit_color", "Display color when non-active VMs are => `threshold` " - "(default: #FF0000"), + ("color", "Display color when non-active VMs are =< `threshold`"), + ("crit_color", "Display color when non-active VMs are => `threshold`"). ("threshold", "Set critical indicators when non-active VM pass this " - "number (default: 0)"), + "number"), ("horizon_url", "When clicked, open this URL in a browser") ) required = ("auth_url", "password", "tenant_name", "username") From 33aba21cd3d09ed1ee31344fa73825456d6d897d Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 10:06:07 -0700 Subject: [PATCH 6/7] Fix typo --- i3pystatus/openstack_vms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i3pystatus/openstack_vms.py b/i3pystatus/openstack_vms.py index faa866b..99b7fdf 100644 --- a/i3pystatus/openstack_vms.py +++ b/i3pystatus/openstack_vms.py @@ -18,7 +18,7 @@ class Openstack_vms(IntervalModule): ("password", "Password for Openstack authentication (OS_PASSWORD)"), ("tenant_name", "Tenant/Project name to view (OS_TENANT_NAME)"), ("color", "Display color when non-active VMs are =< `threshold`"), - ("crit_color", "Display color when non-active VMs are => `threshold`"). + ("crit_color", "Display color when non-active VMs are => `threshold`"), ("threshold", "Set critical indicators when non-active VM pass this " "number"), ("horizon_url", "When clicked, open this URL in a browser") From efcf36205d64559dc5b5bf3fd3211e6a6d6019f9 Mon Sep 17 00:00:00 2001 From: David Wahlstrom Date: Wed, 3 Jun 2015 10:08:42 -0700 Subject: [PATCH 7/7] Remove unused import --- i3pystatus/openstack_vms.py | 1 - 1 file changed, 1 deletion(-) diff --git a/i3pystatus/openstack_vms.py b/i3pystatus/openstack_vms.py index 99b7fdf..85e08d1 100644 --- a/i3pystatus/openstack_vms.py +++ b/i3pystatus/openstack_vms.py @@ -1,5 +1,4 @@ from i3pystatus import IntervalModule -from .core.util import round_dict # requires python-novaclient from novaclient.v2 import client import webbrowser