packer-cn/builder/virtualbox/common/run_config.go

62 lines
1.2 KiB
Go
Raw Normal View History

2013-12-22 13:30:12 -05:00
package common
import (
"errors"
2013-12-22 13:30:12 -05:00
"fmt"
"time"
"github.com/mitchellh/packer/packer"
2013-12-22 13:30:12 -05:00
)
type RunConfig struct {
Headless bool `mapstructure:"headless"`
RawBootWait string `mapstructure:"boot_wait"`
HTTPDir string `mapstructure:"http_directory"`
HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"`
2013-12-22 13:30:12 -05:00
BootWait time.Duration ``
}
func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
if c.RawBootWait == "" {
c.RawBootWait = "10s"
}
if c.HTTPPortMin == 0 {
c.HTTPPortMin = 8000
}
if c.HTTPPortMax == 0 {
c.HTTPPortMax = 9000
}
2013-12-22 13:30:12 -05:00
templates := map[string]*string{
"boot_wait": &c.RawBootWait,
"http_directory": &c.HTTPDir,
2013-12-22 13:30:12 -05:00
}
errs := make([]error, 0)
for n, ptr := range templates {
var err error
*ptr, err = t.Process(*ptr, nil)
if err != nil {
errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err))
}
}
var err error
c.BootWait, err = time.ParseDuration(c.RawBootWait)
if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err))
}
if c.HTTPPortMin > c.HTTPPortMax {
errs = append(errs,
errors.New("http_port_min must be less than http_port_max"))
}
2013-12-22 13:30:12 -05:00
return errs
}