Fix terminate error

This commit is contained in:
Edouard BONLIEU 2017-07-21 12:26:20 +02:00 committed by Matthew Hooker
parent b44798b38d
commit eb56b1b70e
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
3 changed files with 9 additions and 37 deletions

View File

@ -33,7 +33,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
client, _ := api.NewScalewayAPI(b.config.Organization, b.config.Token, b.config.UserAgent, b.config.Region)
client, err := api.NewScalewayAPI(b.config.Organization, b.config.Token, b.config.UserAgent, b.config.Region)
if err != nil {
return nil, err
}
state := new(multistep.BasicStateBag)
state.Put("config", b.config)
@ -58,7 +62,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(stepShutdown),
new(stepSnapshot),
new(stepImage),
new(stepTerminate),
}
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)

View File

@ -66,9 +66,12 @@ func (s *stepCreateServer) Cleanup(state multistep.StateBag) {
ui := state.Get("ui").(packer.Ui)
ui.Say("Destroying server...")
err := client.PostServerAction(s.serverID, "terminate")
err := client.DeleteServerForce(s.serverID)
if err != nil {
ui.Error(fmt.Sprintf(
"Error destroying server. Please destroy it manually: %s", err))
}
}

View File

@ -1,34 +0,0 @@
package scaleway
import (
"fmt"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
"github.com/scaleway/scaleway-cli/pkg/api"
)
type stepTerminate struct{}
func (s *stepTerminate) 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("Terminating server...")
err := client.DeleteServerForce(serverID)
if err != nil {
err := fmt.Errorf("Error terminating server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepTerminate) Cleanup(state multistep.StateBag) {
// no cleanup
}