diff options
Diffstat (limited to 'openstackclient/compute/v2/hypervisor.py')
| -rw-r--r-- | openstackclient/compute/v2/hypervisor.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/openstackclient/compute/v2/hypervisor.py b/openstackclient/compute/v2/hypervisor.py index e01258d1..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 @@ -33,8 +34,8 @@ class ListHypervisor(lister.Lister): parser = super(ListHypervisor, self).get_parser(prog_name) parser.add_argument( "--matching", - metavar="<hostname-str>", - help="Filter hypervisors using <hostname-str> substring", + metavar="<hostname>", + help="Filter hypervisors using <hostname> substring", ) return parser @@ -58,23 +59,35 @@ class ListHypervisor(lister.Lister): class ShowHypervisor(show.ShowOne): - """Show hypervisor details""" + """Display hypervisor details""" log = logging.getLogger(__name__ + ".ShowHypervisor") def get_parser(self, prog_name): parser = super(ShowHypervisor, self).get_parser(prog_name) parser.add_argument( - "id", - metavar="<id>", - help="ID of the hypervisor to display") + "hypervisor", + metavar="<hypervisor>", + help="Hypervisor to display (name or ID)") return parser def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) compute_client = self.app.client_manager.compute hypervisor = utils.find_resource(compute_client.hypervisors, - parsed_args.id)._info.copy() + 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"] |
