From b3943d714275b276a973de9c52307e82c90be8bc Mon Sep 17 00:00:00 2001 From: NiallBunting Date: Mon, 14 Dec 2015 14:28:45 +0000 Subject: Add image re/deactivate commands This change allows admins to deactivate and reactivate their images. Currently this has to be done with the REST api or the glanceclient. This change introduces `--deactivate` and `--activate` for the `image set` command. This requires glanceclient 1.2.0. Which got bumped here: https://review.openstack.org/#/c/257512/ Change-Id: I476c44a0343cdc92d58ddc93fb06470242de2345 Depends-On: I2c370c6bf6ff664d94d756cc76aaa983fbdb8869 Closes-Bug: 1516661 --- openstackclient/image/v2/image.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'openstackclient/image') diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index a3c1a99d..1fcb92d9 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -693,6 +693,17 @@ class SetImage(command.Command): metavar="", help="ID of ramdisk image used to boot this disk image", ) + deactivate_group = parser.add_mutually_exclusive_group() + deactivate_group.add_argument( + "--deactivate", + action="store_true", + help="Deactivate the image", + ) + deactivate_group.add_argument( + "--activate", + action="store_true", + help="Activate the image", + ) for deadopt in self.deadopts: parser.add_argument( "--%s" % deadopt, @@ -745,18 +756,35 @@ class SetImage(command.Command): if parsed_args.private: kwargs['visibility'] = 'private' - if not kwargs: + # Checks if anything that requires getting the image + if not (kwargs or parsed_args.deactivate or parsed_args.activate): self.log.warning("No arguments specified") return {}, {} image = utils.find_resource( image_client.images, parsed_args.image) + if parsed_args.deactivate: + image_client.images.deactivate(image.id) + activation_status = "deactivated" + if parsed_args.activate: + image_client.images.reactivate(image.id) + activation_status = "activated" + + # Check if need to do the actual update + if not kwargs: + return {}, {} + 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) + try: + image = image_client.images.update(image.id, **kwargs) + except Exception as e: + if activation_status is not None: + print("Image %s was %s." % (image.id, activation_status)) + raise e class ShowImage(show.ShowOne): -- cgit v1.2.1