github.phpd.cn/hashicorp/packer@v1.3.2/builder/scaleway/step_shutdown.go (about) 1 package scaleway 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/hashicorp/packer/helper/multistep" 8 "github.com/hashicorp/packer/packer" 9 "github.com/scaleway/scaleway-cli/pkg/api" 10 ) 11 12 type stepShutdown struct{} 13 14 func (s *stepShutdown) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 15 client := state.Get("client").(*api.ScalewayAPI) 16 ui := state.Get("ui").(packer.Ui) 17 serverID := state.Get("server_id").(string) 18 19 ui.Say("Shutting down server...") 20 21 err := client.PostServerAction(serverID, "poweroff") 22 23 if err != nil { 24 err := fmt.Errorf("Error stopping server: %s", err) 25 state.Put("error", err) 26 ui.Error(err.Error()) 27 return multistep.ActionHalt 28 } 29 30 _, err = api.WaitForServerState(client, serverID, "stopped") 31 32 if err != nil { 33 err := fmt.Errorf("Error shutting down server: %s", err) 34 state.Put("error", err) 35 ui.Error(err.Error()) 36 return multistep.ActionHalt 37 } 38 39 return multistep.ActionContinue 40 } 41 42 func (s *stepShutdown) Cleanup(state multistep.StateBag) { 43 // no cleanup 44 }