Add cfgupgrade for changing nic.network to uuid
authorDimitris Aragiorgis <dimara@grnet.gr>
Sat, 16 Feb 2013 13:19:40 +0000 (15:19 +0200)
committerHelga Velroyen <helgav@google.com>
Mon, 18 Feb 2013 10:16:44 +0000 (11:16 +0100)
This gets all network info from config_data and parses
all instances and their NICs and makes the substitution.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: Helga Velroyen <helgav@google.com>

tools/cfgupgrade

index bccb34e..4fa49d9 100755 (executable)
@@ -111,6 +111,20 @@ def UpgradeGroups(config_data):
       group["networks"] = {}
 
 
+def UpgradeInstances(config_data):
+  network2uuid = dict((n["name"], n["uuid"])
+                      for n in config_data["networks"].values())
+  for inst in config_data["instances"].values():
+    for nic in inst["nics"]:
+      name = nic.get("network", None)
+      if name:
+        uuid = network2uuid.get(name, None)
+        if uuid:
+          print("NIC with network name %s found."
+                " Substituting with uuid %s." % (name, uuid))
+          nic["network"] = uuid
+
+
 def main():
   """Main program.
 
@@ -294,6 +308,7 @@ def main():
 
   UpgradeNetworks(config_data)
   UpgradeGroups(config_data)
+  UpgradeInstances(config_data)
 
   try:
     logging.info("Writing configuration file to %s", options.CONFIG_DATA_PATH)