+ # Check whether it's a Ganeti configuration directory
+ if not (os.path.isfile(options.CONFIG_DATA_PATH) and
+ os.path.isfile(options.SERVER_PEM_PATH) or
+ os.path.isfile(options.KNOWN_HOSTS_PATH)):
+ raise Error(("%s does not seem to be a known Ganeti configuration"
+ " directory") % options.data_dir)
+
+ config_version = ReadFile(SsconfName('config_version'), "1.2").strip()
+ logging.info("Found configuration version %s", config_version)
+
+ config_data = serializer.LoadJson(ReadFile(options.CONFIG_DATA_PATH))
+
+ # Ganeti 1.2?
+ if config_version == "1.2":
+ logging.info("Found a Ganeti 1.2 configuration")
+
+ cluster = config_data["cluster"]
+
+ old_config_version = cluster.get("config_version", None)
+ logging.info("Found old configuration version %s", old_config_version)
+ if old_config_version not in (3, ):
+ raise Error("Unsupported configuration version: %s" %
+ old_config_version)
+ if 'version' not in config_data:
+ config_data['version'] = constants.BuildVersion(2, 0, 0)
+ if F_SERIAL not in config_data:
+ config_data[F_SERIAL] = 1
+
+ # Make sure no instance uses remote_raid1 anymore
+ remote_raid1_instances = []
+ for instance in config_data["instances"].values():
+ if instance["disk_template"] == "remote_raid1":
+ remote_raid1_instances.append(instance["name"])
+ if remote_raid1_instances:
+ for name in remote_raid1_instances:
+ logging.error("Instance %s still using remote_raid1 disk template")
+ raise Error("Unable to convert configuration as long as there are"
+ " instances using remote_raid1 disk template")
+
+ # Build content of new known_hosts file
+ cluster_name = ReadFile(SsconfName('cluster_name')).rstrip()
+ cluster_key = cluster['rsahostkeypub']
+ known_hosts = "%s ssh-rsa %s\n" % (cluster_name, cluster_key)
+
+ Cluster12To20(cluster)
+
+ # Add node attributes
+ logging.info("Upgrading nodes")
+ # stable-sort the names to have repeatable runs
+ for node_name in utils.NiceSort(config_data['nodes'].keys()):
+ Node12To20(config_data['nodes'][node_name])
+
+ # Instance changes
+ logging.info("Upgrading instances")
+ drbd_minors = dict.fromkeys(config_data['nodes'], 0)
+ secrets = set()
+ # stable-sort the names to have repeatable runs
+ for instance_name in utils.NiceSort(config_data['instances'].keys()):
+ Instance12To20(drbd_minors, secrets, cluster['default_hypervisor'],
+ config_data['instances'][instance_name])