diff options
| author | whoami-rajat <rajatdhasmana@gmail.com> | 2019-03-07 20:50:55 +0530 |
|---|---|---|
| committer | Rajat Dhasmana <rajatdhasmana@gmail.com> | 2019-04-15 08:36:27 +0000 |
| commit | 6a498163e2b0cf1256743d84200a99f840dc9135 (patch) | |
| tree | 1b9ef2c15b038bac07f47a097b6dc294d1793731 | |
| parent | 15295acb074a778674f2b92f45f8dd1e7ff5f60c (diff) | |
| download | python-cinderclient-6a498163e2b0cf1256743d84200a99f840dc9135.tar.gz | |
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
| -rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 26 | ||||
| -rw-r--r-- | cinderclient/v3/group_types.py | 11 | ||||
| -rw-r--r-- | cinderclient/v3/shell.py | 13 | ||||
| -rw-r--r-- | cinderclient/v3/volume_types.py | 3 | ||||
| -rw-r--r-- | releasenotes/notes/adding-option-is-public-to-type-list-9a16bd9c2b8eb65a.yaml | 13 |
5 files changed, 61 insertions, 5 deletions
diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index b145d8e..bb03342 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 636c192..74ea9b7 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 bc79860..46ece3a 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='<key=value>', + 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 4d24756..c55a4a4 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 0000000..4f85a31 --- /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 |
