diff options
| author | Steve Martinelli <stevemar@ca.ibm.com> | 2015-09-20 15:44:00 -0400 |
|---|---|---|
| committer | Steve Martinelli <stevemar@ca.ibm.com> | 2015-09-21 18:53:01 +0000 |
| commit | d8f7527ff2231c4755b0bce28d1ad38fe11a9370 (patch) | |
| tree | e769ba73ae8fbe2715d6cb63d879ad70d6fe52dc /openstackclient | |
| parent | f5b50df8ea6de7e763f1c2e7079429d9c783f963 (diff) | |
| download | python-openstackclient-d8f7527ff2231c4755b0bce28d1ad38fe11a9370.tar.gz | |
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
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/image/v2/image.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 67390118..01468c4d 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -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))) |
