'Check if the router scheduling is needed.
:raises: RouterHostedByL3Agent if router is already assigned
to a different agent.
:returns: True if scheduling is needed, otherwise False'

def check_agent_router_scheduling_needed(self, context, agent, router):

    router_id = router['id']
    agent_id = agent['id']
    bindings = rb_obj.RouterL3AgentBinding.get_objects(context, router_id=router_id)
    if (not bindings):
        return True
    for binding in bindings:
        if (binding.l3_agent_id == agent_id):
            return False
    if router.get('ha'):
        return True
    raise l3agentscheduler.RouterHostedByL3Agent(router_id=router_id, agent_id=bindings[0].l3_agent_id)
