From 51144e3356f5766579380b0f82cd50bbf40eab6f Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 13 Aug 2008 12:55:58 +0000
Subject: [PATCH] Fix adding pristine nodes

If a node hasn't been part of the cluster before being added it'll not
have the cluster's SSH key. This patch makes sure to accept those by
not aliasing the machine name to the cluster name.

Reviewed-by: ultrotter
---
 lib/bootstrap.py |  3 ++-
 lib/ssh.py       | 12 ++++++++----
 scripts/gnt-node |  1 +
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 6c2f516ba..3045a44e8 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -285,7 +285,8 @@ def SetupNodeDaemon(node):
                 constants.SSL_CERT_FILE, gntpem,
                 constants.NODE_INITD_SCRIPT))
 
-  result = sshrunner.Run(node, 'root', mycommand, batch=False, ask_key=True)
+  result = sshrunner.Run(node, 'root', mycommand, batch=False, ask_key=True,
+                         use_cluster_key=False)
   if result.failed:
     raise errors.OpExecError("Remote command on node %s, error: %s,"
                              " output: %s" %
diff --git a/lib/ssh.py b/lib/ssh.py
index 6f32e5683..366426a0d 100644
--- a/lib/ssh.py
+++ b/lib/ssh.py
@@ -101,7 +101,7 @@ class SshRunner:
     return "-oHostKeyAlias=%s" % self.sstore.GetClusterName()
 
   def BuildCmd(self, hostname, user, command, batch=True, ask_key=False,
-               tty=False):
+               tty=False, use_cluster_key=True):
     """Build an ssh command to execute a command on a remote node.
 
     Args:
@@ -111,6 +111,7 @@ class SshRunner:
       batch: if true, ssh will run in batch mode with no prompting
       ask_key: if true, ssh will run with StrictHostKeyChecking=ask, so that
                we can connect to an unknown host (not valid in batch mode)
+      use_cluster_key: Whether to expect and use the cluster-global SSH key
 
     Returns:
       The ssh call to run 'command' on the remote host.
@@ -118,7 +119,8 @@ class SshRunner:
     """
     argv = [constants.SSH, "-q"]
     argv.extend(KNOWN_HOSTS_OPTS)
-    argv.append(self._GetHostKeyAliasOption())
+    if use_cluster_key:
+      argv.append(self._GetHostKeyAliasOption())
     if batch:
       # if we are in batch mode, we can't ask the key
       if ask_key:
@@ -131,7 +133,8 @@ class SshRunner:
     argv.extend(["%s@%s" % (user, hostname), command])
     return argv
 
-  def Run(self, hostname, user, command, batch=True, ask_key=False):
+  def Run(self, hostname, user, command, batch=True, ask_key=False,
+          use_cluster_key=True):
     """Runs a command on a remote node.
 
     This method has the same return value as `utils.RunCmd()`, which it
@@ -150,7 +153,8 @@ class SshRunner:
 
     """
     return utils.RunCmd(self.BuildCmd(hostname, user, command, batch=batch,
-                                      ask_key=ask_key))
+                                      ask_key=ask_key,
+                                      use_cluster_key=use_cluster_key))
 
   def CopyFileToNode(self, node, filename):
     """Copy a file to another node with scp.
diff --git a/scripts/gnt-node b/scripts/gnt-node
index 439d9d843..20461b587 100755
--- a/scripts/gnt-node
+++ b/scripts/gnt-node
@@ -37,6 +37,7 @@ _LIST_DEF_FIELDS = [
   "pinst_cnt", "sinst_cnt",
   ]
 
+
 def AddNode(opts, args):
   """Add node cli-to-processor bridge.
 
-- 
GitLab