allocated = allocated_qry.filter_by(subnet_id=id).all()
if allocated:
raise q_exc.SubnetInUse(subnet_id=id)
- # Delete IP Allocations on subnet
- range_qry = context.session.query(models_v2.IPAllocationRange)
- range_qry.filter_by(subnet_id=id).delete()
context.session.delete(subnet)
def get_subnet(self, context, id, fields=None, verbose=None):
"""
allocation_pool_id = sa.Column(sa.String(36),
- sa.ForeignKey('ipallocationpools.id'),
+ sa.ForeignKey('ipallocationpools.id',
+ ondelete="CASCADE"),
nullable=True,
primary_key=True)
first_ip = sa.Column(sa.String(64), nullable=False, primary_key=True)
class IPAllocationPool(model_base.BASEV2, HasId):
"""Representation of an allocation pool in a Quantum subnet."""
- subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id'),
+ subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id',
+ ondelete="CASCADE"),
nullable=True)
first_ip = sa.Column(sa.String(64), nullable=False)
last_ip = sa.Column(sa.String(64), nullable=False)
class IPAllocation(model_base.BASEV2):
"""Internal representation of allocated IP addresses in a Quantum subnet.
"""
- port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id'),
+ port_id = sa.Column(sa.String(36), sa.ForeignKey('ports.id',
+ ondelete="CASCADE"),
nullable=False, primary_key=True)
ip_address = sa.Column(sa.String(64), nullable=False, primary_key=True)
- subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id'),
+ subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id',
+ ondelete="CASCADE"),
nullable=False, primary_key=True)
- network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id"),
+ network_id = sa.Column(sa.String(36), sa.ForeignKey("networks.id",
+ ondelete="CASCADE"),
nullable=False, primary_key=True)
def delete_network(self, context, id):
vlan_binding = cdb.get_vlan_binding(id)
- cdb.release_vlanid(vlan_binding[const.VLANID])
+ cdb.release_vlanid(vlan_binding['vlan_id'])
cdb.remove_vlan_binding(id)
return super(LinuxBridgePluginV2, self).delete_network(context, id)
self._test_create_subnet(gateway_ip=gateway_ip,
cidr=cidr)
+ def test_delete_subnet(self):
+ gateway_ip = '10.0.0.1'
+ cidr = '10.0.0.0/24'
+ fmt = 'json'
+ # Create new network
+ res = self._create_network(fmt=fmt, name='net',
+ admin_status_up=True)
+ network = self.deserialize(fmt, res)
+ subnet = self._make_subnet(fmt, network, gateway_ip,
+ cidr, ip_version=4)
+ req = self.new_delete_request('subnets', subnet['subnet']['id'])
+ res = req.get_response(self.api)
+ self.assertEquals(res.status_int, 204)
+
+ def test_delete_network(self):
+ gateway_ip = '10.0.0.1'
+ cidr = '10.0.0.0/24'
+ fmt = 'json'
+ # Create new network
+ res = self._create_network(fmt=fmt, name='net',
+ admin_status_up=True)
+ network = self.deserialize(fmt, res)
+ subnet = self._make_subnet(fmt, network, gateway_ip,
+ cidr, ip_version=4)
+ req = self.new_delete_request('networks', network['network']['id'])
+ res = req.get_response(self.api)
+ self.assertEquals(res.status_int, 204)
+
def test_create_subnet_defaults(self):
gateway = '10.0.0.1'
cidr = '10.0.0.0/24'