packer-cn/builder/virtualbox/common/ssh_config.go

49 lines
1.1 KiB
Go
Raw Normal View History

2013-12-22 12:08:09 -05:00
package common
import (
"errors"
"time"
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 {
Comm communicator.Config `mapstructure:",squash"`
2013-12-22 12:08:09 -05:00
2019-03-19 09:47:21 -04:00
SSHHostPortMin int `mapstructure:"ssh_host_port_min"`
SSHHostPortMax int `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
}
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
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
}
// TODO: backwards compatibility, write fixer instead
if c.SSHWaitTimeout != 0 {
c.Comm.SSHTimeout = c.SSHWaitTimeout
2013-12-22 12:08:09 -05: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
}