Remove ClientManager._service_catalog
Anything that needs a service catalog can get it directly from auth_ref.service_catalog, no need to carry the extra attribute. ClientManager.get_endpoint_for_service_type() reamins the proper method to get an endpoint for clients that still need one directly. Change-Id: I809091c9c71d08f29606d7fd8b500898ff2cb8ae
This commit is contained in:
parent
0de67016c7
commit
2166d7d3af
@ -66,7 +66,6 @@ class ClientManager(object):
|
|||||||
self._auth_params = auth.build_auth_params(auth_options)
|
self._auth_params = auth.build_auth_params(auth_options)
|
||||||
self._region_name = auth_options.os_region_name
|
self._region_name = auth_options.os_region_name
|
||||||
self._api_version = api_version
|
self._api_version = api_version
|
||||||
self._service_catalog = None
|
|
||||||
self.timing = auth_options.timing
|
self.timing = auth_options.timing
|
||||||
|
|
||||||
# For compatibility until all clients can be updated
|
# For compatibility until all clients can be updated
|
||||||
@ -104,7 +103,6 @@ class ClientManager(object):
|
|||||||
if 'token' not in self._auth_params:
|
if 'token' not in self._auth_params:
|
||||||
LOG.debug("Get service catalog")
|
LOG.debug("Get service catalog")
|
||||||
self.auth_ref = self.auth.get_auth_ref(self.session)
|
self.auth_ref = self.auth.get_auth_ref(self.session)
|
||||||
self._service_catalog = self.auth_ref.service_catalog
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -112,12 +110,14 @@ class ClientManager(object):
|
|||||||
"""Return the endpoint URL for the service type."""
|
"""Return the endpoint URL for the service type."""
|
||||||
# See if we are using password flow auth, i.e. we have a
|
# See if we are using password flow auth, i.e. we have a
|
||||||
# service catalog to select endpoints from
|
# service catalog to select endpoints from
|
||||||
if self._service_catalog:
|
if self.auth_ref:
|
||||||
endpoint = self._service_catalog.url_for(
|
endpoint = self.auth_ref.service_catalog.url_for(
|
||||||
service_type=service_type, region_name=region_name)
|
service_type=service_type,
|
||||||
|
region_name=region_name,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# Hope we were given the correct URL.
|
# Get the passed endpoint directly from the auth plugin
|
||||||
endpoint = self._auth_url or self._url
|
endpoint = self.auth.get_endpoint(self.session)
|
||||||
return endpoint
|
return endpoint
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,27 +44,11 @@ def make_client(instance):
|
|||||||
API_VERSIONS)
|
API_VERSIONS)
|
||||||
LOG.debug('Instantiating identity client: %s', identity_client)
|
LOG.debug('Instantiating identity client: %s', identity_client)
|
||||||
|
|
||||||
# TODO(dtroyer): Something doesn't like the session.auth when using
|
LOG.debug('Using auth plugin: %s' % instance._auth_plugin)
|
||||||
# token auth, chase that down.
|
client = identity_client(
|
||||||
if instance._url:
|
session=instance.session,
|
||||||
LOG.debug('Using service token auth')
|
)
|
||||||
client = identity_client(
|
|
||||||
endpoint=instance._url,
|
|
||||||
token=instance._auth_params['token'],
|
|
||||||
cacert=instance._cacert,
|
|
||||||
insecure=instance._insecure
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
LOG.debug('Using auth plugin: %s' % instance._auth_plugin)
|
|
||||||
client = identity_client(
|
|
||||||
session=instance.session,
|
|
||||||
cacert=instance._cacert,
|
|
||||||
)
|
|
||||||
|
|
||||||
# TODO(dtroyer): the identity v2 role commands use this yet, fix that
|
|
||||||
# so we can remove it
|
|
||||||
if not instance._url:
|
|
||||||
instance.auth_ref = instance.auth.get_auth_ref(instance.session)
|
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,9 +141,10 @@ class ShowService(show.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
|
auth_ref = self.app.client_manager.auth_ref
|
||||||
|
|
||||||
if parsed_args.catalog:
|
if parsed_args.catalog:
|
||||||
endpoints = identity_client.service_catalog.get_endpoints(
|
endpoints = auth_ref.service_catalog.get_endpoints(
|
||||||
service_type=parsed_args.service)
|
service_type=parsed_args.service)
|
||||||
for (service, service_endpoints) in six.iteritems(endpoints):
|
for (service, service_endpoints) in six.iteritems(endpoints):
|
||||||
if service_endpoints:
|
if service_endpoints:
|
||||||
|
@ -40,11 +40,13 @@ def make_client(instance):
|
|||||||
API_VERSIONS)
|
API_VERSIONS)
|
||||||
LOG.debug('Instantiating image client: %s', image_client)
|
LOG.debug('Instantiating image client: %s', image_client)
|
||||||
|
|
||||||
if not instance._url:
|
endpoint = instance.get_endpoint_for_service_type(
|
||||||
instance._url = instance.get_endpoint_for_service_type(API_NAME)
|
API_NAME,
|
||||||
|
region_name=instance._region_name,
|
||||||
|
)
|
||||||
|
|
||||||
return image_client(
|
return image_client(
|
||||||
instance._url,
|
endpoint,
|
||||||
token=instance.auth.get_token(instance.session),
|
token=instance.auth.get_token(instance.session),
|
||||||
cacert=instance._cacert,
|
cacert=instance._cacert,
|
||||||
insecure=instance._insecure,
|
insecure=instance._insecure,
|
||||||
|
@ -34,16 +34,18 @@ def make_client(instance):
|
|||||||
API_VERSIONS)
|
API_VERSIONS)
|
||||||
LOG.debug('Instantiating network client: %s', network_client)
|
LOG.debug('Instantiating network client: %s', network_client)
|
||||||
|
|
||||||
if not instance._url:
|
endpoint = instance.get_endpoint_for_service_type(
|
||||||
instance._url = instance.get_endpoint_for_service_type(
|
API_NAME,
|
||||||
"network", region_name=instance._region_name)
|
region_name=instance._region_name,
|
||||||
|
)
|
||||||
|
|
||||||
return network_client(
|
return network_client(
|
||||||
username=instance._username,
|
username=instance._username,
|
||||||
tenant_name=instance._project_name,
|
tenant_name=instance._project_name,
|
||||||
password=instance._password,
|
password=instance._password,
|
||||||
region_name=instance._region_name,
|
region_name=instance._region_name,
|
||||||
auth_url=instance._auth_url,
|
auth_url=instance._auth_url,
|
||||||
endpoint_url=instance._url,
|
endpoint_url=endpoint,
|
||||||
token=instance.auth.get_token(instance.session),
|
token=instance.auth.get_token(instance.session),
|
||||||
insecure=instance._insecure,
|
insecure=instance._insecure,
|
||||||
ca_cert=instance._cacert,
|
ca_cert=instance._cacert,
|
||||||
|
@ -33,10 +33,10 @@ API_VERSIONS = {
|
|||||||
def make_client(instance):
|
def make_client(instance):
|
||||||
"""Returns an object-store API client."""
|
"""Returns an object-store API client."""
|
||||||
|
|
||||||
if instance._url:
|
endpoint = instance.get_endpoint_for_service_type(
|
||||||
endpoint = instance._url
|
'object-store',
|
||||||
else:
|
region_name=instance._region_name,
|
||||||
endpoint = instance.get_endpoint_for_service_type("object-store")
|
)
|
||||||
|
|
||||||
client = object_store_v1.APIv1(
|
client = object_store_v1.APIv1(
|
||||||
session=instance.session,
|
session=instance.session,
|
||||||
|
@ -157,7 +157,7 @@ class TestClientManager(utils.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
dir(SERVICE_CATALOG),
|
dir(SERVICE_CATALOG),
|
||||||
dir(client_manager._service_catalog),
|
dir(client_manager.auth_ref.service_catalog),
|
||||||
)
|
)
|
||||||
|
|
||||||
def stub_auth(self, json=None, url=None, verb=None, **kwargs):
|
def stub_auth(self, json=None, url=None, verb=None, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user