def MakeNodePath(node, path): """Builds an absolute path for a virtual node. @type node: string or L{qa_config._QaNode} @param node: Node @type path: string @param path: Path without node-specific prefix """ (_, basedir) = qa_config.GetVclusterSettings() if isinstance(node, basestring): name = node else: name = node.primary if basedir: assert path.startswith("/") return "%s%s" % (vcluster.MakeNodeRoot(basedir, name), path) else: return path
def GetSSHCommand(node, cmd, strict=True, opts=None, tty=False, use_multiplexer=True): """Builds SSH command to be executed. @type node: string @param node: node the command should run on @type cmd: string @param cmd: command to be executed in the node; if None or empty string, no command will be executed @type strict: boolean @param strict: whether to enable strict host key checking @type opts: list @param opts: list of additional options @type tty: boolean or None @param tty: if we should use tty; if None, will be auto-detected @type use_multiplexer: boolean @param use_multiplexer: if the multiplexer for the node should be used """ args = ["ssh", "-oEscapeChar=none", "-oBatchMode=yes", "-lroot"] if tty is None: tty = sys.stdout.isatty() if tty: args.append("-t") if strict: tmp = "yes" else: tmp = "no" args.append("-oStrictHostKeyChecking=%s" % tmp) args.append("-oClearAllForwardings=yes") args.append("-oForwardAgent=yes") if opts: args.extend(opts) if node in _MULTIPLEXERS and use_multiplexer: spath = _MULTIPLEXERS[node][0] args.append("-oControlPath=%s" % spath) args.append("-oControlMaster=no") (vcluster_master, vcluster_basedir) = \ qa_config.GetVclusterSettings() if vcluster_master: args.append(vcluster_master) args.append("%s/%s/cmd" % (vcluster_basedir, node)) if cmd: # For virtual clusters the whole command must be wrapped using the "cmd" # script, as that script sets a number of environment variables. If the # command contains shell meta characters the whole command needs to be # quoted. args.append(utils.ShellQuote(cmd)) else: args.append(node) if cmd: args.append(cmd) return args