From 9f51ccdf8c2b2e1afceeb9e6570ed629191a71c8 Mon Sep 17 00:00:00 2001 From: kafka Date: Wed, 12 Aug 2015 12:22:41 +0800 Subject: [PATCH] Add filtering by project/user for 'openstack volume list' added project, user and domain options for filtering results, also cleaned up the order to match the docs. Co-Authored-By: Steve Martinelli Closed-bug: #1483976 Change-Id: I9d955094d31d4a28e215d24f7521a11c62bee8db --- doc/source/command-objects/volume.rst | 30 ++++++++++++++++----- openstackclient/volume/v2/volume.py | 39 +++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/doc/source/command-objects/volume.rst b/doc/source/command-objects/volume.rst index 556d1645f3..c94cbd23ad 100644 --- a/doc/source/command-objects/volume.rst +++ b/doc/source/command-objects/volume.rst @@ -102,22 +102,40 @@ List volumes .. code:: bash os volume list - [--status ] - [--name ] [--all-projects] + [--project [--project-domain ]] + [--user [--user-domain ]] + [--name ] + [--status ] [--long] -.. option:: --status +.. option:: --all-projects - Filter results by status +.. option:: --project + + Filter results by project (name or ID) (admin only) + +.. option:: --project-domain + + Domain the project belongs to (name or ID). + This can be used in case collisions between project names exist. + +.. option:: --user + + Filter results by user (name or ID) (admin only) + +.. option:: --user-domain + + Domain the user belongs to (name or ID). + This can be used in case collisions between user names exist. .. option:: --name Filter results by name -.. option:: --all-projects +.. option:: --status - Include all projects (admin only) + Filter results by status .. option:: --long diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 758f312b4b..5df656354c 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -25,6 +25,7 @@ import six from openstackclient.common import parseractions from openstackclient.common import utils +from openstackclient.identity import common as identity_common class CreateVolume(show.ShowOne): @@ -206,11 +207,17 @@ class ListVolume(lister.Lister): help='Include all projects (admin only)', ) parser.add_argument( - '--long', - action='store_true', - default=False, - help='List additional fields in output', + '--project', + metavar='', + help='Filter results by project (name or ID) (admin only)' ) + identity_common.add_project_domain_option_to_parser(parser) + parser.add_argument( + '--user', + metavar='', + help='Filter results by user (name or ID) (admin only)' + ) + identity_common.add_user_domain_option_to_parser(parser) parser.add_argument( '--name', metavar='', @@ -221,6 +228,12 @@ class ListVolume(lister.Lister): metavar='', help='Filter results by status', ) + parser.add_argument( + '--long', + action='store_true', + default=False, + help='List additional fields in output', + ) return parser @utils.log_method(log) @@ -228,6 +241,7 @@ class ListVolume(lister.Lister): volume_client = self.app.client_manager.volume compute_client = self.app.client_manager.compute + identity_client = self.app.client_manager.identity def _format_attach(attachments): """Return a formatted string of a volume's attached instances @@ -282,8 +296,23 @@ class ListVolume(lister.Lister): # Just forget it if there's any trouble pass + project_id = None + if parsed_args.project: + project_id = identity_common.find_project( + identity_client, + parsed_args.project, + parsed_args.project_domain) + + user_id = None + if parsed_args.user: + user_id = identity_common.find_project(identity_client, + parsed_args.user, + parsed_args.user_domain) + search_opts = { - 'all_projects': parsed_args.all_projects, + 'all_tenants': parsed_args.all_projects, + 'project_id': project_id, + 'user_id': user_id, 'display_name': parsed_args.name, 'status': parsed_args.status, }