Revision fdc94944 snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
63 | 63 |
|
64 | 64 |
from synnefo.lib.astakos import get_user |
65 | 65 |
from synnefo.plankton.backend import ImageBackend |
66 |
from synnefo.db.pools import IPPool |
|
67 | 66 |
from synnefo.settings import MAX_CIDR_BLOCK |
68 | 67 |
|
69 | 68 |
|
... | ... | |
231 | 230 |
def get_network_free_address(network): |
232 | 231 |
"""Reserve an IP address from the IP Pool of the network. |
233 | 232 |
|
234 |
Raises Network.DoesNotExist , IPPool.IPPoolExhausted
|
|
233 |
Raises EmptyPool
|
|
235 | 234 |
|
236 | 235 |
""" |
237 | 236 |
|
238 |
# Get the Network object in exclusive mode in order to |
|
239 |
# safely (isolated) reserve an IP address |
|
240 |
network = Network.objects.select_for_update().get(id=network.id) |
|
241 |
pool = IPPool(network) |
|
242 |
address = pool.get_free_address() |
|
237 |
pool = network.get_pool() |
|
238 |
address = pool.get() |
|
243 | 239 |
pool.save() |
244 | 240 |
return address |
245 | 241 |
|
Also available in: Unified diff