Add --long option and more columns to the hypervisor list command
Support --long option and more columns in output of hypervisor list command, including 'Hypervisor Type', 'Host IP', 'State', and 'vCPU Used', 'vCPUs', 'Memory MB Used', 'Memory MB' with --long option. Change-Id: I0c790c7835309dded03e230cf497168e19404537 Closes-Bug: #1637074
This commit is contained in:
parent
0b63d5d586
commit
8ca1cc6370
@ -14,11 +14,16 @@ List hypervisors
|
|||||||
|
|
||||||
os hypervisor list
|
os hypervisor list
|
||||||
[--matching <hostname>]
|
[--matching <hostname>]
|
||||||
|
[--long]
|
||||||
|
|
||||||
.. option:: --matching <hostname>
|
.. option:: --matching <hostname>
|
||||||
|
|
||||||
Filter hypervisors using <hostname> substring
|
Filter hypervisors using <hostname> substring
|
||||||
|
|
||||||
|
.. option:: --long
|
||||||
|
|
||||||
|
List additional fields in output
|
||||||
|
|
||||||
hypervisor show
|
hypervisor show
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
@ -35,14 +35,24 @@ class ListHypervisor(command.Lister):
|
|||||||
metavar="<hostname>",
|
metavar="<hostname>",
|
||||||
help=_("Filter hypervisors using <hostname> substring")
|
help=_("Filter hypervisors using <hostname> substring")
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--long',
|
||||||
|
action='store_true',
|
||||||
|
help=_("List additional fields in output")
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
columns = (
|
columns = (
|
||||||
"ID",
|
"ID",
|
||||||
"Hypervisor Hostname"
|
"Hypervisor Hostname",
|
||||||
|
"Hypervisor Type",
|
||||||
|
"Host IP",
|
||||||
|
"State"
|
||||||
)
|
)
|
||||||
|
if parsed_args.long:
|
||||||
|
columns += ("vCPUs Used", "vCPUs", "Memory MB Used", "Memory MB")
|
||||||
|
|
||||||
if parsed_args.matching:
|
if parsed_args.matching:
|
||||||
data = compute_client.hypervisors.search(parsed_args.matching)
|
data = compute_client.hypervisors.search(parsed_args.matching)
|
||||||
|
@ -48,19 +48,63 @@ class TestHypervisorList(TestHypervisor):
|
|||||||
|
|
||||||
self.columns = (
|
self.columns = (
|
||||||
"ID",
|
"ID",
|
||||||
"Hypervisor Hostname"
|
"Hypervisor Hostname",
|
||||||
|
"Hypervisor Type",
|
||||||
|
"Host IP",
|
||||||
|
"State"
|
||||||
|
)
|
||||||
|
self.columns_long = (
|
||||||
|
"ID",
|
||||||
|
"Hypervisor Hostname",
|
||||||
|
"Hypervisor Type",
|
||||||
|
"Host IP",
|
||||||
|
"State",
|
||||||
|
"vCPUs Used",
|
||||||
|
"vCPUs",
|
||||||
|
"Memory MB Used",
|
||||||
|
"Memory MB"
|
||||||
)
|
)
|
||||||
self.data = (
|
self.data = (
|
||||||
(
|
(
|
||||||
self.hypervisors[0].id,
|
self.hypervisors[0].id,
|
||||||
self.hypervisors[0].hypervisor_hostname,
|
self.hypervisors[0].hypervisor_hostname,
|
||||||
|
self.hypervisors[0].hypervisor_type,
|
||||||
|
self.hypervisors[0].host_ip,
|
||||||
|
self.hypervisors[0].state
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
self.hypervisors[1].id,
|
self.hypervisors[1].id,
|
||||||
self.hypervisors[1].hypervisor_hostname,
|
self.hypervisors[1].hypervisor_hostname,
|
||||||
|
self.hypervisors[1].hypervisor_type,
|
||||||
|
self.hypervisors[1].host_ip,
|
||||||
|
self.hypervisors[1].state
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.data_long = (
|
||||||
|
(
|
||||||
|
self.hypervisors[0].id,
|
||||||
|
self.hypervisors[0].hypervisor_hostname,
|
||||||
|
self.hypervisors[0].hypervisor_type,
|
||||||
|
self.hypervisors[0].host_ip,
|
||||||
|
self.hypervisors[0].state,
|
||||||
|
self.hypervisors[0].vcpus_used,
|
||||||
|
self.hypervisors[0].vcpus,
|
||||||
|
self.hypervisors[0].memory_mb_used,
|
||||||
|
self.hypervisors[0].memory_mb
|
||||||
|
),
|
||||||
|
(
|
||||||
|
self.hypervisors[1].id,
|
||||||
|
self.hypervisors[1].hypervisor_hostname,
|
||||||
|
self.hypervisors[1].hypervisor_type,
|
||||||
|
self.hypervisors[1].host_ip,
|
||||||
|
self.hypervisors[1].state,
|
||||||
|
self.hypervisors[1].vcpus_used,
|
||||||
|
self.hypervisors[1].vcpus,
|
||||||
|
self.hypervisors[1].memory_mb_used,
|
||||||
|
self.hypervisors[1].memory_mb
|
||||||
|
),
|
||||||
|
)
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = hypervisor.ListHypervisor(self.app, None)
|
self.cmd = hypervisor.ListHypervisor(self.app, None)
|
||||||
|
|
||||||
@ -93,6 +137,9 @@ class TestHypervisorList(TestHypervisor):
|
|||||||
(
|
(
|
||||||
self.hypervisors[0].id,
|
self.hypervisors[0].id,
|
||||||
self.hypervisors[0].hypervisor_hostname,
|
self.hypervisors[0].hypervisor_hostname,
|
||||||
|
self.hypervisors[1].hypervisor_type,
|
||||||
|
self.hypervisors[1].host_ip,
|
||||||
|
self.hypervisors[1].state,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -123,6 +170,24 @@ class TestHypervisorList(TestHypervisor):
|
|||||||
self.cmd.take_action,
|
self.cmd.take_action,
|
||||||
parsed_args)
|
parsed_args)
|
||||||
|
|
||||||
|
def test_hypervisor_list_long_option(self):
|
||||||
|
arglist = [
|
||||||
|
'--long',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('long', True),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
# In base command class Lister in cliff, abstract method take_action()
|
||||||
|
# returns a tuple containing the column names and an iterable
|
||||||
|
# containing the data to be listed.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.hypervisors_mock.list.assert_called_with()
|
||||||
|
self.assertEqual(self.columns_long, columns)
|
||||||
|
self.assertEqual(self.data_long, tuple(data))
|
||||||
|
|
||||||
|
|
||||||
class TestHypervisorShow(TestHypervisor):
|
class TestHypervisorShow(TestHypervisor):
|
||||||
|
|
||||||
|
5
releasenotes/notes/bug-1637074-1b0e409f30f715ca.yaml
Normal file
5
releasenotes/notes/bug-1637074-1b0e409f30f715ca.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--long`` option and more columns to the ``hypervisor list`` command.
|
||||||
|
[Bug `1637074 <https://bugs.launchpad.net/bugs/1637074>`_]
|
Loading…
x
Reference in New Issue
Block a user