diff options
| author | NiallBunting <niall.bunting@hpe.com> | 2015-12-14 14:28:45 +0000 |
|---|---|---|
| committer | NiallBunting <niall.bunting@hpe.com> | 2015-12-16 14:25:41 +0000 |
| commit | b3943d714275b276a973de9c52307e82c90be8bc (patch) | |
| tree | d5c5587bbe10f62d4692487759f6a5c9b5edda71 /openstackclient/image/v2 | |
| parent | 1ee5191cec53df588d51a7cee31cfe9cf3a57a1b (diff) | |
| download | python-openstackclient-b3943d714275b276a973de9c52307e82c90be8bc.tar.gz | |
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
Diffstat (limited to 'openstackclient/image/v2')
| -rw-r--r-- | openstackclient/image/v2/image.py | 32 |
1 files changed, 30 insertions, 2 deletions
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="<ramdisk-id>", 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): |
