mirror of https://github.com/docker/docs.git
Move over to real retries method
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
parent
37bfe3a1dd
commit
e4785ad879
|
@ -2,7 +2,6 @@ package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -10,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
|
"github.com/docker/machine/utils"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,23 +63,29 @@ func NewConfig(user string, auth *Auth) (*ssh.ClientConfig, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dialSuccess(client *Client) func() bool {
|
||||||
|
return func() bool {
|
||||||
|
if _, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", client.Hostname, client.Port), client.Config); err != nil {
|
||||||
|
log.Debugf("Error dialing TCP: %s", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) Run(command string) (Output, error) {
|
func (client *Client) Run(command string) (Output, error) {
|
||||||
var (
|
var (
|
||||||
output Output
|
output Output
|
||||||
conn *ssh.Client
|
stdout, stderr bytes.Buffer
|
||||||
err error
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; ; i++ {
|
if err := utils.WaitFor(dialSuccess(client)); err != nil {
|
||||||
conn, err = ssh.Dial("tcp", fmt.Sprintf("%s:%d", client.Hostname, client.Port), client.Config)
|
return output, fmt.Errorf("Error attempting SSH client dial: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", client.Hostname, client.Port), client.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error dialing TCP: %s", err)
|
return output, fmt.Errorf("Mysterious error dialing TCP for SSH (we already succeeded at least once) : %s", err)
|
||||||
if i == maxDialAttempts {
|
|
||||||
return output, errors.New("Max SSH/TCP dial attempts exceeded")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := conn.NewSession()
|
session, err := conn.NewSession()
|
||||||
|
@ -89,8 +95,6 @@ func (client *Client) Run(command string) (Output, error) {
|
||||||
|
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
|
|
||||||
var stdout, stderr bytes.Buffer
|
|
||||||
|
|
||||||
session.Stdout = &stdout
|
session.Stdout = &stdout
|
||||||
session.Stderr = &stderr
|
session.Stderr = &stderr
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue