diff --git a/manilaclient/tests/unit/v2/fakes.py b/manilaclient/tests/unit/v2/fakes.py index d0e3dfb58..6c0bab644 100644 --- a/manilaclient/tests/unit/v2/fakes.py +++ b/manilaclient/tests/unit/v2/fakes.py @@ -830,6 +830,13 @@ class FakeHTTPClient(fakes.FakeHTTPClient): def get_types_default(self, **kw): return self.get_types_1(**kw) + def get_types_1234(self, **kw): + return (200, {}, { + 'share_type': {'id': 1, + 'name': 'test-type-1', + 'extra_specs': {'test': 'test'}, + 'required_extra_specs': {'test': 'test'}}}) + def get_types(self, **kw): return (200, {}, { 'share_types': [{'id': 1, diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 517ba3134..878ec49f6 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -484,6 +484,10 @@ class ShellTest(test_utils.TestCase): self.run_command('share-instance-force-delete 1234') manager_mock.force_delete.assert_called_once_with(share_instance) + def test_type_show_details(self): + self.run_command('type-show 1234') + self.assert_called_anytime('GET', '/types/1234') + @mock.patch.object(cliutils, 'print_list', mock.Mock()) def test_type_list(self): self.run_command('type-list') diff --git a/manilaclient/v2/share_types.py b/manilaclient/v2/share_types.py index a5b14b942..48f4a656e 100644 --- a/manilaclient/v2/share_types.py +++ b/manilaclient/v2/share_types.py @@ -117,6 +117,15 @@ class ShareTypeManager(base.ManagerWithFind): query_string = '?is_public=all' return self._list("/types%s" % query_string, "share_types") + def show(self, share_type): + """Get a share. + + :param share: either share object or text with its ID. + :rtype: :class:`Share` + """ + type_id = common_base.getid(share_type) + return self._get("/types/%s" % type_id, "share_type") + def get(self, share_type="default"): """Get a specific share type. diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index b11c6d616..6499449c2 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -151,6 +151,21 @@ def _find_share_instance(cs, instance): return apiclient_utils.find_resource(cs.share_instances, instance) +def _print_type_show(stype, default_share_type=None): + + is_default = 'YES' if stype == default_share_type else 'NO' + stype_dict = { + 'id': stype.id, + 'name': stype.name, + 'visibility': _is_share_type_public(stype), + 'is_default': is_default, + 'description': None, + 'required_extra_specs': _print_type_required_extra_specs(stype), + 'optional_extra_specs': _print_type_optional_extra_specs(stype), + } + cliutils.print_dict(stype_dict) + + @api_versions.wraps("1.0", "2.8") def _print_share_instance(cs, instance): info = instance._info.copy() @@ -3649,6 +3664,20 @@ def do_type_list(cs, args): columns=args.columns) +@cliutils.arg( + 'share_type', + metavar='', + help='Name or ID of the share type.') +def do_type_show(cs, args): + """Show share type details.""" + share_type = cs.share_types.show(args.share_type) + try: + default = cs.share_types.get() + except exceptions.NotFound: + default = None + _print_type_show(share_type, default_share_type=default) + + @cliutils.arg( '--columns', metavar='', diff --git a/releasenotes/notes/support-show-type-6380b7c539c95ba8.yaml b/releasenotes/notes/support-show-type-6380b7c539c95ba8.yaml new file mode 100644 index 000000000..d998845b0 --- /dev/null +++ b/releasenotes/notes/support-show-type-6380b7c539c95ba8.yaml @@ -0,0 +1,3 @@ +--- +features: + - Support show type details command.