github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/triton/step_stop_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 // StepStopMachine stops the machine with the given Machine ID, and waits 12 // for it to reach the stopped state. 13 type StepStopMachine struct{} 14 15 func (s *StepStopMachine) Run(state multistep.StateBag) multistep.StepAction { 16 driver := state.Get("driver").(Driver) 17 ui := state.Get("ui").(packer.Ui) 18 19 machineId := state.Get("machine").(string) 20 21 ui.Say(fmt.Sprintf("Stopping source machine (%s)...", machineId)) 22 err := driver.StopMachine(machineId) 23 if err != nil { 24 state.Put("error", fmt.Errorf("Problem stopping source machine: %s", err)) 25 return multistep.ActionHalt 26 } 27 28 ui.Say(fmt.Sprintf("Waiting for source machine to stop (%s)...", machineId)) 29 err = driver.WaitForMachineState(machineId, "stopped", 10*time.Minute) 30 if err != nil { 31 state.Put("error", fmt.Errorf("Problem waiting for source machine to stop: %s", err)) 32 return multistep.ActionHalt 33 } 34 35 return multistep.ActionContinue 36 } 37 38 func (s *StepStopMachine) Cleanup(state multistep.StateBag) { 39 // Explicitly don't clean up here as StepCreateSourceMachine will do it if necessary 40 // and there is no real meaning to cleaning this up. 41 }