github.com/emate/packer@v0.8.1-0.20150625195101-fe0fde195dc6/builder/virtualbox/common/run_config.go (about) 1 package common 2 3 import ( 4 "errors" 5 "fmt" 6 "time" 7 8 "github.com/mitchellh/packer/template/interpolate" 9 ) 10 11 type RunConfig struct { 12 Headless bool `mapstructure:"headless"` 13 RawBootWait string `mapstructure:"boot_wait"` 14 15 HTTPDir string `mapstructure:"http_directory"` 16 HTTPPortMin uint `mapstructure:"http_port_min"` 17 HTTPPortMax uint `mapstructure:"http_port_max"` 18 19 BootWait time.Duration `` 20 } 21 22 func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { 23 if c.RawBootWait == "" { 24 c.RawBootWait = "10s" 25 } 26 27 if c.HTTPPortMin == 0 { 28 c.HTTPPortMin = 8000 29 } 30 31 if c.HTTPPortMax == 0 { 32 c.HTTPPortMax = 9000 33 } 34 35 var errs []error 36 var err error 37 c.BootWait, err = time.ParseDuration(c.RawBootWait) 38 if err != nil { 39 errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) 40 } 41 42 if c.HTTPPortMin > c.HTTPPortMax { 43 errs = append(errs, 44 errors.New("http_port_min must be less than http_port_max")) 45 } 46 47 return errs 48 }