Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ Common
Compute
~~~~~~~

- [CloudSigma] Report the IPv6 address of a NIC instead of its IPv4 address
a second time, and stop raising ``TypeError`` for a NIC with only an IPv6
address. IPv6 unique local addresses are reported as private.
(#2244)
[@aad1tyaaaaa]

- [OVH] Remove the static location mapping and use the location code returned
by the API as both the location ID and name, avoiding failures for codes not
known to Libcloud.
Expand Down
14 changes: 11 additions & 3 deletions libcloud/compute/drivers/cloudsigma.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import time
import base64
import hashlib
import ipaddress

from libcloud.utils.py3 import b, httplib
from libcloud.utils.misc import dict2str, str2list, str2dicts, get_secure_random_string
Expand Down Expand Up @@ -2269,7 +2270,7 @@ def _parse_ips_from_nic(self, nic):
ip_v6 = ipv6_conf["ip"] if ipv6_conf else None

ipv4 = ip_v4["uuid"] if ip_v4 else None
ipv6 = ip_v4["uuid"] if ip_v6 else None
ipv6 = ip_v6["uuid"] if ip_v6 else None

ips = []

Expand All @@ -2285,7 +2286,7 @@ def _parse_ips_from_nic(self, nic):
ip_v6 = runtime["ip_v6"] if nic["runtime"] else None

ipv4 = ip_v4["uuid"] if ip_v4 else None
ipv6 = ip_v4["uuid"] if ip_v6 else None
ipv6 = ip_v6["uuid"] if ip_v6 else None

if ipv4:
ips.append(ipv4)
Expand All @@ -2296,7 +2297,14 @@ def _parse_ips_from_nic(self, nic):
ips = set(ips)

for ip in ips:
if is_private_subnet(ip):
if ":" in ip:
# is_private_subnet only handles IPv4; unique local addresses
# (RFC 4193) are the IPv6 counterpart of the private ranges
is_private = ipaddress.ip_address(ip) in ipaddress.ip_network("fc00::/7")
else:
is_private = is_private_subnet(ip)

if is_private:
private_ips.append(ip)
else:
public_ips.append(ip)
Expand Down
19 changes: 19 additions & 0 deletions libcloud/test/compute/test_cloudsigma_v2_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,25 @@ def test_delete_key_pair(self):
response = self.driver.delete_key_pair(key)
self.assertTrue(response)

def test_parse_ips_from_nic_ipv6(self):
def nic(ipv4, ipv6):
return {
"ip_v4_conf": {"conf": "static", "ip": {"uuid": ipv4}} if ipv4 else None,
"ip_v6_conf": {"conf": "static", "ip": {"uuid": ipv6}} if ipv6 else None,
"runtime": None,
}

public_ips, private_ips = self.driver._parse_ips_from_nic(
nic("185.12.5.10", "2a00:c31:1:2::10")
)
self.assertEqual(sorted(public_ips), ["185.12.5.10", "2a00:c31:1:2::10"])
self.assertEqual(private_ips, [])

# An IPv6-only NIC
public_ips, private_ips = self.driver._parse_ips_from_nic(nic(None, "fd00::10"))
self.assertEqual(public_ips, [])
self.assertEqual(private_ips, ["fd00::10"])


class CloudSigmaAPI20DirectTestCase(CloudSigmaAPI20BaseTestCase, unittest.TestCase):
driver_klass = CloudSigma_2_0_NodeDriver
Expand Down