Files
Packer-Cn/builder/triton/step_delete_machine.go
T

43 lines
1.1 KiB
Go
Raw Normal View History

2016-04-14 17:29:27 -07:00
package triton
import (
2018-01-22 15:32:33 -08:00
"context"
2016-04-14 17:29:27 -07:00
"fmt"
"time"
2018-01-19 16:18:44 -08:00
"github.com/hashicorp/packer/helper/multistep"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/packer"
2016-04-14 17:29:27 -07:00
)
// StepDeleteMachine deletes the machine with the ID specified in state["machine"]
type StepDeleteMachine struct{}
func (s *StepDeleteMachine) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2016-04-14 17:29:27 -07:00
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
machineId := state.Get("machine").(string)
ui.Say("Deleting source machine...")
err := driver.DeleteMachine(machineId)
if err != nil {
state.Put("error", fmt.Errorf("Problem deleting source machine: %s", err))
return multistep.ActionHalt
}
ui.Say("Waiting for source machine to be deleted...")
err = driver.WaitForMachineDeletion(machineId, 10*time.Minute)
if err != nil {
state.Put("error", fmt.Errorf("Problem waiting for source machine to be deleted: %s", err))
return multistep.ActionHalt
}
state.Put("machine", "")
return multistep.ActionContinue
}
func (s *StepDeleteMachine) Cleanup(state multistep.StateBag) {
// No clean up to do here...
}