Merge pull request #2358 from mitchellh/b-do-private-network
Detect the first public IPv4 address for Digital Ocean
This commit is contained in:
commit
caa518b294
|
@ -14,11 +14,11 @@ func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
client := state.Get("client").(*godo.Client)
|
client := state.Get("client").(*godo.Client)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
c := state.Get("config").(Config)
|
c := state.Get("config").(Config)
|
||||||
dropletId := state.Get("droplet_id").(int)
|
dropletID := state.Get("droplet_id").(int)
|
||||||
|
|
||||||
ui.Say("Waiting for droplet to become active...")
|
ui.Say("Waiting for droplet to become active...")
|
||||||
|
|
||||||
err := waitForDropletState("active", dropletId, client, c.StateTimeout)
|
err := waitForDropletState("active", dropletID, client, c.StateTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error waiting for droplet to become active: %s", err)
|
err := fmt.Errorf("Error waiting for droplet to become active: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -27,7 +27,7 @@ func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the IP on the state for later
|
// Set the IP on the state for later
|
||||||
droplet, _, err := client.Droplets.Get(dropletId)
|
droplet, _, err := client.Droplets.Get(dropletID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error retrieving droplet: %s", err)
|
err := fmt.Errorf("Error retrieving droplet: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -39,13 +39,28 @@ func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
invalid := droplet.Networks == nil ||
|
invalid := droplet.Networks == nil ||
|
||||||
len(droplet.Networks.V4) == 0
|
len(droplet.Networks.V4) == 0
|
||||||
if invalid {
|
if invalid {
|
||||||
err := fmt.Errorf("IPv4 address not found for droplet!")
|
err := fmt.Errorf("IPv4 address not found for droplet")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find a public IPv4 network
|
||||||
|
foundNetwork := false
|
||||||
|
for _, network := range droplet.Networks.V4 {
|
||||||
|
if network.Type == "public" {
|
||||||
|
state.Put("droplet_ip", network.IPAddress)
|
||||||
|
foundNetwork = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundNetwork {
|
||||||
|
err := fmt.Errorf("Count not find a public IPv4 address for this droplet")
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
state.Put("droplet_ip", droplet.Networks.V4[0].IPAddress)
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue