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.
---
 lib/bootstrap.py               |   18 +++++++++++++++-
 lib/config.py                  |   41 ++++++++++++++-------------------------
 test/ganeti.config_unittest.py |   17 +++++++++++++--
 3 files changed, 45 insertions(+), 31 deletions(-)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 160c1a5..b0fb955 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -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)
 
diff --git a/lib/config.py b/lib/config.py
index 8198b1c..adf1184 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -777,36 +777,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)
-
-    self._config_data = objects.ConfigData(nodes={node: nodeconfig},
-                                           instances={},
-                                           cluster=globalconfig)
+    @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={})
     self._WriteConfig()
 
   @locking.ssynchronized(_config_lock, shared=1)
diff --git a/test/ganeti.config_unittest.py b/test/ganeti.config_unittest.py
index 737dbc8..fb7bd02 100755
--- a/test/ganeti.config_unittest.py
+++ b/test/ganeti.config_unittest.py
@@ -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"""
-- 
1.6.0.2

Reply via email to