github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/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/packer" 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(t *packer.ConfigTemplate) []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 templates := map[string]*string{ 36 "boot_wait": &c.RawBootWait, 37 "http_directory": &c.HTTPDir, 38 } 39 40 errs := make([]error, 0) 41 for n, ptr := range templates { 42 var err error 43 *ptr, err = t.Process(*ptr, nil) 44 if err != nil { 45 errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err)) 46 } 47 } 48 49 var err error 50 c.BootWait, err = time.ParseDuration(c.RawBootWait) 51 if err != nil { 52 errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) 53 } 54 55 if c.HTTPPortMin > c.HTTPPortMax { 56 errs = append(errs, 57 errors.New("http_port_min must be less than http_port_max")) 58 } 59 60 return errs 61 }