Allow image filtering by custom properties

A user can filter a list of images by passing in a 'properties'
sub-dictionary inside of the 'filters' keyword argumen to
ImageManager.list(). The same functionality can be used through
the CLI through the use of one or more'--property-filter' options.

Related to bp glance-client-parity.

Change-Id: I7d119174d83faa894dde557e1944289de296a02c
This commit is contained in:
Brian Waldon
2012-07-04 15:46:29 -07:00
parent e7db533bc0
commit a1691ddc10
3 changed files with 16 additions and 0 deletions
+8
View File
@@ -32,12 +32,20 @@ import glanceclient.v1.images
help='Filter images to those with a size greater than this.')
@utils.arg('--size-max', metavar='<SIZE>',
help='Filter images to those with a size less than this.')
@utils.arg('--property-filter', metavar='<KEY=VALUE>',
help="Filter images by a user-defined image property.",
action='append', dest='properties', default=[])
def do_image_list(gc, args):
"""List images."""
filter_keys = ['name', 'status', 'container_format', 'disk_format',
'size_min', 'size_max']
filter_items = [(key, getattr(args, key)) for key in filter_keys]
filters = dict([item for item in filter_items if item[1] is not None])
if args.properties:
property_filter_items = [p.split('=', 1) for p in args.properties]
filters['properties'] = dict(property_filter_items)
images = gc.images.list(filters=filters)
columns = ['ID', 'Name', 'Disk Format', 'Container Format',
'Size', 'Status']