Revision fdc94944 snf-cyclades-app/synnefo/api/actions.py
b/snf-cyclades-app/synnefo/api/actions.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
from synnefo.api.faults import (BadRequest, ServiceUnavailable, |
44 | 44 |
ItemNotFound, BuildInProgress) |
45 |
from synnefo.api.util import random_password, get_vm, get_nic_from_index |
|
45 |
from synnefo.api.util import (random_password, get_vm, get_nic_from_index, |
|
46 |
get_network_free_address) |
|
46 | 47 |
from synnefo.db.models import NetworkInterface, Network |
47 |
from synnefo.db.pools import IPPool
|
|
48 |
from synnefo.db.pools import EmptyPool
|
|
48 | 49 |
from synnefo.logic import backend |
49 | 50 |
from synnefo.logic.utils import get_rsapi_state |
50 | 51 |
|
... | ... | |
314 | 315 |
raise ServiceUnavailable('Network not active yet') |
315 | 316 |
|
316 | 317 |
# Get a free IP from the address pool. |
317 |
pool = IPPool(net) |
|
318 | 318 |
try: |
319 |
address = pool.get_free_address()
|
|
320 |
except IPPool.IPPoolExhausted:
|
|
319 |
address = get_network_free_address(net)
|
|
320 |
except EmptyPool:
|
|
321 | 321 |
raise ServiceUnavailable('Network is full') |
322 |
pool.save() |
|
323 | 322 |
|
324 | 323 |
backend.connect_to_network(vm, net, address) |
325 | 324 |
return HttpResponse(status=202) |
Also available in: Unified diff