#NEWLINE# def _v2_auth( self , token_url ) : #NEWLINE# #INDENT# creds = self . creds #NEWLINE# creds = { #NEWLINE# #INDENT# 'auth' : { #NEWLINE# #INDENT# 'tenantName' : creds [ 'tenant' ] , #NEWLINE# 'passwordCredentials' : { #NEWLINE# #INDENT# 'username' : creds [ 'username' ] , #NEWLINE# 'password' : creds [ 'password' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# headers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# headers [ 'Content-Type' ] = 'application/json' #NEWLINE# req_body = json . dumps ( creds ) #NEWLINE# ( resp , resp_body ) = self . _do_request ( token_url , 'POST' , headers = headers , body = req_body ) #NEWLINE# if ( resp . status == 200 ) : #NEWLINE# #INDENT# resp_auth = json . loads ( resp_body ) [ 'access' ] #NEWLINE# for service in resp_auth [ 'serviceCatalog' ] : #NEWLINE# #INDENT# if ( service [ 'name' ] == 'glance' ) : #NEWLINE# #INDENT# glance_endpoint = service [ 'endpoints' ] [ 0 ] [ 'publicURL' ] #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise exception . NoServiceEndpoint ( ) #NEWLINE# #UNINDENT# self . management_url = glance_endpoint #NEWLINE# self . auth_token = resp_auth [ 'token' ] [ 'id' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( resp . status == 305 ) : #NEWLINE# #INDENT# raise exception . RedirectException ( resp [ 'location' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( resp . status == 400 ) : #NEWLINE# #INDENT# raise exception . AuthBadRequest ( url = token_url ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( resp . status == 401 ) : #NEWLINE# #INDENT# raise exception . NotAuthorized ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( resp . status == 404 ) : #NEWLINE# #INDENT# raise exception . AuthUrlNotFound ( url = token_url ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( ( _ ( 'Unexpected response: %s' ) % resp . status ) )