|
35 | 35 | DEFAULT_DISK_FORMAT = 'raw' |
36 | 36 |
|
37 | 37 |
|
| 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 | + |
38 | 70 | class AddProjectToImage(show.ShowOne): |
39 | 71 | """Associate project with image""" |
40 | 72 |
|
@@ -254,7 +286,8 @@ def take_action(self, parsed_args): |
254 | 286 | # update the image after the data has been uploaded |
255 | 287 | image = image_client.images.get(image.id) |
256 | 288 |
|
257 | | - return zip(*sorted(six.iteritems(image))) |
| 289 | + info = _format_image(image) |
| 290 | + return zip(*sorted(six.iteritems(info))) |
258 | 291 |
|
259 | 292 |
|
260 | 293 | class DeleteImage(command.Command): |
@@ -512,8 +545,7 @@ def take_action(self, parsed_args): |
512 | 545 | parsed_args.image, |
513 | 546 | ) |
514 | 547 |
|
515 | | - info = {} |
516 | | - info.update(image) |
| 548 | + info = _format_image(image) |
517 | 549 | return zip(*sorted(six.iteritems(info))) |
518 | 550 |
|
519 | 551 |
|
|
0 commit comments