python-rtslib/python-rtslib-use-ethtool.patch

46 lines
1.6 KiB
Diff
Raw Normal View History

2011-11-16 20:15:36 +00:00
diff --git a/rtslib/utils.py b/rtslib/utils.py
index c66292c..02fef1e 100644
--- a/rtslib/utils.py
+++ b/rtslib/utils.py
@@ -24,7 +24,7 @@ import uuid
import glob
import socket
import ipaddr
-import netifaces
+import ethtool
import subprocess
from array import array
@@ -690,19 +690,19 @@ def list_eth_ips(ifnames=None):
all IPs of all ifaces excepted for lo.
'''
if ifnames is None:
- ifnames = [iface for iface in list_eth_names() if iface != 'lo']
+ devcfgs = [d for d in ethtool.get_devices() if d != 'lo']
+ else:
+ devcfgs = ethtool.get_interfaces_info(ifnames)
+
addrs = []
- for iface in list_eth_names():
- ifaddresses = netifaces.ifaddresses(iface)
- if netifaces.AF_INET in ifaddresses:
- addrs.extend(addr['addr']
- for addr in ifaddresses[netifaces.AF_INET]
- if not addr['addr'].startswith('127.'))
- if netifaces.AF_INET6 in ifaddresses:
- addrs.extend(addr['addr']
- for addr in ifaddresses[netifaces.AF_INET6]
- if not '%' in addr['addr']
- if not addr['addr'].startswith('::'))
+ for d in devcfgs:
+ if d.ipv4_address:
+ addrs.append(d.ipv4_address)
+ # For IPv6 addresses, we might have more of them on the same device,
+ # and only grab global (universe) addresses.
+ for ip6 in [a for a in d.get_ipv6_addresses() if a.scope == 'universe']:
+ addrs.append(ip6.address)
+
return sorted(set(addrs))
def is_ipv4_address(addr):