Skip to content

Commit 5d98bb3

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add 'uptime' in 'hypervisor show'"
2 parents 0443c20 + 5fddec3 commit 5d98bb3

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎openstackclient/compute/v2/hypervisor.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Hypervisor action implementations"""
1717

1818
import logging
19+
import re
1920
import six
2021

2122
from cliff import lister
@@ -76,6 +77,18 @@ def take_action(self, parsed_args):
7677
hypervisor = utils.find_resource(compute_client.hypervisors,
7778
parsed_args.hypervisor)._info.copy()
7879

80+
uptime = compute_client.hypervisors.uptime(hypervisor['id'])._info
81+
# Extract data from uptime value
82+
# format: 0 up 0, 0 users, load average: 0, 0, 0
83+
# example: 17:37:14 up 2:33, 3 users, load average: 0.33, 0.36, 0.34
84+
m = re.match("(.+)\sup\s+(.+),\s+(.+)\susers,\s+load average:\s(.+)",
85+
uptime['uptime'])
86+
if m:
87+
hypervisor["host_time"] = m.group(1)
88+
hypervisor["uptime"] = m.group(2)
89+
hypervisor["users"] = m.group(3)
90+
hypervisor["load_average"] = m.group(4)
91+
7992
hypervisor["service_id"] = hypervisor["service"]["id"]
8093
hypervisor["service_host"] = hypervisor["service"]["host"]
8194
del hypervisor["service"]

0 commit comments

Comments
 (0)