Files
docker-docs/drivers/utils.go
Christy Perez 91d945431f Log ssh command output to Debug
I struggled to figure out why a machine create was failing, and
eventually asked if anyone else had seen the vague error I was getting:
"Error creating machine: Process exited with: 100. Reason was: ()"

It is immensely helpful if we log the command output instead of
just the rc.

It would also have been useful if the driver providers used the output, but
this covers most scenarios since they don't.

Signed-off-by: Christy Perez <christy@linux.vnet.ibm.com>
2015-05-08 09:35:59 -05:00

70 lines
1.5 KiB
Go

package drivers
import (
"fmt"
"github.com/docker/machine/log"
"github.com/docker/machine/ssh"
"github.com/docker/machine/utils"
)
func RunSSHCommandFromDriver(d Driver, command string) (ssh.Output, error) {
var output ssh.Output
addr, err := d.GetSSHHostname()
if err != nil {
return output, err
}
port, err := d.GetSSHPort()
if err != nil {
return output, err
}
auth := &ssh.Auth{
Keys: []string{d.GetSSHKeyPath()},
}
client, err := ssh.NewClient(d.GetSSHUsername(), addr, port, auth)
if err != nil {
return output, err
}
output, err = client.Run(command)
log.Debug(fmt.Sprintf("SSH cmd err, output: %v: %s", err, output))
return output, err
}
func sshAvailableFunc(d Driver) func() bool {
return func() bool {
log.Debug("Getting to WaitForSSH function...")
hostname, err := d.GetSSHHostname()
if err != nil {
log.Debugf("Error getting IP address waiting for SSH: %s", err)
return false
}
port, err := d.GetSSHPort()
if err != nil {
log.Debugf("Error getting SSH port: %s", err)
return false
}
if err := ssh.WaitForTCP(fmt.Sprintf("%s:%d", hostname, port)); err != nil {
log.Debugf("Error waiting for TCP waiting for SSH: %s", err)
return false
}
if _, err := RunSSHCommandFromDriver(d, "exit 0"); err != nil {
log.Debugf("Error getting ssh command 'exit 0' : %s", err)
return false
}
return true
}
}
func WaitForSSH(d Driver) error {
if err := utils.WaitFor(sshAvailableFunc(d)); err != nil {
return fmt.Errorf("Too many retries. Last error: %s", err)
}
return nil
}