38 lines
794 B
Go
38 lines
794 B
Go
package digitalocean
|
|
|
|
import (
|
|
"github.com/mitchellh/multistep"
|
|
"github.com/mitchellh/packer/packer"
|
|
)
|
|
|
|
type stepPowerOff struct{}
|
|
|
|
func (s *stepPowerOff) Run(state map[string]interface{}) multistep.StepAction {
|
|
client := state["client"].(*DigitalOceanClient)
|
|
ui := state["ui"].(packer.Ui)
|
|
dropletId := state["droplet_id"].(uint)
|
|
|
|
// Poweroff the droplet so it can be snapshot
|
|
err := client.PowerOffDroplet(dropletId)
|
|
|
|
if err != nil {
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
ui.Say("Waiting for droplet to power off...")
|
|
|
|
err = waitForDropletState("off", dropletId, client)
|
|
|
|
if err != nil {
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *stepPowerOff) Cleanup(state map[string]interface{}) {
|
|
// no cleanup
|
|
}
|