Revision 6dd70a5c snf-cyclades-app/synnefo/api/networks.py

b/snf-cyclades-app/synnefo/api/networks.py
40 40
from django.template.loader import render_to_string
41 41
from django.utils import simplejson as json
42 42

  
43
from synnefo import settings
44 43
from synnefo.api import util
45 44
from synnefo.api.actions import network_actions
46 45
from synnefo.api.common import method_not_allowed
47
from synnefo.api.faults import (BadRequest, OverLimit,
48
                                Unauthorized, NetworkInUse)
49
from synnefo.db.models import Network, Pool, BridgePool, MacPrefixPool
46
from synnefo.api.faults import (BadRequest, Unauthorized,
47
                                NetworkInUse)
48
from synnefo.db.models import Network
50 49
from synnefo.logic import backend
51 50

  
52 51

  
......
169 168
    if type == 'PUBLIC_ROUTED':
170 169
        raise Unauthorized('Can not create a public network.')
171 170

  
172
    mac_prefix = None
173
    try:
174
        if type == 'PRIVATE_MAC_FILTERED':
175
            link = settings.PRIVATE_MAC_FILTERED_BRIDGE
176
            mac_prefix = MacPrefixPool.get_available().value
177
        elif type == 'PRIVATE_PHYSICAL_VLAN':
178
            link = BridgePool.get_available().value
179
        elif type == 'CUSTOM_ROUTED':
180
            link = settings.CUSTOM_ROUTED_ROUTING_TABLE
181
        elif type == 'CUSTOM_BRIDGED':
182
            link = settings.CUSTOM_BRIDGED_BRIDGE
183
        else:
184
            raise BadRequest('Unknown network type')
185
    except Pool.PoolExhausted:
186
        raise OverLimit('Network count limit exceeded.')
171

  
172
    link, mac_prefix = util.network_specs_from_type(type)
173
    if not link:
174
        raise Exception("Can not create network. No connectivity link.")
187 175

  
188 176
    network = Network.objects.create(
189 177
            name=name,

Also available in: Unified diff