Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add floating IP info to the droplet #343

Open
roidelapluie opened this issue Jul 1, 2020 · 3 comments
Open

Add floating IP info to the droplet #343

roidelapluie opened this issue Jul 1, 2020 · 3 comments

Comments

@roidelapluie
Copy link
Contributor

The API returns the Floating IP's but there is no way to get them via godo. That would be useful.

@andrewsomething
Copy link
Member

Hi @roidelapluie,

The Droplet.PublicIPv4() method is a helper that returns the first public IPv4 address for a Droplet. You can dig into the Droplet's networks to find additional IP addresses. Droplet.Networks.v4 is a slice of NetworkV4

https://godoc.org/github.com/digitalocean/godo#NetworkV4

In practice, currently a Droplet can only have two public IPv4 addresses, it's assigned address and a floating IP. So you could get at it using something like:

func getFloatingIP(droplet *godo.Droplet) (string, error) {
	if droplet.Networks == nil {
		return "", errors.New("no networks found")
	}

	publicIP, err := droplet.PublicIPv4()
	if err != nil {
		return "", err
	}

	for _, v4 := range droplet.Networks.V4 {
		if v4.Type == "public" && v4.IPAddress != publicIP {
			return v4.IPAddress, nil
		}
	}

	return "", nil
}

It could be nice to expose something like that in godo itself.

@roidelapluie
Copy link
Contributor Author

Yes I did find out but is that guaranteed by the API docs that the second will always be the floating IP?

@ChiefMateStarbuck
Copy link
Contributor

hello @roidelapluie,

I was able to talk to the internal droplets team. We do not guarantee an order of ips.
That said, @andrewsomething's suggestion works great for this use case and we will review and assist with any PR's that add this functionality to the droplets file. This would be a great first issue for any newcomers.

Thank you for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants