packer-plugin-xenserver/builder/xenserver/common/step_boot_wait.go

34 lines
919 B
Go
Raw Normal View History

package common
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
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
)
type StepBootWait struct{}
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)
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
}
func (self *StepBootWait) Cleanup(state multistep.StateBag) {}