2013-06-13 12:48:19 -04:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
2013-06-20 00:00:51 -04:00
|
|
|
"fmt"
|
2013-06-13 12:48:19 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepDropletInfo struct{}
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
client := state.Get("client").(*DigitalOceanClient)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
c := state.Get("config").(config)
|
|
|
|
dropletId := state.Get("droplet_id").(uint)
|
2013-06-13 12:48:19 -04:00
|
|
|
|
|
|
|
ui.Say("Waiting for droplet to become active...")
|
|
|
|
|
2013-09-05 00:59:58 -04:00
|
|
|
err := waitForDropletState("active", dropletId, client, c.stateTimeout)
|
2013-06-13 13:56:34 -04:00
|
|
|
if err != nil {
|
2013-06-20 00:00:51 -04:00
|
|
|
err := fmt.Errorf("Error waiting for droplet to become active: %s", err)
|
2013-08-31 15:25:08 -04:00
|
|
|
state.Put("error", err)
|
2013-06-13 13:56:34 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
2013-06-13 12:48:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the IP on the state for later
|
|
|
|
ip, _, err := client.DropletStatus(dropletId)
|
|
|
|
if err != nil {
|
2013-06-20 00:00:51 -04:00
|
|
|
err := fmt.Errorf("Error retrieving droplet ID: %s", err)
|
2013-08-31 15:25:08 -04:00
|
|
|
state.Put("error", err)
|
2013-06-13 12:48:19 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
state.Put("droplet_ip", ip)
|
2013-06-13 12:48:19 -04:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func (s *stepDropletInfo) Cleanup(state multistep.StateBag) {
|
2013-06-13 12:48:19 -04:00
|
|
|
// no cleanup
|
|
|
|
}
|