summaryrefslogtreecommitdiff
path: root/openstackclient/compute/v2/server_volume.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/compute/v2/server_volume.py')
-rw-r--r--openstackclient/compute/v2/server_volume.py73
1 files changed, 35 insertions, 38 deletions
diff --git a/openstackclient/compute/v2/server_volume.py b/openstackclient/compute/v2/server_volume.py
index d53cec93..b4322c0b 100644
--- a/openstackclient/compute/v2/server_volume.py
+++ b/openstackclient/compute/v2/server_volume.py
@@ -14,7 +14,7 @@
"""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
from osc_lib import utils
@@ -34,27 +34,25 @@ class ListServerVolume(command.Lister):
return parser
def take_action(self, parsed_args):
+ compute_client = self.app.client_manager.sdk_connection.compute
- compute_client = self.app.client_manager.compute
-
- server = utils.find_resource(
- compute_client.servers,
+ server = compute_client.find_server(
parsed_args.server,
+ ignore_missing=False,
)
-
- volumes = compute_client.volumes.get_server_volumes(server.id)
+ volumes = compute_client.volume_attachments(server)
columns = ()
column_headers = ()
- if compute_client.api_version < api_versions.APIVersion('2.89'):
+ if not sdk_utils.supports_microversion(compute_client, '2.89'):
columns += ('id',)
column_headers += ('ID',)
columns += (
'device',
- 'serverId',
- 'volumeId',
+ 'server_id',
+ 'volume_id',
)
column_headers += (
'Device',
@@ -62,40 +60,36 @@ class ListServerVolume(command.Lister):
'Volume ID',
)
- if compute_client.api_version >= api_versions.APIVersion('2.70'):
+ if sdk_utils.supports_microversion(compute_client, '2.70'):
columns += ('tag',)
column_headers += ('Tag',)
- if compute_client.api_version >= api_versions.APIVersion('2.79'):
+ if sdk_utils.supports_microversion(compute_client, '2.79'):
columns += ('delete_on_termination',)
column_headers += ('Delete On Termination?',)
- if compute_client.api_version >= api_versions.APIVersion('2.89'):
- columns += ('attachment_id', 'bdm_uuid')
+ if sdk_utils.supports_microversion(compute_client, '2.89'):
+ columns += ('attachment_id', 'bdm_id')
column_headers += ('Attachment ID', 'BlockDeviceMapping UUID')
return (
column_headers,
- (
- utils.get_item_properties(
- s, columns, mixed_case_fields=('serverId', 'volumeId')
- ) for s in volumes
- ),
+ (utils.get_item_properties(s, columns) for s in volumes),
)
-class UpdateServerVolume(command.Command):
+class SetServerVolume(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(
@@ -120,31 +114,34 @@ 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,
)
+
+
+# Legacy alias
+class UpdateServerVolume(SetServerVolume):
+ """DEPRECATED: Use 'server volume set' instead."""