Skip to content

Commit d8f7527

Browse files
author
Steve Martinelli
committed
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
1 parent f5b50df commit d8f7527

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@
3535
DEFAULT_DISK_FORMAT = 'raw'
3636

3737

38+
def _format_image(image):
39+
"""Format an image to make it more consistent with OSC operations. """
40+
41+
info = {}
42+
properties = {}
43+
44+
# the only fields we're not including is "links", "tags" and the properties
45+
fields_to_show = ['status', 'name', 'container_format', 'created_at',
46+
'size', 'disk_format', 'updated_at', 'visibility',
47+
'min_disk', 'protected', 'id', 'file', 'checksum',
48+
'owner', 'virtual_size', 'min_ram', 'schema']
49+
50+
# split out the usual key and the properties which are top-level
51+
for key in six.iterkeys(image):
52+
if key in fields_to_show:
53+
info[key] = image.get(key)
54+
elif key == 'tags':
55+
continue # handle this later
56+
else:
57+
properties[key] = image.get(key)
58+
59+
# format the tags if they are there
60+
if image.get('tags'):
61+
info['tags'] = utils.format_list(image.get('tags'))
62+
63+
# add properties back into the dictionary as a top-level key
64+
if properties:
65+
info['properties'] = utils.format_dict(properties)
66+
67+
return info
68+
69+
3870
class AddProjectToImage(show.ShowOne):
3971
"""Associate project with image"""
4072

@@ -254,7 +286,8 @@ def take_action(self, parsed_args):
254286
# update the image after the data has been uploaded
255287
image = image_client.images.get(image.id)
256288

257-
return zip(*sorted(six.iteritems(image)))
289+
info = _format_image(image)
290+
return zip(*sorted(six.iteritems(info)))
258291

259292

260293
class DeleteImage(command.Command):
@@ -512,8 +545,7 @@ def take_action(self, parsed_args):
512545
parsed_args.image,
513546
)
514547

515-
info = {}
516-
info.update(image)
548+
info = _format_image(image)
517549
return zip(*sorted(six.iteritems(info)))
518550

519551

0 commit comments

Comments
 (0)