Revision 264bb3c5

b/lib/config.py
53 53
  def __init__(self, cfg_file=None, offline=False):
54 54
    self._config_data = None
55 55
    self._config_time = None
56
    self._config_size = None
57
    self._config_inode = None
56 58
    self._offline = offline
57 59
    if cfg_file is None:
58 60
      self._cfg_file = constants.CLUSTER_CONF_FILE
......
167 169
      disk.physical_id = disk.logical_id
168 170
    return
169 171

  
172
  def AddTcpIpPort(self, port):
173
    if not isinstance(port, int):
174
      raise errors.ProgrammerError("Invalid type passed for port")
175

  
176
    self._OpenConfig()
177
    self._config_data.tcpudp_port_pool.add(port)
178
    self._WriteConfig()
179

  
180
  def GetPortList():
181
    """Returns a copy of the current port list.
182

  
183
    """
184
    self._OpenConfig()
185
    self._ReleaseLock()
186
    return self._config_data.tcpudp_port_pool.copy()
187

  
170 188
  def AllocatePort(self):
171 189
    """Allocate a port.
172 190

  
......
175 193
    """
176 194
    self._OpenConfig()
177 195

  
178
    self._config_data.cluster.highest_used_port += 1
179
    if self._config_data.cluster.highest_used_port >= constants.LAST_DRBD_PORT:
180
      raise errors.ConfigurationError, ("The highest used port is greater"
181
                                        " than %s. Aborting." %
182
                                        constants.LAST_DRBD_PORT)
183
    port = self._config_data.cluster.highest_used_port
196
    # If there are TCP/IP ports configured, we use them first.
197
    if self._config_data.tcpudp_port_pool:
198
      port = self._config_data.tcpudp_port_pool.pop()
199
    else:
200
      port = self._config_data.cluster.highest_used_port + 1
201
      if port >= constants.LAST_DRBD_PORT:
202
        raise errors.ConfigurationError, ("The highest used port is greater"
203
                                          " than %s. Aborting." %
204
                                          constants.LAST_DRBD_PORT)
205
      self._config_data.cluster.highest_used_port = port
184 206

  
185 207
    self._WriteConfig()
186 208
    return port
......
377 399
      raise errors.ConfigurationError, "Can't stat config file: %s" % err
378 400
    if (self._config_data is not None and
379 401
        self._config_time is not None and
380
        self._config_time == st.st_mtime):
402
        self._config_time == st.st_mtime and
403
        self._config_size == st.st_size and
404
        self._config_inode == st.st_ino):
381 405
      # data is current, so skip loading of config file
382 406
      return
383 407
    f = open(self._cfg_file, 'r')
......
399 423
                                         constants.CONFIG_VERSION))
400 424
    self._config_data = data
401 425
    self._config_time = st.st_mtime
426
    self._config_size = st.st_size
427
    self._config_inode = st.st_ino
402 428

  
403 429
  def _ReleaseLock(self):
404 430
    """xxxx
......
464 490
      secondary_ip: the secondary IP of the current host or None
465 491
      clustername: the name of the cluster
466 492
      hostkeypub: the public hostkey of this host
467
    """
468 493

  
494
    """
469 495
    hu_port = constants.FIRST_DRBD_PORT - 1
470 496
    globalconfig = objects.Cluster(config_version=constants.CONFIG_VERSION,
471 497
                                   serial_no=1, master_node=node,
......
482 508

  
483 509
    self._config_data = objects.ConfigData(nodes={node: nodeconfig},
484 510
                                           instances={},
485
                                           cluster=globalconfig)
511
                                           cluster=globalconfig,
512
                                           tcpudp_port_pool=set())
486 513
    self._WriteConfig()
487 514

  
488 515
  def GetClusterName(self):
b/lib/objects.py
100 100
        cls = Node
101 101
      elif name == "Cluster":
102 102
        cls = Cluster
103
    elif module == "__builtin__":
104
      if name == "set":
105
        cls = set
103 106
    if cls is None:
104 107
      raise cPickle.UnpicklingError, ("Class %s.%s not allowed due to"
105 108
                                      " security concerns" % (module, name))
......
140 143

  
141 144
class ConfigData(ConfigObject):
142 145
  """Top-level config object."""
143
  __slots__ = ["cluster", "nodes", "instances"]
146
  __slots__ = ["cluster", "nodes", "instances", "tcpudp_port_pool"]
144 147

  
145 148

  
146 149
class NIC(ConfigObject):

Also available in: Unified diff