diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-02-16 09:05:17 -0800 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-02-16 13:23:23 -0800 |
commit | 0cc939c9040d9c35865603cc6806deaf6205004e (patch) | |
tree | 8f380550d0f464c3a44c14b846ba27d5c00b8578 /keystoneclient/service_catalog.py | |
parent | 0414cf1ef26517f1f18443bdcd1deb5ef4a47c11 (diff) | |
download | python-keystoneclient-0cc939c9040d9c35865603cc6806deaf6205004e.tar.gz |
Display token and service catalog for user
* Adds commands 'token', 'catalog' and 'endpoint-get' to keystone CLI
* Fixes bug 930421
Change-Id: I9eceea3bf98a5c87b122fa663c96f7119ef8d3cc
Diffstat (limited to 'keystoneclient/service_catalog.py')
-rw-r--r-- | keystoneclient/service_catalog.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/keystoneclient/service_catalog.py b/keystoneclient/service_catalog.py index 0e7cd88..91ac170 100644 --- a/keystoneclient/service_catalog.py +++ b/keystoneclient/service_catalog.py @@ -27,7 +27,15 @@ class ServiceCatalog(object): self.catalog = resource_dict def get_token(self): - return self.catalog['token']['id'] + """Fetch token details fron service catalog""" + token = {'id': self.catalog['token']['id'], + 'expires': self.catalog['token']['expires']} + try: + token['tenant'] = self.catalog['token']['tenant']['id'] + except: + # just leave the tenant out if it doesn't exist + pass + return token def url_for(self, attr=None, filter_value=None, service_type='identity', endpoint_type='publicURL'): @@ -47,7 +55,24 @@ class ServiceCatalog(object): endpoints = service['endpoints'] for endpoint in endpoints: - if not filter_value or endpoint[attr] == filter_value: + if not filter_value or endpoint.get(attr) == filter_value: return endpoint[endpoint_type] raise exceptions.EndpointNotFound('Endpoint not found.') + + def get_endpoints(self, service_type=None, endpoint_type=None): + """Fetch and filter endpoints for the specified service(s) + + Returns endpoints for the specified service (or all) and + that contain the specified type (or all). + """ + sc = {} + for service in self.catalog.get('serviceCatalog', []): + if service_type and service_type != service['type']: + continue + sc[service['type']] = [] + for endpoint in service['endpoints']: + if endpoint_type and endpoint_type not in endpoint.keys(): + continue + sc[service['type']].append(endpoint) + return sc |