From 1ff085706667454ec50564add3ed982cf8789bdc Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Tue, 18 Mar 2008 13:03:59 +0000 Subject: [PATCH] Use new cluster alias in known_hosts file Reviewed-by: ultrotter --- lib/cmdlib.py | 2 +- lib/ssh.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index cb2a5bcd4..e0be0b79e 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -96,7 +96,7 @@ class LogicalUnit(object): """ if not self.__ssh: - self.__ssh = ssh.SshRunner() + self.__ssh = ssh.SshRunner(self.sstore) return self.__ssh ssh = property(fget=__GetSSH) diff --git a/lib/ssh.py b/lib/ssh.py index d4fc2174c..6481d70fa 100644 --- a/lib/ssh.py +++ b/lib/ssh.py @@ -30,6 +30,7 @@ from ganeti import logger from ganeti import utils from ganeti import errors from ganeti import constants +from ganeti import ssconf KNOWN_HOSTS_OPTS = [ @@ -90,6 +91,15 @@ class SshRunner: """Wrapper for SSH commands. """ + def __init__(self, sstore=None): + if sstore is None: + self.sstore = ssconf.SimpleStore() + else: + self.sstore = sstore + + def _GetHostKeyAliasOption(self): + return "-oHostKeyAlias=%s" % self.sstore.GetClusterName() + def BuildCmd(self, hostname, user, command, batch=True, ask_key=False, tty=False): """Build an ssh command to execute a command on a remote node. @@ -108,6 +118,7 @@ class SshRunner: """ argv = ["ssh", "-q"] argv.extend(KNOWN_HOSTS_OPTS) + argv.append(self._GetHostKeyAliasOption()) if batch: # if we are in batch mode, we can't ask the key if ask_key: @@ -163,6 +174,7 @@ class SshRunner: command = ["scp", "-q", "-p"] command.extend(KNOWN_HOSTS_OPTS) command.extend(BATCH_MODE_OPTS) + command.append(self._GetHostKeyAliasOption()) command.append(filename) command.append("%s:%s" % (node, filename)) -- GitLab