From 6a498163e2b0cf1256743d84200a99f840dc9135 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Thu, 7 Mar 2019 20:50:55 +0530 Subject: [PATCH] Add 'is_public' support in '--filters' option '--is-public' is a valid argument for cinder type-list command[1] and cinder group-type-list command but is missing in cinderclient. This patch adds the support for it. [1] https://developer.openstack.org/api-ref/block-storage/v3/?expanded=list-all-volume-types-detail#list-all-volume-types Change-Id: I8af9bb06a28f3cc384c4925b8b52bdeaed52cb15 --- cinderclient/tests/unit/v3/test_shell.py | 26 ++++++++++++++++++- cinderclient/v3/group_types.py | 11 ++++++-- cinderclient/v3/shell.py | 13 +++++++++- cinderclient/v3/volume_types.py | 3 ++- ...-public-to-type-list-9a16bd9c2b8eb65a.yaml | 13 ++++++++++ 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/adding-option-is-public-to-type-list-9a16bd9c2b8eb65a.yaml diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index b145d8e5e..bb0334219 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -265,7 +265,17 @@ class ShellTest(utils.TestCase): {six.text_type('key'): six.text_type('value')}})) self.assert_call_contained(parse.urlencode({'is_public': None})) - def test_type_list_no_filters(self): + def test_type_list_public(self): + self.run_command('--os-volume-api-version 3.52 type-list ' + '--filters is_public=True') + self.assert_called('GET', '/types?is_public=True') + + def test_type_list_private(self): + self.run_command('--os-volume-api-version 3.52 type-list ' + '--filters is_public=False') + self.assert_called('GET', '/types?is_public=False') + + def test_type_list_public_private(self): self.run_command('--os-volume-api-version 3.52 type-list') self.assert_called('GET', '/types?is_public=None') @@ -555,6 +565,20 @@ class ShellTest(utils.TestCase): self.run_command('--os-volume-api-version 3.11 group-type-list') self.assert_called_anytime('GET', '/group_types?is_public=None') + def test_group_type_list_public(self): + self.run_command('--os-volume-api-version 3.52 group-type-list ' + '--filters is_public=True') + self.assert_called('GET', '/group_types?is_public=True') + + def test_group_type_list_private(self): + self.run_command('--os-volume-api-version 3.52 group-type-list ' + '--filters is_public=False') + self.assert_called('GET', '/group_types?is_public=False') + + def test_group_type_list_public_private(self): + self.run_command('--os-volume-api-version 3.52 group-type-list') + self.assert_called('GET', '/group_types?is_public=None') + def test_group_type_show(self): self.run_command('--os-volume-api-version 3.11 ' 'group-type-show 1') diff --git a/cinderclient/v3/group_types.py b/cinderclient/v3/group_types.py index 636c192a2..74ea9b740 100644 --- a/cinderclient/v3/group_types.py +++ b/cinderclient/v3/group_types.py @@ -16,6 +16,8 @@ """Group Type interface.""" +from six.moves.urllib import parse + from cinderclient import api_versions from cinderclient import base @@ -84,9 +86,14 @@ class GroupTypeManager(base.ManagerWithFind): :rtype: list of :class:`GroupType`. """ + if not search_opts: + search_opts = dict() + query_string = '' - if not is_public: - query_string = '?is_public=%s' % is_public + if 'is_public' not in search_opts: + search_opts['is_public'] = is_public + + query_string = "?%s" % parse.urlencode(search_opts) return self._list("/group_types%s" % (query_string), "group_types") @api_versions.wraps("3.11") diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index bc79860c1..46ece3a2b 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -750,9 +750,20 @@ def do_summary(cs, args): @api_versions.wraps('3.11') +@utils.arg('--filters', + type=six.text_type, + nargs='*', + start_version='3.52', + metavar='', + default=None, + help="Filter key and value pairs. Admin only.") def do_group_type_list(cs, args): """Lists available 'group types'. (Admin only will see private types)""" - gtypes = cs.group_types.list() + search_opts = {} + # Update search option with `filters` + if hasattr(args, 'filters') and args.filters is not None: + search_opts.update(shell_utils.extract_filters(args.filters)) + gtypes = cs.group_types.list(search_opts=search_opts) shell_utils.print_group_type_list(gtypes) diff --git a/cinderclient/v3/volume_types.py b/cinderclient/v3/volume_types.py index 4d24756fe..c55a4a4a3 100644 --- a/cinderclient/v3/volume_types.py +++ b/cinderclient/v3/volume_types.py @@ -99,7 +99,8 @@ class VolumeTypeManager(base.ManagerWithFind): # Need to keep backwards compatibility with is_public usage. If it # isn't included then cinder will assume you want is_public=True, which # negatively affects the results. - search_opts['is_public'] = is_public + if 'is_public' not in search_opts: + search_opts['is_public'] = is_public query_string = "?%s" % parse.urlencode(search_opts) return self._list("/types%s" % query_string, "volume_types") diff --git a/releasenotes/notes/adding-option-is-public-to-type-list-9a16bd9c2b8eb65a.yaml b/releasenotes/notes/adding-option-is-public-to-type-list-9a16bd9c2b8eb65a.yaml new file mode 100644 index 000000000..4f85a315e --- /dev/null +++ b/releasenotes/notes/adding-option-is-public-to-type-list-9a16bd9c2b8eb65a.yaml @@ -0,0 +1,13 @@ +--- +upgrade: + - | + Adding ``is_public`` support in ``--filters`` option for ``type-list`` + and ``group-type-list`` command. + This option is used to filter volume types and group types on the basis + of visibility. + This option has 3 possible values : True, False, None with details as + follows : + + * True: List public types only + * False: List private types only + * None: List both public and private types