summaryrefslogtreecommitdiff
path: root/openstackclient/image
diff options
context:
space:
mode:
authorJordan Pittier <jordan.pittier@scality.com>2016-12-15 22:20:30 +0100
committerJordan Pittier <jordan.pittier@scality.com>2017-01-04 19:26:01 +0100
commitf055fe67c11fff020ae959b1672844aaff382491 (patch)
tree5f05551742886962d24d4e38efb7a5b810b29810 /openstackclient/image
parentc416aecb2f7fc8e993ca2b22edd4dea3673d2cac (diff)
downloadpython-openstackclient-f055fe67c11fff020ae959b1672844aaff382491.tar.gz
Add support for Glance 'update image members' feature
This patch adds 3 new options to the "image set" command: --accept, --reject and --pending. This updates the membership status for an image. Closes-Bug: 1620481 Change-Id: I13b8c067aad68ece9ff636fbdd83bcb3663c91b2
Diffstat (limited to 'openstackclient/image')
-rw-r--r--openstackclient/image/v2/image.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 55eb7eb1..418cc397 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -777,6 +777,23 @@ class SetImage(command.Command):
dest=deadopt.replace('-', '_'),
help=argparse.SUPPRESS,
)
+
+ membership_group = parser.add_mutually_exclusive_group()
+ membership_group.add_argument(
+ "--accept",
+ action="store_true",
+ help=_("Accept the image membership"),
+ )
+ membership_group.add_argument(
+ "--reject",
+ action="store_true",
+ help=_("Reject the image membership"),
+ )
+ membership_group.add_argument(
+ "--pending",
+ action="store_true",
+ help=_("Reset the image membership to 'pending'"),
+ )
return parser
def take_action(self, parsed_args):
@@ -828,12 +845,14 @@ class SetImage(command.Command):
project_arg = parsed_args.owner
LOG.warning(_('The --owner option is deprecated, '
'please use --project instead.'))
+ project_id = None
if project_arg:
- kwargs['owner'] = common.find_project(
+ project_id = common.find_project(
identity_client,
project_arg,
parsed_args.project_domain,
).id
+ kwargs['owner'] = project_id
image = utils.find_resource(
image_client.images, parsed_args.image)
@@ -846,6 +865,21 @@ class SetImage(command.Command):
image_client.images.reactivate(image.id)
activation_status = "activated"
+ membership_group_args = ('accept', 'reject', 'pending')
+ membership_status = [status for status in membership_group_args
+ if getattr(parsed_args, status)]
+ if membership_status:
+ # If a specific project is not passed, assume we want to update
+ # our own membership
+ if not project_id:
+ project_id = self.app.client_manager.auth_ref.project_id
+ # The mutually exclusive group of the arg parser ensure we have at
+ # most one item in the membership_status list.
+ if membership_status[0] != 'pending':
+ membership_status[0] += 'ed' # Glance expects the past form
+ image_client.image_members.update(
+ image.id, project_id, membership_status[0])
+
if parsed_args.tags:
# Tags should be extended, but duplicates removed
kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))