From 7d702baf171dba9942db44a3814ce2c9575b2fe2 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Fri, 25 Feb 2022 22:43:24 +0530 Subject: compute: Add support for microversion 2.93 Add '--reimage-boot-volume' and '--no-reimage-boot-volume parameters' to the rebuild command to allow rebuilding of volume backed instances. Change-Id: I4a6e30b2cf12f32202a2d9ef1ced347e1dd139f3 (cherry picked from commit 4024bdb3933dd79eec4bcf99c13f3dbf17add40b) --- openstackclient/compute/v2/server.py | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'openstackclient/compute/v2/server.py') diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 61870ff1..1abf7a9e 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -3091,6 +3091,28 @@ class RebuildServer(command.ShowOne): '(supported by --os-compute-api-version 2.90 or above)' ), ) + parser.add_argument( + '--reimage-boot-volume', + action='store_true', + dest='reimage_boot_volume', + default=None, + help=_( + 'Rebuild a volume-backed server. This will wipe the root ' + 'volume data and overwrite it with the provided image. ' + 'Defaults to False. ' + '(supported by --os-compute-api-version 2.93 or above)' + ), + ) + parser.add_argument( + '--no-reimage-boot-volume', + action='store_false', + dest='reimage_boot_volume', + default=None, + help=_( + 'Do not rebuild a volume-backed server. ' + '(supported by --os-compute-api-version 2.93 or above)' + ), + ) parser.add_argument( '--wait', action='store_true', @@ -3226,6 +3248,41 @@ class RebuildServer(command.ShowOne): kwargs['hostname'] = parsed_args.hostname + v2_93 = api_versions.APIVersion('2.93') + if parsed_args.reimage_boot_volume: + if compute_client.api_version < v2_93: + msg = _( + '--os-compute-api-version 2.93 or greater is required to ' + 'support the --reimage-boot-volume option' + ) + raise exceptions.CommandError(msg) + else: + # force user to explicitly request reimaging of volume-backed + # server + if not server.image: + if compute_client.api_version >= v2_93: + msg = ( + '--reimage-boot-volume is required to rebuild a ' + 'volume-backed server' + ) + raise exceptions.CommandError(msg) + else: # microversion < 2.93 + # attempts to rebuild a volume-backed server before API + # microversion 2.93 will fail in all cases except one: if + # the user attempts the rebuild with the exact same image + # that the server was initially built with. We can't check + # for this since we don't have the original image ID to + # hand, so we simply warn the user. + # TODO(stephenfin): Make this a failure in a future + # version + self.log.warning( + 'Attempting to rebuild a volume-backed server using ' + '--os-compute-api-version 2.92 or earlier, which ' + 'will only succeed if the image is identical to the ' + 'one initially used. This will be an error in a ' + 'future release.' + ) + try: server = server.rebuild(image, parsed_args.password, **kwargs) finally: -- cgit v1.2.1