mirror of https://github.com/docker/docs.git
Bail on failed SSH command with information about what failed
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
parent
69dc9fd7f3
commit
6db82141f0
|
@ -2,12 +2,17 @@ package drivers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/ssh"
|
"github.com/docker/machine/ssh"
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ErrExitCode255 = "255"
|
||||||
|
)
|
||||||
|
|
||||||
func GetSSHClientFromDriver(d Driver) (ssh.Client, error) {
|
func GetSSHClientFromDriver(d Driver) (ssh.Client, error) {
|
||||||
addr, err := d.GetSSHHostname()
|
addr, err := d.GetSSHHostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -28,6 +33,10 @@ func GetSSHClientFromDriver(d Driver) (ssh.Client, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isErr255Exit(err error) bool {
|
||||||
|
return strings.Contains(err.Error(), ErrExitCode255)
|
||||||
|
}
|
||||||
|
|
||||||
func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
|
func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
|
||||||
client, err := GetSSHClientFromDriver(d)
|
client, err := GetSSHClientFromDriver(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -38,6 +47,12 @@ func RunSSHCommandFromDriver(d Driver, command string) (string, error) {
|
||||||
|
|
||||||
output, err := client.Output(command)
|
output, err := client.Output(command)
|
||||||
log.Debugf("SSH cmd err, output: %v: %s", err, output)
|
log.Debugf("SSH cmd err, output: %v: %s", err, output)
|
||||||
|
if err != nil && !isErr255Exit(err) {
|
||||||
|
log.Error("SSH cmd error!")
|
||||||
|
log.Errorf("command: %s", command)
|
||||||
|
log.Errorf("err : %v", err)
|
||||||
|
log.Fatalf("output : %s", output)
|
||||||
|
}
|
||||||
|
|
||||||
return output, err
|
return output, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue