@@ -41,6 +41,7 @@ def __init__(self, user, apikey, tenant, auth_url, service_name,
4141 service_url = None , timeout = None ):
4242 super (ReddwarfHTTPClient , self ).__init__ (user , apikey , tenant ,
4343 auth_url , timeout = timeout )
44+ self .api_key = apikey
4445 self .tenant = tenant
4546 self .service = service_name
4647 self .management_url = service_url
@@ -55,14 +56,15 @@ def authenticate(self):
5556
5657 # Auth against Keystone version 2.0
5758 if self .version == "v2.0" :
58- req_body = {'passwordCredentials' : {'username' : self .user ,
59- 'password' : self .apikey ,
60- 'tenantId' : self .tenant }}
59+ req_body = {'auth' : {'passwordCredentials' :
60+ {'username' : self .user ,
61+ 'password' : self .api_key },
62+ 'tenantName' : self .tenant }}
6163 self ._get_token ("/v2.0/tokens" , req_body )
6264 # Auth against Keystone version 1.1
6365 elif self .version == "v1.1" :
6466 req_body = {'credentials' : {'username' : self .user ,
65- 'key' : self .apikey }}
67+ 'key' : self .api_key }}
6668 self ._get_token ("/v1.1/auth" , req_body )
6769 else :
6870 raise NotImplementedError ("Version %s is not supported"
@@ -72,14 +74,24 @@ def _get_token(self, path, req_body):
7274 """Set the management url and auth token"""
7375 token_url = urlparse .urljoin (self .auth_url , path )
7476 resp , body = self .request (token_url , "POST" , body = req_body )
75- try :
77+ if 'access' in body :
7678 if not self .management_url :
77- self .management_url = body ['auth' ]['serviceCatalog' ] \
78- [self .service ][0 ]['publicURL' ]
79- self .auth_token = body ['auth' ]['token' ]['id' ]
80- except KeyError :
81- raise NotImplementedError ("Service: %s is not available"
82- % self .service )
79+ # Assume the new Keystone lite:
80+ catalog = body ['access' ]['serviceCatalog' ]
81+ for service in catalog :
82+ if service ['name' ] == self .service :
83+ self .management_url = service ['adminURL' ]
84+ self .auth_token = body ['access' ]['token' ]['id' ]
85+ else :
86+ # Assume pre-Keystone Light:
87+ try :
88+ if not self .management_url :
89+ self .management_url = body ['auth' ]['serviceCatalog' ] \
90+ [self .service ][0 ]['publicURL' ]
91+ self .auth_token = body ['auth' ]['token' ]['id' ]
92+ except KeyError :
93+ raise NotImplementedError ("Service: %s is not available"
94+ % self .service )
8395
8496
8597class Dbaas (Client ):
@@ -101,10 +113,10 @@ class Dbaas(Client):
101113 &c.
102114 """
103115
104- def __init__ (self , username , apikey , tenant = None , auth_url = None ,
116+ def __init__ (self , username , api_key , tenant = None , auth_url = None ,
105117 service_name = 'reddwarf' , service_url = None ):
106- super (Dbaas , self ).__init__ (self , username , apikey , tenant , auth_url )
107- self .client = ReddwarfHTTPClient (username , apikey , tenant , auth_url ,
118+ super (Dbaas , self ).__init__ (self , username , api_key , tenant , auth_url )
119+ self .client = ReddwarfHTTPClient (username , api_key , tenant , auth_url ,
108120 service_name , service_url )
109121 self .versions = Versions (self )
110122 self .databases = Databases (self )
0 commit comments