summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorDiwei Zhu <zhu.diw@northeastern.edu>2021-10-28 23:25:52 +0000
committerDiwei Zhu <zhu.diw@northeastern.edu>2021-11-22 16:01:29 +0000
commit3078a0a121743c387d83d7f27ce3d8fd8fbb4ccf (patch)
tree4fae6930917e02a95c73e3ba701e254c044b53dc /openstackclient/compute
parent8b394e564120984059d6424bb870c8da51a400e7 (diff)
downloadpython-openstackclient-3078a0a121743c387d83d7f27ce3d8fd8fbb4ccf.tar.gz
Switch command server add volume to sdk.
File tests.unit.volume.v2.fakes is modified to provide sdk volume fakes. File tests.unit.compute.v2.fakes is modified to provide sdk volume attachment fakes. For test, setup_sdk_volumes_mock() method is created so that volumes are created in similar way as servers are created. Change-Id: I290ba83b6ba27a1377ab73fd0ae06ecced25efd1
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server.py38
1 files changed, 17 insertions, 21 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index 08627f9b..18c1197c 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -548,24 +548,25 @@ class AddServerVolume(command.ShowOne):
return parser
def take_action(self, parsed_args):
- compute_client = self.app.client_manager.compute
- volume_client = self.app.client_manager.volume
+ compute_client = self.app.client_manager.sdk_connection.compute
+ volume_client = self.app.client_manager.sdk_connection.volume
- server = utils.find_resource(
- compute_client.servers,
+ server = compute_client.find_server(
parsed_args.server,
+ ignore_missing=False,
)
- volume = utils.find_resource(
- volume_client.volumes,
+ volume = volume_client.find_volume(
parsed_args.volume,
+ ignore_missing=False,
)
kwargs = {
+ "volumeId": volume.id,
"device": parsed_args.device
}
if parsed_args.tag:
- if compute_client.api_version < api_versions.APIVersion('2.49'):
+ if not sdk_utils.supports_microversion(compute_client, '2.49'):
msg = _(
'--os-compute-api-version 2.49 or greater is required to '
'support the --tag option'
@@ -575,7 +576,7 @@ class AddServerVolume(command.ShowOne):
kwargs['tag'] = parsed_args.tag
if parsed_args.enable_delete_on_termination:
- if compute_client.api_version < api_versions.APIVersion('2.79'):
+ if not sdk_utils.supports_microversion(compute_client, '2.79'):
msg = _(
'--os-compute-api-version 2.79 or greater is required to '
'support the --enable-delete-on-termination option.'
@@ -585,7 +586,7 @@ class AddServerVolume(command.ShowOne):
kwargs['delete_on_termination'] = True
if parsed_args.disable_delete_on_termination:
- if compute_client.api_version < api_versions.APIVersion('2.79'):
+ if not sdk_utils.supports_microversion(compute_client, '2.79'):
msg = _(
'--os-compute-api-version 2.79 or greater is required to '
'support the --disable-delete-on-termination option.'
@@ -594,28 +595,23 @@ class AddServerVolume(command.ShowOne):
kwargs['delete_on_termination'] = False
- volume_attachment = compute_client.volumes.create_server_volume(
- server.id,
- volume.id,
- **kwargs
+ volume_attachment = compute_client.create_volume_attachment(
+ server,
+ **kwargs,
)
- columns = ('id', 'serverId', 'volumeId', 'device')
+ columns = ('id', 'server id', 'volume id', 'device')
column_headers = ('ID', 'Server ID', 'Volume ID', 'Device')
- if compute_client.api_version >= api_versions.APIVersion('2.49'):
+ if sdk_utils.supports_microversion(compute_client, '2.49'):
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',)
return (
column_headers,
- utils.get_item_properties(
- volume_attachment,
- columns,
- mixed_case_fields=('serverId', 'volumeId'),
- )
+ utils.get_item_properties(volume_attachment, columns,)
)