Skip to content
Snippets Groups Projects
Commit 9842f020 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>
parent ea7693c1
No related branches found
No related tags found
Loading
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment