cfgupgrade: Remove spindles on downgrade
authorBernardo Dal Seno <bdalseno@google.com>
Wed, 15 May 2013 00:17:56 +0000 (02:17 +0200)
committerBernardo Dal Seno <bdalseno@google.com>
Thu, 23 May 2013 11:04:09 +0000 (13:04 +0200)
Spindles didn't exist in 2.8 and should be removed to downgrade.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

tools/cfgupgrade

index cb65cdf..a2bdc26 100755 (executable)
@@ -260,11 +260,29 @@ def UpgradeAll(config_data):
   UpgradeInstances(config_data)
 
 
+def DowngradeDisks(disks, owner):
+  for disk in disks:
+    # Remove spindles to downgrade to 2.8
+    if "spindles" in disk:
+      logging.warning("Removing spindles (value=%s) from disk %s (%s) of"
+                      " instance %s",
+                      disk["spindles"], disk["iv_name"], disk["uuid"], owner)
+      del disk["spindles"]
+
+
+def DowngradeInstances(config_data):
+  if "instances" not in config_data:
+    raise Error("Cannot find the 'instances' key in the configuration!")
+  for (iname, iobj) in config_data["instances"].items():
+    if "disks" not in iobj:
+      raise Error("Cannot find 'disks' key for instance %s" % iname)
+    DowngradeDisks(iobj["disks"], iname)
+
+
 def DowngradeAll(config_data):
-  # Unused arguments, pylint: disable=W0613
   # Any code specific to a particular version should be labeled that way, so
   # it can be removed when updating to the next version.
-  pass
+  DowngradeInstances(config_data)
 
 
 def main():