Revision 430b923c

b/lib/bootstrap.py
244 244

  
245 245
  _InitSSHSetup()
246 246

  
247
  now = time.time()
248

  
247 249
  # init of cluster config file
248 250
  cluster_config = objects.Cluster(
249 251
    serial_no=1,
......
263 265
    hvparams=hvparams,
264 266
    candidate_pool_size=candidate_pool_size,
265 267
    modify_etc_hosts=modify_etc_hosts,
268
    ctime=now,
269
    mtime=now,
270
    uuid=utils.NewUUID(),
266 271
    )
267 272
  master_node_config = objects.Node(name=hostname.name,
268 273
                                    primary_ip=hostname.ip,
b/lib/config.py
178 178
    existing.update([i.uuid for i in self._AllUUIDObjects() if i.uuid])
179 179
    return existing
180 180

  
181
  @locking.ssynchronized(_config_lock, shared=1)
182
  def GenerateUniqueID(self, exceptions=None):
183
    """Generate an unique disk name.
181
  def _GenerateUniqueID(self, exceptions=None):
182
    """Generate an unique UUID.
184 183

  
185 184
    This checks the current node, instances and disk names for
186 185
    duplicates.
187 186

  
188
    @param exceptions: a list with some other names which should be checked
189
        for uniqueness (used for example when you want to get
190
        more than one id at one time without adding each one in
191
        turn to the config file)
187
    @param exceptions: a list with some other names which should be
188
        checked for uniqueness (used for example when you want to get
189
        more than one id at one time without adding each one in turn
190
        to the config file)
192 191

  
193 192
    @rtype: string
194 193
    @return: the unique id
......
208 207
    self._temporary_ids.add(unique_id)
209 208
    return unique_id
210 209

  
210
  @locking.ssynchronized(_config_lock, shared=1)
211
  def GenerateUniqueID(self, exceptions=None):
212
    """Generate an unique ID.
213

  
214
    This is just a wrapper over the unlocked version.
215

  
216
    """
217
    return self._GenerateUniqueID(exceptions=exceptions)
218

  
211 219
  def _CleanupTemporaryIDs(self):
212 220
    """Cleanups the _temporary_ids structure.
213 221

  
......
727 735
    for nic in instance.nics:
728 736
      if nic.mac in all_macs:
729 737
        raise errors.ConfigurationError("Cannot add instance %s:"
730
          " MAC address '%s' already in use." % (instance.name, nic.mac))
738
                                        " MAC address '%s' already in use." %
739
                                        (instance.name, nic.mac))
740

  
741
    self._EnsureUUID(instance)
731 742

  
732 743
    instance.serial_no = 1
733 744
    instance.ctime = instance.mtime = time.time()
......
738 749
      self._temporary_macs.discard(nic.mac)
739 750
    self._WriteConfig()
740 751

  
752
  def _EnsureUUID(self, item):
753
    """Ensures a given object has a valid UUID.
754

  
755
    @param item: the instance or node to be checked
756

  
757
    """
758
    if not item.uuid:
759
      item.uuid = self._GenerateUniqueID()
760
    elif item.uuid in self._AllIDs(temporary=True):
761
      raise errors.ConfigurationError("Cannot add '%s': UUID already in use" %
762
                                      (item.name, item.uuid))
763

  
741 764
  def _SetInstanceStatus(self, instance_name, status):
742 765
    """Set the instance's status to a given value.
743 766

  
......
883 906
    """
884 907
    logging.info("Adding node %s to configuration" % node.name)
885 908

  
909
    self._EnsureUUID(node)
910

  
886 911
    node.serial_no = 1
887 912
    node.ctime = node.mtime = time.time()
888 913
    self._config_data.nodes[node.name] = node
......
1110 1135
    modified = False
1111 1136
    for item in self._AllUUIDObjects():
1112 1137
      if item.uuid is None:
1113
        item.uuid = self.GenerateUniqueID()
1138
        item.uuid = self._GenerateUniqueID()
1114 1139
        modified = True
1115 1140
    if modified:
1116 1141
      self._WriteConfig()

Also available in: Unified diff