comprcmd = "gzip"
- remotecmd = utils.BuildShellCmd("ssh -q -oStrictHostKeyChecking=yes"
- " -oBatchMode=yes -oEscapeChar=none"
- " %s 'mkdir -p %s; cat > %s/%s'",
- dest_node, destdir, destdir, destfile)
+ destcmd = utils.BuildShellCmd("mkdir -p %s; cat > %s/%s",
+ destdir, destdir, destfile)
+ remotecmd = ssh.BuildSSHCmd(dest_node, 'root', destcmd)
+
+
# all commands have been checked, so we're safe to combine them
- command = '|'.join([expcmd, comprcmd, remotecmd])
+ command = '|'.join([expcmd, comprcmd, ' '.join(remotecmd)])
result = utils.RunCmd(command)
if not os.path.exists(constants.LOG_OS_DIR):
os.mkdir(constants.LOG_OS_DIR, 0750)
- remotecmd = utils.BuildShellCmd("ssh -q -oStrictHostKeyChecking=yes"
- " -oBatchMode=yes -oEscapeChar=none"
- " %s 'cat %s'", src_node, src_image)
+ destcmd = utils.BuildShellCmd('cat %s', src_image)
+ remotecmd = ssh.BuildSSHCmd(src_node, 'root', destcmd)
comprcmd = "gunzip"
impcmd = utils.BuildShellCmd("(cd %s; %s -i %s -b %s -s %s &>%s)",
real_os_dev.dev_path, real_swap_dev.dev_path,
logfile)
- command = '|'.join([remotecmd, comprcmd, impcmd])
+ command = '|'.join([' '.join(remotecmd), comprcmd, impcmd])
result = utils.RunCmd(command)
"-oHashKnownHosts=no",
]
-
-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.
+def BuildSSHCmd(hostname, user, command, batch=True, ask_key=False):
+ """Build an ssh string to execute a command on a remote node.
Args:
hostname: the target host, string
we can connect to an unknown host (not valid in batch mode)
Returns:
- `utils.RunResult` as for `utils.RunCmd()`
+ The ssh call to run 'command' on the remote host.
"""
argv = ["ssh", "-q"]
argv.extend(BATCH_MODE_OPTS)
elif ask_key:
argv.extend(ASK_KEY_OPTS)
- argv.extend(["%s@%s" % (user, hostname), command])
- return utils.RunCmd(argv)
+ argv.extend(["%s@%s" % (user, hostname), "'%s'" % 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()`
+
+ """
+ return utils.RunCmd(BuildSSHCmd(hostname, user, command, batch=batch, ask_key=ask_key))
def CopyFileToNode(node, filename):