github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/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/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 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(t *packer.ConfigTemplate) []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 templates := map[string]*string{ 47 "boot_wait": &c.RawBootWait, 48 "http_directory": &c.HTTPDir, 49 } 50 51 var err error 52 errs := make([]error, 0) 53 for n, ptr := range templates { 54 *ptr, err = t.Process(*ptr, nil) 55 if err != nil { 56 errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err)) 57 } 58 } 59 60 if c.RawBootWait != "" { 61 c.BootWait, err = time.ParseDuration(c.RawBootWait) 62 if err != nil { 63 errs = append( 64 errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) 65 } 66 } 67 68 if c.HTTPPortMin > c.HTTPPortMax { 69 errs = append(errs, 70 errors.New("http_port_min must be less than http_port_max")) 71 } 72 73 if c.VNCPortMin > c.VNCPortMax { 74 errs = append( 75 errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max")) 76 } 77 78 return errs 79 }