Skip to content

Commit 6fdc9a8

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add filtering by project/user for 'openstack volume list'"
2 parents cb533ef + 9f51ccd commit 6fdc9a8

2 files changed

Lines changed: 58 additions & 11 deletions

File tree

doc/source/command-objects/volume.rst

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,40 @@ List volumes
102102
.. code:: bash
103103
104104
os volume list
105-
[--status <status>]
106-
[--name <name>]
107105
[--all-projects]
106+
[--project <project> [--project-domain <project-domain>]]
107+
[--user <user> [--user-domain <user-domain>]]
108+
[--name <name>]
109+
[--status <status>]
108110
[--long]
109111
110-
.. option:: --status <status>
112+
.. option:: --all-projects
111113
112-
Filter results by status
114+
.. option:: --project <project>
115+
116+
Filter results by project (name or ID) (admin only)
117+
118+
.. option:: --project-domain <project-domain>
119+
120+
Domain the project belongs to (name or ID).
121+
This can be used in case collisions between project names exist.
122+
123+
.. option:: --user <user>
124+
125+
Filter results by user (name or ID) (admin only)
126+
127+
.. option:: --user-domain <user-domain>
128+
129+
Domain the user belongs to (name or ID).
130+
This can be used in case collisions between user names exist.
113131
114132
.. option:: --name <name>
115133
116134
Filter results by name
117135
118-
.. option:: --all-projects
136+
.. option:: --status <status>
119137
120-
Include all projects (admin only)
138+
Filter results by status
121139
122140
.. option:: --long
123141

openstackclient/volume/v2/volume.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from openstackclient.common import parseractions
2727
from openstackclient.common import utils
28+
from openstackclient.identity import common as identity_common
2829

2930

3031
class CreateVolume(show.ShowOne):
@@ -206,11 +207,17 @@ def get_parser(self, prog_name):
206207
help='Include all projects (admin only)',
207208
)
208209
parser.add_argument(
209-
'--long',
210-
action='store_true',
211-
default=False,
212-
help='List additional fields in output',
210+
'--project',
211+
metavar='<project-id>',
212+
help='Filter results by project (name or ID) (admin only)'
213213
)
214+
identity_common.add_project_domain_option_to_parser(parser)
215+
parser.add_argument(
216+
'--user',
217+
metavar='<user-id>',
218+
help='Filter results by user (name or ID) (admin only)'
219+
)
220+
identity_common.add_user_domain_option_to_parser(parser)
214221
parser.add_argument(
215222
'--name',
216223
metavar='<name>',
@@ -221,13 +228,20 @@ def get_parser(self, prog_name):
221228
metavar='<status>',
222229
help='Filter results by status',
223230
)
231+
parser.add_argument(
232+
'--long',
233+
action='store_true',
234+
default=False,
235+
help='List additional fields in output',
236+
)
224237
return parser
225238

226239
@utils.log_method(log)
227240
def take_action(self, parsed_args):
228241

229242
volume_client = self.app.client_manager.volume
230243
compute_client = self.app.client_manager.compute
244+
identity_client = self.app.client_manager.identity
231245

232246
def _format_attach(attachments):
233247
"""Return a formatted string of a volume's attached instances
@@ -282,8 +296,23 @@ def _format_attach(attachments):
282296
# Just forget it if there's any trouble
283297
pass
284298

299+
project_id = None
300+
if parsed_args.project:
301+
project_id = identity_common.find_project(
302+
identity_client,
303+
parsed_args.project,
304+
parsed_args.project_domain)
305+
306+
user_id = None
307+
if parsed_args.user:
308+
user_id = identity_common.find_project(identity_client,
309+
parsed_args.user,
310+
parsed_args.user_domain)
311+
285312
search_opts = {
286-
'all_projects': parsed_args.all_projects,
313+
'all_tenants': parsed_args.all_projects,
314+
'project_id': project_id,
315+
'user_id': user_id,
287316
'display_name': parsed_args.name,
288317
'status': parsed_args.status,
289318
}

0 commit comments

Comments
 (0)