2013-12-26 17:26:09 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-12-26 17:26:09 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type RunConfig struct {
|
2017-10-09 20:12:33 -04:00
|
|
|
Headless bool `mapstructure:"headless"`
|
|
|
|
RawBootWait string `mapstructure:"boot_wait"`
|
|
|
|
DisableVNC bool `mapstructure:"disable_vnc"`
|
|
|
|
BootCommand []string `mapstructure:"boot_command"`
|
2013-12-26 17:26:09 -05:00
|
|
|
|
2016-08-19 06:49:23 -04:00
|
|
|
VNCBindAddress string `mapstructure:"vnc_bind_address"`
|
|
|
|
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
|
|
|
VNCPortMax uint `mapstructure:"vnc_port_max"`
|
|
|
|
VNCDisablePassword bool `mapstructure:"vnc_disable_password"`
|
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 15:10:40 -04:00
|
|
|
if c.VNCPortMin == 0 {
|
|
|
|
c.VNCPortMin = 5900
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VNCPortMax == 0 {
|
|
|
|
c.VNCPortMax = 6000
|
|
|
|
}
|
|
|
|
|
2016-05-23 09:02:56 -04:00
|
|
|
if c.VNCBindAddress == "" {
|
|
|
|
c.VNCBindAddress = "127.0.0.1"
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
var errs []error
|
2013-12-26 17:26:09 -05:00
|
|
|
var err error
|
2017-10-09 20:12:33 -04:00
|
|
|
if len(c.BootCommand) > 0 && c.DisableVNC {
|
|
|
|
errs = append(errs,
|
|
|
|
fmt.Errorf("A boot command cannot be used when vnc is disabled."))
|
|
|
|
}
|
|
|
|
|
2013-12-26 17:26:09 -05:00
|
|
|
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 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
|
|
|
|
}
|