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)
|
2017-04-11 06:19:28 -04:00
|
|
|
serverID := state.Get("server_id").(string)
|
2017-04-06 05:19:17 -04:00
|
|
|
|
|
|
|
ui.Say("Shutting down server...")
|
|
|
|
|
2017-04-11 06:19:28 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-04-11 06:19:28 -04:00
|
|
|
_, 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
|
|
|
|
}
|