#NEWLINE# def _get_router_for_floatingip( self , context , internal_port , internal_subnet_id , external_network_id ) : #NEWLINE# #INDENT# 'We need to over-load this function so that we only return the\n        user visible router and never its redundancy routers (as they never\n        have floatingips associated with them).\n        ' #NEWLINE# subnet = self . _core_plugin . _get_subnet ( context , internal_subnet_id ) #NEWLINE# if ( not subnet [ 'gateway_ip' ] ) : #NEWLINE# #INDENT# msg = ( _ ( 'Cannot add floating IP to port on subnet %s which has no gateway_ip' ) % internal_subnet_id ) #NEWLINE# raise n_exc . BadRequest ( resource = 'floatingip' , msg = msg ) #NEWLINE# #UNINDENT# gw_port = orm . aliased ( models_v2 . Port , name = 'gw_port' ) #NEWLINE# routerport_qry = context . session . query ( l3_db . RouterPort . router_id , models_v2 . IPAllocation . ip_address ) . join ( models_v2 . Port , models_v2 . IPAllocation ) . filter ( ( models_v2 . Port . network_id == internal_port [ 'network_id' ] ) , l3_db . RouterPort . port_type . in_ ( l3_constants . ROUTER_INTERFACE_OWNERS ) , ( models_v2 . IPAllocation . subnet_id == internal_subnet_id ) ) . join ( gw_port , ( gw_port . device_id == l3_db . RouterPort . router_id ) ) . filter ( ( gw_port . network_id == external_network_id ) ) . distinct ( ) #NEWLINE# routerport_qry = routerport_qry . outerjoin ( RouterRedundancyBinding , ( RouterRedundancyBinding . redundancy_router_id == l3_db . RouterPort . router_id ) ) #NEWLINE# routerport_qry = routerport_qry . filter ( ( RouterRedundancyBinding . redundancy_router_id == expr . null ( ) ) ) #NEWLINE# first_router_id = None #NEWLINE# for ( router_id , interface_ip ) in routerport_qry : #NEWLINE# #INDENT# if ( interface_ip == subnet [ 'gateway_ip' ] ) : #NEWLINE# #INDENT# return router_id #NEWLINE# #UNINDENT# if ( not first_router_id ) : #NEWLINE# #INDENT# first_router_id = router_id #NEWLINE# #UNINDENT# #UNINDENT# if first_router_id : #NEWLINE# #INDENT# return first_router_id #NEWLINE# #UNINDENT# raise l3 . ExternalGatewayForFloatingIPNotFound ( subnet_id = internal_subnet_id , external_network_id = external_network_id , port_id = internal_port [ 'id' ] )