summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2020-12-03 12:47:10 +0000
committerStephen Finucane <sfinucan@redhat.com>2021-01-08 12:14:43 +0000
commitd5026278ede4dbe8126839ec59ec4ca371e806a8 (patch)
treeec2f75cf1e4753df07ea63cdceacc89fbff5ddc3 /openstackclient/compute
parentb34905722015646538c8557f9fa91fc2b5edffdb (diff)
downloadpython-openstackclient-d5026278ede4dbe8126839ec59ec4ca371e806a8.tar.gz
compute: Add 'server volume list' command
This replaces the old 'nova volume-attachments' command. Change-Id: Icb98766f98bd1f2469bdb6df62b4624711f98422 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/server_volume.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/openstackclient/compute/v2/server_volume.py b/openstackclient/compute/v2/server_volume.py
new file mode 100644
index 00000000..8a931ae5
--- /dev/null
+++ b/openstackclient/compute/v2/server_volume.py
@@ -0,0 +1,73 @@
+# Copyright 2020, Red Hat Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""Compute v2 Server action implementations"""
+
+from novaclient import api_versions
+from osc_lib.command import command
+from osc_lib import utils
+
+from openstackclient.i18n import _
+
+
+class ListServerVolume(command.Lister):
+ """List all the volumes attached to a server."""
+
+ def get_parser(self, prog_name):
+ parser = super().get_parser(prog_name)
+ parser.add_argument(
+ 'server',
+ help=_('Server to list volume attachments for (name or ID)'),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+
+ compute_client = self.app.client_manager.compute
+
+ server = utils.find_resource(
+ compute_client.servers,
+ parsed_args.server,
+ )
+
+ volumes = compute_client.volumes.get_server_volumes(server.id)
+
+ columns = (
+ 'id',
+ 'device',
+ 'serverId',
+ 'volumeId',
+ )
+ column_headers = (
+ 'ID',
+ 'Device',
+ 'Server ID',
+ 'Volume ID',
+ )
+ if compute_client.api_version >= api_versions.APIVersion('2.70'):
+ columns += ('tag',)
+ column_headers += ('Tag',)
+
+ if compute_client.api_version >= api_versions.APIVersion('2.79'):
+ columns += ('delete_on_termination',)
+ column_headers += ('Delete On Termination?',)
+
+ return (
+ column_headers,
+ (
+ utils.get_item_properties(
+ s, columns, mixed_case_fields=('serverId', 'volumeId')
+ ) for s in volumes
+ ),
+ )