Commit 28eddce5 authored by Guido Trotter's avatar Guido Trotter
Browse files

_RedistributeAncillaryFiles function



This function is shared between AddNode and RedistributeConfig, and used
to redistribute additional files which are inherently part of the
cluster configuration.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 4d2a7c95
......@@ -1548,6 +1548,39 @@ class LUSetClusterParams(LogicalUnit):
_AdjustCandidatePool(self)
def _RedistributeAncillaryFiles(lu, additional_nodes=None):
"""Distribute additional files which are part of the cluster configuration.
ConfigWriter takes care of distributing the config and ssconf files, but
there are more files which should be distributed to all nodes. This function
makes sure those are copied.
@param lu: calling logical unit
@param additional_nodes: list of nodes not in the config to distribute to
"""
# 1. Gather target nodes
myself = lu.cfg.GetNodeInfo(lu.cfg.GetMasterNode())
dist_nodes = lu.cfg.GetNodeList()
if additional_nodes is not None:
dist_nodes.extend(additional_nodes)
if myself.name in dist_nodes:
dist_nodes.remove(myself.name)
# 2. Gather files to distribute
dist_files = set([constants.ETC_HOSTS,
constants.SSH_KNOWN_HOSTS_FILE,
constants.RAPI_CERT_FILE,
constants.RAPI_USERS_FILE,
])
# 3. Perform the files upload
for fname in dist_files:
if os.path.exists(fname):
result = lu.rpc.call_upload_file(dist_nodes, fname)
for to_node, to_result in result.items():
if to_result.failed or not to_result.data:
logging.error("Copy of file %s to node %s failed", fname, to_node)
class LURedistributeConfig(NoHooksLU):
"""Force the redistribution of cluster configuration.
......@@ -1573,6 +1606,7 @@ class LURedistributeConfig(NoHooksLU):
"""
self.cfg.Update(self.cfg.GetClusterInfo())
_RedistributeAncillaryFiles(self)
def _WaitForSync(lu, instance, oneshot=False, unlock=False):
......@@ -2248,25 +2282,11 @@ class LUAddNode(LogicalUnit):
(verifier, result[verifier].data['nodelist'][failed]))
raise errors.OpExecError("ssh/hostname verification failed.")
# Distribute updated /etc/hosts and known_hosts to all nodes,
# including the node just added
myself = self.cfg.GetNodeInfo(self.cfg.GetMasterNode())
dist_nodes = self.cfg.GetNodeList()
if not self.op.readd:
dist_nodes.append(node)
if myself.name in dist_nodes:
dist_nodes.remove(myself.name)
logging.debug("Copying hosts and known_hosts to all nodes")
for fname in (constants.ETC_HOSTS, constants.SSH_KNOWN_HOSTS_FILE):
result = self.rpc.call_upload_file(dist_nodes, fname)
for to_node, to_result in result.iteritems():
if to_result.failed or not to_result.data:
logging.error("Copy of file %s to node %s failed", fname, to_node)
if self.op.readd:
_RedistributeAncillaryFiles(self)
self.context.ReaddNode(new_node)
else:
_RedistributeAncillaryFiles(self, additional_nodes=node)
self.context.AddNode(new_node)
......
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