Rename `detect` to `auto` special values in network segments
Fixes #1205
This commit is contained in:
parent
33b44e8a3f
commit
79f6853f4b
|
@ -68,7 +68,7 @@ Divider highlight group used: ``background:divider``.
|
||||||
try:
|
try:
|
||||||
import netifaces
|
import netifaces
|
||||||
except ImportError:
|
except ImportError:
|
||||||
def internal_ip(pl, interface='detect', ipv=4):
|
def internal_ip(pl, interface='auto', ipv=4):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
_interface_starts = {
|
_interface_starts = {
|
||||||
|
@ -100,8 +100,8 @@ else:
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def internal_ip(pl, interface='detect', ipv=4):
|
def internal_ip(pl, interface='auto', ipv=4):
|
||||||
if interface == 'detect':
|
if interface == 'auto':
|
||||||
try:
|
try:
|
||||||
interface = next(iter(sorted(netifaces.interfaces(), key=_interface_key, reverse=True)))
|
interface = next(iter(sorted(netifaces.interfaces(), key=_interface_key, reverse=True)))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
|
@ -120,7 +120,7 @@ internal_ip = with_docstring(internal_ip,
|
||||||
Requires ``netifaces`` module to work properly.
|
Requires ``netifaces`` module to work properly.
|
||||||
|
|
||||||
:param str interface:
|
:param str interface:
|
||||||
Interface on which IP will be checked. Use ``detect`` to automatically
|
Interface on which IP will be checked. Use ``auto`` to automatically
|
||||||
detect interface. In this case interfaces with lower numbers will be
|
detect interface. In this case interfaces with lower numbers will be
|
||||||
preferred over interfaces with similar names. Order of preference based on
|
preferred over interfaces with similar names. Order of preference based on
|
||||||
names:
|
names:
|
||||||
|
@ -174,11 +174,11 @@ class NetworkLoadSegment(KwThreadedSegment):
|
||||||
replace_num_pat = re.compile(r'[a-zA-Z]+')
|
replace_num_pat = re.compile(r'[a-zA-Z]+')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def key(interface='detect', **kwargs):
|
def key(interface='auto', **kwargs):
|
||||||
return interface
|
return interface
|
||||||
|
|
||||||
def compute_state(self, interface):
|
def compute_state(self, interface):
|
||||||
if interface == 'detect':
|
if interface == 'auto':
|
||||||
proc_exists = getattr(self, 'proc_exists', None)
|
proc_exists = getattr(self, 'proc_exists', None)
|
||||||
if proc_exists is None:
|
if proc_exists is None:
|
||||||
proc_exists = self.proc_exists = os.path.exists('/proc/net/route')
|
proc_exists = self.proc_exists = os.path.exists('/proc/net/route')
|
||||||
|
@ -192,7 +192,7 @@ class NetworkLoadSegment(KwThreadedSegment):
|
||||||
if not destination.replace(b'0', b''):
|
if not destination.replace(b'0', b''):
|
||||||
interface = iface.decode('utf-8')
|
interface = iface.decode('utf-8')
|
||||||
break
|
break
|
||||||
if interface == 'detect':
|
if interface == 'auto':
|
||||||
# Choose interface with most total activity, excluding some
|
# Choose interface with most total activity, excluding some
|
||||||
# well known interface names
|
# well known interface names
|
||||||
interface, total = 'eth0', -1
|
interface, total = 'eth0', -1
|
||||||
|
@ -268,7 +268,7 @@ falls back to reading
|
||||||
:file:`/sys/class/net/{interface}/statistics/{rx,tx}_bytes`.
|
:file:`/sys/class/net/{interface}/statistics/{rx,tx}_bytes`.
|
||||||
|
|
||||||
:param str interface:
|
:param str interface:
|
||||||
network interface to measure (use the special value "detect" to have powerline try to auto-detect the network interface)
|
network interface to measure (use the special value "auto" to have powerline try to auto-detect the network interface)
|
||||||
:param str suffix:
|
:param str suffix:
|
||||||
string appended to each load string
|
string appended to each load string
|
||||||
:param bool si_prefix:
|
:param bool si_prefix:
|
||||||
|
|
|
@ -352,15 +352,15 @@ class TestNet(TestCommon):
|
||||||
AF_INET6=netifaces.AF_INET6,
|
AF_INET6=netifaces.AF_INET6,
|
||||||
):
|
):
|
||||||
self.assertEqual(common.internal_ip(pl=pl), '192.168.100.200')
|
self.assertEqual(common.internal_ip(pl=pl), '192.168.100.200')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='detect'), '192.168.100.200')
|
self.assertEqual(common.internal_ip(pl=pl, interface='auto'), '192.168.100.200')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='lo'), '127.0.0.1')
|
self.assertEqual(common.internal_ip(pl=pl, interface='lo'), '127.0.0.1')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='teredo'), None)
|
self.assertEqual(common.internal_ip(pl=pl, interface='teredo'), None)
|
||||||
self.assertEqual(common.internal_ip(pl=pl, ipv=4), '192.168.100.200')
|
self.assertEqual(common.internal_ip(pl=pl, ipv=4), '192.168.100.200')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='detect', ipv=4), '192.168.100.200')
|
self.assertEqual(common.internal_ip(pl=pl, interface='auto', ipv=4), '192.168.100.200')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='lo', ipv=4), '127.0.0.1')
|
self.assertEqual(common.internal_ip(pl=pl, interface='lo', ipv=4), '127.0.0.1')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='teredo', ipv=4), None)
|
self.assertEqual(common.internal_ip(pl=pl, interface='teredo', ipv=4), None)
|
||||||
self.assertEqual(common.internal_ip(pl=pl, ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
self.assertEqual(common.internal_ip(pl=pl, ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='detect', ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
self.assertEqual(common.internal_ip(pl=pl, interface='auto', ipv=6), 'feff::5446:5eff:fe5a:7777%enp2s0')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='lo', ipv=6), '::1')
|
self.assertEqual(common.internal_ip(pl=pl, interface='lo', ipv=6), '::1')
|
||||||
self.assertEqual(common.internal_ip(pl=pl, interface='teredo', ipv=6), 'feff::5446:5eff:fe5a:7777')
|
self.assertEqual(common.internal_ip(pl=pl, interface='teredo', ipv=6), 'feff::5446:5eff:fe5a:7777')
|
||||||
interfaces[1:2] = ()
|
interfaces[1:2] = ()
|
||||||
|
|
Loading…
Reference in New Issue