Commit 59baad7a authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Check minimum size of networks on creation



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: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent fe05a931
......@@ -29,6 +29,9 @@ from bitarray import bitarray
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.
......@@ -55,6 +58,12 @@ class AddressPool(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)
......
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