Commit a698cdbb authored by Michael Hanselmann's avatar Michael Hanselmann

Factorize running node setup command

Part of the code used for running “prepare-node-join” can be re-used for
running a tool to configure the node daemon.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent cc7f5bfc
......@@ -28,6 +28,7 @@ import os.path
import re
import logging
import time
import tempfile
from ganeti import rpc
from ganeti import ssh
......@@ -255,6 +256,59 @@ def _WaitForMasterDaemon():
" %s seconds" % _DAEMON_READY_TIMEOUT)
def RunNodeSetupCmd(cluster_name, node, basecmd, debug, verbose,
use_cluster_key, ask_key, strict_host_check, data):
"""Runs a command to configure something on a remote machine.
@type cluster_name: string
@param cluster_name: Cluster name
@type node: string
@param node: Node name
@type basecmd: string
@param basecmd: Base command (path on the remote machine)
@type debug: bool
@param debug: Enable debug output
@type verbose: bool
@param verbose: Enable verbose output
@type use_cluster_key: bool
@param use_cluster_key: See L{ssh.SshRunner.BuildCmd}
@type ask_key: bool
@param ask_key: See L{ssh.SshRunner.BuildCmd}
@type strict_host_check: bool
@param strict_host_check: See L{ssh.SshRunner.BuildCmd}
@param data: JSON-serializable input data for script (passed to stdin)
"""
cmd = [basecmd]
# Pass --debug/--verbose to the external script if set on our invocation
if debug:
cmd.append("--debug")
if verbose:
cmd.append("--verbose")
srun = ssh.SshRunner(cluster_name)
scmd = srun.BuildCmd(node, constants.SSH_LOGIN_USER,
utils.ShellQuoteArgs(cmd),
batch=False, ask_key=ask_key, quiet=False,
strict_host_check=strict_host_check,
use_cluster_key=use_cluster_key)
tempfh = tempfile.TemporaryFile()
try:
tempfh.write(serializer.DumpJson(data))
tempfh.seek(0)
result = utils.RunCmd(scmd, interactive=True, input_fd=tempfh)
finally:
tempfh.close()
if result.failed:
raise errors.OpExecError("Command '%s' failed: %s" %
(result.cmd, result.fail_reason))
def _InitFileStorage(file_storage_dir):
"""Initialize if needed the file storage.
......
......@@ -28,7 +28,6 @@
import itertools
import errno
import tempfile
from ganeti.cli import *
from ganeti import cli
......@@ -39,7 +38,6 @@ from ganeti import constants
from ganeti import errors
from ganeti import netutils
from ganeti import pathutils
from ganeti import serializer
from ganeti import ssh
from cStringIO import StringIO
......@@ -198,15 +196,6 @@ def _SetupSSH(options, cluster_name, node):
ToStderr("The \"--force-join\" option is no longer supported and will be"
" ignored.")
cmd = [pathutils.PREPARE_NODE_JOIN]
# Pass --debug/--verbose to the external script if set on our invocation
if options.debug:
cmd.append("--debug")
if options.verbose:
cmd.append("--verbose")
host_keys = _ReadSshKeys(constants.SSH_DAEMON_KEYFILES)
(_, root_keyfiles) = \
......@@ -224,25 +213,9 @@ def _SetupSSH(options, cluster_name, node):
constants.SSHS_SSH_ROOT_KEY: root_keys,
}
srun = ssh.SshRunner(cluster_name)
scmd = srun.BuildCmd(node, constants.SSH_LOGIN_USER,
utils.ShellQuoteArgs(cmd),
batch=False, ask_key=options.ssh_key_check,
strict_host_check=options.ssh_key_check, quiet=False,
use_cluster_key=False)
tempfh = tempfile.TemporaryFile()
try:
tempfh.write(serializer.DumpJson(data))
tempfh.seek(0)
result = utils.RunCmd(scmd, interactive=True, input_fd=tempfh)
finally:
tempfh.close()
if result.failed:
raise errors.OpExecError("Command '%s' failed: %s" %
(result.cmd, result.fail_reason))
bootstrap.RunNodeSetupCmd(cluster_name, node, pathutils.PREPARE_NODE_JOIN,
options.debug, options.verbose, False,
options.ssh_key_check, options.ssh_key_check, data)
@UsesRPC
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment