forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_reboot_vm.go
42 lines (31 loc) · 860 Bytes
/
step_reboot_vm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package common
import (
"context"
"fmt"
"time"
"github.com/hashicorp/packer/helper/multistep"
"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
}