Skip to content
Snippets Groups Projects
Commit 02f99608 authored by Oleksiy Mishchenko's avatar Oleksiy Mishchenko
Browse files

Fix for gnt-cluster init.

Reviewed-by: iustinp
parent e69d05fd
No related merge requests found
......@@ -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
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment