Commit 3dab7faa authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Fix handling of old IP pools

Before implementing the Neutron API, each network had one IP pool that
contained the whole subnet CIDR. This changed since now we have multiple
IP Pools(with base and offset attributes) per network and this IP pools
do not contain the network, broadcast and gateway addreeses. This commit
fixes an old migration to add 'base' and 'offset' attribute to all IP
pool objects, and adds an extra step to old and not-initialized pools in
order to externally reserve those addresses.
parent 0c3b3480
......@@ -19,6 +19,8 @@ class Migration(DataMigration):
deleted=network.deleted)
ip_pool = network.pool
ip_pool.subnet = subnet
ip_pool.base = subnet.cidr
ip_pool.offset = 0
ip_pool.save()
if network.subnet6:
......
......@@ -279,15 +279,31 @@ class IPPool(PoolManager):
def __init__(self, pool_table):
subnet = pool_table.subnet
self.net = ipaddr.IPNetwork(subnet.cidr)
if pool_table.base is None:
self.base = pool_table.subnet.cidr
else:
self.base = pool_table.base
if pool_table.offset is None:
self.offset = 0
if pool_table.available_map:
initialized_pool = True
else:
self.offset = pool_table.offset
initialized_pool = False
super(IPPool, self).__init__(pool_table)
if not initialized_pool:
self.check_pool_integrity()
def check_pool_integtiry(self):
"""Check the integrity of the IP pool
This check is required only for old IP pools(one IP pool per network
that contained the whole subnet cidr) that had not been initialized
before the migration. This checks that the network, gateway and
broadcast IP addresses are externally reserved, and if not reserves
them.
"""
subnet = self.pool_table.subnet
check_ips = [str(self.net.network), str(self.net.broadcast)]
if subnet.gateway is not None:
check_ips.append(subnet.gateway)
for ip in check_ips:
if self.contains(ip):
self.reserve(ip, external=True)
def value_to_index(self, value):
addr = ipaddr.IPAddress(value)
......
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