github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/builder/digitalocean/step_droplet_info.go (about) 1 package digitalocean 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 ) 8 9 type stepDropletInfo struct{} 10 11 func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction { 12 client := state.Get("client").(*DigitalOceanClient) 13 ui := state.Get("ui").(packer.Ui) 14 c := state.Get("config").(config) 15 dropletId := state.Get("droplet_id").(uint) 16 17 ui.Say("Waiting for droplet to become active...") 18 19 err := waitForDropletState("active", dropletId, client, c.stateTimeout) 20 if err != nil { 21 err := fmt.Errorf("Error waiting for droplet to become active: %s", err) 22 state.Put("error", err) 23 ui.Error(err.Error()) 24 return multistep.ActionHalt 25 } 26 27 // Set the IP on the state for later 28 ip, _, err := client.DropletStatus(dropletId) 29 if err != nil { 30 err := fmt.Errorf("Error retrieving droplet ID: %s", err) 31 state.Put("error", err) 32 ui.Error(err.Error()) 33 return multistep.ActionHalt 34 } 35 36 state.Put("droplet_ip", ip) 37 38 return multistep.ActionContinue 39 } 40 41 func (s *stepDropletInfo) Cleanup(state multistep.StateBag) { 42 // no cleanup 43 }