summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/server.py
diff options
context:
space:
mode:
authorwhoami-rajat <rajatdhasmana@gmail.com>2022-02-25 22:43:24 +0530
committerRajat Dhasmana <rajatdhasmana@gmail.com>2022-09-29 06:01:23 +0000
commit7d702baf171dba9942db44a3814ce2c9575b2fe2 (patch)
treed2976a7fe9a3a3b41b93575c6692317b67de0307 /openstackclient/compute/v2/server.py
parent0118d57c027c630f726dba4659c1e554ba833405 (diff)
downloadpython-openstackclient-stable/zed.tar.gz
compute: Add support for microversion 2.93stable/zed
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)
Diffstat (limited to 'openstackclient/compute/v2/server.py')
-rw-r--r--openstackclient/compute/v2/server.py57
1 files changed, 57 insertions, 0 deletions
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
@@ -3092,6 +3092,28 @@ class RebuildServer(command.ShowOne):
),
)
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',
help=_('Wait for rebuild to complete'),
@@ -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: