diff options
| author | Zuul <zuul@review.opendev.org> | 2023-02-21 13:28:37 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2023-02-21 13:28:37 +0000 |
| commit | 2249d0026dd8fb53a743134ffbb76e55ced45f9b (patch) | |
| tree | b016c06f27d3a86d40aa87643c8d4575eb747288 /openstackclient/compute/v2 | |
| parent | fa90ad13925a0c4c560d86c1bf9735b8aafd4bdf (diff) | |
| parent | 25b4714f1cd12c20ff7653f05dddb5486a037fcc (diff) | |
| download | python-openstackclient-2249d0026dd8fb53a743134ffbb76e55ced45f9b.tar.gz | |
Merge "Switch server volume update to sdk"
Diffstat (limited to 'openstackclient/compute/v2')
| -rw-r--r-- | openstackclient/compute/v2/server_volume.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/openstackclient/compute/v2/server_volume.py b/openstackclient/compute/v2/server_volume.py index 45d604a5..7d0cd336 100644 --- a/openstackclient/compute/v2/server_volume.py +++ b/openstackclient/compute/v2/server_volume.py @@ -14,7 +14,6 @@ """Compute v2 Server action implementations""" -from novaclient import api_versions from openstack import utils as sdk_utils from osc_lib.command import command from osc_lib import exceptions @@ -83,14 +82,14 @@ 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 = super().get_parser(prog_name) parser.add_argument( 'server', help=_('Server to update volume for (name or ID)'), ) parser.add_argument( 'volume', - help=_('Volume (ID)'), + help=_('Volume to update attachment for (name or ID)'), ) termination_group = parser.add_mutually_exclusive_group() termination_group.add_argument( @@ -115,31 +114,29 @@ class UpdateServerVolume(command.Command): return parser def take_action(self, parsed_args): - - compute_client = self.app.client_manager.compute + compute_client = self.app.client_manager.sdk_connection.compute + volume_client = self.app.client_manager.sdk_connection.volume if parsed_args.delete_on_termination is not None: - if compute_client.api_version < api_versions.APIVersion('2.85'): + if not sdk_utils.supports_microversion(compute_client, '2.85'): msg = _( '--os-compute-api-version 2.85 or greater is required to ' - 'support the --(no-)delete-on-termination option' + 'support the -delete-on-termination or ' + '--preserve-on-termination option' ) raise exceptions.CommandError(msg) - server = utils.find_resource( - compute_client.servers, + server = compute_client.find_server( parsed_args.server, + ignore_missing=False, ) - - # 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, + volume = volume_client.find_volume( parsed_args.volume, + ignore_missing=False, + ) + + compute_client.update_volume_attachment( + server, + volume, delete_on_termination=parsed_args.delete_on_termination, ) |
