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 <helgav@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
from ganeti import errors
+IPV4_NETWORK_MIN_SIZE = 30
+IPV4_NETWORK_MIN_NUM_HOSTS = 2 ** (32 - IPV4_NETWORK_MIN_SIZE)
+
class AddressPool(object):
"""Address pool class, wrapping an C{objects.Network} object.
self.net = network
self.network = ipaddr.IPNetwork(self.net.network)
+ if self.network.numhosts < IPV4_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),
+ IPV4_NETWORK_MIN_SIZE))
if self.net.gateway:
self.gateway = ipaddr.IPAddress(self.net.gateway)