Merge "Add filtering by project/user for 'openstack volume list'"

This commit is contained in:
Jenkins 2015-10-17 01:46:31 +00:00 committed by Gerrit Code Review
commit 6fdc9a891f
2 changed files with 58 additions and 11 deletions

View File

@ -102,22 +102,40 @@ List volumes
.. code:: bash .. code:: bash
os volume list os volume list
[--status <status>]
[--name <name>]
[--all-projects] [--all-projects]
[--project <project> [--project-domain <project-domain>]]
[--user <user> [--user-domain <user-domain>]]
[--name <name>]
[--status <status>]
[--long] [--long]
.. option:: --status <status> .. option:: --all-projects
Filter results by status .. option:: --project <project>
Filter results by project (name or ID) (admin only)
.. option:: --project-domain <project-domain>
Domain the project belongs to (name or ID).
This can be used in case collisions between project names exist.
.. option:: --user <user>
Filter results by user (name or ID) (admin only)
.. option:: --user-domain <user-domain>
Domain the user belongs to (name or ID).
This can be used in case collisions between user names exist.
.. option:: --name <name> .. option:: --name <name>
Filter results by name Filter results by name
.. option:: --all-projects .. option:: --status <status>
Include all projects (admin only) Filter results by status
.. option:: --long .. option:: --long

View File

@ -25,6 +25,7 @@ import six
from openstackclient.common import parseractions from openstackclient.common import parseractions
from openstackclient.common import utils from openstackclient.common import utils
from openstackclient.identity import common as identity_common
class CreateVolume(show.ShowOne): class CreateVolume(show.ShowOne):
@ -206,11 +207,17 @@ class ListVolume(lister.Lister):
help='Include all projects (admin only)', help='Include all projects (admin only)',
) )
parser.add_argument( parser.add_argument(
'--long', '--project',
action='store_true', metavar='<project-id>',
default=False, help='Filter results by project (name or ID) (admin only)'
help='List additional fields in output',
) )
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--user',
metavar='<user-id>',
help='Filter results by user (name or ID) (admin only)'
)
identity_common.add_user_domain_option_to_parser(parser)
parser.add_argument( parser.add_argument(
'--name', '--name',
metavar='<name>', metavar='<name>',
@ -221,6 +228,12 @@ class ListVolume(lister.Lister):
metavar='<status>', metavar='<status>',
help='Filter results by status', help='Filter results by status',
) )
parser.add_argument(
'--long',
action='store_true',
default=False,
help='List additional fields in output',
)
return parser return parser
@utils.log_method(log) @utils.log_method(log)
@ -228,6 +241,7 @@ class ListVolume(lister.Lister):
volume_client = self.app.client_manager.volume volume_client = self.app.client_manager.volume
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.compute
identity_client = self.app.client_manager.identity
def _format_attach(attachments): def _format_attach(attachments):
"""Return a formatted string of a volume's attached instances """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 # Just forget it if there's any trouble
pass 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 = { 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, 'display_name': parsed_args.name,
'status': parsed_args.status, 'status': parsed_args.status,
} }