Revision a698cdbb lib/bootstrap.py

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

  

Also available in: Unified diff