The patch also starts using the current UUIDs (in the new attributes)
while computing the _AllIDs list.
---
 lib/config.py |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/lib/config.py b/lib/config.py
index 46f4134..fedb387 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -175,6 +175,7 @@ class ConfigWriter:
     existing.update(self._AllLVs())
     existing.update(self._config_data.instances.keys())
     existing.update(self._config_data.nodes.keys())
+    existing.update([o.uuid for o in self._AllUUIDObjects() if o.uuid])
     return existing
 
   @locking.ssynchronized(_config_lock, shared=1)
@@ -1057,6 +1058,14 @@ class ConfigWriter:
     self._config_data.serial_no += 1
     self._config_data.mtime = time.time()
 
+  def _AllUUIDObjects(self):
+    """Returns all objects with uuid attributes.
+
+    """
+    return (self._config_data.instances.values() +
+            self._config_data.nodes.values() +
+            [self._config_data.cluster])
+
   def _OpenConfig(self):
     """Read the config data from disk.
 
@@ -1084,6 +1093,28 @@ class ConfigWriter:
     # ssconf update
     self._last_cluster_serial = -1
 
+    # And finally run our (custom) config upgrade sequence
+    self._UpgradeConfig()
+
+  def _UpgradeConfig(self):
+    """Run upgrade steps that cannot be done purely in the objects.
+
+    This is because some data elements need uniqueness across the
+    whole configuration, etc.
+
+    @warning: this function will call L{_WriteConfig()}, so it needs
+        to either be called with the lock held or from a safe place
+        (the constructor)
+
+    """
+    modified = False
+    for item in self._AllUUIDObjects():
+      if item.uuid is None:
+        item.uuid = self.GenerateUniqueID()
+        modified = True
+    if modified:
+      self._WriteConfig()
+
   def _DistributeConfig(self):
     """Distribute the configuration to the other nodes.
 
-- 
1.6.3.3

Reply via email to