github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/hyperv/common/step_reboot_vm.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "time" 8 ) 9 10 type StepRebootVm struct { 11 } 12 13 func (s *StepRebootVm) Run(state multistep.StateBag) multistep.StepAction { 14 driver := state.Get("driver").(Driver) 15 ui := state.Get("ui").(packer.Ui) 16 17 errorMsg := "Error rebooting vm: %s" 18 vmName := state.Get("vmName").(string) 19 20 ui.Say("Rebooting vm...") 21 22 err := driver.RestartVirtualMachine(vmName) 23 if err != nil { 24 err := fmt.Errorf(errorMsg, err) 25 state.Put("error", err) 26 ui.Error(err.Error()) 27 return multistep.ActionHalt 28 } 29 30 ui.Say("Waiting the VM to complete rebooting (2 minutes)...") 31 32 sleepTime := time.Minute * 2 33 time.Sleep(sleepTime) 34 35 return multistep.ActionContinue 36 } 37 38 func (s *StepRebootVm) Cleanup(state multistep.StateBag) { 39 // do nothing 40 }