Commit 87622829 authored by Iustin Pop's avatar Iustin Pop
Browse files

Improve the node add operation

Currently, the node add operation uses a job to query the node name and
the bootstrap function directly reads the config file for the cluster

This patch changes to that both the cluster name and the verification of
the node is done via queries to the master.

Reviewed-by: ultrotter
parent f34901f8
......@@ -271,19 +271,19 @@ def FinalizeClusterDestroy(master):
logging.warning("Could not shutdown the node daemon and cleanup the node")
def SetupNodeDaemon(node, ssh_key_check):
def SetupNodeDaemon(cluster_name, node, ssh_key_check):
"""Add a node to the cluster.
This function must be called before the actual opcode, and will ssh
to the remote node, copy the needed files, and start ganeti-noded,
allowing the master to do the rest via normal rpc calls.
node: fully qualified domain name for the new node
@param cluster_name: the cluster name
@param node: the name of the new node
@param ssh_key_check: whether to do a strict key check
cfg = ssconf.SimpleConfigReader()
sshrunner = ssh.SshRunner(cfg.GetClusterName())
sshrunner = ssh.SshRunner(cluster_name)
gntpem = utils.ReadFile(constants.SSL_CERT_FILE)
# in the base64 pem encoding, neither '!' nor '.' are valid chars,
# so we use this to detect an invalid certificate; as long as the
......@@ -313,8 +313,6 @@ def SetupNodeDaemon(node, ssh_key_check):
" output: %s" %
(node, result.fail_reason, result.output))
return 0
def MasterFailover():
"""Failover the master node.
......@@ -53,13 +53,13 @@ def AddNode(opts, args):
@return: the desired exit code
cl = GetClient()
dns_data = utils.HostInfo(args[0])
node =
if not opts.readd:
op = opcodes.OpQueryNodes(output_fields=['name'], names=[node])
output = SubmitOpCode(op)
output = cl.QueryNodes(names=[node], fields=['name'])
except (errors.OpPrereqError, errors.OpExecError):
......@@ -67,6 +67,10 @@ def AddNode(opts, args):
" - please use --readd", args[0], output[0][0])
return 1
# read the cluster name from the master
output = cl.QueryConfigValues(['cluster_name'])
cluster_name = output[0]
ToStderr("-- WARNING -- \n"
"Performing this operation is going to replace the ssh daemon"
" keypair\n"
......@@ -74,7 +78,7 @@ def AddNode(opts, args):
" current one\n"
"and grant full intra-cluster ssh root access to/from it\n", node)
bootstrap.SetupNodeDaemon(node, opts.ssh_key_check)
bootstrap.SetupNodeDaemon(cluster_name, node, opts.ssh_key_check)
op = opcodes.OpAddNode(node_name=args[0], secondary_ip=opts.secondary_ip,
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