github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/oneandone/step_take_snapshot.go (about) 1 package oneandone 2 3 import ( 4 "github.com/1and1/oneandone-cloudserver-sdk-go" 5 "github.com/hashicorp/packer/packer" 6 "github.com/mitchellh/multistep" 7 ) 8 9 type stepTakeSnapshot struct{} 10 11 func (s *stepTakeSnapshot) Run(state multistep.StateBag) multistep.StepAction { 12 ui := state.Get("ui").(packer.Ui) 13 c := state.Get("config").(*Config) 14 15 ui.Say("Creating Snapshot...") 16 17 token := oneandone.SetToken(c.Token) 18 api := oneandone.New(token, c.Url) 19 20 serverId := state.Get("server_id").(string) 21 22 req := oneandone.ImageConfig{ 23 Name: c.SnapshotName, 24 Description: "Packer image", 25 ServerId: serverId, 26 Frequency: "WEEKLY", 27 NumImages: 1, 28 } 29 30 img_id, img, err := api.CreateImage(&req) 31 32 if err != nil { 33 ui.Error(err.Error()) 34 return multistep.ActionHalt 35 } 36 37 err = api.WaitForState(img, "ENABLED", 10, c.Retries) 38 39 if err != nil { 40 ui.Error(err.Error()) 41 return multistep.ActionHalt 42 } 43 44 state.Put("snapshot_id", img_id) 45 state.Put("snapshot_name", img.Name) 46 return multistep.ActionContinue 47 } 48 49 func (s *stepTakeSnapshot) Cleanup(state multistep.StateBag) { 50 }