helper/communicator: configurable handshake attempts [GH-1988]
This commit is contained in:
parent
a832e1264b
commit
8d0904e296
|
@ -12,14 +12,15 @@ import (
|
||||||
// Config is the common configuration that communicators allow within
|
// Config is the common configuration that communicators allow within
|
||||||
// a builder.
|
// a builder.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Type string `mapstructure:"communicator"`
|
Type string `mapstructure:"communicator"`
|
||||||
SSHHost string `mapstructure:"ssh_host"`
|
SSHHost string `mapstructure:"ssh_host"`
|
||||||
SSHPort int `mapstructure:"ssh_port"`
|
SSHPort int `mapstructure:"ssh_port"`
|
||||||
SSHUsername string `mapstructure:"ssh_username"`
|
SSHUsername string `mapstructure:"ssh_username"`
|
||||||
SSHPassword string `mapstructure:"ssh_password"`
|
SSHPassword string `mapstructure:"ssh_password"`
|
||||||
SSHPrivateKey string `mapstructure:"ssh_private_key_file"`
|
SSHPrivateKey string `mapstructure:"ssh_private_key_file"`
|
||||||
SSHPty bool `mapstructure:"ssh_pty"`
|
SSHPty bool `mapstructure:"ssh_pty"`
|
||||||
SSHTimeout time.Duration `mapstructure:"ssh_timeout"`
|
SSHTimeout time.Duration `mapstructure:"ssh_timeout"`
|
||||||
|
SSHHandshakeAttempts int `mapstructure:"ssh_handshake_attempts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
||||||
|
@ -35,6 +36,10 @@ func (c *Config) Prepare(ctx *interpolate.Context) []error {
|
||||||
c.SSHTimeout = 5 * time.Minute
|
c.SSHTimeout = 5 * time.Minute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.SSHHandshakeAttempts == 0 {
|
||||||
|
c.SSHHandshakeAttempts = 10
|
||||||
|
}
|
||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
var errs []error
|
var errs []error
|
||||||
if c.Type == "ssh" {
|
if c.Type == "ssh" {
|
||||||
|
|
|
@ -149,8 +149,10 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
|
||||||
handshakeAttempts += 1
|
handshakeAttempts += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if handshakeAttempts < 10 {
|
if handshakeAttempts < s.Config.SSHHandshakeAttempts {
|
||||||
// Try to connect via SSH a handful of times
|
// Try to connect via SSH a handful of times. We sleep here
|
||||||
|
// so we don't get a ton of authentication errors back to back.
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue