diff options
| author | Louis Taylor <kragniz@gmail.com> | 2014-10-20 14:26:14 +0000 |
|---|---|---|
| committer | Louis Taylor <kragniz@gmail.com> | 2014-11-14 10:45:31 +0000 |
| commit | 4194a55a096dbc02275b9a52f60ec96ae8d64473 (patch) | |
| tree | 93bd4200e6a4fddfd698f829632670924239d560 /glanceclient/v2/shell.py | |
| parent | 711f28a5a8aa220f35ef18b9e9e985e1ebbe7166 (diff) | |
| download | python-glanceclient-4194a55a096dbc02275b9a52f60ec96ae8d64473.tar.gz | |
Add --property-filter option to v2 image-list
The option is present in the v1 shell, but missing from the v2 shell. This
allows the user to filter based on any image property.
Example:
$ glance --os-image-api-version 2 image-list --property-filter os_distro=NixOS
DocImpact
Closes-Bug: #1383326
Change-Id: Ia65a08520e3eaf3ecd9b9018be9f6a8e2d3d4f0b
Diffstat (limited to 'glanceclient/v2/shell.py')
| -rw-r--r-- | glanceclient/v2/shell.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 7f56609..a77efd4 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -93,6 +93,9 @@ def do_image_update(gc, args): help='The status of images to display.') @utils.arg('--owner', metavar='<OWNER>', help='Display images owned by <OWNER>.') +@utils.arg('--property-filter', metavar='<KEY=VALUE>', + help="Filter images by a user-defined image property.", + action='append', dest='properties', default=[]) @utils.arg('--checksum', metavar='<CHECKSUM>', help='Displays images that match the checksum.') @utils.arg('--tag', metavar='<TAG>', action='append', @@ -101,6 +104,12 @@ def do_image_list(gc, args): """List images you can access.""" filter_keys = ['visibility', 'member_status', 'owner', 'checksum', 'tag'] filter_items = [(key, getattr(args, key)) for key in filter_keys] + if args.properties: + filter_properties = [prop.split('=', 1) for prop in args.properties] + if False in (len(pair) == 2 for pair in filter_properties): + utils.exit('Argument --property-filter expected properties in the' + ' format KEY=VALUE') + filter_items += filter_properties filters = dict([item for item in filter_items if item[1] is not None]) kwargs = {'filters': filters} |
