From 428d2ebb7ff16f643016d54807fbfa71ab348037 Mon Sep 17 00:00:00 2001 From: Nate Potter Date: Wed, 14 Oct 2015 15:25:09 +0000 Subject: [PATCH] Implement cinder type-show This patch adds the type-show command to the cinder CLI for viewing information on volume types. Change-Id: I7b283b120727f2fbd186e6f07a6450795bdf03c3 Closes-Bug: #1505806 --- cinderclient/tests/unit/v2/test_shell.py | 4 ++++ cinderclient/v2/shell.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 04f09550f..0775f0c4d 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -556,6 +556,10 @@ class ShellTest(utils.TestCase): self.run_command('type-list') self.assert_called_anytime('GET', '/types?is_public=None') + def test_type_show(self): + self.run_command('type-show 1') + self.assert_called('GET', '/types/1') + def test_type_create(self): self.run_command('type-create test-type-1') self.assert_called('POST', '/types') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index b4447d9ab..e8dff81d3 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -66,6 +66,11 @@ def _find_volume_snapshot(cs, snapshot): return utils.find_resource(cs.volume_snapshots, snapshot) +def _find_vtype(cs, vtype): + """Gets a volume type by name or ID.""" + return utils.find_resource(cs.volume_types, vtype) + + def _find_backup(cs, backup): """Gets a backup by name or ID.""" return utils.find_resource(cs.backups, backup) @@ -828,6 +833,20 @@ def do_type_default(cs, args): _print_volume_type_list([vtype]) +@utils.arg('volume_type', + metavar='', + help='Name or ID of the volume type.') +@utils.service_type('volumev2') +def do_type_show(cs, args): + """Show volume type details.""" + vtype = _find_vtype(cs, args.volume_type) + info = dict() + info.update(vtype._info) + + info.pop('links', None) + utils.print_dict(info) + + @utils.arg('id', metavar='', help='ID of the volume type.')