Revision d368ec0c snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
43 | 43 |
from time import time |
44 | 44 |
from traceback import format_exc |
45 | 45 |
from wsgiref.handlers import format_date_time |
46 |
from ipaddr import IPNetwork |
|
46 | 47 |
|
47 | 48 |
import dateutil.parser |
48 | 49 |
|
... | ... | |
239 | 240 |
raise ItemNotFound('Network not found.') |
240 | 241 |
|
241 | 242 |
|
243 |
def validate_network_subnet(subnet): |
|
244 |
try: |
|
245 |
# Use strict option to not all subnets with host bits set |
|
246 |
network = IPNetwork(subnet, strict=True) |
|
247 |
except ValueError: |
|
248 |
raise BadRequest("Invalid network subnet") |
|
249 |
|
|
250 |
# Check that network size is allowed! |
|
251 |
if not validate_network_size(network.prefixlen): |
|
252 |
raise OverLimit("Unsupported network size") |
|
253 |
|
|
254 |
|
|
242 | 255 |
def validate_network_size(cidr_block): |
243 | 256 |
"""Return True if network size is allowed.""" |
244 | 257 |
return cidr_block <= 29 and cidr_block > MAX_CIDR_BLOCK |
Also available in: Unified diff