Add cluster-init --no-etc-hosts parameter
authorGuido Trotter <ultrotter@google.com>
Thu, 28 May 2009 09:12:58 +0000 (10:12 +0100)
committerIustin Pop <iustin@google.com>
Mon, 10 Aug 2009 10:41:39 +0000 (12:41 +0200)
If --no-etc-hosts is passed in at cluster init time we set a new
parameter in the cluster's object to false, and avoid adding nodes to
the hosts file. The UpgradeConfig function is used to set the value to
True, when upgrading from an old configuration version.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
(cherry picked from commit b86a6bcd476e420269a24a9b3d6289bebba69442)

lib/bootstrap.py
lib/cmdlib.py
lib/objects.py
scripts/gnt-cluster

index fda1c2e..c936606 100644 (file)
@@ -126,7 +126,8 @@ def _InitGanetiServerSetup():
 def InitCluster(cluster_name, mac_prefix, def_bridge,
                 master_netdev, file_storage_dir, candidate_pool_size,
                 secondary_ip=None, vg_name=None, beparams=None, hvparams=None,
-                enabled_hypervisors=None, default_hypervisor=None):
+                enabled_hypervisors=None, default_hypervisor=None,
+                modify_etc_hosts=True):
   """Initialise the cluster.
 
   @type candidate_pool_size: int
@@ -236,7 +237,9 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
     f.close()
   sshkey = sshline.split(" ")[1]
 
-  utils.AddHostToEtcHosts(hostname.name)
+  if modify_etc_hosts:
+    utils.AddHostToEtcHosts(hostname.name)
+
   _InitSSHSetup()
 
   # init of cluster config file
@@ -258,6 +261,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
     beparams={constants.BEGR_DEFAULT: beparams},
     hvparams=hvparams,
     candidate_pool_size=candidate_pool_size,
+    modify_etc_hosts=opts.modify_etc_hosts,
     )
   master_node_config = objects.Node(name=hostname.name,
                                     primary_ip=hostname.ip,
index ae2267a..1919663 100644 (file)
@@ -2378,7 +2378,8 @@ class LUAddNode(LogicalUnit):
                                " new node: %s" % msg)
 
     # Add node to our /etc/hosts, and add key to known_hosts
-    utils.AddHostToEtcHosts(new_node.name)
+    if self.cfg.GetClusterInfo().modify_etc_hosts:
+      utils.AddHostToEtcHosts(new_node.name)
 
     if new_node.secondary_ip != new_node.primary_ip:
       result = self.rpc.call_node_has_ip_address(new_node.name,
index 23bb0f9..13e78dd 100644 (file)
@@ -752,8 +752,16 @@ class Cluster(TaggableObject):
     "hvparams",
     "beparams",
     "candidate_pool_size",
+    "modify_etc_hosts",
     ]
 
+  def UpgradeConfig(self):
+    """Fill defaults for missing configuration values.
+
+    """
+    if self.modify_etc_hosts is None:
+      self.modify_etc_hosts = True
+
   def ToDict(self):
     """Custom function for cluster.
 
index e6cb4f7..fff42bb 100755 (executable)
@@ -105,6 +105,7 @@ def InitCluster(opts, args):
                         hvparams=hvparams,
                         beparams=beparams,
                         candidate_pool_size=opts.candidate_pool_size,
+                        modify_etc_hosts=opts.modify_etc_hosts,
                         )
   return 0
 
@@ -582,6 +583,10 @@ commands = {
                         help="No support for lvm based instances"
                              " (cluster-wide)",
                         action="store_false", default=True,),
+            make_option("--no-etc-hosts", dest="modify_etc_hosts",
+                        help="Don't modify /etc/hosts"
+                             " (cluster-wide)",
+                        action="store_false", default=True,),
             make_option("--enabled-hypervisors", dest="enabled_hypervisors",
                         help="Comma-separated list of hypervisors",
                         type="string", default=None),