From dd2c91a7803a27dbce12b37f6bd70ab8d237445e Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Wed, 22 Mar 2017 09:51:06 +0800 Subject: [PATCH] support multi-tenants for resource list API Implement: blueprint resource-list-api Change-Id: I11c5fd26c6bca5d2d47900332ed5ae535dc7acc0 Signed-off-by: dongwenjuan --- vitrageclient/v1/cli/resource.py | 19 ++++++++++++++++--- vitrageclient/v1/resource.py | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/vitrageclient/v1/cli/resource.py b/vitrageclient/v1/cli/resource.py index 2a3b0a8..20969fa 100644 --- a/vitrageclient/v1/cli/resource.py +++ b/vitrageclient/v1/cli/resource.py @@ -36,14 +36,27 @@ class ResourceList(lister.Lister): def get_parser(self, prog_name): parser = super(ResourceList, self).get_parser(prog_name) - parser.add_argument('--type', dest='resource_type', + parser.add_argument('--type', + dest='resource_type', metavar='', help='Type of resource') + parser.add_argument('--all-tenants', + default=False, + dest='all_tenants', + action='store_true', + help='Shows resources of all the tenants') return parser def take_action(self, parsed_args): resource_type = parsed_args.resource_type + all_tenants = parsed_args.all_tenants resources = utils.get_client(self).resource.list( - resource_type=resource_type) - return [], resources + resource_type=resource_type, + all_tenants=all_tenants) + return utils.list2cols(('vitrage_id', + 'type', + 'name', + 'id', + 'state', + 'project_id'), resources) diff --git a/vitrageclient/v1/resource.py b/vitrageclient/v1/resource.py index 90f728f..20a7d06 100644 --- a/vitrageclient/v1/resource.py +++ b/vitrageclient/v1/resource.py @@ -17,12 +17,13 @@ class Resource(object): def __init__(self, api): self.api = api - def list(self, resource_type=None): + def list(self, resource_type=None, all_tenants=False): """Get a all resources :param resource_type: the type for the resources """ - params = dict(resource_type=resource_type) + params = dict(resource_type=resource_type, + all_tenants=all_tenants) return self.api.get(self.url, params=params).json() def get(self, resource_id):