Revision 87994836 snf-cyclades-app/synnefo/api/networks.py
b/snf-cyclades-app/synnefo/api/networks.py | ||
---|---|---|
45 | 45 |
from synnefo.api.actions import network_actions |
46 | 46 |
from synnefo.api.common import method_not_allowed |
47 | 47 |
from synnefo.api.faults import BadRequest, OverLimit, Unauthorized |
48 |
from synnefo.db.models import Network, BridgePool, MacPrefixPool |
|
48 |
from synnefo.db.models import Network, Pool, BridgePool, MacPrefixPool
|
|
49 | 49 |
from synnefo.logic import backend |
50 | 50 |
|
51 | 51 |
|
... | ... | |
162 | 162 |
except (KeyError, ValueError): |
163 | 163 |
raise BadRequest('Malformed request.') |
164 | 164 |
|
165 |
link = None |
|
166 |
mac_prefix = None |
|
167 | 165 |
if type == 'PUBLIC_ROUTED': |
168 |
pass |
|
169 |
# raise Exception (user can not create public) |
|
170 |
if type == 'PRIVATE_FILTERED': |
|
171 |
link = settings.GANETI_PRIVATE_BRIDGE |
|
172 |
mac_prefix = MacPrefixPool.get_available().value |
|
173 |
state = 'PENDING' |
|
174 |
else: # PRIVATE_VLAN |
|
175 |
link = BridgePool.get_available().value |
|
176 |
# Physical-Vlans are pre-provisioned |
|
177 |
state = 'ACTIVE' |
|
166 |
raise Unauthorized('Can not create a public network.') |
|
167 |
|
|
168 |
try: |
|
169 |
if type == 'PRIVATE_FILTERED': |
|
170 |
link = settings.GANETI_PRIVATE_BRIDGE |
|
171 |
mac_prefix = MacPrefixPool.get_available().value |
|
172 |
else: # PRIVATE_VLAN |
|
173 |
link = BridgePool.get_available().value |
|
174 |
mac_prefix = None |
|
175 |
except Pool.PoolExhausted: |
|
176 |
raise OverLimit('Network count limit exceeded.') |
|
178 | 177 |
|
179 | 178 |
network = Network.objects.create( |
180 | 179 |
name=name, |
... | ... | |
185 | 184 |
type=type, |
186 | 185 |
link=link, |
187 | 186 |
mac_prefix=mac_prefix, |
188 |
state=state)
|
|
187 |
state='PENDING')
|
|
189 | 188 |
|
190 |
network = backend.create_network(network) |
|
191 |
if not network: |
|
192 |
raise OverLimit('Network count limit exceeded for your account.') |
|
189 |
backend.create_network(network) |
|
193 | 190 |
|
194 | 191 |
networkdict = network_to_dict(network, request.user_uniq) |
195 | 192 |
return render_network(request, networkdict, status=202) |
Also available in: Unified diff