github.phpd.cn/hashicorp/packer@v1.3.2/builder/virtualbox/common/ssh_config.go (about) 1 package common 2 3 import ( 4 "errors" 5 "time" 6 7 "github.com/hashicorp/packer/helper/communicator" 8 "github.com/hashicorp/packer/template/interpolate" 9 ) 10 11 type SSHConfig struct { 12 Comm communicator.Config `mapstructure:",squash"` 13 14 SSHHostPortMin uint `mapstructure:"ssh_host_port_min"` 15 SSHHostPortMax uint `mapstructure:"ssh_host_port_max"` 16 SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping"` 17 18 // These are deprecated, but we keep them around for BC 19 // TODO(@mitchellh): remove 20 SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"` 21 } 22 23 func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error { 24 if c.Comm.SSHHost == "" { 25 c.Comm.SSHHost = "127.0.0.1" 26 } 27 28 if c.SSHHostPortMin == 0 { 29 c.SSHHostPortMin = 2222 30 } 31 32 if c.SSHHostPortMax == 0 { 33 c.SSHHostPortMax = 4444 34 } 35 36 // TODO: backwards compatibility, write fixer instead 37 if c.SSHWaitTimeout != 0 { 38 c.Comm.SSHTimeout = c.SSHWaitTimeout 39 } 40 41 errs := c.Comm.Prepare(ctx) 42 if c.SSHHostPortMin > c.SSHHostPortMax { 43 errs = append(errs, 44 errors.New("ssh_host_port_min must be less than ssh_host_port_max")) 45 } 46 47 return errs 48 }