2013-08-24 07:04:51 -04:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepShutdown struct{}
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
client := state.Get("client").(*DigitalOceanClient)
|
|
|
|
c := state.Get("config").(config)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
dropletId := state.Get("droplet_id").(uint)
|
2013-08-24 07:04:51 -04:00
|
|
|
|
|
|
|
err := client.ShutdownDroplet(dropletId)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error shutting down droplet: %s", err)
|
2013-08-31 15:25:08 -04:00
|
|
|
state.Put("error", err)
|
2013-08-24 07:04:51 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-09-05 00:59:58 -04:00
|
|
|
err = waitForDropletState("off", dropletId, client, c.stateTimeout)
|
2013-08-24 07:04:51 -04:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error waiting for droplet to become 'off': %s", err)
|
2013-08-31 15:25:08 -04:00
|
|
|
state.Put("error", err)
|
2013-08-24 07:04:51 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func (s *stepShutdown) Cleanup(state multistep.StateBag) {
|
2013-08-24 07:04:51 -04:00
|
|
|
// no cleanup
|
|
|
|
}
|