builder/digitalocean: proper timeouts so poweroff retries

This commit is contained in:
Mitchell Hashimoto 2013-09-04 22:26:05 -07:00
parent aedd1555d3
commit 8643c70e35
2 changed files with 5 additions and 5 deletions

View File

@ -5,13 +5,13 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"time"
) )
type stepPowerOff struct{} type stepPowerOff struct{}
func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction { func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*DigitalOceanClient) client := state.Get("client").(*DigitalOceanClient)
c := state.Get("config").(config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
dropletId := state.Get("droplet_id").(uint) dropletId := state.Get("droplet_id").(uint)
@ -38,7 +38,7 @@ func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
err = waitForDropletState("off", dropletId, client, 20*time.Second) err = waitForDropletState("off", dropletId, client, c.stateTimeout)
if err != nil { if err != nil {
state.Put("error", err) state.Put("error", err)
ui.Error(err.Error()) ui.Error(err.Error())

View File

@ -5,13 +5,13 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"time"
) )
type stepShutdown struct{} type stepShutdown struct{}
func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction { func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*DigitalOceanClient) client := state.Get("client").(*DigitalOceanClient)
c := state.Get("config").(config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
dropletId := state.Get("droplet_id").(uint) dropletId := state.Get("droplet_id").(uint)
@ -22,7 +22,7 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
var err error var err error
ui.Say("Gracefully shutting down droplet...") ui.Say("Gracefully shutting down droplet...")
for attempts := 1; attempts <= 10; attempts++ { for attempts := 1; attempts <= 10; attempts++ {
log.Printf("ShutdownDropetl attempt #%d...", attempts) log.Printf("ShutdownDroplet attempt #%d...", attempts)
err := client.ShutdownDroplet(dropletId) err := client.ShutdownDroplet(dropletId)
if err != nil { if err != nil {
err := fmt.Errorf("Error shutting down droplet: %s", err) err := fmt.Errorf("Error shutting down droplet: %s", err)
@ -31,7 +31,7 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
err = waitForDropletState("off", dropletId, client, c.stateTimeout) err = waitForDropletState("off", dropletId, client, 20*time.Second)
if err == nil { if err == nil {
break break
} }