Commit 88676431 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Fix bugs relative to pool allocation

Fix bug when trying to allocate a specified IPv4 address. Only one of
the IP pools will contain this address, so you must bypass InvalidValue
exceptions until searching all pools.

Also PoolManager raised 'EmptyPool' exception when trying to allocate from an
empty pool. However, if someone tried to allocate a specific value,
'ValueNotAvailable' should be returned.
parent c7834da6
......@@ -284,6 +284,8 @@ def allocate_ip_from_pools(pool_rows, userid, address=None, floating_ip=False):
This function takes as argument a number of PoolTable objects and tries to
allocate a value from them. If all pools are empty EmptyPool is raised.
If an address is specified and does not belong to any of the pools,
InvalidValue is raised.
"""
for pool_row in pool_rows:
......@@ -300,8 +302,14 @@ def allocate_ip_from_pools(pool_rows, userid, address=None, floating_ip=False):
return ipaddress
except pools.EmptyPool:
pass
raise pools.EmptyPool("No more IP addresses available on pools %s" %
pool_rows)
except pools.InvalidValue:
pass
if address is None:
raise pools.EmptyPool("No more IP addresses available on pools %s" %
pool_rows)
else:
raise pools.InvalidValue("Address %s does not belong to pools %s" %
(address, pool_rows))
def allocate_ip(network, userid, address=None, floating_ip=False):
......
......@@ -57,9 +57,9 @@ class PoolManager(object):
def get(self, value=None):
"""Get a value from the pool."""
if self.empty():
raise EmptyPool
if value is None:
if self.empty():
raise EmptyPool
# Get the first available index
index = int(self.pool.index(AVAILABLE))
assert(index < self.pool_size)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment