def get_router_for_floatingip(self, context, internal_port,<EOL>internal_subnet, external_network_id):
gw_port = orm.aliased(models_v2.Port, name="<STR_LIT>")<EOL>routerport_qry = context.session.query(<EOL>RouterPort.router_id, models_v2.IPAllocation.ip_address).join(<EOL>models_v2.Port, models_v2.IPAllocation).filter(<EOL>models_v2.Port.network_id == internal_port['<STR_LIT>'],<EOL>RouterPort.port_type.in_(bc.constants.ROUTER_INTERFACE_OWNERS),<EOL>models_v2.IPAllocation.subnet_id == internal_subnet['<STR_LIT:id>']<EOL>).join(gw_port, gw_port.device_id == RouterPort.router_id).filter(<EOL>gw_port.network_id == external_network_id,<EOL>gw_port.device_owner == bc.constants.DEVICE_OWNER_ROUTER_GW<EOL>).distinct()<EOL>routerport_qry = routerport_qry.outerjoin(<EOL>RouterRedundancyBinding,<EOL>RouterRedundancyBinding.redundancy_router_id ==<EOL>RouterPort.router_id)<EOL>routerport_qry = routerport_qry.filter(<EOL>RouterRedundancyBinding.redundancy_router_id == expr.null())<EOL>first_router_id = None<EOL>for router_id, interface_ip in routerport_qry:<EOL><INDENT>if interface_ip == internal_subnet['<STR_LIT>']:<EOL><INDENT>return router_id<EOL><DEDENT>if not first_router_id:<EOL><INDENT>first_router_id = router_id<EOL><DEDENT><DEDENT>if first_router_id:<EOL><INDENT>return first_router_id<EOL><DEDENT>raise l3_exceptions.ExternalGatewayForFloatingIPNotFound(<EOL>subnet_id=internal_subnet['<STR_LIT:id>'],<EOL>external_network_id=external_network_id,<EOL>port_id=internal_port['<STR_LIT:id>'])<EOL>
We need to over-load this function so that we only return the
        user visible router and never its redundancy routers (as they never
        have floatingips associated with them).