From: Tony Mack Date: Wed, 17 Apr 2013 01:41:50 +0000 (-0400) Subject: clean up ports when deleting networks and subnets X-Git-Tag: 1.0~102 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=94c6ea010bcab8b88eb579ac8e0850e122e7260c;p=plstackapi.git clean up ports when deleting networks and subnets --- diff --git a/plstackapi/openstack/driver.py b/plstackapi/openstack/driver.py index c56dcde..940be6c 100644 --- a/plstackapi/openstack/driver.py +++ b/plstackapi/openstack/driver.py @@ -123,12 +123,33 @@ class OpenStackDriver: nets = self.shell.quantum.list_networks()['networks'] for net in nets: if net['id'] == id: + # delete_all ports + self.delete_network_ports(net['id']) # delete all subnets: for subnet_id in net['subnets']: self.delete_subnet(subnet_id) self.shell.quantum.delete_network(net['id']) return 1 - + + def delete_network_ports(self, network_id): + ports = self.shell.quantum.list_ports()['ports'] + for port in ports: + if port['network_id'] == 'network_id': + self.shell.quantum.delete_port(port['id']) + return 1 + + def delete_subnet_ports(self, subnet_id): + ports = self.shell.quantum.list_ports()['ports'] + for port in ports: + delete = False + for fixed_ip in port['fixed_ips']: + if fixed_ip['subnet_id'] == subnet_id: + delete=True + break + if delete: + self.shell.quantum.delete_port(port['id']) + return 1 + def create_subnet(self, name, network_id, cidr_ip, ip_version, start, end): #nets = self.shell.quantum.list_networks(name=network_name)['networks'] #if not nets: @@ -164,9 +185,9 @@ class OpenStackDriver: subnets = self.shell.quantum.list_subnets()['subnets'] for subnet in subnets: if subnet['id'] == id: + self.delete_subnet_ports(subnet['id']) self.shell.quantum.delete_subnet(id) return - def create_keypair(self, name, key): keys = self.shell.nova.keypairs.findall(name=name)