'Lock subnetpool associated row.
This method disallows to allocate concurrently 2 subnets in the same
subnetpool, it\'s required to ensure non-overlapping cidrs in the same
subnetpool.'

def _lock_subnetpool(self):

    with db_api.context_manager.reader.using(self._context):
        current_hash = self._context.session.query(models_v2.SubnetPool.hash).filter_by(id=self._subnetpool['id']).scalar()
    if (current_hash is None):
        raise n_exc.SubnetPoolNotFound(subnetpool_id=self._subnetpool['id'])
    new_hash = uuidutils.generate_uuid()
    with db_api.context_manager.writer.using(self._context):
        query = self._context.session.query(models_v2.SubnetPool).filter_by(id=self._subnetpool['id'], hash=current_hash)
        count = query.update({'hash': new_hash})
    if (not count):
        raise db_exc.RetryRequest(lib_exc.SubnetPoolInUse(subnet_pool_id=self._subnetpool['id']))
