Commit c223cc55 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Make IPPool manager work for subnets

Temporary commit to make IPPool manager work. This will work only if
there is only one allocation pool for each subnet.
parent 2e094753
......@@ -532,15 +532,21 @@ class Network(models.Model):
BackendNetwork.objects.create(backend=backend, network=self)
def get_pool(self, with_lock=True):
if not self.pool_id:
self.pool = IPPoolTable.objects.create(available_map='',
subnet = self.subnets.get(ipversion=4, deleted=False)
except Subnet.DoesNotExist:
raise pools.EmptyPool
pool = subnet.ip_pools.all()[0]
except IndexError:
pool = IPPoolTable.objects.create(available_map='',
objects = IPPoolTable.objects
if with_lock:
objects = objects.select_for_update()
return objects.get(id=self.pool_id).pool
return objects.get(
def reserve_address(self, address):
pool = self.get_pool()
......@@ -248,12 +248,12 @@ class MacPrefixPool(PoolManager):
class IPPool(PoolManager):
def __init__(self, pool_table):
do_init = False if pool_table.available_map else True
network = = ipaddr.IPNetwork(network.subnet)
subnet = pool_table.subnet = ipaddr.IPNetwork(subnet.cidr)
if not pool_table.size:
pool_table.size =
super(IPPool, self).__init__(pool_table)
gateway = network.gateway
gateway = subnet.gateway
self.gateway = gateway and ipaddr.IPAddress(gateway) or None
if do_init:
self._reserve(0, external=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment