packer-cn/builder/scaleway/step_shutdown.go

44 lines
970 B
Go
Raw Normal View History

2017-04-06 05:19:17 -04:00
package scaleway
import (
"fmt"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
"github.com/scaleway/scaleway-cli/pkg/api"
)
type stepShutdown struct{}
func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*api.ScalewayAPI)
ui := state.Get("ui").(packer.Ui)
serverID := state.Get("server_id").(string)
2017-04-06 05:19:17 -04:00
ui.Say("Shutting down server...")
err := client.PostServerAction(serverID, "poweroff")
2017-04-06 05:19:17 -04:00
if err != nil {
err := fmt.Errorf("Error stopping server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
_, err = api.WaitForServerState(client, serverID, "stopped")
2017-04-06 05:19:17 -04:00
if err != nil {
err := fmt.Errorf("Error shutting down server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepShutdown) Cleanup(state multistep.StateBag) {
// no cleanup
}