@staticmethod
def _hold_ip(context, network_id, subnet_id, port_id, ip_address):
- alloc_qry = context.session.query(models_v2.IPAllocation)
+ alloc_qry = context.session.query(
+ models_v2.IPAllocation).with_lockmode('update')
allocated = alloc_qry.filter_by(network_id=network_id,
port_id=port_id,
ip_address=ip_address,
if network_id in getattr(context, '_recycled_networks', set()):
return
- expired_qry = context.session.query(models_v2.IPAllocation)
+ expired_qry = context.session.query(
+ models_v2.IPAllocation).with_lockmode('update')
expired_qry = expired_qry.filter_by(network_id=network_id,
port_id=None)
expired_qry = expired_qry.filter(
subnet.
"""
# Grab all allocation pools for the subnet
- pool_qry = context.session.query(models_v2.IPAllocationPool)
+ pool_qry = context.session.query(
+ models_v2.IPAllocationPool).with_lockmode('update')
allocation_pools = pool_qry.filter_by(subnet_id=subnet_id).all()
# Find the allocation pool for the IP to recycle
pool_id = None
# If 1 of the above holds true then the specific entry will be
# modified. If both hold true then the two ranges will be merged.
# If there are no entries then a single entry will be added.
- range_qry = context.session.query(models_v2.IPAvailabilityRange)
+ range_qry = context.session.query(
+ models_v2.IPAvailabilityRange).with_lockmode('update')
ip_first = str(netaddr.IPAddress(ip_address) + 1)
ip_last = str(netaddr.IPAddress(ip_address) - 1)
LOG.debug(_("Recycle %s"), ip_address)
# Delete the IP address from the IPAllocate table
LOG.debug(_("Delete allocated IP %(ip_address)s "
"(%(network_id)s/%(subnet_id)s)"), locals())
- alloc_qry = context.session.query(models_v2.IPAllocation)
+ alloc_qry = context.session.query(
+ models_v2.IPAllocation).with_lockmode('update')
allocated = alloc_qry.filter_by(network_id=network_id,
ip_address=ip_address,
subnet_id=subnet_id).delete()
"""
range_qry = context.session.query(
models_v2.IPAvailabilityRange).join(
- models_v2.IPAllocationPool)
+ models_v2.IPAllocationPool).with_lockmode('update')
for subnet in subnets:
range = range_qry.filter_by(subnet_id=subnet['id']).first()
if not range:
range_qry = context.session.query(
models_v2.IPAvailabilityRange,
models_v2.IPAllocationPool).join(
- models_v2.IPAllocationPool)
+ models_v2.IPAllocationPool).with_lockmode('update')
results = range_qry.filter_by(subnet_id=subnet_id).all()
for (range, pool) in results:
first = int(netaddr.IPAddress(range['first_ip']))
def _delete_port(self, context, id):
port = self._get_port(context, id)
- allocated_qry = context.session.query(models_v2.IPAllocation)
+ allocated_qry = context.session.query(
+ models_v2.IPAllocation).with_lockmode('update')
# recycle all of the IP's
allocated = allocated_qry.filter_by(port_id=id).all()
if allocated:
with session.begin(subtransactions=True):
state = (session.query(l2network_models_v2.NetworkState).
filter_by(allocated=False).
+ with_lockmode('update').
first())
if not state:
raise q_exc.NoNetworkAvailable()
state = (session.query(l2network_models_v2.NetworkState).
filter_by(physical_network=physical_network,
vlan_id=vlan_id).
+ with_lockmode('update').
one())
if state.allocated:
if vlan_id == constants.FLAT_VLAN_ID:
state = (session.query(l2network_models_v2.NetworkState).
filter_by(physical_network=physical_network,
vlan_id=vlan_id).
+ with_lockmode('update').
one())
state.allocated = False
inside = False
with session.begin(subtransactions=True):
alloc = (session.query(ovs_models_v2.VlanAllocation).
filter_by(allocated=False).
+ with_lockmode('update').
first())
if alloc:
LOG.debug(_("Reserving vlan %(vlan_id)s on physical network "
alloc = (session.query(ovs_models_v2.VlanAllocation).
filter_by(physical_network=physical_network,
vlan_id=vlan_id).
+ with_lockmode('update').
one())
if alloc.allocated:
if vlan_id == constants.FLAT_VLAN_ID:
alloc = (session.query(ovs_models_v2.VlanAllocation).
filter_by(physical_network=physical_network,
vlan_id=vlan_id).
+ with_lockmode('update').
one())
alloc.allocated = False
inside = False
try:
alloc = (session.query(ovs_models_v2.TunnelAllocation).
filter_by(tunnel_id=tunnel_id).
+ with_lockmode('update').
one())
return alloc
except exc.NoResultFound:
with session.begin(subtransactions=True):
alloc = (session.query(ovs_models_v2.TunnelAllocation).
filter_by(allocated=False).
+ with_lockmode('update').
first())
if alloc:
LOG.debug(_("Reserving tunnel %s from pool"), alloc.tunnel_id)
try:
alloc = (session.query(ovs_models_v2.TunnelAllocation).
filter_by(tunnel_id=tunnel_id).
+ with_lockmode('update').
one())
if alloc.allocated:
raise q_exc.TunnelIdInUse(tunnel_id=tunnel_id)
try:
alloc = (session.query(ovs_models_v2.TunnelAllocation).
filter_by(tunnel_id=tunnel_id).
+ with_lockmode('update').
one())
alloc.allocated = False
inside = False
session = db.get_session()
try:
tunnel = (session.query(ovs_models_v2.TunnelEndpoint).
- filter_by(ip_address=ip).one())
+ filter_by(ip_address=ip).with_lockmode('update').one())
except exc.NoResultFound:
id = _generate_tunnel_id(session)
tunnel = ovs_models_v2.TunnelEndpoint(ip, id)