Merge "Remove SELECT FOR UPDATE use in ML2 type driver release_segment"
This commit is contained in:
commit
6cd7c57aa0
@ -119,14 +119,12 @@ class FlatTypeDriver(api.TypeDriver):
|
|||||||
def release_segment(self, session, segment):
|
def release_segment(self, session, segment):
|
||||||
physical_network = segment[api.PHYSICAL_NETWORK]
|
physical_network = segment[api.PHYSICAL_NETWORK]
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
try:
|
count = (session.query(FlatAllocation).
|
||||||
alloc = (session.query(FlatAllocation).
|
|
||||||
filter_by(physical_network=physical_network).
|
filter_by(physical_network=physical_network).
|
||||||
with_lockmode('update').
|
delete())
|
||||||
one())
|
if count:
|
||||||
session.delete(alloc)
|
LOG.debug("Releasing flat network on physical network %s",
|
||||||
LOG.debug(_("Releasing flat network on physical "
|
physical_network)
|
||||||
"network %s"), physical_network)
|
else:
|
||||||
except sa.orm.exc.NoResultFound:
|
|
||||||
LOG.warning(_("No flat network found on physical network %s"),
|
LOG.warning(_("No flat network found on physical network %s"),
|
||||||
physical_network)
|
physical_network)
|
||||||
|
@ -108,23 +108,21 @@ class GreTypeDriver(type_tunnel.TunnelTypeDriver):
|
|||||||
|
|
||||||
def release_segment(self, session, segment):
|
def release_segment(self, session, segment):
|
||||||
gre_id = segment[api.SEGMENTATION_ID]
|
gre_id = segment[api.SEGMENTATION_ID]
|
||||||
|
|
||||||
|
inside = any(lo <= gre_id <= hi for lo, hi in self.gre_id_ranges)
|
||||||
|
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
try:
|
query = session.query(GreAllocation).filter_by(gre_id=gre_id)
|
||||||
alloc = (session.query(GreAllocation).
|
if inside:
|
||||||
filter_by(gre_id=gre_id).
|
count = query.update({"allocated": False})
|
||||||
with_lockmode('update').
|
if count:
|
||||||
one())
|
LOG.debug("Releasing gre tunnel %s to pool", gre_id)
|
||||||
alloc.allocated = False
|
|
||||||
for lo, hi in self.gre_id_ranges:
|
|
||||||
if lo <= gre_id <= hi:
|
|
||||||
LOG.debug(_("Releasing gre tunnel %s to pool"),
|
|
||||||
gre_id)
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
session.delete(alloc)
|
count = query.delete()
|
||||||
LOG.debug(_("Releasing gre tunnel %s outside pool"),
|
if count:
|
||||||
gre_id)
|
LOG.debug("Releasing gre tunnel %s outside pool", gre_id)
|
||||||
except sa_exc.NoResultFound:
|
|
||||||
|
if not count:
|
||||||
LOG.warning(_("gre_id %s not found"), gre_id)
|
LOG.warning(_("gre_id %s not found"), gre_id)
|
||||||
|
|
||||||
def _sync_gre_allocations(self):
|
def _sync_gre_allocations(self):
|
||||||
|
@ -235,32 +235,30 @@ class VlanTypeDriver(api.TypeDriver):
|
|||||||
def release_segment(self, session, segment):
|
def release_segment(self, session, segment):
|
||||||
physical_network = segment[api.PHYSICAL_NETWORK]
|
physical_network = segment[api.PHYSICAL_NETWORK]
|
||||||
vlan_id = segment[api.SEGMENTATION_ID]
|
vlan_id = segment[api.SEGMENTATION_ID]
|
||||||
|
|
||||||
|
ranges = self.network_vlan_ranges.get(physical_network, [])
|
||||||
|
inside = any(lo <= vlan_id <= hi for lo, hi in ranges)
|
||||||
|
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
try:
|
query = (session.query(VlanAllocation).
|
||||||
alloc = (session.query(VlanAllocation).
|
|
||||||
filter_by(physical_network=physical_network,
|
filter_by(physical_network=physical_network,
|
||||||
vlan_id=vlan_id).
|
vlan_id=vlan_id))
|
||||||
with_lockmode('update').
|
if inside:
|
||||||
one())
|
count = query.update({"allocated": False})
|
||||||
alloc.allocated = False
|
if count:
|
||||||
inside = False
|
LOG.debug("Releasing vlan %(vlan_id)s on physical "
|
||||||
for vlan_min, vlan_max in self.network_vlan_ranges.get(
|
"network %(physical_network)s to pool",
|
||||||
physical_network, []):
|
|
||||||
if vlan_min <= vlan_id <= vlan_max:
|
|
||||||
inside = True
|
|
||||||
break
|
|
||||||
if not inside:
|
|
||||||
session.delete(alloc)
|
|
||||||
LOG.debug(_("Releasing vlan %(vlan_id)s on physical "
|
|
||||||
"network %(physical_network)s outside pool"),
|
|
||||||
{'vlan_id': vlan_id,
|
{'vlan_id': vlan_id,
|
||||||
'physical_network': physical_network})
|
'physical_network': physical_network})
|
||||||
else:
|
else:
|
||||||
LOG.debug(_("Releasing vlan %(vlan_id)s on physical "
|
count = query.delete()
|
||||||
"network %(physical_network)s to pool"),
|
if count:
|
||||||
|
LOG.debug("Releasing vlan %(vlan_id)s on physical "
|
||||||
|
"network %(physical_network)s outside pool",
|
||||||
{'vlan_id': vlan_id,
|
{'vlan_id': vlan_id,
|
||||||
'physical_network': physical_network})
|
'physical_network': physical_network})
|
||||||
except sa.orm.exc.NoResultFound:
|
|
||||||
|
if not count:
|
||||||
LOG.warning(_("No vlan_id %(vlan_id)s found on physical "
|
LOG.warning(_("No vlan_id %(vlan_id)s found on physical "
|
||||||
"network %(physical_network)s"),
|
"network %(physical_network)s"),
|
||||||
{'vlan_id': vlan_id,
|
{'vlan_id': vlan_id,
|
||||||
|
@ -116,23 +116,24 @@ class VxlanTypeDriver(type_tunnel.TunnelTypeDriver):
|
|||||||
|
|
||||||
def release_segment(self, session, segment):
|
def release_segment(self, session, segment):
|
||||||
vxlan_vni = segment[api.SEGMENTATION_ID]
|
vxlan_vni = segment[api.SEGMENTATION_ID]
|
||||||
|
|
||||||
|
inside = any(lo <= vxlan_vni <= hi for lo, hi in self.vxlan_vni_ranges)
|
||||||
|
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
try:
|
query = (session.query(VxlanAllocation).
|
||||||
alloc = (session.query(VxlanAllocation).
|
filter_by(vxlan_vni=vxlan_vni))
|
||||||
filter_by(vxlan_vni=vxlan_vni).
|
if inside:
|
||||||
with_lockmode('update').
|
count = query.update({"allocated": False})
|
||||||
one())
|
if count:
|
||||||
alloc.allocated = False
|
LOG.debug("Releasing vxlan tunnel %s to pool",
|
||||||
for low, high in self.vxlan_vni_ranges:
|
|
||||||
if low <= vxlan_vni <= high:
|
|
||||||
LOG.debug(_("Releasing vxlan tunnel %s to pool"),
|
|
||||||
vxlan_vni)
|
vxlan_vni)
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
session.delete(alloc)
|
count = query.delete()
|
||||||
LOG.debug(_("Releasing vxlan tunnel %s outside pool"),
|
if count:
|
||||||
|
LOG.debug("Releasing vxlan tunnel %s outside pool",
|
||||||
vxlan_vni)
|
vxlan_vni)
|
||||||
except sa_exc.NoResultFound:
|
|
||||||
|
if not count:
|
||||||
LOG.warning(_("vxlan_vni %s not found"), vxlan_vni)
|
LOG.warning(_("vxlan_vni %s not found"), vxlan_vni)
|
||||||
|
|
||||||
def _sync_vxlan_allocations(self):
|
def _sync_vxlan_allocations(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user