Commit b9eeeb02 authored by Michael Hanselmann's avatar Michael Hanselmann

Move instantiation of config into bootstrap.py

Future patches will add even more variables to the cluster config.
Adding more parameters wouldn't make the function easier to use and
it doesn't make sense to pass them to another function, as it's
only done once in bootstrap.py on cluster initialization.

Reviewed-by: iustinp
parent 53c04d04
......@@ -35,6 +35,7 @@ from ganeti import utils
from ganeti import errors
from ganeti import config
from ganeti import constants
from ganeti import objects
from ganeti import ssconf
......@@ -149,6 +150,8 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
raise errors.OpPrereqError("You gave %s as secondary IP,"
" but it does not belong to this host." %
secondary_ip)
else:
secondary_ip = hostname.ip
if vg_name is not None:
# Check if volume group is valid
......@@ -219,9 +222,20 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
_InitSSHSetup(hostname.name)
# init of cluster config file
cluster_config = objects.Cluster(
serial_no=1,
rsahostkeypub=sshkey,
highest_used_port=(constants.FIRST_DRBD_PORT - 1),
mac_prefix=mac_prefix,
volume_group_name=vg_name,
default_bridge=def_bridge,
tcpudp_port_pool=set(),
)
master_node_config = objects.Node(name=hostname.name,
primary_ip=hostname.ip,
secondary_ip=secondary_ip)
cfg = config.ConfigWriter()
cfg.InitConfig(hostname.name, hostname.ip, secondary_ip, sshkey,
mac_prefix, vg_name, def_bridge)
cfg.InitConfig(cluster_config, master_node_config)
ssh.WriteKnownHostsFile(cfg, ss, constants.SSH_KNOWN_HOSTS_FILE)
......
......@@ -861,36 +861,25 @@ class ConfigWriter:
self._DistributeConfig()
@locking.ssynchronized(_config_lock)
def InitConfig(self, node, primary_ip, secondary_ip,
hostkeypub, mac_prefix, vg_name, def_bridge):
def InitConfig(self, cluster_config, master_node_config):
"""Create the initial cluster configuration.
It will contain the current node, which will also be the master
node, and no instances or operating systmes.
node, and no instances.
Args:
node: the nodename of the initial node
primary_ip: the IP address of the current host
secondary_ip: the secondary IP of the current host or None
hostkeypub: the public hostkey of this host
"""
hu_port = constants.FIRST_DRBD_PORT - 1
globalconfig = objects.Cluster(serial_no=1,
rsahostkeypub=hostkeypub,
highest_used_port=hu_port,
mac_prefix=mac_prefix,
volume_group_name=vg_name,
default_bridge=def_bridge,
tcpudp_port_pool=set())
if secondary_ip is None:
secondary_ip = primary_ip
nodeconfig = objects.Node(name=node, primary_ip=primary_ip,
secondary_ip=secondary_ip, serial_no=1)
self._config_data = objects.ConfigData(nodes={node: nodeconfig},
@type cluster_config: objects.Cluster
@param cluster_config: Cluster configuration
@type master_node_config: objects.Node
@param master_node_config: Master node configuration
"""
nodes = {
master_node_config.name: master_node_config,
}
self._config_data = objects.ConfigData(cluster=cluster_config,
nodes=nodes,
instances={},
cluster=globalconfig,
serial_no=1)
self._WriteConfig()
......
......@@ -55,9 +55,20 @@ class TestConfigRunner(unittest.TestCase):
def _init_cluster(self, cfg):
"""Initializes the cfg object"""
cfg.InitConfig(utils.HostInfo().name, constants.LOCALHOST_IP_ADDRESS,
None, '', 'aa:00:00', 'xenvg',
constants.DEFAULT_BRIDGE)
cluster_config = objects.Cluster(
serial_no=1,
rsahostkeypub="",
highest_used_port=(constants.FIRST_DRBD_PORT - 1),
mac_prefix="aa:00:00",
volume_group_name="xenvg",
default_bridge=constants.DEFAULT_BRIDGE,
tcpudp_port_pool=set(),
)
ip = constants.LOCALHOST_IP_ADDRESS
master_node_config = objects.Node(name=utils.HostInfo().name,
primary_ip=ip,
secondary_ip=ip)
cfg.InitConfig(cluster_config, master_node_config)
def _create_instance(self):
"""Create and return an instance object"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment