summaryrefslogtreecommitdiff
path: root/openstackclient/image/v2
diff options
context:
space:
mode:
authorNiallBunting <niall.bunting@hp.com>2015-09-23 14:54:26 +0000
committerSteve Martinelli <stevemar@ca.ibm.com>2015-10-06 20:14:34 +0000
commit1afb57453387f9f81d755f23d75d583b732e2d12 (patch)
tree5a1c11fab97585b4df39b9dc1575e33d770493fe /openstackclient/image/v2
parent201b1cee86a4df8ede6c97d962ac331ad0378140 (diff)
downloadpython-openstackclient-1afb57453387f9f81d755f23d75d583b732e2d12.tar.gz
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 <stevemar@ca.ibm.com> Change-Id: Ie800fcbf8bbc0978c54ace3278750a18023e8ce4
Diffstat (limited to 'openstackclient/image/v2')
-rw-r--r--openstackclient/image/v2/image.py19
1 files changed, 15 insertions, 4 deletions
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="<image>",
@@ -611,6 +609,15 @@ class SetImage(show.ShowOne):
"(repeat option to set multiple properties)",
)
parser.add_argument(
+ "--tag",
+ dest="tags",
+ metavar="<tag>",
+ default=[],
+ action='append',
+ help="Set a tag on this image "
+ "(repeat option to set multiple tags)",
+ )
+ parser.add_argument(
"--architecture",
metavar="<architecture>",
help="Operating system architecture",
@@ -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)