github.com/rothwerx/packer@v0.9.0/builder/virtualbox/common/ssh_config.go (about)

     1  package common
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  
     7  	"github.com/mitchellh/packer/helper/communicator"
     8  	"github.com/mitchellh/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.SSHHostPortMin == 0 {
    25  		c.SSHHostPortMin = 2222
    26  	}
    27  
    28  	if c.SSHHostPortMax == 0 {
    29  		c.SSHHostPortMax = 4444
    30  	}
    31  
    32  	// TODO: backwards compatibility, write fixer instead
    33  	if c.SSHWaitTimeout != 0 {
    34  		c.Comm.SSHTimeout = c.SSHWaitTimeout
    35  	}
    36  
    37  	errs := c.Comm.Prepare(ctx)
    38  	if c.SSHHostPortMin > c.SSHHostPortMax {
    39  		errs = append(errs,
    40  			errors.New("ssh_host_port_min must be less than ssh_host_port_max"))
    41  	}
    42  
    43  	return errs
    44  }