Format an images properties and tags

Currently, these properties are each top level keys, they should
all be under a single 'properties' field. Secondly, the tags are
kept as an array, but can be shown as a comma separated string.

Change-Id: Ic769c657a86e768fee38acc40434c377de70a7bc
This commit is contained in:
Steve Martinelli 2015-09-20 15:44:00 -04:00
parent f5b50df8ea
commit d8f7527ff2

@ -35,6 +35,38 @@ DEFAULT_CONTAINER_FORMAT = 'bare'
DEFAULT_DISK_FORMAT = 'raw'
def _format_image(image):
"""Format an image to make it more consistent with OSC operations. """
info = {}
properties = {}
# the only fields we're not including is "links", "tags" and the properties
fields_to_show = ['status', 'name', 'container_format', 'created_at',
'size', 'disk_format', 'updated_at', 'visibility',
'min_disk', 'protected', 'id', 'file', 'checksum',
'owner', 'virtual_size', 'min_ram', 'schema']
# split out the usual key and the properties which are top-level
for key in six.iterkeys(image):
if key in fields_to_show:
info[key] = image.get(key)
elif key == 'tags':
continue # handle this later
else:
properties[key] = image.get(key)
# format the tags if they are there
if image.get('tags'):
info['tags'] = utils.format_list(image.get('tags'))
# add properties back into the dictionary as a top-level key
if properties:
info['properties'] = utils.format_dict(properties)
return info
class AddProjectToImage(show.ShowOne):
"""Associate project with image"""
@ -254,7 +286,8 @@ class CreateImage(show.ShowOne):
# update the image after the data has been uploaded
image = image_client.images.get(image.id)
return zip(*sorted(six.iteritems(image)))
info = _format_image(image)
return zip(*sorted(six.iteritems(info)))
class DeleteImage(command.Command):
@ -512,8 +545,7 @@ class ShowImage(show.ShowOne):
parsed_args.image,
)
info = {}
info.update(image)
info = _format_image(image)
return zip(*sorted(six.iteritems(info)))