예제 #1
0
 def test(self):
   self.assertEqual(vcluster.EnvironmentForHost("host.example.com",
                                                _basedir=None),
                    {})
   for i in ["host.example.com", "other.example.com"]:
     self.assertEqual(vcluster.EnvironmentForHost(i, _basedir="/tmp"), {
       vcluster._ROOTDIR_ENVNAME: "/tmp/%s" % i,
       vcluster._HOSTNAME_ENVNAME: i,
       })
예제 #2
0
    def BuildCmd(self,
                 hostname,
                 user,
                 command,
                 batch=True,
                 ask_key=False,
                 tty=False,
                 use_cluster_key=True,
                 strict_host_check=True,
                 private_key=None,
                 quiet=True,
                 port=None):
        """Build an ssh command to execute a command on a remote node.

    @param hostname: the target host, string
    @param user: user to auth as
    @param command: the command
    @param batch: if true, ssh will run in batch mode with no prompting
    @param ask_key: if true, ssh will run with
        StrictHostKeyChecking=ask, so that we can connect to an
        unknown host (not valid in batch mode)
    @param use_cluster_key: whether to expect and use the
        cluster-global SSH key
    @param strict_host_check: whether to check the host's SSH key at all
    @param private_key: use this private key instead of the default
    @param quiet: whether to enable -q to ssh
    @param port: the SSH port on which the node's daemon is running

    @return: the ssh call to run 'command' on the remote host.

    """
        argv = [constants.SSH]
        argv.extend(
            self._BuildSshOptions(batch,
                                  ask_key,
                                  use_cluster_key,
                                  strict_host_check,
                                  private_key,
                                  quiet=quiet,
                                  port=port))
        if tty:
            argv.extend(["-t", "-t"])

        argv.append("%s@%s" % (user, hostname))

        # Insert variables for virtual nodes
        argv.extend(
            "export %s=%s;" % (utils.ShellQuote(name), utils.ShellQuote(value))
            for (name, value) in vcluster.EnvironmentForHost(hostname).items())

        argv.append(command)

        return argv