Commit 9952325a authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos
Browse files

cyclades: Add two functions to validate IP Pools

parent 468a3552
......@@ -326,3 +326,50 @@ def get_subnet_fromdb(subnet_id, user_id, for_update=False):
return Subnet.objects.get(id=subnet_id, network__userid=user_id)
except (ValueError, Subnet.DoesNotExist):
raise api.faults.ItemNotFound('Subnet not found.')
def parse_ip_pools(pools):
Convert [{'start': '', 'end': ''},
{'start': '', 'end': ''}]
[["", ""],
["", ""]]
pool_list = list()
for pool in pools:
asd = [pool["start"], pool["end"]]
return pool_list
def validate_subpools(pools, cidr, gateway):
Validate the given IP pools are inside the cidr range
Validate there are no overlaps in the given pools
Input must be a list containing a sublist with start/end ranges as strings
[["", ""], ["", ""]]
pool_list = list()
for pool in pools:
pool_list.append(map(lambda a: IPAddress(a), pool))
pool_list = sorted(pool_list)
if pool_list[0][0] <=
raise api.faults.BadRequest("IP Pool out of bounds")
elif pool_list[-1][1] >= cidr.broadcast:
raise api.faults.BadRequest("IP Pool out of bounds")
for start, end in pool_list:
if start >= end:
raise api.faults.Conflict("Invalid IP pool range")
# Raise BadRequest if gateway is inside the pool range
if not (gateway < start or gateway > end):
raise api.faults.Conflict("Gateway cannot be in pool range")
# Check if there is a conflict between the IP Poll ranges
end =
for pool in pool_list:
if end >= pool[1]:
raise api.faults.Conflict("IP Pool range conflict")
end = pool[1]
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