2013-12-22 12:08:09 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
2014-09-03 23:23:39 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-12-22 12:08:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type SSHConfig struct {
|
2015-06-13 18:08:12 -04:00
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
2013-12-22 12:08:09 -05:00
|
|
|
|
2015-06-13 18:08:12 -04:00
|
|
|
SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
|
|
|
|
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
|
|
|
|
SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping"`
|
|
|
|
|
|
|
|
// These are deprecated, but we keep them around for BC
|
|
|
|
// TODO(@mitchellh): remove
|
|
|
|
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
|
2013-12-22 12:08:09 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
|
2016-08-24 12:30:26 -04:00
|
|
|
if c.Comm.SSHHost == "" {
|
|
|
|
c.Comm.SSHHost = "127.0.0.1"
|
|
|
|
}
|
|
|
|
|
2013-12-22 12:08:09 -05:00
|
|
|
if c.SSHHostPortMin == 0 {
|
|
|
|
c.SSHHostPortMin = 2222
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.SSHHostPortMax == 0 {
|
|
|
|
c.SSHHostPortMax = 4444
|
|
|
|
}
|
|
|
|
|
2015-06-13 18:08:12 -04:00
|
|
|
// TODO: backwards compatibility, write fixer instead
|
|
|
|
if c.SSHWaitTimeout != 0 {
|
|
|
|
c.Comm.SSHTimeout = c.SSHWaitTimeout
|
2013-12-22 12:08:09 -05:00
|
|
|
}
|
|
|
|
|
2015-06-13 18:08:12 -04:00
|
|
|
errs := c.Comm.Prepare(ctx)
|
2013-12-22 12:08:09 -05:00
|
|
|
if c.SSHHostPortMin > c.SSHHostPortMax {
|
|
|
|
errs = append(errs,
|
|
|
|
errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|