Merge "Display hypervisor information without uptime"
This commit is contained in:
commit
4c83d75833
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from novaclient import exceptions as nova_exceptions
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
import six
|
import six
|
||||||
@ -94,18 +95,22 @@ class ShowHypervisor(command.ShowOne):
|
|||||||
if service_host in aggregate.hosts]
|
if service_host in aggregate.hosts]
|
||||||
hypervisor["aggregates"] = member_of
|
hypervisor["aggregates"] = member_of
|
||||||
|
|
||||||
uptime = compute_client.hypervisors.uptime(hypervisor['id'])._info
|
try:
|
||||||
# Extract data from uptime value
|
uptime = compute_client.hypervisors.uptime(hypervisor['id'])._info
|
||||||
# format: 0 up 0, 0 users, load average: 0, 0, 0
|
# Extract data from uptime value
|
||||||
# example: 17:37:14 up 2:33, 3 users, load average: 0.33, 0.36, 0.34
|
# format: 0 up 0, 0 users, load average: 0, 0, 0
|
||||||
m = re.match(
|
# example: 17:37:14 up 2:33, 3 users,
|
||||||
"\s*(.+)\sup\s+(.+),\s+(.+)\susers?,\s+load average:\s(.+)",
|
# load average: 0.33, 0.36, 0.34
|
||||||
uptime['uptime'])
|
m = re.match(
|
||||||
if m:
|
"\s*(.+)\sup\s+(.+),\s+(.+)\susers?,\s+load average:\s(.+)",
|
||||||
hypervisor["host_time"] = m.group(1)
|
uptime['uptime'])
|
||||||
hypervisor["uptime"] = m.group(2)
|
if m:
|
||||||
hypervisor["users"] = m.group(3)
|
hypervisor["host_time"] = m.group(1)
|
||||||
hypervisor["load_average"] = m.group(4)
|
hypervisor["uptime"] = m.group(2)
|
||||||
|
hypervisor["users"] = m.group(3)
|
||||||
|
hypervisor["load_average"] = m.group(4)
|
||||||
|
except nova_exceptions.HTTPNotImplemented:
|
||||||
|
pass
|
||||||
|
|
||||||
hypervisor["service_id"] = hypervisor["service"]["id"]
|
hypervisor["service_id"] = hypervisor["service"]["id"]
|
||||||
hypervisor["service_host"] = hypervisor["service"]["host"]
|
hypervisor["service_host"] = hypervisor["service"]["host"]
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from novaclient import exceptions as nova_exceptions
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
|
|
||||||
from openstackclient.compute.v2 import hypervisor
|
from openstackclient.compute.v2 import hypervisor
|
||||||
@ -227,3 +228,72 @@ class TestHypervisorShow(TestHypervisor):
|
|||||||
|
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, data)
|
self.assertEqual(self.data, data)
|
||||||
|
|
||||||
|
def test_hyprvisor_show_uptime_not_implemented(self):
|
||||||
|
arglist = [
|
||||||
|
self.hypervisor.hypervisor_hostname,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('hypervisor', self.hypervisor.hypervisor_hostname),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.hypervisors_mock.uptime.side_effect = (
|
||||||
|
nova_exceptions.HTTPNotImplemented(501))
|
||||||
|
|
||||||
|
# In base command class ShowOne in cliff, abstract method take_action()
|
||||||
|
# returns a two-part tuple with a tuple of column names and a tuple of
|
||||||
|
# data to be shown.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
expected_columns = (
|
||||||
|
'aggregates',
|
||||||
|
'cpu_info',
|
||||||
|
'current_workload',
|
||||||
|
'disk_available_least',
|
||||||
|
'free_disk_gb',
|
||||||
|
'free_ram_mb',
|
||||||
|
'host_ip',
|
||||||
|
'hypervisor_hostname',
|
||||||
|
'hypervisor_type',
|
||||||
|
'hypervisor_version',
|
||||||
|
'id',
|
||||||
|
'local_gb',
|
||||||
|
'local_gb_used',
|
||||||
|
'memory_mb',
|
||||||
|
'memory_mb_used',
|
||||||
|
'running_vms',
|
||||||
|
'service_host',
|
||||||
|
'service_id',
|
||||||
|
'state',
|
||||||
|
'status',
|
||||||
|
'vcpus',
|
||||||
|
'vcpus_used',
|
||||||
|
)
|
||||||
|
expected_data = (
|
||||||
|
[],
|
||||||
|
{'aaa': 'aaa'},
|
||||||
|
0,
|
||||||
|
50,
|
||||||
|
50,
|
||||||
|
1024,
|
||||||
|
'192.168.0.10',
|
||||||
|
self.hypervisor.hypervisor_hostname,
|
||||||
|
'QEMU',
|
||||||
|
2004001,
|
||||||
|
self.hypervisor.id,
|
||||||
|
50,
|
||||||
|
0,
|
||||||
|
1024,
|
||||||
|
512,
|
||||||
|
0,
|
||||||
|
'aaa',
|
||||||
|
1,
|
||||||
|
'up',
|
||||||
|
'enabled',
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(expected_columns, columns)
|
||||||
|
self.assertEqual(expected_data, data)
|
||||||
|
Loading…
Reference in New Issue
Block a user