|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package ssh
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"log"
|
|
|
|
|
"net"
|
|
|
|
|
"time"
|
|
|
|
|
@ -11,7 +12,22 @@ import (
|
|
|
|
|
// is suitable for use with the SSH communicator configuration.
|
|
|
|
|
func ConnectFunc(network, addr string) func() (net.Conn, error) {
|
|
|
|
|
return func() (net.Conn, error) {
|
|
|
|
|
log.Printf("Opening conn for SSH to %s %s", network, addr)
|
|
|
|
|
return net.DialTimeout(network, addr, 15*time.Second)
|
|
|
|
|
timeout := time.After(5 * time.Minute)
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-timeout:
|
|
|
|
|
return nil, errors.New("timeout connecting to remote machine")
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Printf("Opening conn for SSH to %s %s", network, addr)
|
|
|
|
|
nc, err := net.DialTimeout(network, addr, 15*time.Second)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return nc, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|