2013-12-22 13:30:12 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2014-09-05 14:52:55 -04:00
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-12-22 13:30:12 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type RunConfig struct {
|
|
|
|
Headless bool `mapstructure:"headless"`
|
|
|
|
RawBootWait string `mapstructure:"boot_wait"`
|
|
|
|
|
2016-05-23 09:24:16 -04:00
|
|
|
VRDPBindAddress string `mapstructure:"vrdp_bind_address"`
|
|
|
|
VRDPPortMin uint `mapstructure:"vrdp_port_min"`
|
|
|
|
VRDPPortMax uint `mapstructure:"vrdp_port_max"`
|
2015-08-22 18:41:08 -04:00
|
|
|
|
2013-12-22 13:30:12 -05:00
|
|
|
BootWait time.Duration ``
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-12-22 13:30:12 -05:00
|
|
|
if c.RawBootWait == "" {
|
|
|
|
c.RawBootWait = "10s"
|
|
|
|
}
|
|
|
|
|
2016-05-23 09:24:16 -04:00
|
|
|
if c.VRDPBindAddress == "" {
|
|
|
|
c.VRDPBindAddress = "127.0.0.1"
|
|
|
|
}
|
|
|
|
|
2015-08-22 18:41:08 -04:00
|
|
|
if c.VRDPPortMin == 0 {
|
|
|
|
c.VRDPPortMin = 5900
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VRDPPortMax == 0 {
|
|
|
|
c.VRDPPortMax = 6000
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
var errs []error
|
2013-12-22 13:30:12 -05:00
|
|
|
var err error
|
|
|
|
c.BootWait, err = time.ParseDuration(c.RawBootWait)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err))
|
|
|
|
}
|
|
|
|
|
2015-08-22 18:41:08 -04:00
|
|
|
if c.VRDPPortMin > c.VRDPPortMax {
|
|
|
|
errs = append(
|
|
|
|
errs, fmt.Errorf("vrdp_port_min must be less than vrdp_port_max"))
|
|
|
|
}
|
|
|
|
|
2013-12-22 13:30:12 -05:00
|
|
|
return errs
|
|
|
|
}
|