Revision a698cdbb
b/lib/bootstrap.py | ||
---|---|---|
28 | 28 |
import re |
29 | 29 |
import logging |
30 | 30 |
import time |
31 |
import tempfile |
|
31 | 32 |
|
32 | 33 |
from ganeti import rpc |
33 | 34 |
from ganeti import ssh |
... | ... | |
255 | 256 |
" %s seconds" % _DAEMON_READY_TIMEOUT) |
256 | 257 |
|
257 | 258 |
|
259 |
def RunNodeSetupCmd(cluster_name, node, basecmd, debug, verbose, |
|
260 |
use_cluster_key, ask_key, strict_host_check, data): |
|
261 |
"""Runs a command to configure something on a remote machine. |
|
262 |
|
|
263 |
@type cluster_name: string |
|
264 |
@param cluster_name: Cluster name |
|
265 |
@type node: string |
|
266 |
@param node: Node name |
|
267 |
@type basecmd: string |
|
268 |
@param basecmd: Base command (path on the remote machine) |
|
269 |
@type debug: bool |
|
270 |
@param debug: Enable debug output |
|
271 |
@type verbose: bool |
|
272 |
@param verbose: Enable verbose output |
|
273 |
@type use_cluster_key: bool |
|
274 |
@param use_cluster_key: See L{ssh.SshRunner.BuildCmd} |
|
275 |
@type ask_key: bool |
|
276 |
@param ask_key: See L{ssh.SshRunner.BuildCmd} |
|
277 |
@type strict_host_check: bool |
|
278 |
@param strict_host_check: See L{ssh.SshRunner.BuildCmd} |
|
279 |
@param data: JSON-serializable input data for script (passed to stdin) |
|
280 |
|
|
281 |
""" |
|
282 |
cmd = [basecmd] |
|
283 |
|
|
284 |
# Pass --debug/--verbose to the external script if set on our invocation |
|
285 |
if debug: |
|
286 |
cmd.append("--debug") |
|
287 |
|
|
288 |
if verbose: |
|
289 |
cmd.append("--verbose") |
|
290 |
|
|
291 |
srun = ssh.SshRunner(cluster_name) |
|
292 |
scmd = srun.BuildCmd(node, constants.SSH_LOGIN_USER, |
|
293 |
utils.ShellQuoteArgs(cmd), |
|
294 |
batch=False, ask_key=ask_key, quiet=False, |
|
295 |
strict_host_check=strict_host_check, |
|
296 |
use_cluster_key=use_cluster_key) |
|
297 |
|
|
298 |
tempfh = tempfile.TemporaryFile() |
|
299 |
try: |
|
300 |
tempfh.write(serializer.DumpJson(data)) |
|
301 |
tempfh.seek(0) |
|
302 |
|
|
303 |
result = utils.RunCmd(scmd, interactive=True, input_fd=tempfh) |
|
304 |
finally: |
|
305 |
tempfh.close() |
|
306 |
|
|
307 |
if result.failed: |
|
308 |
raise errors.OpExecError("Command '%s' failed: %s" % |
|
309 |
(result.cmd, result.fail_reason)) |
|
310 |
|
|
311 |
|
|
258 | 312 |
def _InitFileStorage(file_storage_dir): |
259 | 313 |
"""Initialize if needed the file storage. |
260 | 314 |
|
b/lib/client/gnt_node.py | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import itertools |
30 | 30 |
import errno |
31 |
import tempfile |
|
32 | 31 |
|
33 | 32 |
from ganeti.cli import * |
34 | 33 |
from ganeti import cli |
... | ... | |
39 | 38 |
from ganeti import errors |
40 | 39 |
from ganeti import netutils |
41 | 40 |
from ganeti import pathutils |
42 |
from ganeti import serializer |
|
43 | 41 |
from ganeti import ssh |
44 | 42 |
from cStringIO import StringIO |
45 | 43 |
|
... | ... | |
198 | 196 |
ToStderr("The \"--force-join\" option is no longer supported and will be" |
199 | 197 |
" ignored.") |
200 | 198 |
|
201 |
cmd = [pathutils.PREPARE_NODE_JOIN] |
|
202 |
|
|
203 |
# Pass --debug/--verbose to the external script if set on our invocation |
|
204 |
if options.debug: |
|
205 |
cmd.append("--debug") |
|
206 |
|
|
207 |
if options.verbose: |
|
208 |
cmd.append("--verbose") |
|
209 |
|
|
210 | 199 |
host_keys = _ReadSshKeys(constants.SSH_DAEMON_KEYFILES) |
211 | 200 |
|
212 | 201 |
(_, root_keyfiles) = \ |
... | ... | |
224 | 213 |
constants.SSHS_SSH_ROOT_KEY: root_keys, |
225 | 214 |
} |
226 | 215 |
|
227 |
srun = ssh.SshRunner(cluster_name) |
|
228 |
scmd = srun.BuildCmd(node, constants.SSH_LOGIN_USER, |
|
229 |
utils.ShellQuoteArgs(cmd), |
|
230 |
batch=False, ask_key=options.ssh_key_check, |
|
231 |
strict_host_check=options.ssh_key_check, quiet=False, |
|
232 |
use_cluster_key=False) |
|
233 |
|
|
234 |
tempfh = tempfile.TemporaryFile() |
|
235 |
try: |
|
236 |
tempfh.write(serializer.DumpJson(data)) |
|
237 |
tempfh.seek(0) |
|
238 |
|
|
239 |
result = utils.RunCmd(scmd, interactive=True, input_fd=tempfh) |
|
240 |
finally: |
|
241 |
tempfh.close() |
|
242 |
|
|
243 |
if result.failed: |
|
244 |
raise errors.OpExecError("Command '%s' failed: %s" % |
|
245 |
(result.cmd, result.fail_reason)) |
|
216 |
bootstrap.RunNodeSetupCmd(cluster_name, node, pathutils.PREPARE_NODE_JOIN, |
|
217 |
options.debug, options.verbose, False, |
|
218 |
options.ssh_key_check, options.ssh_key_check, data) |
|
246 | 219 |
|
247 | 220 |
|
248 | 221 |
@UsesRPC |
Also available in: Unified diff