- # delete all subnets:
- #subnets = self.api.client_shell.quantum.list_subnets(network_id=net['network_id'])['subnets']
- for subnet_id in net['subnets']:
- self.delete_subnet(subnet_id)
- self.shell.quantum.delete_network(net['id'])
-
- def create_subnet(self, network_name, cidr_ip, ip_version, start, end):
- nets = self.shell.quantum.list_networks(name=network_name)
- if not nets:
- raise Exception, "No such network: %s" % network_name
- nets = nets[0]
-
- subnets = self.shell.quantum.list_subnets(name=self.name)
- allocation_pools = [{'start': start, 'end': end}]
- subnet = self.shell.quantum.create_subnet(network_id=net['id'],
- ip_version=ip_version,
- cidr=cidr_ip,
- dns_nameservers=['8.8.8.8'],
- allocation_pools=allocation_pools)
+ 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:
+ # raise Exception, "No such network: %s" % network_name
+ #net = nets[0]
+
+ subnet = None
+ subnets = self.shell.quantum.list_subnets()['subnets']
+ for snet in subnets:
+ if snet['cidr'] == cidr_ip and snet['network_id'] == network_id:
+ subnet = snet
+
+ if not subnet:
+ allocation_pools = [{'start': start, 'end': end}]
+ subnet = {'subnet': {'name': name,
+ 'network_id': network_id,
+ 'ip_version': ip_version,
+ 'cidr': cidr_ip,
+ 'dns_nameservers': ['8.8.8.8', '8.8.8.4'],
+ 'allocation_pools': allocation_pools}}
+ subnet = self.shell.quantum.create_subnet(subnet)['subnet']