44 lines
970 B
Go
44 lines
970 B
Go
|
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)
|
||
|
|
||
|
ui.Say("Shutting down server...")
|
||
|
|
||
|
err := client.PostServerAction(serverId, "poweroff")
|
||
|
|
||
|
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")
|
||
|
|
||
|
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
|
||
|
}
|