#NEWLINE# def detect_external_network( self , tenant ) : #NEWLINE# #INDENT# neutron = self . neutron_admin_client #NEWLINE# routers = neutron . list_routers ( tenant_id = tenant . backend_id ) [ 'routers' ] #NEWLINE# if bool ( routers ) : #NEWLINE# #INDENT# router = routers [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . warning ( 'Tenant %s (PK: %s) does not have connected routers.' , tenant , tenant . pk ) #NEWLINE# return #NEWLINE# #UNINDENT# ext_gw = router . get ( 'external_gateway_info' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( 'network_id' in ext_gw ) : #NEWLINE# #INDENT# tenant . external_network_id = neutron [ 'network_id' ] #NEWLINE# tenant . save ( ) #NEWLINE# logger . info ( 'Found and set external network with id %s for tenant %s (PK: %s)' , ext_gw [ 'network_id' ] , tenant , tenant . pk )