Revision 812a1114 snf-cyclades-app/synnefo/api/subnets.py
b/snf-cyclades-app/synnefo/api/subnets.py | ||
---|---|---|
326 | 326 |
return Subnet.objects.get(id=subnet_id, network__userid=user_id) |
327 | 327 |
except (ValueError, Subnet.DoesNotExist): |
328 | 328 |
raise api.faults.ItemNotFound('Subnet not found.') |
329 |
|
|
330 |
|
|
331 |
def parse_ip_pools(pools): |
|
332 |
""" |
|
333 |
Convert [{'start': '192.168.42.1', 'end': '192.168.42.15'}, |
|
334 |
{'start': '192.168.42.30', 'end': '192.168.42.60'}] |
|
335 |
to |
|
336 |
[["192.168.42.1", "192.168.42.15"], |
|
337 |
["192.168.42.30", "192.168.42.60"]] |
|
338 |
""" |
|
339 |
pool_list = list() |
|
340 |
for pool in pools: |
|
341 |
asd = [pool["start"], pool["end"]] |
|
342 |
pool_list.append(asd) |
|
343 |
return pool_list |
|
344 |
|
|
345 |
|
|
346 |
def validate_subpools(pools, cidr, gateway): |
|
347 |
""" |
|
348 |
Validate the given IP pools are inside the cidr range |
|
349 |
Validate there are no overlaps in the given pools |
|
350 |
Input must be a list containing a sublist with start/end ranges as strings |
|
351 |
[["192.168.42.1", "192.168.42.15"], ["192.168.42.30", "192.168.42.60"]] |
|
352 |
""" |
|
353 |
pool_list = list() |
|
354 |
for pool in pools: |
|
355 |
pool_list.append(map(lambda a: IPAddress(a), pool)) |
|
356 |
pool_list = sorted(pool_list) |
|
357 |
|
|
358 |
if pool_list[0][0] <= cidr.network: |
|
359 |
raise api.faults.BadRequest("IP Pool out of bounds") |
|
360 |
elif pool_list[-1][1] >= cidr.broadcast: |
|
361 |
raise api.faults.BadRequest("IP Pool out of bounds") |
|
362 |
|
|
363 |
for start, end in pool_list: |
|
364 |
if start >= end: |
|
365 |
raise api.faults.Conflict("Invalid IP pool range") |
|
366 |
# Raise BadRequest if gateway is inside the pool range |
|
367 |
if not (gateway < start or gateway > end): |
|
368 |
raise api.faults.Conflict("Gateway cannot be in pool range") |
|
369 |
|
|
370 |
# Check if there is a conflict between the IP Poll ranges |
|
371 |
end = cidr.network |
|
372 |
for pool in pool_list: |
|
373 |
if end >= pool[1]: |
|
374 |
raise api.faults.Conflict("IP Pool range conflict") |
|
375 |
end = pool[1] |
Also available in: Unified diff