How to use the ethtool.get_interfaces_info function in ethtool

To help you get started, we’ve selected a few ethtool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oVirt / vdsm / tests / netinfoTests.py View on Github external
def testGetIfaceByIP(self):
        for dev in ethtool.get_interfaces_info(ethtool.get_active_devices()):
            # Link-local IPv6 addresses are generated from the MAC address,
            # which is shared between a nic and its bridge. Since We don't
            # support having the same IP address on two different NICs, and
            # link-local IPv6 addresses aren't interesting for 'getDeviceByIP'
            # then ignore them in the test
            ipaddrs = [ipv6.address for ipv6 in dev.get_ipv6_addresses()
                       if ipv6.scope != 'link']
            if dev.ipv4_address is not None:
                ipaddrs.append(dev.ipv4_address)
            for ip in ipaddrs:
                self.assertEqual(dev.device, netinfo.getIfaceByIP(ip))
github kimchi-project / kimchi / network.py View on Github external
def get_dev_netaddr(dev):
    info = ethtool.get_interfaces_info(dev)[0]
    return (info.ipv4_address and
            '%s/%s' % (info.ipv4_address, info.ipv4_netmask) or '')
github uyuni-project / uyuni / client / debian / packages-already-in-debian / rhn-client-tools / src / up2date_client / hardware.py View on Github external
ipaddr = ethtool.get_ipaddr(interface)
        except:
            ipaddr = ""

        try:
            netmask = ethtool.get_netmask(interface)
        except:
            netmask = ""

        try:
            broadcast = ethtool.get_broadcast(interface)
        except:
            broadcast = ""

        ip6_list = []
        dev_info = ethtool.get_interfaces_info(interface)
        for info in dev_info:
            # one interface may have more IPv6 addresses
            for ip6 in info.get_ipv6_addresses():
                scope = ip6.scope
                if scope == 'global':
                    scope = 'universe'
                ip6_list.append({
                    'scope':   scope,
                    'addr':    ip6.address,
                    'netmask': ip6.netmask
                })
        intDict[interface] = {'hwaddr':hwaddr,
                              'ipaddr':ipaddr,
                              'netmask':netmask,
                              'broadcast':broadcast,
                              'module': module,
github uyuni-project / uyuni / client / rhel / spacewalk-client-tools / src / up2date_client / hardware.py View on Github external
else:
                netmask = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['netmask']
        except:
            netmask = ""

        try:
            if ethtool_present:
                broadcast = ethtool.get_broadcast(interface)
            else:
                broadcast = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['broadcast']
        except:
            broadcast = ""

        ip6_list = []
        if ethtool_present:
            dev_info = ethtool.get_interfaces_info(interface)
            # an interface with label (contains character ':') does not have ipv6
            # addresses assigned which confuses python-ethtool
            # so collect info about ipv6 addresses for the "base" interface only
            # correct change would require fixing python-ethtool on all supported
            # operating systems (it still mimics old style ifconfig output) and
            # extend UI to allow list of ipv4 addresses for single interface
            if ':' not in interface:
                for info in dev_info:
                    # one interface may have more IPv6 addresses
                    for ip6 in info.get_ipv6_addresses():
                        scope = ip6.scope
                        if scope == 'global':
                            scope = 'universe'
                        ip6_list.append({
                            'scope':   scope,
                            'addr':    ip6.address,