def test_non_existent_S(): e = Ethtool('/usr/sbin/ethtool') try: e.ethtool_S('no_such') except NoSuchDevice: print "device not found! (yippee)" else: assert False
def _fetch_info_linux(self): nics = [] with Ethtool() as ethtool: for iface in fetch_network_devices(): try: drvinfo = ethtool.fetch_drvinfo(iface_name=iface) except: continue bus_info = drvinfo.get('bus_info') if not bus_info or bus_info in ('N/A',): continue pci = PCIDevice(bus_info) brand = ' '.join(( pci.get('vendor', '').strip(), pci.get('device', '').strip(), )) mtu = ethtool.fetch_mtu(iface_name=iface) flags = ethtool.fetch_if_flags(iface_name=iface) mac = ethtool.fetch_hardware_address(iface_name=iface) try: link_settings = ethtool.fetch_link_setttings(iface_name=iface) speed = link_settings.get('speed', None) except: settings = ethtool.fetch_settings(iface_name=iface) speed = settings['speed'] try: ip = ethtool.fetch_ip_address(iface_name=iface) except: ip = None ips = [ ip for ip in (ip,) if ip ] if speed in (0xffff, 0xffffffff): speed = None nic = OrderedDict([ (self.FIELD_IFACE, iface), (self.FIELD_BRAND, brand), (self.FIELD_BUS, bus_info), (self.FIELD_SPEED, speed), (self.FIELD_MAC, mac), (self.FIELD_IPS, ips), (self.FIELD_MTU, mtu), (self.FIELD_UP, flags.is_up), (self.FIELD_LINKED, flags.is_running), ]) nics.append(nic) return nics
def test_ethtool_S(): e = Ethtool('/usr/sbin/ethtool') e.ethtool_S('eth0') print e.S.result