diff options
author | Zuul <zuul@review.opendev.org> | 2019-08-21 11:13:18 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-08-21 11:13:18 +0000 |
commit | fd106c77bffecaf81985fa0006ffe147ce7b8ef2 (patch) | |
tree | 9b61019c15e3c8f75c392d2643137b0a1c727ecd | |
parent | c4b50a10b3970aaf2d2e675e2fe8fd9b9bd4496b (diff) | |
parent | 6a498163e2b0cf1256743d84200a99f840dc9135 (diff) | |
download | python-cinderclient-fd106c77bffecaf81985fa0006ffe147ce7b8ef2.tar.gz |
Merge "Add 'is_public' support in '--filters' option"
-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 88ea6d8..dd244e0 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -266,7 +266,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') @@ -571,6 +581,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 9e62245..e69a411 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -753,9 +753,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 |