github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/triton/step_delete_machine.go (about)

     1  package triton
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/hashicorp/packer/packer"
     8  	"github.com/mitchellh/multistep"
     9  )
    10  
    11  // StepDeleteMachine deletes the machine with the ID specified in state["machine"]
    12  type StepDeleteMachine struct{}
    13  
    14  func (s *StepDeleteMachine) Run(state multistep.StateBag) multistep.StepAction {
    15  	driver := state.Get("driver").(Driver)
    16  	ui := state.Get("ui").(packer.Ui)
    17  
    18  	machineId := state.Get("machine").(string)
    19  
    20  	ui.Say("Deleting source machine...")
    21  	err := driver.DeleteMachine(machineId)
    22  	if err != nil {
    23  		state.Put("error", fmt.Errorf("Problem deleting source machine: %s", err))
    24  		return multistep.ActionHalt
    25  	}
    26  
    27  	ui.Say("Waiting for source machine to be deleted...")
    28  	err = driver.WaitForMachineDeletion(machineId, 10*time.Minute)
    29  	if err != nil {
    30  		state.Put("error", fmt.Errorf("Problem waiting for source machine to be deleted: %s", err))
    31  		return multistep.ActionHalt
    32  	}
    33  
    34  	state.Put("machine", "")
    35  
    36  	return multistep.ActionContinue
    37  }
    38  
    39  func (s *StepDeleteMachine) Cleanup(state multistep.StateBag) {
    40  	// No clean up to do here...
    41  }