diff options
| author | TommyLike <tommylikehu@gmail.com> | 2018-03-14 15:18:55 +0800 |
|---|---|---|
| committer | TommyLike <tommylikehu@gmail.com> | 2018-05-02 10:25:27 +0800 |
| commit | 5a1513244caf7acbd41e181419bc8b62bf4bcaba (patch) | |
| tree | 139c3b3e71b6eeb6c56006c6e9ae9af56aafa361 | |
| parent | bd712fa0cac8ce4cdcd435fb083160be15efb694 (diff) | |
| download | python-cinderclient-5a1513244caf7acbd41e181419bc8b62bf4bcaba.tar.gz | |
Support availability-zone in volume type
Since 3.52, new option '--filters' has been
added to 'type-list' command, and it's only
valid for administrator.
Change-Id: I140f6d61a2747d4fcaabfbccea864dcc7eb841d1
Depends-On: I4e6aa7af707bd063e7edf2b0bf28e3071ad5c67a
Partial-Implements: bp support-az-in-volumetype
| -rw-r--r-- | cinderclient/api_versions.py | 2 | ||||
| -rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 14 | ||||
| -rw-r--r-- | cinderclient/v3/shell.py | 21 | ||||
| -rw-r--r-- | cinderclient/v3/volume_types.py | 12 | ||||
| -rw-r--r-- | doc/source/cli/details.rst | 9 | ||||
| -rw-r--r-- | releasenotes/notes/support-filter-type-7yt69ub7ccbf7419.yaml | 5 |
6 files changed, 57 insertions, 6 deletions
diff --git a/cinderclient/api_versions.py b/cinderclient/api_versions.py index 1dad794..0fcb208 100644 --- a/cinderclient/api_versions.py +++ b/cinderclient/api_versions.py @@ -29,7 +29,7 @@ LOG = logging.getLogger(__name__) # key is a deprecated version and value is an alternative version. DEPRECATED_VERSIONS = {"1": "2"} DEPRECATED_VERSION = "2.0" -MAX_VERSION = "3.50" +MAX_VERSION = "3.52" MIN_VERSION = "3.0" _SUBSTITUTIONS = {} diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 84ca4cb..cff2145 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -244,6 +244,20 @@ class ShellTest(utils.TestCase): self.run_command, 'list --group_id fake_id') + def test_type_list_with_filters_invalid(self): + self.assertRaises(exceptions.UnsupportedAttribute, + self.run_command, + '--os-volume-api-version 3.51 type-list ' + '--filters key=value') + + def test_type_list_with_filters(self): + self.run_command('--os-volume-api-version 3.52 type-list ' + '--filters extra_specs={key:value}') + self.assert_called( + 'GET', '/types?%s' % parse.urlencode( + {'extra_specs': + {six.text_type('key'): six.text_type('value')}})) + @ddt.data("3.10", "3.11") def test_list_with_group_id_after_3_10(self, version): command = ('--os-volume-api-version %s list --group_id fake_id' % diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index f012cc8..4149f61 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -52,6 +52,27 @@ def do_list_filters(cs, args): shell_utils.print_resource_filter_list(filters) +@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_type_list(cs, args): + """Lists available 'volume types'. + + (Only admin and tenant users will see private types) + """ + # pylint: disable=function-redefined + 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)) + vtypes = cs.volume_types.list(search_opts=search_opts) + shell_utils.print_volume_type_list(vtypes) + + @utils.arg('--all-tenants', metavar='<all_tenants>', nargs='?', diff --git a/cinderclient/v3/volume_types.py b/cinderclient/v3/volume_types.py index 7f26d69..5030b5e 100644 --- a/cinderclient/v3/volume_types.py +++ b/cinderclient/v3/volume_types.py @@ -15,6 +15,7 @@ """Volume Type interface.""" +from six.moves.urllib import parse from cinderclient.apiclient import base as common_base from cinderclient import base @@ -86,10 +87,13 @@ class VolumeTypeManager(base.ManagerWithFind): :rtype: list of :class:`VolumeType`. """ - query_string = '' - if not is_public: - query_string = '?is_public=%s' % is_public - return self._list("/types%s" % (query_string), "volume_types") + if not search_opts: + search_opts = dict() + if is_public: + search_opts.update({"is_public": is_public}) + query_string = "?%s" % parse.urlencode( + search_opts) if search_opts else '' + return self._list("/types%s" % query_string, "volume_types") def get(self, volume_type): """Get a specific volume type. diff --git a/doc/source/cli/details.rst b/doc/source/cli/details.rst index 351ee9b..87e18f5 100644 --- a/doc/source/cli/details.rst +++ b/doc/source/cli/details.rst @@ -4341,11 +4341,18 @@ cinder type-list .. code-block:: console - usage: cinder type-list + usage: cinder type-list [--filters <key=value> [<key=value> ...]] Lists available 'volume types'. (Only admin and tenant users will see private types) +**Optional arguments:** + +``--filters [<key=value> [<key=value> ...]]`` + Filter key and value pairs. Please use 'cinder list-filters' + to check enabled filters from server, Default=None. + (Supported by API version 3.52 and later) + .. _cinder_type-show: cinder type-show diff --git a/releasenotes/notes/support-filter-type-7yt69ub7ccbf7419.yaml b/releasenotes/notes/support-filter-type-7yt69ub7ccbf7419.yaml new file mode 100644 index 0000000..9036c13 --- /dev/null +++ b/releasenotes/notes/support-filter-type-7yt69ub7ccbf7419.yaml @@ -0,0 +1,5 @@ +--- +features: + - New command option ``--filters`` is added to ``type-list`` + command to support filter types since 3.52, and it's only + valid for administrator. |
