From 02f99608dd26b7e91953630870585cd1a431d20b Mon Sep 17 00:00:00 2001 From: Oleksiy Mishchenko <oleksiy@google.com> Date: Wed, 8 Oct 2008 13:04:52 +0000 Subject: [PATCH] Fix for gnt-cluster init. Reviewed-by: iustinp --- lib/bootstrap.py | 39 +++++++++++++++++++++++++++++++++++++-- lib/ssconf.py | 12 +++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/bootstrap.py b/lib/bootstrap.py index 2dfb1fa74..af9cb9297 100644 --- a/lib/bootstrap.py +++ b/lib/bootstrap.py @@ -229,9 +229,9 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge, master_node_config = objects.Node(name=hostname.name, primary_ip=hostname.ip, secondary_ip=secondary_ip) - cfg = config.ConfigWriter() - cfg.InitConfig(constants.CONFIG_VERSION, cluster_config, master_node_config) + cfg = InitConfig(constants.CONFIG_VERSION, + cluster_config, master_node_config) ssh.WriteKnownHostsFile(cfg, constants.SSH_KNOWN_HOSTS_FILE) # start the master ip @@ -239,6 +239,41 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge, rpc.call_node_start_master(hostname.name, True) +def InitConfig(version, cluster_config, master_node_config, + cfg_file=constants.CLUSTER_CONF_FILE): + """Create the initial cluster configuration. + + It will contain the current node, which will also be the master + node, and no instances. + + @type version: int + @param version: Configuration version + @type cluster_config: objects.Cluster + @param cluster_config: Cluster configuration + @type master_node_config: objects.Node + @param master_node_config: Master node configuration + @type file_name: string + @param file_name: Configuration file path + + @rtype: ssconf.SimpleConfigWriter + @returns: Initialized config instance + + """ + nodes = { + master_node_config.name: master_node_config, + } + + config_data = objects.ConfigData(version=version, + cluster=cluster_config, + nodes=nodes, + instances={}, + serial_no=1) + cfg = ssconf.SimpleConfigWriter.FromDict(config_data.ToDict(), cfg_file) + cfg.Save() + + return cfg + + def FinalizeClusterDestroy(master): """Execute the last steps of cluster destroy diff --git a/lib/ssconf.py b/lib/ssconf.py index f7bf49c33..b800f2503 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -35,7 +35,7 @@ from ganeti import utils from ganeti import serializer -class SimpleConfigReader: +class SimpleConfigReader(object): """Simple class to read configuration file. """ @@ -74,6 +74,16 @@ class SimpleConfigReader: def GetNodeList(self): return self._config_data["nodes"].keys() + @classmethod + def FromDict(cls, val, cfg_file=constants.CLUSTER_CONF_FILE): + """Alternative construction from a dictionary. + + """ + obj = SimpleConfigReader.__new__(cls) + obj._config_data = val + obj._file_name = cfg_file + return obj + class SimpleConfigWriter(SimpleConfigReader): """Simple class to write configuration file. -- GitLab