summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-01-15 04:09:58 +0000
committerGerrit Code Review <review@openstack.org>2021-01-15 04:09:58 +0000
commit3864ceea269a606c47dc8a26691d044c28fd3c87 (patch)
treeb0d2cc549186d792f496d7b6be22f4b3c3054c29 /openstackclient/compute/v2
parent1febc8cd0335c6f9ffada9a3b24589b55b76f1af (diff)
parentca7f23d0d1876dc53ef4d5ecbf2c5f367aafe13e (diff)
downloadpython-openstackclient-3864ceea269a606c47dc8a26691d044c28fd3c87.tar.gz
Merge "compute: Add 'server volume update' command"
Diffstat (limited to 'openstackclient/compute/v2')
-rw-r--r--openstackclient/compute/v2/server.py16
-rw-r--r--openstackclient/compute/v2/server_volume.py67
2 files changed, 75 insertions, 8 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 59fc4b7d..1b601efe 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -513,27 +513,27 @@ class AddServerVolume(command.Command):
'--tag',
metavar='<tag>',
help=_(
- "Tag for the attached volume. "
- "(Supported by API versions '2.49' - '2.latest')"
+ 'Tag for the attached volume '
+ '(supported by --os-compute-api-version 2.49 or above)'
),
)
+ # TODO(stephenfin): These should be called 'delete-on-termination' and
+ # 'preserve-on-termination'
termination_group = parser.add_mutually_exclusive_group()
termination_group.add_argument(
'--enable-delete-on-termination',
action='store_true',
help=_(
- "Specify if the attached volume should be deleted when the "
- "server is destroyed. "
- "(Supported by API versions '2.79' - '2.latest')"
+ 'Delete the volume when the server is destroyed '
+ '(supported by --os-compute-api-version 2.79 or above)'
),
)
termination_group.add_argument(
'--disable-delete-on-termination',
action='store_true',
help=_(
- "Specify if the attached volume should not be deleted when "
- "the server is destroyed. "
- "(Supported by API versions '2.79' - '2.latest')"
+ 'Do not delete the volume when the server is destroyed '
+ '(supported by --os-compute-api-version 2.79 or above)'
),
)
return parser
diff --git a/openstackclient/compute/v2/server_volume.py b/openstackclient/compute/v2/server_volume.py
index 8a931ae5..b53c92fe 100644
--- a/openstackclient/compute/v2/server_volume.py
+++ b/openstackclient/compute/v2/server_volume.py
@@ -16,6 +16,7 @@
from novaclient import api_versions
from osc_lib.command import command
+from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
@@ -71,3 +72,69 @@ class ListServerVolume(command.Lister):
) for s in volumes
),
)
+
+
+class UpdateServerVolume(command.Command):
+ """Update a volume attachment on the server."""
+
+ def get_parser(self, prog_name):
+ parser = super(UpdateServerVolume, self).get_parser(prog_name)
+ parser.add_argument(
+ 'server',
+ help=_('Server to update volume for (name or ID)'),
+ )
+ parser.add_argument(
+ 'volume',
+ help=_('Volume (ID)'),
+ )
+ termination_group = parser.add_mutually_exclusive_group()
+ termination_group.add_argument(
+ '--delete-on-termination',
+ action='store_true',
+ dest='delete_on_termination',
+ default=None,
+ help=_(
+ 'Delete the volume when the server is destroyed '
+ '(supported by --os-compute-api-version 2.85 or above)'
+ ),
+ )
+ termination_group.add_argument(
+ '--preserve-on-termination',
+ action='store_false',
+ dest='delete_on_termination',
+ help=_(
+ 'Preserve the volume when the server is destroyed '
+ '(supported by --os-compute-api-version 2.85 or above)'
+ ),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+
+ compute_client = self.app.client_manager.compute
+
+ if parsed_args.delete_on_termination is not None:
+ if compute_client.api_version < api_versions.APIVersion('2.85'):
+ msg = _(
+ '--os-compute-api-version 2.85 or greater is required to '
+ 'support the --(no-)delete-on-termination option'
+ )
+ raise exceptions.CommandError(msg)
+
+ server = utils.find_resource(
+ compute_client.servers,
+ parsed_args.server,
+ )
+
+ # NOTE(stephenfin): This may look silly, and that's because it is.
+ # This API was originally used only for the swapping volumes, which
+ # is an internal operation that should only be done by
+ # orchestration software rather than a human. We're not going to
+ # expose that, but we are going to expose the ability to change the
+ # delete on termination behavior.
+ compute_client.volumes.update_server_volume(
+ server.id,
+ parsed_args.volume,
+ parsed_args.volume,
+ delete_on_termination=parsed_args.delete_on_termination,
+ )