/
step_boot.go
50 lines (39 loc) · 1.22 KB
/
step_boot.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
43
44
45
46
47
48
49
50
package p2pub
import (
"context"
"fmt"
"time"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/iij/p2pubapi"
"github.com/iij/p2pubapi/protocol"
)
type stepBoot struct {
}
func (s *stepBoot) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
api := state.Get("api").(*p2pubapi.API)
config := state.Get("config").(*Config)
ui.Say(fmt.Sprintf("Starting server ..."))
ivm := state.Get("IvmServiceCode").(string)
args := protocol.VMPower{
GisServiceCode: config.GisServiceCode,
IvmServiceCode: ivm,
Power: "On",
}
resp := protocol.VMPowerResponse{}
if err := p2pubapi.Call(*api, args, &resp); err != nil {
ui.Error(fmt.Sprintf("Failed to start server. reason: %s", err.Error()))
state.Put("error", err)
return multistep.ActionHalt
}
if err := p2pubapi.WaitVM(api, config.GisServiceCode, ivm,
p2pubapi.InService, p2pubapi.Running, 5*time.Minute); err != nil {
ui.Error(fmt.Sprintf("Virtual server could not be ready. reason: %s", err.Error()))
state.Put("error", err)
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepBoot) Cleanup(state multistep.StateBag) {
}