mirror of https://github.com/nicolargo/glances.git
Add another check for the famous Netifaces issue - Related to #3219
This commit is contained in:
parent
2cf92f93a9
commit
c1c0d4038f
|
|
@ -19,18 +19,18 @@ from glances.timer import Timer, getTimeSinceLastUpdate
|
|||
try:
|
||||
import netifaces
|
||||
except ImportError as e:
|
||||
import_error_tag = True
|
||||
netifaces_tag = True
|
||||
logger.warning(f"Missing Python Lib ({e}), IP plugin is disabled")
|
||||
else:
|
||||
import_error_tag = False
|
||||
netifaces_tag = False
|
||||
|
||||
try:
|
||||
netifaces.default_gateway()
|
||||
except Exception:
|
||||
import_error_tag = True
|
||||
netifaces_tag = True
|
||||
logger.warning("Netifaces2 should be installed in your Python environment, IP plugin is disabled")
|
||||
else:
|
||||
import_error_tag = False
|
||||
netifaces_tag = False
|
||||
|
||||
|
||||
# Fields description
|
||||
|
|
@ -150,7 +150,7 @@ class IpPlugin(GlancesPluginModel):
|
|||
# Init new stats
|
||||
stats = self.get_init_value()
|
||||
|
||||
if self.input_method == 'local' and not import_error_tag:
|
||||
if self.input_method == 'local' and not netifaces_tag:
|
||||
stats = self.get_stats_for_local_input(stats)
|
||||
|
||||
elif self.input_method == 'snmp':
|
||||
|
|
@ -178,7 +178,7 @@ class IpPlugin(GlancesPluginModel):
|
|||
ret = []
|
||||
|
||||
# Only process if stats exist and display plugin enable...
|
||||
if not self.stats or self.is_disabled() or import_error_tag:
|
||||
if not self.stats or self.is_disabled() or netifaces_tag:
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ except ImportError:
|
|||
try:
|
||||
netifaces.gateways()
|
||||
except Exception:
|
||||
import_error_tag = True
|
||||
netifaces_tag = True
|
||||
else:
|
||||
logger.warning(
|
||||
"Ports plugin - Netifaces2 do not support gateways() method, port_default_gateway feature is disabled"
|
||||
)
|
||||
import_error_tag = False
|
||||
netifaces_tag = False
|
||||
|
||||
|
||||
class GlancesPortsList:
|
||||
|
|
|
|||
|
|
@ -14,6 +14,23 @@ import sys
|
|||
from glances.globals import BSD
|
||||
from glances.logger import logger
|
||||
|
||||
try:
|
||||
import netifaces
|
||||
|
||||
netifaces_tag = True
|
||||
except ImportError:
|
||||
logger.warning("Servers list - Netifaces2 lib not found, active IP address not possible")
|
||||
netifaces_tag = False
|
||||
|
||||
try:
|
||||
netifaces.gateways()
|
||||
except Exception:
|
||||
netifaces_tag = True
|
||||
else:
|
||||
logger.warning("Servers list - Netifaces2 do not support gateways() method, active IP address not possible")
|
||||
netifaces_tag = False
|
||||
|
||||
|
||||
try:
|
||||
from zeroconf import ServiceBrowser, ServiceInfo, Zeroconf
|
||||
from zeroconf import __version__ as __zeroconf_version
|
||||
|
|
@ -192,10 +209,11 @@ class GlancesAutoDiscoverClient:
|
|||
if not BSD:
|
||||
try:
|
||||
# -B @ overwrite the dynamic IPv4 choice
|
||||
if zeroconf_bind_address == '0.0.0.0':
|
||||
if netifaces_tag and zeroconf_bind_address == '0.0.0.0':
|
||||
zeroconf_bind_address = self.find_active_ip_address()
|
||||
except KeyError:
|
||||
except Exception:
|
||||
# Issue #528 (no network interface available)
|
||||
# Issue #3219 (no implementation for gateway())
|
||||
pass
|
||||
|
||||
# Ensure zeroconf_bind_address is an IP address not an host
|
||||
|
|
@ -241,8 +259,6 @@ class GlancesAutoDiscoverClient:
|
|||
@staticmethod
|
||||
def find_active_ip_address():
|
||||
"""Try to find the active IP addresses."""
|
||||
import netifaces
|
||||
|
||||
# Interface of the default gateway
|
||||
gateway_itf = netifaces.gateways()[netifaces.AF_INET][0][1]
|
||||
# IP address for the interface
|
||||
|
|
|
|||
Loading…
Reference in New Issue