From 1b6a1370d501255ac44dfebddca28bf655dea301 Mon Sep 17 00:00:00 2001 From: Igor Malinovskiy Date: Mon, 2 Feb 2015 15:36:42 +0200 Subject: [PATCH] Add is_default column to type-list command output Add additional column "is_default" to output provided by command "type-list". Partially implements blueprint default-volume-type Change-Id: Ia0a97a7a4999e239b6cee89502cfa3cc5d0b950a --- manilaclient/tests/unit/v1/fakes.py | 3 +++ manilaclient/tests/unit/v1/test_shell.py | 4 ++++ manilaclient/v1/share_types.py | 2 +- manilaclient/v1/shell.py | 19 ++++++++++++++++--- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/manilaclient/tests/unit/v1/fakes.py b/manilaclient/tests/unit/v1/fakes.py index e6b4a1563..49ccac372 100644 --- a/manilaclient/tests/unit/v1/fakes.py +++ b/manilaclient/tests/unit/v1/fakes.py @@ -266,6 +266,9 @@ class FakeHTTPClient(fakes.FakeHTTPClient): def get_shares_1234_metadata(self, **kw): return (200, {}, {"metadata": {"key1": "val1", "key2": "val2"}}) + def get_types_default(self, **kw): + return self.get_types_1(**kw) + def get_types(self, **kw): return (200, {}, { 'share_types': [{'id': 1, diff --git a/manilaclient/tests/unit/v1/test_shell.py b/manilaclient/tests/unit/v1/test_shell.py index 02e467f4a..6da929d63 100644 --- a/manilaclient/tests/unit/v1/test_shell.py +++ b/manilaclient/tests/unit/v1/test_shell.py @@ -252,6 +252,10 @@ class ShellTest(test_utils.TestCase): ) self.assert_called('GET', '/share-networks/detail') + def test_type_list_default_volume_type(self): + self.run_command('type-list') + self.assert_called_anytime('GET', '/types/default') + def test_list_filter_by_project_id(self): aliases = ['--project-id', '--project_id'] for alias in aliases: diff --git a/manilaclient/v1/share_types.py b/manilaclient/v1/share_types.py index 5ba1aaa9f..769e22fa6 100644 --- a/manilaclient/v1/share_types.py +++ b/manilaclient/v1/share_types.py @@ -82,7 +82,7 @@ class ShareTypeManager(base.ManagerWithFind): """ return self._list("/types", "share_types") - def get(self, share_type): + def get(self, share_type="default"): """Get a specific share type. :param share_type: The ID of the :class:`ShareType` to get. diff --git a/manilaclient/v1/shell.py b/manilaclient/v1/shell.py index 999cd5051..6ac76cc95 100644 --- a/manilaclient/v1/shell.py +++ b/manilaclient/v1/shell.py @@ -1589,8 +1589,16 @@ def _print_type_extra_specs(share_type): return None -def _print_share_type_list(stypes): - cliutils.print_list(stypes, ['ID', 'Name']) +def _print_share_type_list(stypes, default_share_type=None): + + def _is_default(share_type): + if share_type == default_share_type: + return 'YES' + else: + return '-' + + formatters = {'is_default': _is_default} + cliutils.print_list(stypes, ['ID', 'Name', 'is_default'], formatters) def _print_type_and_extra_specs_list(stypes): @@ -1606,8 +1614,13 @@ def _find_share_type(cs, stype): @cliutils.service_type('share') def do_type_list(cs, args): """Print a list of available 'share types'.""" + try: + default = cs.share_types.get() + except exceptions.NotFound: + default = None + stypes = cs.share_types.list() - _print_share_type_list(stypes) + _print_share_type_list(stypes, default_share_type=default) @cliutils.service_type('share')