Add "boot_wait" parameter

This commit is contained in:
Andrei Tonkikh 2018-02-12 16:07:43 +03:00
parent 4875b82d12
commit 47cccb4e02
1 changed files with 33 additions and 2 deletions

View File

@ -6,14 +6,29 @@ import (
"fmt"
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
"strings"
"time"
)
type RunConfig struct {
BootOrder string `mapstructure:"boot_order"` // example: "floppy,cdrom,ethernet,disk"
RawBootWait string `mapstructure:"boot_wait"` // example: "1m30s"; default: "10s"
bootWait time.Duration ``
}
func (c *RunConfig) Prepare() []error {
return nil
var errs []error
if c.RawBootWait == "" {
c.RawBootWait = "10s"
}
var err error
c.bootWait, err = time.ParseDuration(c.RawBootWait)
if err != nil {
errs = append(errs, fmt.Errorf("failed parsing boot_wait: %s", err))
}
return errs
}
type StepRun struct {
@ -39,6 +54,22 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
if int64(s.Config.bootWait) > 0 {
ui.Say(fmt.Sprintf("Waiting %s for boot...", s.Config.bootWait))
wait := time.After(s.Config.bootWait)
WAITLOOP:
for {
select {
case <-wait:
break WAITLOOP
case <-time.After(1 * time.Second):
if _, ok := state.GetOk(multistep.StateCancelled); ok {
return multistep.ActionHalt
}
}
}
}
return multistep.ActionContinue
}