Esempio n. 1
0
def _SetupSSH(options, cluster_name, node, ssh_port, cl):
  """Configures a destination node's SSH daemon.

  @param options: Command line options
  @type cluster_name
  @param cluster_name: Cluster name
  @type node: string
  @param node: Destination node name
  @type ssh_port: int
  @param ssh_port: Destination node ssh port
  @param cl: luxi client

  """
  # Retrieve the list of master and master candidates
  candidate_filter = ["|", ["=", "role", "M"], ["=", "role", "C"]]
  result = cl.Query(constants.QR_NODE, ["uuid"], candidate_filter)
  if len(result.data) < 1:
    raise errors.OpPrereqError("No master or master candidate node is found.")
  candidates = [uuid for ((_, uuid),) in result.data]
  candidate_keys = ssh.QueryPubKeyFile(candidates)

  if options.force_join:
    ToStderr("The \"--force-join\" option is no longer supported and will be"
             " ignored.")

  host_keys = _ReadSshKeys(constants.SSH_DAEMON_KEYFILES)

  (_, root_keyfiles) = \
    ssh.GetAllUserFiles(constants.SSH_LOGIN_USER, mkdir=False, dircheck=False)

  dsa_root_keyfiles = dict((kind, value) for (kind, value)
                           in root_keyfiles.items()
                           if kind == constants.SSHK_DSA)
  root_keys = _ReadSshKeys(dsa_root_keyfiles)

  (_, cert_pem) = \
    utils.ExtractX509Certificate(utils.ReadFile(pathutils.NODED_CERT_FILE))

  data = {
    constants.SSHS_CLUSTER_NAME: cluster_name,
    constants.SSHS_NODE_DAEMON_CERTIFICATE: cert_pem,
    constants.SSHS_SSH_HOST_KEY: host_keys,
    constants.SSHS_SSH_ROOT_KEY: root_keys,
    constants.SSHS_SSH_AUTHORIZED_KEYS: candidate_keys,
    }

  ssh.RunSshCmdWithStdin(cluster_name, node, pathutils.PREPARE_NODE_JOIN,
                         ssh_port, data,
                         debug=options.debug, verbose=options.verbose,
                         use_cluster_key=False, ask_key=options.ssh_key_check,
                         strict_host_check=options.ssh_key_check)

  (_, dsa_pub_keyfile) = root_keyfiles[constants.SSHK_DSA]
  pub_key = ssh.ReadRemoteSshPubKeys(dsa_pub_keyfile, node, cluster_name,
                                     ssh_port, options.ssh_key_check,
                                     options.ssh_key_check)
  # Unfortunately, we have to add the key with the node name rather than
  # the node's UUID here, because at this point, we do not have a UUID yet.
  # The entry will be corrected in noded later.
  ssh.AddPublicKey(node, pub_key)
Esempio n. 2
0
def SetupNodeDaemon(opts, cluster_name, node, ssh_port):
  """Add a node to the cluster.

  This function must be called before the actual opcode, and will ssh
  to the remote node, copy the needed files, and start ganeti-noded,
  allowing the master to do the rest via normal rpc calls.

  @param cluster_name: the cluster name
  @param node: the name of the new node
  @param ssh_port: the SSH port of the new node

  """
  data = {
    constants.NDS_CLUSTER_NAME: cluster_name,
    constants.NDS_NODE_DAEMON_CERTIFICATE:
      utils.ReadFile(pathutils.NODED_CERT_FILE),
    constants.NDS_HMAC:
      utils.ReadFile(pathutils.CONFD_HMAC_KEY),
    constants.NDS_SSCONF: ssconf.SimpleStore().ReadAll(),
    constants.NDS_START_NODE_DAEMON: True,
    constants.NDS_NODE_NAME: node,
    }

  ssh.RunSshCmdWithStdin(cluster_name, node, pathutils.NODE_DAEMON_SETUP,
                         ssh_port, data,
                         debug=opts.debug, verbose=opts.verbose,
                         use_cluster_key=True, ask_key=opts.ssh_key_check,
                         strict_host_check=opts.ssh_key_check,
                         ensure_version=True)

  _WaitForSshDaemon(node, ssh_port)
  _WaitForNodeDaemon(node)