- argv = ["ssh", "-q"]
- argv.extend(KNOWN_HOSTS_OPTS)
- if batch:
- # if we are in batch mode, we can't ask the key
- if ask_key:
- raise errors.ProgrammerError("SSH call requested conflicting options")
- argv.extend(BATCH_MODE_OPTS)
- elif ask_key:
- argv.extend(ASK_KEY_OPTS)
- argv.extend(["%s@%s" % (user, hostname), command])
- return argv
-
-
-def SSHCall(hostname, user, command, batch=True, ask_key=False):
- """Execute a command on a remote node.
-
- This method has the same return value as `utils.RunCmd()`, which it
- uses to launch ssh.
-
- Args:
- hostname: the target host, string
- user: user to auth as
- command: the command
- 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)
-
- Returns:
- `utils.RunResult` as for `utils.RunCmd()`
+ def __init__(self, cluster_name):
+ self.cluster_name = cluster_name
+
+ def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
+ strict_host_check):
+ """Builds a list with needed SSH options.
+
+ @param batch: same as ssh's batch option
+ @param ask_key: allows ssh to ask for key confirmation; this
+ parameter conflicts with the batch one
+ @param use_cluster_key: if True, use the cluster name as the
+ HostKeyAlias name
+ @param strict_host_check: this makes the host key checking strict
+
+ @rtype: list
+ @return: the list of options ready to use in L{utils.RunCmd}
+
+ """
+ options = [
+ "-oEscapeChar=none",
+ "-oHashKnownHosts=no",
+ "-oGlobalKnownHostsFile=%s" % constants.SSH_KNOWN_HOSTS_FILE,
+ "-oUserKnownHostsFile=/dev/null",
+ ]