'Bind the router to the l3 agent which has been chosen.
The function tries to create a RouterL3AgentBinding object and add it
to the database. It returns the binding that was created or None if it
failed to create it due to some conflict.
In the HA router case, when creating a RouterL3AgentBinding (with some
binding_index) fails because some other RouterL3AgentBinding was
concurrently created using the same binding_index, then the function
will retry to create an entry with a new binding_index. This creation
will be retried up to db_api.MAX_RETRIES times.
If, still in the HA router case, the creation failed because the
router has already been bound to the l3 agent in question or has been
removed (by a concurrent operation), then no further attempts will be
made and the function will return None.
Note that for non-HA routers, the function will always perform exactly
one try, regardless of the error preventing the addition of a new
RouterL3AgentBinding object to the database.'

@db_api.retry_db_errors
def bind_router(self, plugin, context, router_id, agent_id, is_manual_scheduling=False, is_ha=False):

    if rb_obj.RouterL3AgentBinding.objects_exist(context, router_id=router_id, l3_agent_id=agent_id):
        LOG.debug('Router    %(router_id)s    has    already    been    scheduled    to    L3    agent    %(agent_id)s.', {'router_id': router_id, 'agent_id': agent_id})
        return
    if (not is_ha):
        binding_index = rb_model.LOWEST_BINDING_INDEX
        if rb_obj.RouterL3AgentBinding.objects_exist(context, router_id=router_id, binding_index=binding_index):
            LOG.debug('Non-HA    router    %s    has    already    been    scheduled', router_id)
            return
    else:
        binding_index = plugin.get_vacant_binding_index(context, router_id, is_manual_scheduling)
        if (binding_index < rb_model.LOWEST_BINDING_INDEX):
            LOG.debug('Unable    to    find    a    vacant    binding_index    for    router    %(router_id)s    and    agent    %(agent_id)s', {'router_id': router_id, 'agent_id': agent_id})
            return
    try:
        binding = rb_obj.RouterL3AgentBinding(context, l3_agent_id=agent_id, router_id=router_id, binding_index=binding_index)
        binding.create()
        LOG.debug('Router    %(router_id)s    is    scheduled    to    L3    agent    %(agent_id)s    with    binding_index    %(binding_index)d', {'router_id': router_id, 'agent_id': agent_id, 'binding_index': binding_index})
        return binding
    except db_exc.DBReferenceError:
        LOG.debug('Router    %s    has    already    been    removed    by    concurrent    operation', router_id)
