@@ -176,17 +176,6 @@ def json_request(method, url, **kwargs):
176
176
return resp , body
177
177
178
178
179
- def get_conn (options ):
180
- """
181
- Return a connection building it from the options.
182
- """
183
- return Connection (options .auth ,
184
- options .user ,
185
- options .key ,
186
- snet = options .snet ,
187
- auth_version = options .auth_version )
188
-
189
-
190
179
def _get_auth_v1_0 (url , user , key , snet ):
191
180
parsed , conn = http_connection (url )
192
181
conn .request ('GET' , parsed .path , '' ,
@@ -209,15 +198,10 @@ def _get_auth_v1_0(url, user, key, snet):
209
198
resp .getheader ('x-auth-token' ))
210
199
211
200
212
- def _get_auth_v2_0 (url , user , key , snet ):
213
- if ':' in user :
214
- tenant , user = user .split (':' )
215
- else :
216
- tenant = user
217
-
218
- body = {"auth" : {"tenantName" : tenant ,
219
- "passwordCredentials" :
220
- {"username" : user , "password" : key }}}
201
+ def _get_auth_v2_0 (url , user , tenant_name , key , snet ):
202
+ body = {'auth' : {'passwordCredentials' :
203
+ {'password' : key , 'username' : user },
204
+ 'tenantName' : tenant_name }}
221
205
token_url = urljoin (url , "tokens" )
222
206
resp , body = json_request ("POST" , token_url , body = body )
223
207
token_id = None
@@ -243,7 +227,7 @@ def _get_auth_v2_0(url, user, key, snet):
243
227
return url , token_id
244
228
245
229
246
- def get_auth (url , user , key , snet = False , auth_version = "1.0" ):
230
+ def get_auth (url , user , key , snet = False , tenant_name = None , auth_version = "1.0" ):
247
231
"""
248
232
Get authentication/authorization credentials.
249
233
@@ -257,14 +241,18 @@ def get_auth(url, user, key, snet=False, auth_version="1.0"):
257
241
:param user: user to authenticate as
258
242
:param key: key or password for authorization
259
243
:param snet: use SERVICENET internal network (see above), default is False
260
- :param auth_version: OpenStack authentication version (default is 1.0)
244
+ :param auth_version: OpenStack auth version, default is 1.0
245
+ :param tenant_name: The tenant/account name, required when connecting
246
+ to a auth 2.0 system.
261
247
:returns: tuple of (storage URL, auth token)
262
248
:raises: ClientException: HTTP GET request to auth URL failed
263
249
"""
264
250
if auth_version in ["1.0" , "1" ]:
265
251
return _get_auth_v1_0 (url , user , key , snet )
266
252
elif auth_version in ["2.0" , "2" ]:
267
- return _get_auth_v2_0 (url , user , key , snet )
253
+ if not tenant_name :
254
+ raise ClientException ('No tenant specified' )
255
+ return _get_auth_v2_0 (url , user , tenant_name , key , snet )
268
256
269
257
270
258
def get_account (url , token , marker = None , limit = None , prefix = None ,
@@ -818,17 +806,20 @@ class Connection(object):
818
806
819
807
def __init__ (self , authurl , user , key , retries = 5 , preauthurl = None ,
820
808
preauthtoken = None , snet = False , starting_backoff = 1 ,
809
+ tenant_name = None ,
821
810
auth_version = "1" ):
822
811
"""
823
- :param authurl: authenitcation URL
812
+ :param authurl: authentication URL
824
813
:param user: user name to authenticate as
825
814
:param key: key/password to authenticate with
826
815
:param retries: Number of times to retry the request before failing
827
816
:param preauthurl: storage URL (if you have already authenticated)
828
817
:param preauthtoken: authentication token (if you have already
829
818
authenticated)
830
819
:param snet: use SERVICENET internal network default is False
831
- :param auth_version: Openstack auth version.
820
+ :param auth_version: OpenStack auth version, default is 1.0
821
+ :param tenant_name: The tenant/account name, required when connecting
822
+ to a auth 2.0 system.
832
823
"""
833
824
self .authurl = authurl
834
825
self .user = user
@@ -841,9 +832,12 @@ class Connection(object):
841
832
self .snet = snet
842
833
self .starting_backoff = starting_backoff
843
834
self .auth_version = auth_version
835
+ self .tenant_name = tenant_name
844
836
845
837
def get_auth (self ):
846
- return get_auth (self .authurl , self .user , self .key , snet = self .snet ,
838
+ return get_auth (self .authurl , self .user ,
839
+ self .key , snet = self .snet ,
840
+ tenant_name = self .tenant_name ,
847
841
auth_version = self .auth_version )
848
842
849
843
def http_connection (self ):
@@ -971,6 +965,18 @@ class Connection(object):
971
965
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
972
966
973
967
968
+ def get_conn (options ):
969
+ """
970
+ Return a connection building it from the options.
971
+ """
972
+ return Connection (options .auth ,
973
+ options .user ,
974
+ options .key ,
975
+ snet = options .snet ,
976
+ tenant_name = options .os_tenant_name ,
977
+ auth_version = options .auth_version )
978
+
979
+
974
980
def mkdirs (path ):
975
981
try :
976
982
makedirs (path )
@@ -1931,6 +1937,9 @@ Example:
1931
1937
parser .add_option ('--os_username' , dest = 'os_username' ,
1932
1938
default = environ .get ('OS_USERNAME' ),
1933
1939
help = SUPPRESS_HELP )
1940
+ parser .add_option ('--os_tenant_name' , dest = 'os_tenant_name' ,
1941
+ default = environ .get ('OS_TENANT_NAME' ),
1942
+ help = SUPPRESS_HELP )
1934
1943
parser .add_option ('--os_password' , dest = 'os_password' ,
1935
1944
default = environ .get ('OS_PASSWORD' ),
1936
1945
help = SUPPRESS_HELP )
0 commit comments