Commit 7cf9699b authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Handle 'EmptyPool' in util method

Refactor cyclades code to handle 'EmptyPool' exception in
'get_network_free_address' function.
parent d15f509c
......@@ -273,9 +273,10 @@ def allocate_public_address(backend):
for network in backend_public_networks(backend):
address = get_network_free_address(network)
return (network, address)
except EmptyPool:
except faults.OverLimit:
return (network, address)
return (None, None)
......@@ -323,14 +324,14 @@ def backend_public_networks(backend):
def get_network_free_address(network):
"""Reserve an IP address from the IP Pool of the network.
Raises EmptyPool
"""Reserve an IP address from the IP Pool of the network."""
pool = network.get_pool()
address = pool.get()
address = pool.get()
except EmptyPool:
raise faults.OverLimit("Network %s is full." % network.backend_id)
address = None
return address
......@@ -303,10 +303,7 @@ def connect(vm, network):
address = None
if network.dhcp:
# Get a free IP from the address pool.
address = util.get_network_free_address(network)
except EmptyPool:
raise faults.OverLimit('Network is full')
address = util.get_network_free_address(network)"Connecting VM %s to Network %s(%s)", vm, network, address)
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