+ def __init__(self, cluster_name, ipv6=False):
+ """Initializes this class.
+
+ @type cluster_name: str
+ @param cluster_name: name of the cluster
+ @type ipv6: bool
+ @param ipv6: If true, force ssh to use IPv6 addresses only
+
+ """
+ self.cluster_name = cluster_name
+ self.ipv6 = ipv6
+
+ def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
+ strict_host_check, private_key=None, quiet=True):
+ """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
+ @param private_key: use this private key instead of the default
+ @param quiet: whether to enable -q to ssh
+
+ @rtype: list
+ @return: the list of options ready to use in L{utils.process.RunCmd}
+
+ """
+ options = [
+ "-oEscapeChar=none",
+ "-oHashKnownHosts=no",
+ "-oGlobalKnownHostsFile=%s" % pathutils.SSH_KNOWN_HOSTS_FILE,
+ "-oUserKnownHostsFile=/dev/null",
+ "-oCheckHostIp=no",
+ ]
+
+ if use_cluster_key:
+ options.append("-oHostKeyAlias=%s" % self.cluster_name)
+
+ if quiet:
+ options.append("-q")
+
+ if private_key:
+ options.append("-i%s" % private_key)
+
+ # TODO: Too many boolean options, maybe convert them to more descriptive
+ # constants.
+
+ # Note: ask_key conflicts with batch mode
+ if batch:
+ if ask_key:
+ raise errors.ProgrammerError("SSH call requested conflicting options")
+
+ options.append("-oBatchMode=yes")
+
+ if strict_host_check:
+ options.append("-oStrictHostKeyChecking=yes")
+ else:
+ options.append("-oStrictHostKeyChecking=no")
+
+ else:
+ # non-batch mode
+
+ if ask_key:
+ options.append("-oStrictHostKeyChecking=ask")
+ elif strict_host_check:
+ options.append("-oStrictHostKeyChecking=yes")
+ else:
+ options.append("-oStrictHostKeyChecking=no")