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

Digital Ocean compute: public_ips += IPv6 addresses #1738

Open
danielshahaf opened this issue Aug 8, 2022 · 0 comments
Open

Digital Ocean compute: public_ips += IPv6 addresses #1738

danielshahaf opened this issue Aug 8, 2022 · 0 comments

Comments

@danielshahaf
Copy link

Summary

Digital Ocean compute nodes' .public_ips attribute doesn't list IPv6 addresses. Patch for 3.6 tested against 3.4 included.

Detailed Information

Create a node with a public IPv6 address:

driver.create_node(
	name = ...,
	size = driver.list_sizes()[0],
	image = driver.list_images()[0],
	location = driver.list_locations()}[0],
	ex_create_attr = dict(ipv6=True),
)
driver.wait_until_running([node])

(docs for ex_create_attr).

Now inspect the node's public IP addresses:

>>> print(driver.list_nodes()[0].public_ips)
['159.223.187.157']

The IPv6 address is missing. (Observed in libcloud 3.4.1-5 in Debian sid — the latest I can easily test — but by code inspection applies to HEAD too.)

Patch

Here's a patch too. Not packaging it as a PR because I haven't done all the legwork (test it in 3.6 by hand and by test suite) yet, but posting it here since I didn't want to sit on it until I had time to finish it.

diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index df7f0ae..0ea5346 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -689,11 +689,11 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver, DigitalOceanNodeDri
         private_ips = []
         public_ips = []
         if networks:
-            for net in networks["v4"]:
+            for net in networks.get('v4', []) + networks.get('v6', []):
                 if net["type"] == "private":
-                    private_ips = [net["ip_address"]]
+                    private_ips.append(net["ip_address"])
                 if net["type"] == "public":
-                    public_ips = [net["ip_address"]]
+                    public_ips.append(net["ip_address"])
 
         extra = {}
         for key in extra_keys:

This was written against 3.4 but applied cleanly to 3.6 after changing single quotes to double quotes.

Result

>>> print(driver.list_nodes()[0].public_ips)
['159.223.187.157', '2604:a880:400:d0::1c58:e001']

I'm not sure whether the API contract allows this change.

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

No branches or pull requests

1 participant