Revision 6dd70a5c snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
55 | 55 |
from django.utils.cache import add_never_cache_headers |
56 | 56 |
|
57 | 57 |
from synnefo.api.faults import (Fault, BadRequest, BuildInProgress, |
58 |
ItemNotFound, ServiceUnavailable, Unauthorized, BadMediaType) |
|
58 |
ItemNotFound, ServiceUnavailable, Unauthorized, |
|
59 |
BadMediaType, OverLimit) |
|
59 | 60 |
from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata, |
60 |
Network, NetworkInterface) |
|
61 |
Network, NetworkInterface, BridgePool, |
|
62 |
MacPrefixPool, Pool) |
|
63 |
|
|
61 | 64 |
from synnefo.lib.astakos import get_user |
62 | 65 |
from synnefo.plankton.backend import ImageBackend |
63 | 66 |
|
... | ... | |
354 | 357 |
|
355 | 358 |
def construct_nic_id(nic): |
356 | 359 |
return "-".join(["nic", unicode(nic.machine.id), unicode(nic.index)]) |
360 |
|
|
361 |
|
|
362 |
def network_specs_from_type(network_type): |
|
363 |
mac_prefix = None |
|
364 |
try: |
|
365 |
if network_type == 'PRIVATE_MAC_FILTERED': |
|
366 |
link = settings.PRIVATE_MAC_FILTERED_BRIDGE |
|
367 |
mac_prefix = MacPrefixPool.get_available().value |
|
368 |
elif network_type == 'PRIVATE_PHYSICAL_VLAN': |
|
369 |
link = BridgePool.get_available().value |
|
370 |
elif network_type == 'CUSTOM_ROUTED': |
|
371 |
link = settings.CUSTOM_ROUTED_ROUTING_TABLE |
|
372 |
elif network_type == 'CUSTOM_BRIDGED': |
|
373 |
link = settings.CUSTOM_BRIDGED_BRIDGE |
|
374 |
else: |
|
375 |
raise BadRequest('Unknown network network_type') |
|
376 |
except Pool.PoolExhausted: |
|
377 |
raise OverLimit('Network count limit exceeded.') |
|
378 |
|
|
379 |
return link, mac_prefix |
Also available in: Unified diff