From 7df9a721efdbe854e6fd4d39d6d1c92c5d1c6c43 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 7 Oct 2024 01:08:31 +0900 Subject: [PATCH] Replace netifaces library The natifaces library[1] was abandoned more than 3 years ago. Replace it by psutils which is already used by a few other projects. [1] https://github.com/al45tair/netifaces Closes-Bug: #2071596 Change-Id: I805321229e84a57312bbe160d330281e6c13ab97 --- openstack/cloud/_utils.py | 22 ++++++++++++------- .../replace-netifaces-632f60884fb7ae00.yaml | 7 ++++++ requirements.txt | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/replace-netifaces-632f60884fb7ae00.yaml diff --git a/openstack/cloud/_utils.py b/openstack/cloud/_utils.py index a4f5ebc1f..5f7efc65f 100644 --- a/openstack/cloud/_utils.py +++ b/openstack/cloud/_utils.py @@ -15,12 +15,14 @@ import contextlib import fnmatch import inspect +import ipaddress import re +import socket import uuid from decorator import decorator import jmespath -import netifaces +import psutil from openstack import _log from openstack import exceptions @@ -182,15 +184,19 @@ def _get_entity(cloud, resource, name_or_id, filters, **kwargs): def localhost_supports_ipv6(): """Determine whether the local host supports IPv6 - We look for a default route that supports the IPv6 address family, - and assume that if it is present, this host has globally routable - IPv6 connectivity. + We look for the all ip addresses configured to this node, and assume that + if any of these is IPv6 address (but not loopback or link local), this host + has IPv6 connectivity. """ - try: - return netifaces.AF_INET6 in netifaces.gateways()['default'] - except AttributeError: - return False + for ifname, if_addrs in psutil.net_if_addrs().items(): + for if_addr in if_addrs: + if if_addr.family != socket.AF_INET6: + continue + addr = ipaddress.ip_address(if_addr.address) + if not addr.is_link_local and not addr.is_loopback: + return True + return False def valid_kwargs(*valid_args): diff --git a/releasenotes/notes/replace-netifaces-632f60884fb7ae00.yaml b/releasenotes/notes/replace-netifaces-632f60884fb7ae00.yaml new file mode 100644 index 000000000..a7f97eec3 --- /dev/null +++ b/releasenotes/notes/replace-netifaces-632f60884fb7ae00.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + IPv6 support now is detected according to the IP addresses assigned to all + network interfaces, instead of presence of IPv6 default route. In case + there is any IP v6 address, which is not loopback or link-local, then + the host is considered to support IPv6. diff --git a/requirements.txt b/requirements.txt index ad1c7e95a..1637cc40e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,9 +5,9 @@ iso8601>=0.1.11 # MIT jmespath>=0.9.0 # MIT jsonpatch!=1.20,>=1.16 # BSD keystoneauth1>=3.18.0 # Apache-2.0 -netifaces>=0.10.4 # MIT os-service-types>=1.7.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0 platformdirs>=3 # MIT License +psutil>=3.2.2 # BSD PyYAML>=3.13 # MIT requestsexceptions>=1.2.0 # Apache-2.0