summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/command-objects/hypervisor.rst5
-rw-r--r--openstackclient/compute/v2/hypervisor.py12
-rw-r--r--openstackclient/tests/unit/compute/v2/test_hypervisor.py67
-rw-r--r--releasenotes/notes/bug-1637074-1b0e409f30f715ca.yaml5
4 files changed, 87 insertions, 2 deletions
diff --git a/doc/source/command-objects/hypervisor.rst b/doc/source/command-objects/hypervisor.rst
index d6d0469b..3053a758 100644
--- a/doc/source/command-objects/hypervisor.rst
+++ b/doc/source/command-objects/hypervisor.rst
@@ -14,11 +14,16 @@ List hypervisors
os hypervisor list
[--matching <hostname>]
+ [--long]
.. option:: --matching <hostname>
Filter hypervisors using <hostname> substring
+.. option:: --long
+
+ List additional fields in output
+
hypervisor show
---------------
diff --git a/openstackclient/compute/v2/hypervisor.py b/openstackclient/compute/v2/hypervisor.py
index 0222e899..69b5d137 100644
--- a/openstackclient/compute/v2/hypervisor.py
+++ b/openstackclient/compute/v2/hypervisor.py
@@ -35,14 +35,24 @@ class ListHypervisor(command.Lister):
metavar="<hostname>",
help=_("Filter hypervisors using <hostname> substring")
)
+ parser.add_argument(
+ '--long',
+ action='store_true',
+ help=_("List additional fields in output")
+ )
return parser
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
columns = (
"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:
data = compute_client.hypervisors.search(parsed_args.matching)
diff --git a/openstackclient/tests/unit/compute/v2/test_hypervisor.py b/openstackclient/tests/unit/compute/v2/test_hypervisor.py
index e39570af..7200d04e 100644
--- a/openstackclient/tests/unit/compute/v2/test_hypervisor.py
+++ b/openstackclient/tests/unit/compute/v2/test_hypervisor.py
@@ -48,19 +48,63 @@ class TestHypervisorList(TestHypervisor):
self.columns = (
"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.hypervisors[0].id,
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].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
self.cmd = hypervisor.ListHypervisor(self.app, None)
@@ -93,6 +137,9 @@ class TestHypervisorList(TestHypervisor):
(
self.hypervisors[0].id,
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,
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):
diff --git a/releasenotes/notes/bug-1637074-1b0e409f30f715ca.yaml b/releasenotes/notes/bug-1637074-1b0e409f30f715ca.yaml
new file mode 100644
index 00000000..705542b1
--- /dev/null
+++ b/releasenotes/notes/bug-1637074-1b0e409f30f715ca.yaml
@@ -0,0 +1,5 @@
+---
+features:
+ - |
+ Add ``--long`` option and more columns to the ``hypervisor list`` command.
+ [Bug `1637074 <https://bugs.launchpad.net/bugs/1637074>`_]