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

Fix IP pool exceptions

parent 151136a9
......@@ -41,7 +41,7 @@ from datetime import datetime
from synnefo.db.models import (Backend, VirtualMachine, Network,
BackendNetwork, BACKEND_STATUSES)
from synnefo.logic import utils, ippool
from synnefo.api.faults import ServiceUnavailable
from synnefo.api.faults import OverLimit
from synnefo.util.rapi import GanetiRapiClient
log = getLogger('synnefo.logic')
......@@ -281,7 +281,8 @@ def create_instance(vm, flavor, image, password, personality):
try:
address = pool.get_free_address()
except ippool.IPPool.IPPoolExhausted:
raise ServiceUnavailable('Network is full')
raise OverLimit("Can not allocate IP for new machine."
" Public network is full.")
pool.save()
nic = {'ip': address, 'network': settings.GANETI_PUBLIC_NETWORK}
......
......@@ -36,7 +36,7 @@ class IPPool(object):
"""
if not self._contains(address):
raise Exception("%s does not contain %s" % (self.network, address))
raise Exception("%s does not contain %s" % (str(self.network), address))
addr = ipaddr.IPAddress(address)
return int(addr) - int(self.network.network)
......@@ -69,7 +69,7 @@ class IPPool(object):
def get_free_address(self):
if self.is_full():
raise Exception("%s if full", self.network)
raise IPPool.IPPoolExhausted("%s if full" % str(self.network))
index = self.reservations.index(False)
address = str(self.network[index])
......
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