When creating a network, so far no size constraints were checked.
We no 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 <[email protected]>
---
 lib/network.py |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/lib/network.py b/lib/network.py
index cc3bfd6..eb10ba3 100644
--- a/lib/network.py
+++ b/lib/network.py
@@ -29,6 +29,9 @@ from bitarray import bitarray
 
 from ganeti import errors
 
+# minimum number of hosts of a network
+NETWORK_SIZE_MIN = 4
+
 
 class AddressPool(object):
   """Address pool class, wrapping an C{objects.Network} object.
@@ -55,6 +58,10 @@ class AddressPool(object):
     self.net = network
 
     self.network = ipaddr.IPNetwork(self.net.network)
+    if self.network.numhosts < NETWORK_SIZE_MIN:
+      raise errors.AddressPoolError("A network of size %s is too small. Please 
"
+                                    "specify at least a /30 network." %
+                                    str(self.network.numhosts))
     if self.net.gateway:
       self.gateway = ipaddr.IPAddress(self.net.gateway)
 
-- 
1.7.7.3

Reply via email to