Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Add "boot_wait" parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
xosmig committed Feb 12, 2018
1 parent 4875b82 commit 47cccb4
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions common/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 47cccb4

Please sign in to comment.