2015-06-21 07:36:07 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-06-21 07:36:07 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StepRebootVm struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepRebootVm) Run(state multistep.StateBag) multistep.StepAction {
|
2015-10-30 04:23:30 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
2015-06-21 07:36:07 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
errorMsg := "Error rebooting vm: %s"
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
|
|
|
ui.Say("Rebooting vm...")
|
|
|
|
|
2015-10-30 04:23:30 -04:00
|
|
|
err := driver.RestartVirtualMachine(vmName)
|
2015-06-21 07:36:07 -04:00
|
|
|
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
|
|
|
|
}
|