+ else:
+ # non-batch mode
+
+ if ask_key:
+ options.append("-oStrictHostKeyChecking=ask")
+ elif strict_host_check:
+ options.append("-oStrictHostKeyChecking=yes")
+ else:
+ options.append("-oStrictHostKeyChecking=no")
+
+ return options
+
+ def BuildCmd(self, hostname, user, command, batch=True, ask_key=False,
+ tty=False, use_cluster_key=True, strict_host_check=True,
+ private_key=None):
+ """Build an ssh command to execute a command on a remote node.
+
+ @param hostname: the target host, string
+ @param user: user to auth as
+ @param command: the command
+ @param batch: if true, ssh will run in batch mode with no prompting
+ @param ask_key: if true, ssh will run with
+ StrictHostKeyChecking=ask, so that we can connect to an
+ unknown host (not valid in batch mode)
+ @param use_cluster_key: whether to expect and use the
+ cluster-global SSH key
+ @param strict_host_check: whether to check the host's SSH key at all
+ @param private_key: use this private key instead of the default
+
+ @return: the ssh call to run 'command' on the remote host.
+
+ """
+ argv = [constants.SSH, "-q"]
+ argv.extend(self._BuildSshOptions(batch, ask_key, use_cluster_key,
+ strict_host_check, private_key))
+ if tty:
+ argv.append("-t")
+ argv.extend(["%s@%s" % (user, hostname), command])
+ return argv
+
+ def Run(self, *args, **kwargs):
+ """Runs a command on a remote node.
+
+ This method has the same return value as `utils.RunCmd()`, which it
+ uses to launch ssh.
+
+ Args: see SshRunner.BuildCmd.
+
+ @rtype: L{utils.RunResult}
+ @return: the result as from L{utils.RunCmd()}
+
+ """
+ return utils.RunCmd(self.BuildCmd(*args, **kwargs))
+
+ def CopyFileToNode(self, node, filename):
+ """Copy a file to another node with scp.
+
+ @param node: node in the cluster
+ @param filename: absolute pathname of a local file