2013-12-26 17:26:09 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2014-09-05 14:59:46 -04:00
|
|
|
"errors"
|
2013-12-26 17:26:09 -05:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-12-26 17:26:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type RunConfig struct {
|
|
|
|
Headless bool `mapstructure:"headless"`
|
|
|
|
RawBootWait string `mapstructure:"boot_wait"`
|
|
|
|
|
2014-09-05 14:59:46 -04:00
|
|
|
HTTPDir string `mapstructure:"http_directory"`
|
|
|
|
HTTPPortMin uint `mapstructure:"http_port_min"`
|
|
|
|
HTTPPortMax uint `mapstructure:"http_port_max"`
|
|
|
|
|
2014-09-08 13:28:21 -04:00
|
|
|
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
|
|
|
VNCPortMax uint `mapstructure:"vnc_port_max"`
|
2014-09-05 15:10:40 -04:00
|
|
|
|
2013-12-26 17:26:09 -05:00
|
|
|
BootWait time.Duration ``
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-12-26 17:26:09 -05:00
|
|
|
if c.RawBootWait == "" {
|
|
|
|
c.RawBootWait = "10s"
|
|
|
|
}
|
|
|
|
|
2014-09-05 14:59:46 -04:00
|
|
|
if c.HTTPPortMin == 0 {
|
|
|
|
c.HTTPPortMin = 8000
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.HTTPPortMax == 0 {
|
|
|
|
c.HTTPPortMax = 9000
|
|
|
|
}
|
|
|
|
|
2014-09-05 15:10:40 -04:00
|
|
|
if c.VNCPortMin == 0 {
|
|
|
|
c.VNCPortMin = 5900
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VNCPortMax == 0 {
|
|
|
|
c.VNCPortMax = 6000
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
var errs []error
|
2013-12-26 17:26:09 -05:00
|
|
|
var err error
|
|
|
|
if c.RawBootWait != "" {
|
|
|
|
c.BootWait, err = time.ParseDuration(c.RawBootWait)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(
|
|
|
|
errs, fmt.Errorf("Failed parsing boot_wait: %s", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-05 14:59:46 -04:00
|
|
|
if c.HTTPPortMin > c.HTTPPortMax {
|
|
|
|
errs = append(errs,
|
|
|
|
errors.New("http_port_min must be less than http_port_max"))
|
|
|
|
}
|
|
|
|
|
2014-09-05 15:10:40 -04:00
|
|
|
if c.VNCPortMin > c.VNCPortMax {
|
|
|
|
errs = append(
|
|
|
|
errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max"))
|
|
|
|
}
|
|
|
|
|
2013-12-26 17:26:09 -05:00
|
|
|
return errs
|
|
|
|
}
|