summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/v2/hypervisor.py12
-rw-r--r--openstackclient/tests/unit/compute/v2/test_hypervisor.py67
2 files changed, 77 insertions, 2 deletions
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):