Skip to content

Commit 70b3246

Browse files
author
Dean Troyer
committed
Add Identity to ClientManager
* Make the Identity client in identity.client.make_client() * Auth via ClientManager.identity * Skip extra auth roundtrip in compute client Change-Id: I0190639e38f83997c233195f6cc27ff3afdfba10
1 parent 5e40321 commit 70b3246

4 files changed

Lines changed: 39 additions & 17 deletions

File tree

‎openstackclient/common/clientmanager.py‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
from openstackclient.common import exceptions as exc
77
from openstackclient.compute import client as compute_client
8-
9-
from keystoneclient.v2_0 import client as keystone_client
8+
from openstackclient.identity import client as identity_client
109

1110
LOG = logging.getLogger(__name__)
1211

@@ -31,6 +30,9 @@ class ClientManager(object):
3130
"""Manages access to API clients, including authentication.
3231
"""
3332

33+
# Identity client is instantiated in init_token()
34+
# otherwise we have a recursion problem
35+
identity = None
3436
compute = ClientCache(compute_client.make_client)
3537

3638
def __init__(self, token=None, url=None,
@@ -82,24 +84,20 @@ def init_token(self):
8284
"You must provide an auth url via"
8385
" either --os-auth-url or via env[OS_AUTH_URL]")
8486

85-
kwargs = {
86-
'username': self._username,
87-
'password': self._password,
88-
'tenant_id': self._tenant_id,
89-
'tenant_name': self._tenant_name,
90-
'auth_url': self._auth_url
91-
}
92-
self._auth_client = keystone_client.Client(**kwargs)
93-
self._token = self._auth_client.auth_token
87+
# Get an Identity client and keep a token and catalog
88+
if not self.identity:
89+
self.identity = identity_client.make_client(self)
90+
self._token = self.identity.auth_token
91+
self._service_catalog = self.identity.service_catalog
9492
return
9593

9694
def get_endpoint_for_service_type(self, service_type):
9795
"""Return the endpoint URL for the service type.
9896
"""
9997
# See if we are using password flow auth, i.e. we have a
10098
# service catalog to select endpoints from
101-
if self._auth_client and self._auth_client.service_catalog:
102-
endpoint = self._auth_client.service_catalog.url_for(
99+
if self._service_catalog:
100+
endpoint = self._service_catalog.url_for(
103101
service_type=service_type)
104102
else:
105103
# Hope we were given the correct URL.

‎openstackclient/compute/client.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def make_client(instance):
99
"""Returns a compute service client.
1010
"""
1111
LOG.debug('instantiating compute client')
12-
# FIXME(dhellmann): Where is the endpoint value used?
13-
# url = instance.get_endpoint_for_service_type('compute')
1412
client = nova_client.Client(
1513
version=instance._compute_api_version,
1614
username=instance._username,
@@ -28,5 +26,10 @@ def make_client(instance):
2826
# FIXME(dhellmann): what is service_name?
2927
service_name='',
3028
)
31-
client.authenticate()
29+
30+
# Populate the Nova client to skip another auth query to Identity
31+
client.client.management_url = instance.get_endpoint_for_service_type(
32+
'compute')
33+
client.client.service_catalog = instance._service_catalog
34+
client.client.auth_token = instance._token
3235
return client

‎openstackclient/identity/client.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import logging
2+
3+
from keystoneclient.v2_0 import client as identity_client
4+
5+
LOG = logging.getLogger(__name__)
6+
7+
8+
def make_client(instance):
9+
"""Returns an identity service client.
10+
"""
11+
LOG.debug('instantiating identity client')
12+
client = identity_client.Client(
13+
username=instance._username,
14+
password=instance._password,
15+
tenant_name=instance._tenant_name,
16+
tenant_id=instance._tenant_id,
17+
auth_url=instance._auth_url,
18+
region_name=instance._region_name,
19+
)
20+
return client

‎tools/pip-requires‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ mock
66
prettytable
77
simplejson
88
-e git://github.com/openstack/python-keystoneclient.git#egg=python-keystoneclient
9-
-e git+https://github.com/openstack/python-novaclient.git#egg=python_novaclient
9+
-e git+https://github.com/openstack/python-novaclient.git#egg=python_novaclient
10+

0 commit comments

Comments
 (0)