2016-04-14 20:29:27 -04:00
|
|
|
package triton
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2016-04-14 20:29:27 -04:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2016-04-14 20:29:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepStopMachine stops the machine with the given Machine ID, and waits
|
|
|
|
// for it to reach the stopped state.
|
|
|
|
type StepStopMachine struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepStopMachine) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2016-04-14 20:29:27 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
machineId := state.Get("machine").(string)
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Stopping source machine (%s)...", machineId))
|
|
|
|
err := driver.StopMachine(machineId)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Problem stopping source machine: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Waiting for source machine to stop (%s)...", machineId))
|
|
|
|
err = driver.WaitForMachineState(machineId, "stopped", 10*time.Minute)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Problem waiting for source machine to stop: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepStopMachine) Cleanup(state multistep.StateBag) {
|
|
|
|
// Explicitly don't clean up here as StepCreateSourceMachine will do it if necessary
|
|
|
|
// and there is no real meaning to cleaning this up.
|
|
|
|
}
|