diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index eb61bab549..b00b94479d 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -185,6 +185,7 @@ List servers [--image ] [--host ] [--all-projects] + [--project [--project-domain ]] [--long] .. option:: --reservation-id @@ -227,6 +228,15 @@ List servers Include all projects (admin only) +.. option:: --project + + Search by project (admin only) (name or ID) + +.. option:: --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 diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 4efef975bb..a246a04d2a 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -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='', + 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)