Fix bug in network module
authorDimitris Aragiorgis <dimara@grnet.gr>
Fri, 23 Nov 2012 08:32:47 +0000 (10:32 +0200)
committerIustin Pop <iustin@google.com>
Fri, 23 Nov 2012 14:22:56 +0000 (15:22 +0100)
Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Iustin Pop <iustin@google.com>
[iustin@google.com: slightly improved code flow]
Reviewed-by: Iustin Pop <iustin@google.com>

lib/network.py

index 736a03a..cc3bfd6 100644 (file)
@@ -201,10 +201,11 @@ class AddressPool(object):
     @raise errors.AddressPoolError: Pool is full
 
     """
-    if self.IsFull():
-      raise errors.AddressPoolError("%s is full" % self.network)
     idx = self.all_reservations.search(self.FREE, 1)
-    return str(self.network[idx])
+    if idx:
+      return str(self.network[idx[0]])
+    else:
+      raise errors.AddressPoolError("%s is full" % self.network)
 
   def GetExternalReservations(self):
     """Returns a list of all externally reserved addresses.