Revision 06c056d3

b/lib/network.py
29 29

  
30 30
from ganeti import errors
31 31

  
32

  
33
def _ComputeIpv4NumHosts(network_size):
34
  """Derives the number of hosts in an IPv4 network from the size.
35

  
36
  """
37
  return 2 ** (32 - network_size)
38

  
39

  
32 40
IPV4_NETWORK_MIN_SIZE = 30
33
IPV4_NETWORK_MIN_NUM_HOSTS = 2 ** (32 - IPV4_NETWORK_MIN_SIZE)
41
# FIXME: This limit is for performance reasons. Remove when refactoring
42
# for performance tuning was successful.
43
IPV4_NETWORK_MAX_SIZE = 16
44
IPV4_NETWORK_MIN_NUM_HOSTS = _ComputeIpv4NumHosts(IPV4_NETWORK_MIN_SIZE)
45
IPV4_NETWORK_MAX_NUM_HOSTS = _ComputeIpv4NumHosts(IPV4_NETWORK_MAX_SIZE)
34 46

  
35 47

  
36 48
class AddressPool(object):
......
58 70
    self.net = network
59 71

  
60 72
    self.network = ipaddr.IPNetwork(self.net.network)
73
    if self.network.numhosts > IPV4_NETWORK_MAX_NUM_HOSTS:
74
      raise errors.AddressPoolError("A big network with %s host(s) is currently"
75
                                    " not supported. please specify at most a"
76
                                    " /%s network" %
77
                                    (str(self.network.numhosts),
78
                                     IPV4_NETWORK_MAX_SIZE))
79

  
61 80
    if self.network.numhosts < IPV4_NETWORK_MIN_NUM_HOSTS:
62 81
      raise errors.AddressPoolError("A network with only %s host(s) is too"
63 82
                                    " small, please specify at least a /%s"

Also available in: Unified diff