summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2021-05-26 15:04:28 +0100
committerStephen Finucane <sfinucan@redhat.com>2022-05-13 12:42:16 +0100
commit53a7e67b4132281c9e217061aac03429a77f869c (patch)
tree0da45168002016e3e40f89e4cff863072a927d5f /openstackclient/volume
parentd727a6502369a6a7244ef1c07c1c483dbe0a8dab (diff)
downloadpython-openstackclient-53a7e67b4132281c9e217061aac03429a77f869c.tar.gz
volume: Add 'block storage resource filter list' command
These are based on the 'cinder list-filters' command, which accepts an optional '--resource {resource}' option to limit the listed filters to a single resource type. block storage resource filter list block storage resource filter show We used the 'block storage resource filter' terminology rather than simply 'resource filter' to highlight the fact that this is specific to the block storage service. Note that while this feature is a bit weird, good documentation can be found at [1]. [1] https://docs.openstack.org/cinder/latest/admin/generalized_filters.html Change-Id: I21e7c0ea427aef1f6665394d4b8e9a1f30d6dbb1 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v3/block_storage_resource_filter.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/openstackclient/volume/v3/block_storage_resource_filter.py b/openstackclient/volume/v3/block_storage_resource_filter.py
new file mode 100644
index 00000000..4bcacf90
--- /dev/null
+++ b/openstackclient/volume/v3/block_storage_resource_filter.py
@@ -0,0 +1,83 @@
+# 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.
+
+"""Volume V3 Resource Filters implementations"""
+
+from cinderclient import api_versions
+from osc_lib.command import command
+from osc_lib import exceptions
+from osc_lib import utils
+
+from openstackclient.i18n import _
+
+
+class ListBlockStorageResourceFilter(command.Lister):
+ _description = _('List block storage resource filters')
+
+ def take_action(self, parsed_args):
+ volume_client = self.app.client_manager.volume
+
+ if volume_client.api_version < api_versions.APIVersion('3.33'):
+ msg = _(
+ "--os-volume-api-version 3.33 or greater is required to "
+ "support the 'block storage resource filter list' command"
+ )
+ raise exceptions.CommandError(msg)
+
+ column_headers = (
+ 'Resource',
+ 'Filters',
+ )
+
+ data = volume_client.resource_filters.list()
+
+ return (
+ column_headers,
+ (utils.get_item_properties(s, column_headers) for s in data)
+ )
+
+
+class ShowBlockStorageResourceFilter(command.ShowOne):
+ _description = _('Show filters for a block storage resource type')
+
+ def get_parser(self, prog_name):
+ parser = super().get_parser(prog_name)
+ parser.add_argument(
+ 'resource',
+ metavar='<resource>',
+ help=_('Resource to show filters for (name).')
+ )
+
+ return parser
+
+ def take_action(self, parsed_args):
+ volume_client = self.app.client_manager.volume
+
+ if volume_client.api_version < api_versions.APIVersion('3.33'):
+ msg = _(
+ "--os-volume-api-version 3.33 or greater is required to "
+ "support the 'block storage resource filter show' command"
+ )
+ raise exceptions.CommandError(msg)
+
+ data = volume_client.resource_filters.list(
+ resource=parsed_args.resource
+ )
+ if not data:
+ msg = _(
+ "No resource filter with a name of {parsed_args.resource}' "
+ "exists."
+ )
+ raise exceptions.CommandError(msg)
+ resource_filter = next(data)
+
+ return zip(*sorted(resource_filter._info.items()))