Useful error msg when missing catalog (bug 949904)
Change-Id: I498e9b79e9739437b7e61997b37e84283b496561
This commit is contained in:
@@ -27,7 +27,16 @@ class ServiceCatalog(object):
|
|||||||
self.catalog = resource_dict
|
self.catalog = resource_dict
|
||||||
|
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
"""Fetch token details fron service catalog"""
|
"""Fetch token details fron service catalog.
|
||||||
|
|
||||||
|
Returns a dictionary containing the following::
|
||||||
|
|
||||||
|
- `id`: Token's ID
|
||||||
|
- `expires`: Token's expiration
|
||||||
|
- `user_id`: Authenticated user's ID
|
||||||
|
- `tenant_id`: Authorized project's ID
|
||||||
|
|
||||||
|
"""
|
||||||
token = {'id': self.catalog['token']['id'],
|
token = {'id': self.catalog['token']['id'],
|
||||||
'expires': self.catalog['token']['expires']}
|
'expires': self.catalog['token']['expires']}
|
||||||
try:
|
try:
|
||||||
@@ -46,6 +55,8 @@ class ServiceCatalog(object):
|
|||||||
a particular endpoint attribute. If no attribute is given, return
|
a particular endpoint attribute. If no attribute is given, return
|
||||||
the first endpoint of the specified type.
|
the first endpoint of the specified type.
|
||||||
|
|
||||||
|
Valid endpoint types: `publicURL`, `internalURL`, `adminURL`
|
||||||
|
|
||||||
See tests for a sample service catalog.
|
See tests for a sample service catalog.
|
||||||
"""
|
"""
|
||||||
catalog = self.catalog.get('serviceCatalog', [])
|
catalog = self.catalog.get('serviceCatalog', [])
|
||||||
@@ -62,7 +73,7 @@ class ServiceCatalog(object):
|
|||||||
raise exceptions.EndpointNotFound('Endpoint not found.')
|
raise exceptions.EndpointNotFound('Endpoint not found.')
|
||||||
|
|
||||||
def get_endpoints(self, service_type=None, endpoint_type=None):
|
def get_endpoints(self, service_type=None, endpoint_type=None):
|
||||||
"""Fetch and filter endpoints for the specified service(s)
|
"""Fetch and filter endpoints for the specified service(s).
|
||||||
|
|
||||||
Returns endpoints for the specified service (or all) and
|
Returns endpoints for the specified service (or all) and
|
||||||
that contain the specified type (or all).
|
that contain the specified type (or all).
|
||||||
|
@@ -76,10 +76,13 @@ class Client(client.HTTPClient):
|
|||||||
# extensions
|
# extensions
|
||||||
self.ec2 = ec2.CredentialsManager(self)
|
self.ec2 = ec2.CredentialsManager(self)
|
||||||
|
|
||||||
|
self.management_url = endpoint
|
||||||
if endpoint is None:
|
if endpoint is None:
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
else:
|
|
||||||
self.management_url = endpoint
|
def has_service_catalog(self):
|
||||||
|
"""Returns True if this client provides a service catalog."""
|
||||||
|
return hasattr(self, 'service_catalog')
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
""" Authenticate against the Keystone API.
|
""" Authenticate against the Keystone API.
|
||||||
|
@@ -20,9 +20,23 @@ import argparse
|
|||||||
from keystoneclient.v2_0 import client
|
from keystoneclient.v2_0 import client
|
||||||
from keystoneclient import utils
|
from keystoneclient import utils
|
||||||
|
|
||||||
|
|
||||||
CLIENT_CLASS = client.Client
|
CLIENT_CLASS = client.Client
|
||||||
|
|
||||||
|
|
||||||
|
def require_service_catalog(f):
|
||||||
|
msg = ('Configuration error: Client configured to run without a service '
|
||||||
|
'catalog. Run the client using --os-auth-url or OS_AUTH_URL, '
|
||||||
|
'instead of --os-endpoint or OS_SERVICE_ENDPOINT, for example.')
|
||||||
|
|
||||||
|
def wrapped(kc, args):
|
||||||
|
if not kc.has_service_catalog():
|
||||||
|
raise Exception(msg)
|
||||||
|
return f(kc, args)
|
||||||
|
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('--tenant-id', metavar='<tenant-id>',
|
@utils.arg('--tenant-id', metavar='<tenant-id>',
|
||||||
help='Tenant ID; lists all users if not specified')
|
help='Tenant ID; lists all users if not specified')
|
||||||
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
|
@utils.arg('--tenant_id', help=argparse.SUPPRESS)
|
||||||
@@ -332,6 +346,7 @@ def do_ec2_credentials_delete(kc, args):
|
|||||||
|
|
||||||
@utils.arg('--service', metavar='<service-type>', default=None,
|
@utils.arg('--service', metavar='<service-type>', default=None,
|
||||||
help='Service type to return')
|
help='Service type to return')
|
||||||
|
@require_service_catalog
|
||||||
def do_catalog(kc, args):
|
def do_catalog(kc, args):
|
||||||
"""List service catalog, possibly filtered by service."""
|
"""List service catalog, possibly filtered by service."""
|
||||||
endpoints = kc.service_catalog.get_endpoints(service_type=args.service)
|
endpoints = kc.service_catalog.get_endpoints(service_type=args.service)
|
||||||
@@ -352,6 +367,7 @@ def do_catalog(kc, args):
|
|||||||
help='Service attribute to match for selection')
|
help='Service attribute to match for selection')
|
||||||
@utils.arg('--value', metavar='<value>',
|
@utils.arg('--value', metavar='<value>',
|
||||||
help='Value of attribute to match')
|
help='Value of attribute to match')
|
||||||
|
@require_service_catalog
|
||||||
def do_endpoint_get(kc, args):
|
def do_endpoint_get(kc, args):
|
||||||
"""Find endpoint filtered by a specific attribute or service type"""
|
"""Find endpoint filtered by a specific attribute or service type"""
|
||||||
kwargs = {
|
kwargs = {
|
||||||
@@ -408,6 +424,7 @@ def do_endpoint_delete(kc, args):
|
|||||||
|
|
||||||
@utils.arg('--wrap', metavar='<integer>', default=0,
|
@utils.arg('--wrap', metavar='<integer>', default=0,
|
||||||
help='wrap PKI tokens to a specified length, or 0 to disable')
|
help='wrap PKI tokens to a specified length, or 0 to disable')
|
||||||
|
@require_service_catalog
|
||||||
def do_token_get(kc, args):
|
def do_token_get(kc, args):
|
||||||
"""Display the current user token"""
|
"""Display the current user token"""
|
||||||
utils.print_dict(kc.service_catalog.get_token(),
|
utils.print_dict(kc.service_catalog.get_token(),
|
||||||
|
Reference in New Issue
Block a user