-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
step_take_snapshot.go
52 lines (38 loc) · 1.1 KB
/
step_take_snapshot.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
51
52
package oneandone
import (
"context"
"github.com/1and1/oneandone-cloudserver-sdk-go"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
type stepTakeSnapshot struct{}
func (s *stepTakeSnapshot) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
c := state.Get("config").(*Config)
ui.Say("Creating Snapshot...")
token := oneandone.SetToken(c.Token)
api := oneandone.New(token, c.Url)
serverId := state.Get("server_id").(string)
req := oneandone.ImageConfig{
Name: c.SnapshotName,
Description: "Packer image",
ServerId: serverId,
Frequency: "WEEKLY",
NumImages: 1,
}
img_id, img, err := api.CreateImage(&req)
if err != nil {
ui.Error(err.Error())
return multistep.ActionHalt
}
err = api.WaitForState(img, "ENABLED", 10, c.Retries)
if err != nil {
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("snapshot_id", img_id)
state.Put("snapshot_name", img.Name)
return multistep.ActionContinue
}
func (s *stepTakeSnapshot) Cleanup(state multistep.StateBag) {
}