support multi-tenants for resource list API

Implement: blueprint resource-list-api

Change-Id: I11c5fd26c6bca5d2d47900332ed5ae535dc7acc0
Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
This commit is contained in:
dongwenjuan 2017-03-22 09:51:06 +08:00
parent 1913f98d96
commit dd2c91a780
2 changed files with 19 additions and 5 deletions

View File

@ -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='<resource type>',
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)

View File

@ -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):