github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/builder/virtualbox/common/run_config.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/mitchellh/packer/template/interpolate"
     8  )
     9  
    10  type RunConfig struct {
    11  	Headless    bool   `mapstructure:"headless"`
    12  	RawBootWait string `mapstructure:"boot_wait"`
    13  
    14  	VRDPBindAddress string `mapstructure:"vrdp_bind_address"`
    15  	VRDPPortMin     uint   `mapstructure:"vrdp_port_min"`
    16  	VRDPPortMax     uint   `mapstructure:"vrdp_port_max"`
    17  
    18  	BootWait time.Duration ``
    19  }
    20  
    21  func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
    22  	if c.RawBootWait == "" {
    23  		c.RawBootWait = "10s"
    24  	}
    25  
    26  	if c.VRDPBindAddress == "" {
    27  		c.VRDPBindAddress = "127.0.0.1"
    28  	}
    29  
    30  	if c.VRDPPortMin == 0 {
    31  		c.VRDPPortMin = 5900
    32  	}
    33  
    34  	if c.VRDPPortMax == 0 {
    35  		c.VRDPPortMax = 6000
    36  	}
    37  
    38  	var errs []error
    39  	var err error
    40  	c.BootWait, err = time.ParseDuration(c.RawBootWait)
    41  	if err != nil {
    42  		errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err))
    43  	}
    44  
    45  	if c.VRDPPortMin > c.VRDPPortMax {
    46  		errs = append(
    47  			errs, fmt.Errorf("vrdp_port_min must be less than vrdp_port_max"))
    48  	}
    49  
    50  	return errs
    51  }