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

Do not allow creation of two big/small networks

- Networks smaller than /29 are not supported in Ganeti.
- Big networks will result in degraded performance in Ganeti
and DB due to the big reservation map.
parent 2b00bd8f
......@@ -36,8 +36,9 @@ from optparse import make_option
from import BaseCommand, CommandError
from synnefo.db.models import Network, Backend
from synnefo.api.util import network_link_from_type
from synnefo.api.util import network_link_from_type, validate_network_size
from synnefo.logic.backend import create_network
from synnefo import settings
import ipaddr
class Command(BaseCommand):
can_import_settings = True
help = "Create a new network"
option_list = BaseCommand.option_list + (
......@@ -154,7 +157,6 @@ class Command(BaseCommand):
def validate_network_info(options):
subnet = options['subnet']
gateway = options['gateway']
......@@ -162,7 +164,12 @@ def validate_network_info(options):
gateway6 = options['gateway6']
net = ipaddr.IPv4Network(subnet)
prefix = net.prefixlen
if not validate_network_size(prefix):
raise CommandError("Unsupport network mask %d."
" Must be in range (%s,29] "
% (prefix, settings.MAX_CIDR_BLOCK))
except ValueError:
raise CommandError('Malformed subnet')
......@@ -48,7 +48,6 @@ from synnefo.api.faults import (BadRequest, Unauthorized,
NetworkInUse, OverLimit)
from synnefo.db.models import Network, Pool
from synnefo.logic import backend
from synnefo.settings import MAX_CIDR_BLOCK
log = getLogger('synnefo.api')
......@@ -179,9 +178,8 @@ def create_network(request):
raise OverLimit('Network count limit exceeded for your account.')
cidr_block = int(subnet.split('/')[1])
if cidr_block <= MAX_CIDR_BLOCK:
raise OverLimit("Network size is to big. Please specify a network"
" smaller than /" + str(MAX_CIDR_BLOCK) + '.')
if not util.validate_network_size(cidr_block):
raise OverLimit("Unsupported network size.")
link = util.network_link_from_type(typ)
......@@ -64,6 +64,7 @@ from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata,
from synnefo.lib.astakos import get_user
from synnefo.plankton.backend import ImageBackend
from synnefo.logic import ippool
from synnefo.settings import MAX_CIDR_BLOCK
log = getLogger('synnefo.api')
......@@ -209,6 +210,11 @@ def get_network(network_id, user_id):
raise ItemNotFound('Network not found.')
def validate_network_size(cidr_block):
"""Return True if network size is allowed."""
return cidr_block <= 29 and cidr_block > MAX_CIDR_BLOCK
def backend_public_networks(backend):
"""Return available public networks of the backend.
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