Add support for listing servers of other projects

Added project and project-domain option to server list
command for listing servers based on project name or id

Co-Authored-By: Steve Martinelli <stevemar@ca.ibm.com>

Change-Id: Iaadfffe734ad8a72fa4b1eeb2222748c66f7fae0
Closes-Bug: #1488486
This commit is contained in:
Ashish Singh 2015-08-27 17:07:09 +05:30 committed by Dean Troyer
parent f14251669f
commit 66010b41f1
2 changed files with 28 additions and 0 deletions

View File

@ -185,6 +185,7 @@ List servers
[--image <image>]
[--host <hostname>]
[--all-projects]
[--project <project> [--project-domain <project-domain>]]
[--long]
.. option:: --reservation-id <reservation-id>
@ -227,6 +228,15 @@ List servers
Include all projects (admin only)
.. option:: --project <project>
Search by project (admin only) (name or ID)
.. 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:: --long
List additional fields in output

View File

@ -36,6 +36,7 @@ from openstackclient.common import exceptions
from openstackclient.common import parseractions
from openstackclient.common import utils
from openstackclient.i18n import _ # noqa
from openstackclient.identity import common as identity_common
from openstackclient.network import common
@ -693,6 +694,11 @@ class ListServer(lister.Lister):
default=bool(int(os.environ.get("ALL_PROJECTS", 0))),
help=_('Include all projects (admin only)'),
)
parser.add_argument(
'--project',
metavar='<project>',
help="Search by project (admin only) (name or ID)")
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--long',
action='store_true',
@ -704,6 +710,17 @@ class ListServer(lister.Lister):
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
compute_client = self.app.client_manager.compute
project_id = None
if parsed_args.project:
identity_client = self.app.client_manager.identity
project_id = identity_common.find_project(
identity_client,
parsed_args.project,
parsed_args.project_domain,
).id
parsed_args.all_projects = True
search_opts = {
'reservation_id': parsed_args.reservation_id,
'ip': parsed_args.ip,
@ -714,6 +731,7 @@ class ListServer(lister.Lister):
'flavor': parsed_args.flavor,
'image': parsed_args.image,
'host': parsed_args.host,
'tenant_id': project_id,
'all_tenants': parsed_args.all_projects,
}
self.log.debug('search options: %s', search_opts)