packer-cn/builder/hyperv/common/step_reboot_vm.go

43 lines
860 B
Go
Raw Normal View History

package common
import (
"context"
"fmt"
"time"
"github.com/hashicorp/packer/helper/multistep"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/packer"
)
type StepRebootVm struct {
}
func (s *StepRebootVm) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
errorMsg := "Error rebooting vm: %s"
vmName := state.Get("vmName").(string)
ui.Say("Rebooting vm...")
err := driver.RestartVirtualMachine(vmName)
if err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ui.Say("Waiting the VM to complete rebooting (2 minutes)...")
sleepTime := time.Minute * 2
time.Sleep(sleepTime)
return multistep.ActionContinue
}
func (s *StepRebootVm) Cleanup(state multistep.StateBag) {
// do nothing
}