

def get_l3_agent_with_min_routers(self, context, agent_ids):
    'Return l3 agent with the least number of routers.'
    if (not agent_ids):
        return None
    query = context.session.query(agents_db.Agent, func.count(RouterL3AgentBinding.router_id).label('count')).outerjoin(RouterL3AgentBinding).group_by(agents_db.Agent.id, RouterL3AgentBinding.l3_agent_id).order_by('count')
    res = query.filter(agents_db.Agent.id.in_(agent_ids)).first()
    return res[0]

dataset/ETHPy150Open openstack/neutron/neutron/db/l3_agentschedulers_db.py L3AgentSchedulerDbMixin.get_l3_agent_with_min_routers/original