#NEWLINE# def _v2_auth( self , token_url ) : #NEWLINE# #INDENT# def get_endpoint( service_catalog ) : #NEWLINE# #INDENT# '\n            Select an endpoint from the service catalog\n\n            We search the full service catalog for services\n            matching both type and region. If the client\n            supplied no region then any endpoint for the service\n            is considered a match. There must be one -- and\n            only one -- successful match in the catalog,\n            otherwise we will raise an exception.\n            ' #NEWLINE# region = self . creds . get ( 'region' ) #NEWLINE# service_type_matches = ( lambda s : ( s . get ( 'type' ) == self . service_type ) ) #NEWLINE# region_matches = ( lambda e : ( ( region is None ) or ( e [ 'region' ] == region ) ) ) #NEWLINE# endpoints = [ ep for s in service_catalog if service_type_matches ( s ) for ep in s [ 'endpoints' ] if region_matches ( ep ) ] #NEWLINE# if ( len ( endpoints ) > 1 ) : #NEWLINE# #INDENT# raise exception . RegionAmbiguity ( region = region ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not endpoints ) : #NEWLINE# #INDENT# raise exception . NoServiceEndpoint ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return endpoints [ 0 ] [ 'publicURL' ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# 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# self . management_url = get_endpoint ( resp_auth [ 'serviceCatalog' ] ) #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# try : #NEWLINE# #INDENT# body = json . loads ( resp_body ) #NEWLINE# msg = body [ 'error' ] [ 'message' ] #NEWLINE# #UNINDENT# except ( ValueError , KeyError ) : #NEWLINE# #INDENT# msg = resp_body #NEWLINE# #UNINDENT# raise exception . KeystoneError ( resp . status , msg )