summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorlin-hua-cheng <os.lcheng@gmail.com>2015-02-20 22:23:30 -0800
committerlin-hua-cheng <os.lcheng@gmail.com>2015-03-06 00:09:20 -0800
commit5fddec359dbf6106fd72fcc469d37fd432c85cf3 (patch)
tree97954a709f750ec3e41969184a4e55c54806fbc2 /openstackclient
parent0047b022d55ffe9192e03b1c9c5e6932a53fbd5e (diff)
downloadpython-openstackclient-5fddec359dbf6106fd72fcc469d37fd432c85cf3.tar.gz
Add 'uptime' in 'hypervisor show'
Fetch the 'uptime' by making a call to hypervisor-uptime. Update the help for 'hypervisor show' to mention that it supports by Name or Id. Change-Id: I31060d203e87749cfc05810c2d9db42f2416051d Partial-Bug: #1423748
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/v2/hypervisor.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/openstackclient/compute/v2/hypervisor.py b/openstackclient/compute/v2/hypervisor.py
index 355ffbb3..65035d04 100644
--- a/openstackclient/compute/v2/hypervisor.py
+++ b/openstackclient/compute/v2/hypervisor.py
@@ -16,6 +16,7 @@
"""Hypervisor action implementations"""
import logging
+import re
import six
from cliff import lister
@@ -76,6 +77,18 @@ class ShowHypervisor(show.ShowOne):
hypervisor = utils.find_resource(compute_client.hypervisors,
parsed_args.hypervisor)._info.copy()
+ uptime = compute_client.hypervisors.uptime(hypervisor['id'])._info
+ # Extract data from uptime value
+ # format: 0 up 0, 0 users, load average: 0, 0, 0
+ # example: 17:37:14 up 2:33, 3 users, load average: 0.33, 0.36, 0.34
+ m = re.match("(.+)\sup\s+(.+),\s+(.+)\susers,\s+load average:\s(.+)",
+ uptime['uptime'])
+ if m:
+ hypervisor["host_time"] = m.group(1)
+ hypervisor["uptime"] = m.group(2)
+ hypervisor["users"] = m.group(3)
+ hypervisor["load_average"] = m.group(4)
+
hypervisor["service_id"] = hypervisor["service"]["id"]
hypervisor["service_host"] = hypervisor["service"]["host"]
del hypervisor["service"]