Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def lookup(self, name):
if encode_value(name) not in map(encode_value, ethtool.get_devices()):
raise NotFoundError('KCHIFACE0001E', {'name': name})
ipaddr = ''
netmask = ''
module = 'unknown'
status = 'down'
try:
ipaddr = ethtool.get_ipaddr(encode_value(name))
netmask = ethtool.get_netmask(encode_value(name))
module = ethtool.get_module(encode_value(name))
flags = ethtool.get_flags(encode_value(name))
status = 'up' if flags & (
ethtool.IFF_RUNNING | ethtool.IFF_UP) else 'down'
except IOError:
pass
iface_type = netinfo.get_interface_type(name)
return {
'name': name,
'type': iface_type,
'status': status,
'ipaddr': ipaddr,
'netmask': netmask,
'module': module,
}
def operstate(dev):
"""Get the operstate status of a device.
Args:
dev (str): name of the device.
Returns:
str: "up" or "down"
"""
flags = ethtool.get_flags(encode_value(dev))
return 'up' if flags & (ethtool.IFF_RUNNING | ethtool.IFF_UP) else 'down'
def flags2str(flags):
string = ""
if flags & ethtool.IFF_UP:
string += "UP "
if flags & ethtool.IFF_BROADCAST:
string += "BROADCAST "
if flags & ethtool.IFF_DEBUG:
string += "DEBUG "
if flags & ethtool.IFF_LOOPBACK:
string += "LOOPBACK "
if flags & ethtool.IFF_POINTOPOINT:
string += "POINTOPOINT "
if flags & ethtool.IFF_NOTRAILERS:
string += "NOTRAILERS "
if flags & ethtool.IFF_RUNNING:
string += "RUNNING "
if flags & ethtool.IFF_NOARP:
string += "NOARP "
if flags & ethtool.IFF_PROMISC: