Commit b86a6bcd authored by Guido Trotter's avatar Guido Trotter
Browse files

Add cluster-init --no-etc-hosts parameter



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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 560428be
...@@ -123,7 +123,8 @@ def _InitGanetiServerSetup(): ...@@ -123,7 +123,8 @@ def _InitGanetiServerSetup():
def InitCluster(cluster_name, mac_prefix, def_bridge, def InitCluster(cluster_name, mac_prefix, def_bridge,
master_netdev, file_storage_dir, candidate_pool_size, master_netdev, file_storage_dir, candidate_pool_size,
secondary_ip=None, vg_name=None, beparams=None, hvparams=None, 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. """Initialise the cluster.
@type candidate_pool_size: int @type candidate_pool_size: int
...@@ -225,7 +226,9 @@ def InitCluster(cluster_name, mac_prefix, def_bridge, ...@@ -225,7 +226,9 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
f.close() f.close()
sshkey = sshline.split(" ")[1] sshkey = sshline.split(" ")[1]
utils.AddHostToEtcHosts(hostname.name) if modify_etc_hosts:
utils.AddHostToEtcHosts(hostname.name)
_InitSSHSetup() _InitSSHSetup()
# init of cluster config file # init of cluster config file
...@@ -247,6 +250,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge, ...@@ -247,6 +250,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
beparams={constants.BEGR_DEFAULT: beparams}, beparams={constants.BEGR_DEFAULT: beparams},
hvparams=hvparams, hvparams=hvparams,
candidate_pool_size=candidate_pool_size, candidate_pool_size=candidate_pool_size,
modify_etc_hosts=opts.modify_etc_hosts,
) )
master_node_config = objects.Node(name=hostname.name, master_node_config = objects.Node(name=hostname.name,
primary_ip=hostname.ip, primary_ip=hostname.ip,
......
...@@ -2265,7 +2265,8 @@ class LUAddNode(LogicalUnit): ...@@ -2265,7 +2265,8 @@ class LUAddNode(LogicalUnit):
" new node: %s" % msg) " new node: %s" % msg)
# Add node to our /etc/hosts, and add key to known_hosts # 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: if new_node.secondary_ip != new_node.primary_ip:
result = self.rpc.call_node_has_ip_address(new_node.name, result = self.rpc.call_node_has_ip_address(new_node.name,
......
...@@ -735,8 +735,16 @@ class Cluster(TaggableObject): ...@@ -735,8 +735,16 @@ class Cluster(TaggableObject):
"hvparams", "hvparams",
"beparams", "beparams",
"candidate_pool_size", "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): def ToDict(self):
"""Custom function for cluster. """Custom function for cluster.
......
...@@ -110,6 +110,7 @@ def InitCluster(opts, args): ...@@ -110,6 +110,7 @@ def InitCluster(opts, args):
hvparams=hvparams, hvparams=hvparams,
beparams=beparams, beparams=beparams,
candidate_pool_size=opts.candidate_pool_size, candidate_pool_size=opts.candidate_pool_size,
modify_etc_hosts=opts.modify_etc_hosts,
) )
return 0 return 0
...@@ -565,6 +566,10 @@ commands = { ...@@ -565,6 +566,10 @@ commands = {
help="No support for lvm based instances" help="No support for lvm based instances"
" (cluster-wide)", " (cluster-wide)",
action="store_false", default=True,), 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", make_option("--enabled-hypervisors", dest="enabled_hypervisors",
help="Comma-separated list of hypervisors", help="Comma-separated list of hypervisors",
type="string", default=None), type="string", default=None),
......
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