github.com/emate/packer@v0.8.1-0.20150625195101-fe0fde195dc6/builder/vmware/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 VNCPortMin uint `mapstructure:"vnc_port_min"` 20 VNCPortMax uint `mapstructure:"vnc_port_max"` 21 22 BootWait time.Duration `` 23 } 24 25 func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { 26 if c.RawBootWait == "" { 27 c.RawBootWait = "10s" 28 } 29 30 if c.HTTPPortMin == 0 { 31 c.HTTPPortMin = 8000 32 } 33 34 if c.HTTPPortMax == 0 { 35 c.HTTPPortMax = 9000 36 } 37 38 if c.VNCPortMin == 0 { 39 c.VNCPortMin = 5900 40 } 41 42 if c.VNCPortMax == 0 { 43 c.VNCPortMax = 6000 44 } 45 46 var errs []error 47 var err error 48 if c.RawBootWait != "" { 49 c.BootWait, err = time.ParseDuration(c.RawBootWait) 50 if err != nil { 51 errs = append( 52 errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) 53 } 54 } 55 56 if c.HTTPPortMin > c.HTTPPortMax { 57 errs = append(errs, 58 errors.New("http_port_min must be less than http_port_max")) 59 } 60 61 if c.VNCPortMin > c.VNCPortMax { 62 errs = append( 63 errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max")) 64 } 65 66 return errs 67 }