From 1afb57453387f9f81d755f23d75d583b732e2d12 Mon Sep 17 00:00:00 2001 From: NiallBunting Date: Wed, 23 Sep 2015 14:54:26 +0000 Subject: Add tags to `image set` This adds --tag to the v2 version of `image set`. This is another step to compatability between the osc image api. Added merge of tags into existing tags and handling duplicates, and tests for same. Co-Authored-By: Steve Martinelli Change-Id: Ie800fcbf8bbc0978c54ace3278750a18023e8ce4 --- openstackclient/image/v2/image.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'openstackclient/image') diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 11c7483b..7ef1f780 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -57,8 +57,7 @@ def _format_image(image): properties[key] = image.get(key) # format the tags if they are there - if image.get('tags'): - info['tags'] = utils.format_list(image.get('tags')) + info['tags'] = utils.format_list(image.get('tags')) # add properties back into the dictionary as a top-level key if properties: @@ -540,7 +539,6 @@ class SetImage(show.ShowOne): # --force - needs adding # --checksum - maybe could be done client side # --stdin - could be implemented - # --tags - needs adding parser.add_argument( "image", metavar="", @@ -610,6 +608,15 @@ class SetImage(show.ShowOne): help="Set a property on this image " "(repeat option to set multiple properties)", ) + parser.add_argument( + "--tag", + dest="tags", + metavar="", + default=[], + action='append', + help="Set a tag on this image " + "(repeat option to set multiple tags)", + ) parser.add_argument( "--architecture", metavar="", @@ -669,7 +676,7 @@ class SetImage(show.ShowOne): copy_attrs = ('architecture', 'container_format', 'disk_format', 'file', 'instance_id', 'kernel_id', 'locations', 'min_disk', 'min_ram', 'name', 'os_distro', 'os_version', - 'owner', 'prefix', 'progress', 'ramdisk_id') + 'owner', 'prefix', 'progress', 'ramdisk_id', 'tags') for attr in copy_attrs: if attr in parsed_args: val = getattr(parsed_args, attr, None) @@ -705,6 +712,10 @@ class SetImage(show.ShowOne): image = utils.find_resource( image_client.images, parsed_args.image) + if parsed_args.tags: + # Tags should be extended, but duplicates removed + kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags))) + image = image_client.images.update(image.id, **kwargs) info = {} info.update(image) -- cgit v1.2.1