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
This commit is contained in:
Takashi Kajinami 2024-10-07 01:08:31 +09:00
parent c2470a21de
commit 7df9a721ef
3 changed files with 22 additions and 9 deletions

View File

@ -15,12 +15,14 @@
import contextlib import contextlib
import fnmatch import fnmatch
import inspect import inspect
import ipaddress
import re import re
import socket
import uuid import uuid
from decorator import decorator from decorator import decorator
import jmespath import jmespath
import netifaces import psutil
from openstack import _log from openstack import _log
from openstack import exceptions from openstack import exceptions
@ -182,15 +184,19 @@ def _get_entity(cloud, resource, name_or_id, filters, **kwargs):
def localhost_supports_ipv6(): def localhost_supports_ipv6():
"""Determine whether the local host supports IPv6 """Determine whether the local host supports IPv6
We look for a default route that supports the IPv6 address family, We look for the all ip addresses configured to this node, and assume that
and assume that if it is present, this host has globally routable if any of these is IPv6 address (but not loopback or link local), this host
IPv6 connectivity. has IPv6 connectivity.
""" """
try: for ifname, if_addrs in psutil.net_if_addrs().items():
return netifaces.AF_INET6 in netifaces.gateways()['default'] for if_addr in if_addrs:
except AttributeError: if if_addr.family != socket.AF_INET6:
return False 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): def valid_kwargs(*valid_args):

View File

@ -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.

View File

@ -5,9 +5,9 @@ iso8601>=0.1.11 # MIT
jmespath>=0.9.0 # MIT jmespath>=0.9.0 # MIT
jsonpatch!=1.20,>=1.16 # BSD jsonpatch!=1.20,>=1.16 # BSD
keystoneauth1>=3.18.0 # Apache-2.0 keystoneauth1>=3.18.0 # Apache-2.0
netifaces>=0.10.4 # MIT
os-service-types>=1.7.0 # Apache-2.0 os-service-types>=1.7.0 # Apache-2.0
pbr!=2.1.0,>=2.0.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0
platformdirs>=3 # MIT License platformdirs>=3 # MIT License
psutil>=3.2.2 # BSD
PyYAML>=3.13 # MIT PyYAML>=3.13 # MIT
requestsexceptions>=1.2.0 # Apache-2.0 requestsexceptions>=1.2.0 # Apache-2.0