2014-12-29 06:46:54 -06:00
|
|
|
package common
|
2014-11-10 12:16:02 -06:00
|
|
|
|
|
|
|
import (
|
2021-01-03 16:08:24 -06:00
|
|
|
"context"
|
2014-12-08 09:34:48 -06:00
|
|
|
"fmt"
|
2020-09-13 03:21:07 -05:00
|
|
|
|
2021-02-23 16:43:20 -06:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/packer"
|
2014-11-10 12:16:02 -06:00
|
|
|
)
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
type StepBootWait struct{}
|
2014-11-10 12:16:02 -06:00
|
|
|
|
2021-01-03 16:08:24 -06:00
|
|
|
func (self *StepBootWait) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2020-09-13 03:21:07 -05:00
|
|
|
c := state.Get("client").(*Connection)
|
2014-12-29 06:46:54 -06:00
|
|
|
config := state.Get("commonconfig").(CommonConfig)
|
2014-12-08 09:34:48 -06:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
instance, _ := c.client.VM.GetByUUID(c.session, state.Get("instance_uuid").(string))
|
2014-12-08 09:34:48 -06:00
|
|
|
ui.Say("Unpausing VM " + state.Get("instance_uuid").(string))
|
2020-09-13 03:21:07 -05:00
|
|
|
Unpause(c, instance)
|
2014-12-08 09:34:48 -06:00
|
|
|
|
|
|
|
if int64(config.BootWait) > 0 {
|
|
|
|
ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait))
|
2014-12-09 08:56:21 -06:00
|
|
|
err := InterruptibleWait{Timeout: config.BootWait}.Wait(state)
|
|
|
|
if err != nil {
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-12-08 09:34:48 -06:00
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
2014-11-10 12:16:02 -06:00
|
|
|
}
|
|
|
|
|
2014-12-29 06:46:54 -06:00
|
|
|
func (self *StepBootWait) Cleanup(state multistep.StateBag) {}
|