Skip to content

Commit 2166d7d

Browse files
author
Dean Troyer
committed
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
1 parent 0de6701 commit 2166d7d

7 files changed

Lines changed: 29 additions & 40 deletions

File tree

openstackclient/common/clientmanager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def __init__(self, auth_options, api_version=None, verify=True):
6666
self._auth_params = auth.build_auth_params(auth_options)
6767
self._region_name = auth_options.os_region_name
6868
self._api_version = api_version
69-
self._service_catalog = None
7069
self.timing = auth_options.timing
7170

7271
# For compatibility until all clients can be updated
@@ -104,20 +103,21 @@ def __init__(self, auth_options, api_version=None, verify=True):
104103
if 'token' not in self._auth_params:
105104
LOG.debug("Get service catalog")
106105
self.auth_ref = self.auth.get_auth_ref(self.session)
107-
self._service_catalog = self.auth_ref.service_catalog
108106

109107
return
110108

111109
def get_endpoint_for_service_type(self, service_type, region_name=None):
112110
"""Return the endpoint URL for the service type."""
113111
# See if we are using password flow auth, i.e. we have a
114112
# service catalog to select endpoints from
115-
if self._service_catalog:
116-
endpoint = self._service_catalog.url_for(
117-
service_type=service_type, region_name=region_name)
113+
if self.auth_ref:
114+
endpoint = self.auth_ref.service_catalog.url_for(
115+
service_type=service_type,
116+
region_name=region_name,
117+
)
118118
else:
119-
# Hope we were given the correct URL.
120-
endpoint = self._auth_url or self._url
119+
# Get the passed endpoint directly from the auth plugin
120+
endpoint = self.auth.get_endpoint(self.session)
121121
return endpoint
122122

123123

openstackclient/identity/client.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,11 @@ def make_client(instance):
4444
API_VERSIONS)
4545
LOG.debug('Instantiating identity client: %s', identity_client)
4646

47-
# TODO(dtroyer): Something doesn't like the session.auth when using
48-
# token auth, chase that down.
49-
if instance._url:
50-
LOG.debug('Using service token auth')
51-
client = identity_client(
52-
endpoint=instance._url,
53-
token=instance._auth_params['token'],
54-
cacert=instance._cacert,
55-
insecure=instance._insecure
56-
)
57-
else:
58-
LOG.debug('Using auth plugin: %s' % instance._auth_plugin)
59-
client = identity_client(
60-
session=instance.session,
61-
cacert=instance._cacert,
62-
)
47+
LOG.debug('Using auth plugin: %s' % instance._auth_plugin)
48+
client = identity_client(
49+
session=instance.session,
50+
)
6351

64-
# TODO(dtroyer): the identity v2 role commands use this yet, fix that
65-
# so we can remove it
66-
if not instance._url:
67-
instance.auth_ref = instance.auth.get_auth_ref(instance.session)
6852
return client
6953

7054

openstackclient/identity/v2_0/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ def get_parser(self, prog_name):
141141
def take_action(self, parsed_args):
142142
self.log.debug('take_action(%s)', parsed_args)
143143
identity_client = self.app.client_manager.identity
144+
auth_ref = self.app.client_manager.auth_ref
144145

145146
if parsed_args.catalog:
146-
endpoints = identity_client.service_catalog.get_endpoints(
147+
endpoints = auth_ref.service_catalog.get_endpoints(
147148
service_type=parsed_args.service)
148149
for (service, service_endpoints) in six.iteritems(endpoints):
149150
if service_endpoints:

openstackclient/image/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ def make_client(instance):
4040
API_VERSIONS)
4141
LOG.debug('Instantiating image client: %s', image_client)
4242

43-
if not instance._url:
44-
instance._url = instance.get_endpoint_for_service_type(API_NAME)
43+
endpoint = instance.get_endpoint_for_service_type(
44+
API_NAME,
45+
region_name=instance._region_name,
46+
)
4547

4648
return image_client(
47-
instance._url,
49+
endpoint,
4850
token=instance.auth.get_token(instance.session),
4951
cacert=instance._cacert,
5052
insecure=instance._insecure,

openstackclient/network/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ def make_client(instance):
3434
API_VERSIONS)
3535
LOG.debug('Instantiating network client: %s', network_client)
3636

37-
if not instance._url:
38-
instance._url = instance.get_endpoint_for_service_type(
39-
"network", region_name=instance._region_name)
37+
endpoint = instance.get_endpoint_for_service_type(
38+
API_NAME,
39+
region_name=instance._region_name,
40+
)
41+
4042
return network_client(
4143
username=instance._username,
4244
tenant_name=instance._project_name,
4345
password=instance._password,
4446
region_name=instance._region_name,
4547
auth_url=instance._auth_url,
46-
endpoint_url=instance._url,
48+
endpoint_url=endpoint,
4749
token=instance.auth.get_token(instance.session),
4850
insecure=instance._insecure,
4951
ca_cert=instance._cacert,

openstackclient/object/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
def make_client(instance):
3434
"""Returns an object-store API client."""
3535

36-
if instance._url:
37-
endpoint = instance._url
38-
else:
39-
endpoint = instance.get_endpoint_for_service_type("object-store")
36+
endpoint = instance.get_endpoint_for_service_type(
37+
'object-store',
38+
region_name=instance._region_name,
39+
)
4040

4141
client = object_store_v1.APIv1(
4242
session=instance.session,

openstackclient/tests/common/test_clientmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_client_manager_password(self):
157157
)
158158
self.assertEqual(
159159
dir(SERVICE_CATALOG),
160-
dir(client_manager._service_catalog),
160+
dir(client_manager.auth_ref.service_catalog),
161161
)
162162

163163
def stub_auth(self, json=None, url=None, verb=None, **kwargs):

0 commit comments

Comments
 (0)