use new session in keystone

Makes it use the new session in keystone to work with newer versions of
the python-*client modules.

Change-Id: Ia3fdee58039906a993fc8b1df8da6c25d4e8cdc8
Signed-off-by: Robert Marklund <robbelibobban@gmail.com>
This commit is contained in:
Robert Marklund 2017-01-25 16:41:14 +01:00
parent 2cc573d049
commit 4fd5712604
2 changed files with 14 additions and 40 deletions

View File

@ -47,22 +47,18 @@ class KeystoneManager(object):
self.auth_token = auth_token self.auth_token = auth_token
def authenticate(self): def authenticate(self):
self.client().authenticate()
self.auth_token = self.client().auth_token self.auth_token = self.client().auth_token
def client(self): def client(self):
if not self._client: if not self._client:
self._client = keystone_client.Client( from keystoneauth1.identity import v2
username=self.username, from keystoneauth1 import session
password=self.password, auth = v2.Password(auth_url=self.auth_url,
tenant_name=self.project, username=self.username,
auth_url=self.auth_url, password=self.password,
cert=self.cert, tenant_name=self.project,)
key=self.key, self.sess = session.Session(auth=auth)
region_name=self.region_name, self._client = keystone_client.Client(session=self.sess)
insecure=self.insecure,
endpoint_type=self.endpoint_type,
token=self.auth_token)
return self._client return self._client
def set_client(self, client): def set_client(self, client):
@ -76,7 +72,8 @@ class KeystoneManager(object):
return catalog[service_type][0][endpoint_type] return catalog[service_type][0][endpoint_type]
def get_project_id(self): def get_project_id(self):
return self.client().project_id self.client()
return self.sess.get_project_id()
class NeutronManager(object): class NeutronManager(object):
@ -89,11 +86,7 @@ class NeutronManager(object):
def client(self): def client(self):
if not self._client: if not self._client:
# Create the client # Create the client
self._client = neutron_client.Client( self._client = neutron_client.Client(session=self.keystone_mgr.sess)
auth_url=self.keystone_mgr.auth_url,
insecure=self.keystone_mgr.insecure,
endpoint_url=self.keystone_mgr.get_endpoint('network'),
token=self.keystone_mgr.auth_token)
if not self._project_id: if not self._project_id:
self._project_id = self.keystone_mgr.get_project_id() self._project_id = self.keystone_mgr.get_project_id()
return self._client return self._client
@ -146,15 +139,7 @@ class NovaManager(object):
if not self._client: if not self._client:
self._client = nova_client.Client( self._client = nova_client.Client(
'2', '2',
self.keystone_mgr.username, session=self.keystone_mgr.sess)
self.keystone_mgr.auth_token,
self.keystone_mgr.project,
self.keystone_mgr.auth_url,
region_name=self.keystone_mgr.region_name,
insecure=self.keystone_mgr.insecure,
endpoint_type=self.keystone_mgr.endpoint_type,
auth_token=self.keystone_mgr.auth_token
)
return self._client return self._client
def set_client(self, client): def set_client(self, client):
@ -195,20 +180,8 @@ class CinderManager(object):
def client(self): def client(self):
if self.defined and not self._client: if self.defined and not self._client:
try:
cinder_url = self.keystone_mgr.get_endpoint("volumev2")
except KeyError:
cinder_url = self.keystone_mgr.get_endpoint("volume")
client = cinder_client.Client( client = cinder_client.Client(
self.keystone_mgr.username, session=self.keystone_mgr.sess)
self.keystone_mgr.auth_token,
project_id=self.keystone_mgr.project,
auth_url=cinder_url,
http_log_debug=True,
insecure=self.keystone_mgr.insecure
)
client.client.auth_token = self.keystone_mgr.auth_token
client.client.management_url = cinder_url
self._client = client self._client = client
return self._client return self._client

View File

@ -3,6 +3,7 @@ Babel>=1.3
futures futures
netaddr>=0.7.12,!=0.7.16 netaddr>=0.7.12,!=0.7.16
keystoneauth>=0.5.0
python-keystoneclient python-keystoneclient
python-neutronclient python-neutronclient
python-novaclient python-novaclient