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"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/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
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
SSHKeyPath string `mapstructure:"ssh_key_path"`
SSHWaitTimeout time.Duration `mapstructure:"ssh_wait_timeout"`
2013-12-22 12:08:09 -05:00
}
func (c *SSHConfig) Prepare(ctx *interpolate.Context) []error {
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
2013-12-22 12:08:09 -05:00
if c.SSHKeyPath != "" {
c.Comm.SSHPrivateKey = c.SSHKeyPath
}
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
}