enable_eagerloads(False).filter_by(id=id))
if not context.is_admin:
query = query.filter_by(tenant_id=context.tenant_id)
- port = query.with_lockmode('update').one()
-
- 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)
- for a in allocated:
- subnet = self._get_subnet(context, a['subnet_id'])
- # Check if IP was allocated from allocation pool
- if NeutronDbPluginV2._check_ip_in_allocation_pool(
- context, a['subnet_id'], subnet['gateway_ip'],
- a['ip_address']):
- NeutronDbPluginV2._delete_ip_allocation(context,
- a['network_id'],
- a['subnet_id'],
- a['ip_address'])
- else:
- # IPs out of allocation pool will not be recycled, but
- # we do need to delete the allocation from the DB
- NeutronDbPluginV2._delete_ip_allocation(
- context, a['network_id'],
- a['subnet_id'], a['ip_address'])
- msg_dict = {'address': a['ip_address'],
- 'subnet_id': a['subnet_id']}
- msg = _("%(address)s (%(subnet_id)s) is not "
- "recycled") % msg_dict
- LOG.debug(msg)
-
- context.session.delete(port)
+ query.delete()
def get_port(self, context, id, fields=None):
port = self._get_port(context, id)
if vpnservice:
vpnservice.check_router_in_use(context, id)
- # delete any gw port
+ context.session.delete(router)
+
+ # Delete the gw port after the router has been removed to
+ # avoid a constraint violation.
device_filter = {'device_id': [id],
'device_owner': [DEVICE_OWNER_ROUTER_GW]}
ports = self._core_plugin.get_ports(context.elevated(),
self._core_plugin._delete_port(context.elevated(),
ports[0]['id'])
- context.session.delete(router)
self.l3_rpc_notifier.router_deleted(context, id)
def get_router(self, context, id, fields=None):