+ This is used to detect problems in ssh known_hosts files
+ (conflicting known hosts) and incosistencies between dns/hosts
+ entries and local machine names
+
+ @param node: nodename of a host to check; can be short or
+ full qualified hostname
+
+ @return: (success, detail), where:
+ - success: True/False
+ - detail: string with details
+
+ """
+ retval = self.Run(node, 'root', 'hostname')
+
+ if retval.failed:
+ msg = "ssh problem"
+ output = retval.output
+ if output:
+ msg += ": %s" % output
+ else:
+ msg += ": %s (no output)" % retval.fail_reason
+ logging.error("Command %s failed: %s" % (retval.cmd, msg))
+ return False, msg
+
+ remotehostname = retval.stdout.strip()
+
+ if not remotehostname or remotehostname != node:
+ return False, "hostname mismatch, got %s" % remotehostname
+
+ return True, "host matches"
+
+
+def WriteKnownHostsFile(cfg, file_name):
+ """Writes the cluster-wide equally known_hosts file.
+
+ """
+ utils.WriteFile(file_name, mode=0600,
+ data="%s ssh-rsa %s\n" % (cfg.GetClusterName(),
+ cfg.GetHostKey()))