When creating a network, so far no size constraints were checked. We now limit the size of a network to a /30 or bigger, although tecnically, the ipaddr library supports even /32 networks.
Signed-off-by: Helga Velroyen <hel...@google.com> --- lib/network.py | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/lib/network.py b/lib/network.py index cc3bfd6..d8753d7 100644 --- a/lib/network.py +++ b/lib/network.py @@ -29,6 +29,8 @@ from bitarray import bitarray from ganeti import errors +NETWORK_MIN_SIZE = 30 +NETWORK_MIN_NUM_HOSTS = 2 ** (32 - NETWORK_MIN_SIZE) class AddressPool(object): """Address pool class, wrapping an C{objects.Network} object. @@ -55,6 +57,12 @@ class AddressPool(object): self.net = network self.network = ipaddr.IPNetwork(self.net.network) + if self.network.numhosts < NETWORK_MIN_NUM_HOSTS: + raise errors.AddressPoolError("A network with only %s host(s) is too" + " small, please specify at least a /%s" + " network" % + (str(self.network.numhosts), + NETWORK_MIN_SIZE)) if self.net.gateway: self.gateway = ipaddr.IPAddress(self.net.gateway) -- 1.7.7.3