github.com/emate/packer@v0.8.1-0.20150625195101-fe0fde195dc6/builder/digitalocean/step_droplet_info.go (about) 1 package digitalocean 2 3 import ( 4 "fmt" 5 6 "github.com/digitalocean/godo" 7 "github.com/mitchellh/multistep" 8 "github.com/mitchellh/packer/packer" 9 ) 10 11 type stepDropletInfo struct{} 12 13 func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction { 14 client := state.Get("client").(*godo.Client) 15 ui := state.Get("ui").(packer.Ui) 16 c := state.Get("config").(Config) 17 dropletId := state.Get("droplet_id").(int) 18 19 ui.Say("Waiting for droplet to become active...") 20 21 err := waitForDropletState("active", dropletId, client, c.StateTimeout) 22 if err != nil { 23 err := fmt.Errorf("Error waiting for droplet to become active: %s", err) 24 state.Put("error", err) 25 ui.Error(err.Error()) 26 return multistep.ActionHalt 27 } 28 29 // Set the IP on the state for later 30 droplet, _, err := client.Droplets.Get(dropletId) 31 if err != nil { 32 err := fmt.Errorf("Error retrieving droplet: %s", err) 33 state.Put("error", err) 34 ui.Error(err.Error()) 35 return multistep.ActionHalt 36 } 37 38 // Verify we have an IPv4 address 39 invalid := droplet.Networks == nil || 40 len(droplet.Networks.V4) == 0 41 if invalid { 42 err := fmt.Errorf("IPv4 address not found for droplet!") 43 state.Put("error", err) 44 ui.Error(err.Error()) 45 return multistep.ActionHalt 46 } 47 48 state.Put("droplet_ip", droplet.Networks.V4[0].IPAddress) 49 return multistep.ActionContinue 50 } 51 52 func (s *stepDropletInfo) Cleanup(state multistep.StateBag) { 53 // no cleanup 54 }