1package provision
2
3import (
4	"fmt"
5
6	"github.com/docker/machine/libmachine/drivers"
7	"github.com/docker/machine/libmachine/log"
8	"github.com/docker/machine/libmachine/ssh"
9)
10
11type RedHatSSHCommander struct {
12	Driver drivers.Driver
13}
14
15func (sshCmder RedHatSSHCommander) SSHCommand(args string) (string, error) {
16	client, err := drivers.GetSSHClientFromDriver(sshCmder.Driver)
17	if err != nil {
18		return "", err
19	}
20
21	log.Debugf("About to run SSH command:\n%s", args)
22
23	// redhat needs "-t" for tty allocation on ssh therefore we check for the
24	// external client and add as needed.
25	// Note: CentOS 7.0 needs multiple "-tt" to force tty allocation when ssh has
26	// no local tty.
27	var output string
28	switch c := client.(type) {
29	case *ssh.ExternalClient:
30		c.BaseArgs = append(c.BaseArgs, "-tt")
31		output, err = c.Output(args)
32	case *ssh.NativeClient:
33		output, err = c.OutputWithPty(args)
34	}
35
36	log.Debugf("SSH cmd err, output: %v: %s", err, output)
37	if err != nil {
38		return "", fmt.Errorf(`something went wrong running an SSH command
39command : %s
40err     : %v
41output  : %s`, args, err, output)
42	}
43
44	return output, nil
45}
46