Lock table in _try_generate_ip even if there's no free range

In _try_generate_ip if the pool is exhausted, the table won't be
locked since the query to get the first available range will
return None. Lock the table anyway to prevent cuncurrent operations
to rebuild the availability ranges.

Change-Id: I15e5800c6c1df2db4085b0942edc5f06f753e3a4
Closes-bug: #1364085