github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/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 map[string]interface{}) multistep.StepAction { 12 client := state["client"].(*DigitalOceanClient) 13 ui := state["ui"].(packer.Ui) 14 c := state["config"].(config) 15 dropletId := state["droplet_id"].(uint) 16 17 ui.Say("Waiting for droplet to become active...") 18 19 err := waitForDropletState("active", dropletId, client, c) 20 if err != nil { 21 err := fmt.Errorf("Error waiting for droplet to become active: %s", err) 22 state["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["error"] = err 32 ui.Error(err.Error()) 33 return multistep.ActionHalt 34 } 35 36 state["droplet_ip"] = ip 37 38 return multistep.ActionContinue 39 } 40 41 func (s *stepDropletInfo) Cleanup(state map[string]interface{}) { 42 // no cleanup 43 }