Revision 00003458
b/lib/backend.py | ||
---|---|---|
1022 | 1022 |
|
1023 | 1023 |
comprcmd = "gzip" |
1024 | 1024 |
|
1025 |
remotecmd = utils.BuildShellCmd("ssh -q -oStrictHostKeyChecking=yes" |
|
1026 |
" -oBatchMode=yes -oEscapeChar=none" |
|
1027 |
" %s 'mkdir -p %s; cat > %s/%s'", |
|
1028 |
dest_node, destdir, destdir, destfile) |
|
1025 |
destcmd = utils.BuildShellCmd("mkdir -p %s; cat > %s/%s", |
|
1026 |
destdir, destdir, destfile) |
|
1027 |
remotecmd = ssh.BuildSSHCmd(dest_node, 'root', destcmd) |
|
1028 |
|
|
1029 |
|
|
1029 | 1030 |
|
1030 | 1031 |
# all commands have been checked, so we're safe to combine them |
1031 |
command = '|'.join([expcmd, comprcmd, remotecmd])
|
|
1032 |
command = '|'.join([expcmd, comprcmd, ' '.join(remotecmd)])
|
|
1032 | 1033 |
|
1033 | 1034 |
result = utils.RunCmd(command) |
1034 | 1035 |
|
... | ... | |
1168 | 1169 |
if not os.path.exists(constants.LOG_OS_DIR): |
1169 | 1170 |
os.mkdir(constants.LOG_OS_DIR, 0750) |
1170 | 1171 |
|
1171 |
remotecmd = utils.BuildShellCmd("ssh -q -oStrictHostKeyChecking=yes" |
|
1172 |
" -oBatchMode=yes -oEscapeChar=none" |
|
1173 |
" %s 'cat %s'", src_node, src_image) |
|
1172 |
destcmd = utils.BuildShellCmd('cat %s', src_image) |
|
1173 |
remotecmd = ssh.BuildSSHCmd(src_node, 'root', destcmd) |
|
1174 | 1174 |
|
1175 | 1175 |
comprcmd = "gunzip" |
1176 | 1176 |
impcmd = utils.BuildShellCmd("(cd %s; %s -i %s -b %s -s %s &>%s)", |
... | ... | |
1178 | 1178 |
real_os_dev.dev_path, real_swap_dev.dev_path, |
1179 | 1179 |
logfile) |
1180 | 1180 |
|
1181 |
command = '|'.join([remotecmd, comprcmd, impcmd])
|
|
1181 |
command = '|'.join([' '.join(remotecmd), comprcmd, impcmd])
|
|
1182 | 1182 |
|
1183 | 1183 |
result = utils.RunCmd(command) |
1184 | 1184 |
|
b/lib/ssh.py | ||
---|---|---|
54 | 54 |
"-oHashKnownHosts=no", |
55 | 55 |
] |
56 | 56 |
|
57 |
|
|
58 |
def SSHCall(hostname, user, command, batch=True, ask_key=False): |
|
59 |
"""Execute a command on a remote node. |
|
60 |
|
|
61 |
This method has the same return value as `utils.RunCmd()`, which it |
|
62 |
uses to launch ssh. |
|
57 |
def BuildSSHCmd(hostname, user, command, batch=True, ask_key=False): |
|
58 |
"""Build an ssh string to execute a command on a remote node. |
|
63 | 59 |
|
64 | 60 |
Args: |
65 | 61 |
hostname: the target host, string |
... | ... | |
70 | 66 |
we can connect to an unknown host (not valid in batch mode) |
71 | 67 |
|
72 | 68 |
Returns: |
73 |
`utils.RunResult` as for `utils.RunCmd()`
|
|
69 |
The ssh call to run 'command' on the remote host.
|
|
74 | 70 |
|
75 | 71 |
""" |
76 | 72 |
argv = ["ssh", "-q"] |
... | ... | |
82 | 78 |
argv.extend(BATCH_MODE_OPTS) |
83 | 79 |
elif ask_key: |
84 | 80 |
argv.extend(ASK_KEY_OPTS) |
85 |
argv.extend(["%s@%s" % (user, hostname), command]) |
|
86 |
return utils.RunCmd(argv) |
|
81 |
argv.extend(["%s@%s" % (user, hostname), "'%s'" % command]) |
|
82 |
return argv |
|
83 |
|
|
84 |
|
|
85 |
def SSHCall(hostname, user, command, batch=True, ask_key=False): |
|
86 |
"""Execute a command on a remote node. |
|
87 |
|
|
88 |
This method has the same return value as `utils.RunCmd()`, which it |
|
89 |
uses to launch ssh. |
|
90 |
|
|
91 |
Args: |
|
92 |
hostname: the target host, string |
|
93 |
user: user to auth as |
|
94 |
command: the command |
|
95 |
batch: if true, ssh will run in batch mode with no prompting |
|
96 |
ask_key: if true, ssh will run with StrictHostKeyChecking=ask, so that |
|
97 |
we can connect to an unknown host (not valid in batch mode) |
|
98 |
|
|
99 |
Returns: |
|
100 |
`utils.RunResult` as for `utils.RunCmd()` |
|
101 |
|
|
102 |
""" |
|
103 |
return utils.RunCmd(BuildSSHCmd(hostname, user, command, batch=batch, ask_key=ask_key)) |
|
87 | 104 |
|
88 | 105 |
|
89 | 106 |
def CopyFileToNode(node, filename): |
Also available in: Unified diff