#NEWLINE# def obtain_port_correspondence( self ) : #NEWLINE# #INDENT# 'Obtain the correspondence between physical and openflow port names\n        return:\n             0, dictionary: with physical name as key, openflow name as value\n            -1, error_text: if fails\n        ' #NEWLINE# try : #NEWLINE# #INDENT# of_response = requests . get ( ( self . url + '/restconf/operational/opendaylight-inventory:nodes' ) , headers = self . headers ) #NEWLINE# error_text = ( 'Openflow response %d: %s' % ( of_response . status_code , of_response . text ) ) #NEWLINE# if ( of_response . status_code != 200 ) : #NEWLINE# #INDENT# self . logger . warning ( ( 'obtain_port_correspondence ' + error_text ) ) #NEWLINE# return ( ( - 1 ) , error_text ) #NEWLINE# #UNINDENT# self . logger . debug ( ( 'obtain_port_correspondence ' + error_text ) ) #NEWLINE# info = of_response . json ( ) #NEWLINE# if ( type ( info ) != dict ) : #NEWLINE# #INDENT# self . logger . error ( 'obtain_port_correspondence. Unexpected response not a dict: %s' , str ( info ) ) #NEWLINE# return ( ( - 1 ) , 'Unexpected openflow response, not a dict. Wrong version?' ) #NEWLINE# #UNINDENT# nodes = info . get ( 'nodes' ) #NEWLINE# if ( type ( nodes ) is not dict ) : #NEWLINE# #INDENT# self . logger . error ( "obtain_port_correspondence. Unexpected response at 'nodes', not found or not a dict: %s" , str ( type ( nodes ) ) ) #NEWLINE# return ( ( - 1 ) , "Unexpected response at 'nodes',not found or not a dict. Wrong version?" ) #NEWLINE# #UNINDENT# node_list = nodes . get ( 'node' ) #NEWLINE# if ( type ( node_list ) is not list ) : #NEWLINE# #INDENT# self . logger . error ( "obtain_port_correspondence. Unexpected response, at 'nodes':'node', not found or not a list: %s" , str ( type ( node_list ) ) ) #NEWLINE# return ( ( - 1 ) , "Unexpected response, at 'nodes':'node', not found or not a list. Wrong version?" ) #NEWLINE# #UNINDENT# for node in node_list : #NEWLINE# #INDENT# node_id = node . get ( 'id' ) #NEWLINE# if ( node_id is None ) : #NEWLINE# #INDENT# self . logger . error ( "obtain_port_correspondence. Unexpected response at 'nodes':'node'[]:'id', not found: %s" , str ( node ) ) #NEWLINE# return ( ( - 1 ) , "Unexpected response at 'nodes':'node'[]:'id', not found . Wrong version?" ) #NEWLINE# #UNINDENT# if ( node_id == 'controller-config' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( self . id != node_id ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# node_connector_list = node . get ( 'node-connector' ) #NEWLINE# if ( type ( node_connector_list ) is not list ) : #NEWLINE# #INDENT# self . logger . error ( "obtain_port_correspondence. Unexpected response at 'nodes':'node'[]:'node-connector', not found or not a list: %s" , str ( node ) ) #NEWLINE# return ( ( - 1 ) , "Unexpected response at 'nodes':'node'[]:'node-connector', not found  or not a list. Wrong version?" ) #NEWLINE# #UNINDENT# for node_connector in node_connector_list : #NEWLINE# #INDENT# self . pp2ofi [ str ( node_connector [ 'flow-node-inventory:name' ] ) ] = str ( node_connector [ 'id' ] ) #NEWLINE# self . ofi2pp [ node_connector [ 'id' ] ] = str ( node_connector [ 'flow-node-inventory:name' ] ) #NEWLINE# #UNINDENT# node_ip_address = node . get ( 'flow-node-inventory:ip-address' ) #NEWLINE# if ( node_ip_address is None ) : #NEWLINE# #INDENT# self . logger . error ( "obtain_port_correspondence. Unexpected response at 'nodes':'node'[]:'flow-node-inventory:ip-address', not found: %s" , str ( node ) ) #NEWLINE# return ( ( - 1 ) , "Unexpected response at 'nodes':'node'[]:'flow-node-inventory:ip-address', not found. Wrong version?" ) #NEWLINE# #UNINDENT# self . ip_address = node_ip_address #NEWLINE# break #NEWLINE# #UNINDENT# return ( 0 , self . pp2ofi ) #NEWLINE# #UNINDENT# except ( requests . exceptions . RequestException , ValueError ) as e : #NEWLINE# #INDENT# error_text = ( ( type ( e ) . __name__ + ': ' ) + str ( e ) ) #NEWLINE# self . logger . error ( ( 'obtain_port_correspondence ' + error_text ) ) #NEWLINE# return ( ( - 1 ) , error_text )