diff options
author | TommyLike <tommylikehu@gmail.com> | 2017-05-16 17:22:08 +0800 |
---|---|---|
committer | TommyLike <tommylikehu@gmail.com> | 2017-05-31 11:32:49 +0000 |
commit | a6affea92157a5656ba4beae6ffd059d12e23bdc (patch) | |
tree | c2a99b0c5ebf3cab6701bc45af7be9650a34e3da /cinderclient/shell_utils.py | |
parent | 8cd147028f013b1565d2444f63f4944dc7eea1c9 (diff) | |
download | python-cinderclient-a6affea92157a5656ba4beae6ffd059d12e23bdc.tar.gz |
Support generalized resource filter in client
Introduce new command 'list-filters' to retrieve
enabled resource filters.
```
command: cinder list-filters --resource=volume
output:
+----------------+-------------------------------+
| Resource | Filters |
+----------------+-------------------------------+
| volume | name, status, image_metadata |
+----------------+-------------------------------+
```
Also Added new option '--filters' to these list commands:
1. list
2. snapshot-list
3. backup-list
4. attachment-list
5. message-list
6. group-list
7. group-snapshot-list
8. get-pools
Change-Id: I062e6227342ea0d940a8333e84014969c33b49df
Partial: blueprint generalized-filtering-for-cinder-list-resource
Depends-On: 04bd22c1eb371805a3ce9f6c8915325bc0da2d36
Depends-On: 7fdc4688fea373afb85d929e649d311568d1855a
Diffstat (limited to 'cinderclient/shell_utils.py')
-rw-r--r-- | cinderclient/shell_utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cinderclient/shell_utils.py b/cinderclient/shell_utils.py index e386558..949f7f7 100644 --- a/cinderclient/shell_utils.py +++ b/cinderclient/shell_utils.py @@ -143,6 +143,26 @@ def translate_availability_zone_keys(collection): translate_keys(collection, convert) +def extract_filters(args): + filters = {} + for f in args: + if '=' in f: + (key, value) = f.split('=', 1) + if value.startswith('{') and value.endswith('}'): + value = _build_internal_dict(value[1:-1]) + filters[key] = value + + return filters + + +def _build_internal_dict(content): + result = {} + for pair in content.split(','): + k, v = pair.split(':', 1) + result.update({k.strip(): v.strip()}) + return result + + def extract_metadata(args, type='user_metadata'): metadata = {} if type == 'image_metadata': @@ -169,6 +189,11 @@ def print_group_type_list(gtypes): utils.print_list(gtypes, ['ID', 'Name', 'Description']) +def print_resource_filter_list(filters): + formatter = {'Filters': lambda resource: ', '.join(resource.filters)} + utils.print_list(filters, ['Resource', 'Filters'], formatters=formatter) + + def quota_show(quotas): quotas_info_dict = utils.unicode_key_value_to_string(quotas._info) quota_dict = {} |