Revision 691c98cf
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
284 | 284 |
|
285 | 285 |
This function takes as argument a number of PoolTable objects and tries to |
286 | 286 |
allocate a value from them. If all pools are empty EmptyPool is raised. |
287 |
If an address is specified and does not belong to any of the pools, |
|
288 |
InvalidValue is raised. |
|
287 | 289 |
|
288 | 290 |
""" |
289 | 291 |
for pool_row in pool_rows: |
... | ... | |
300 | 302 |
return ipaddress |
301 | 303 |
except pools.EmptyPool: |
302 | 304 |
pass |
303 |
raise pools.EmptyPool("No more IP addresses available on pools %s" % |
|
304 |
pool_rows) |
|
305 |
except pools.InvalidValue: |
|
306 |
pass |
|
307 |
if address is None: |
|
308 |
raise pools.EmptyPool("No more IP addresses available on pools %s" % |
|
309 |
pool_rows) |
|
310 |
else: |
|
311 |
raise pools.InvalidValue("Address %s does not belong to pools %s" % |
|
312 |
(address, pool_rows)) |
|
305 | 313 |
|
306 | 314 |
|
307 | 315 |
def allocate_ip(network, userid, address=None, floating_ip=False): |
b/snf-cyclades-app/synnefo/db/pools/__init__.py | ||
---|---|---|
57 | 57 |
|
58 | 58 |
def get(self, value=None): |
59 | 59 |
"""Get a value from the pool.""" |
60 |
if self.empty(): |
|
61 |
raise EmptyPool |
|
62 | 60 |
if value is None: |
61 |
if self.empty(): |
|
62 |
raise EmptyPool |
|
63 | 63 |
# Get the first available index |
64 | 64 |
index = int(self.pool.index(AVAILABLE)) |
65 | 65 |
assert(index < self.pool_size) |
Also available in: Unified diff