summaryrefslogtreecommitdiff
path: root/openstackclient/image
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-09-21 21:54:22 +0000
committerGerrit Code Review <review@openstack.org>2015-09-21 21:54:22 +0000
commit4cb88704d9304ee1beda53542d4e3e097d116a7f (patch)
tree4b2749c744ed78632f44066bc4dc98223a61326a /openstackclient/image
parentb2e72e6aee37a55fc30fecf70f1ce7f5a824031e (diff)
parentd8f7527ff2231c4755b0bce28d1ad38fe11a9370 (diff)
downloadpython-openstackclient-4cb88704d9304ee1beda53542d4e3e097d116a7f.tar.gz
Merge "Format an images properties and tags"
Diffstat (limited to 'openstackclient/image')
-rw-r--r--openstackclient/image/v2/image.py38
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)))