+ @locking.ssynchronized(_config_lock, shared=1)
+ def IsMacInUse(self, mac):
+ """Predicate: check if the specified MAC is in use in the Ganeti cluster.
+
+ This only checks instances managed by this cluster, it does not
+ check for potential collisions elsewhere.
+
+ """
+ self._OpenConfig()
+ all_macs = self._AllMACs()
+ return mac in all_macs
+
+ def _ComputeAllLVs(self):
+ """Compute the list of all LVs.
+
+ """
+ self._OpenConfig()
+ lvnames = set()
+ for instance in self._config_data.instances.values():
+ node_data = instance.MapLVsByNode()
+ for lv_list in node_data.values():
+ lvnames.update(lv_list)
+ return lvnames
+
+ @locking.ssynchronized(_config_lock, shared=1)
+ def GenerateUniqueID(self, exceptions=None):
+ """Generate an unique disk name.
+
+ This checks the current node, instances and disk names for
+ duplicates.
+
+ Args:
+ - exceptions: a list with some other names which should be checked
+ for uniqueness (used for example when you want to get
+ more than one id at one time without adding each one in
+ turn to the config file
+
+ Returns: the unique id as a string
+
+ """
+ existing = set()
+ existing.update(self._temporary_ids)
+ existing.update(self._ComputeAllLVs())
+ existing.update(self._config_data.instances.keys())
+ existing.update(self._config_data.nodes.keys())
+ if exceptions is not None:
+ existing.update(exceptions)
+ retries = 64
+ while retries > 0:
+ unique_id = utils.NewUUID()
+ if unique_id not in existing and unique_id is not None:
+ break
+ else:
+ raise errors.ConfigurationError("Not able generate an unique ID"
+ " (last tried ID: %s" % unique_id)
+ self._temporary_ids.add(unique_id)
+ return unique_id
+