From 26b316d09e8ef1b4f530be603faaa38076df8719 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Wed, 23 Sep 2009 17:37:46 +0200 Subject: [PATCH] Separate the computation of all config IDs We will need this in another place, so we abstract the 'compute all current IDs' functionality into a separate function. We also change the name of the _ComputeAllLVs to _AllLVs to match the other _All*s functions. Signed-off-by: Iustin Pop Reviewed-by: Michael Hanselmann (cherry picked from commit 34e54ebc1417f843bc96c86025f15fb76c3a023a) --- lib/config.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/config.py b/lib/config.py index b43b3e8..af45aa3 100644 --- a/lib/config.py +++ b/lib/config.py @@ -148,7 +148,7 @@ class ConfigWriter: raise errors.ConfigurationError("Can't generate unique DRBD secret") return secret - def _ComputeAllLVs(self): + def _AllLVs(self): """Compute the list of all LVs. """ @@ -159,6 +159,23 @@ class ConfigWriter: lvnames.update(lv_list) return lvnames + def _AllIDs(self, include_temporary): + """Compute the list of all UUIDs and names we have. + + @type include_temporary: boolean + @param include_temporary: whether to include the _temporary_ids set + @rtype: set + @return: a set of IDs + + """ + existing = set() + if include_temporary: + existing.update(self._temporary_ids) + existing.update(self._AllLVs()) + existing.update(self._config_data.instances.keys()) + existing.update(self._config_data.nodes.keys()) + return existing + @locking.ssynchronized(_config_lock, shared=1) def GenerateUniqueID(self, exceptions=None): """Generate an unique disk name. @@ -175,11 +192,7 @@ class ConfigWriter: @return: the unique id """ - 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()) + existing = self._AllIDs(include_temporary=True) if exceptions is not None: existing.update(exceptions) retries = 64 -- 1.7.10.4