Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def ib_global_info(card_drv):
'''Return global info of a IB card in a python dict.
Take in argument a card_drv (ex: mlx4_0).
'''
global_card_info = {}
ret, global_info = cmd('ibstat %s -s' % card_drv)
if ret == 0:
for line in global_info.split('\n'):
re_dev = re.search('CA type: (.*)', line)
if re_dev is not None:
global_card_info['device_type'] = re_dev.group(1)
re_nb_ports = re.search('Number of ports: (.*)', line)
if re_nb_ports is not None:
global_card_info['nb_ports'] = re_nb_ports.group(1)
re_fw_ver = re.search('Firmware version: (.*)', line)
if re_fw_ver is not None:
global_card_info['fw_ver'] = re_fw_ver.group(1)
re_hw_ver = re.search('Hardware version: (.*)', line)
if re_hw_ver is not None:
global_card_info['hw_ver'] = re_hw_ver.group(1)
re_node_guid = re.search('Node GUID: (.*)', line)
if re_node_guid is not None:
def parse_dmesg(hrdw):
"""Run dmesg and parse the output."""
_, output = detect_utils.cmd("dmesg")
for line in output.split('\n'):
words = line.strip().split(" ")
if words[0].startswith("[") and words[0].endswith("]"):
words = words[1:]
if not words:
continue
if "ahci" in words[0]:
parse_ahci(hrdw, words)
def ib_card_drv():
'''Return an array of IB device (ex: ['mlx4_0']).'''
ret, output = cmd('ibstat -l')
if ret == 0:
# Use filter to omit empty item due to trailing newline.
return list(filter(None, output.split('\n')))
return []
'driver', name.text, 'network', 'value')
find_element(elt, "configuration/setting[@id='duplex']",
'duplex', name.text, 'network', 'value')
find_element(elt, "configuration/setting[@id='speed']",
'speed', name.text, 'network', 'value')
find_element(elt, "configuration/setting[@id='latency']",
'latency', name.text, 'network', 'value')
find_element(elt,
"configuration/setting[@id='autonegotiation']",
'autonegotiation', name.text, 'network', 'value')
# lshw is not able to get the complete mac addr for ib
# devices Let's workaround it with an ip command.
if name.text.startswith('ib'):
cmds = "ip addr show %s | grep link | awk '{print $2}'"
status_ip, output_ip = detect_utils.cmd(cmds % name.text)
if status_ip == 0:
hw_lst.append(('network',
name.text,
'serial',
output_ip.split('\n')[0].lower()))
else:
find_element(elt, 'serial', 'serial', name.text, 'network',
transform=lambda x: x.lower())
if not nic_id:
nic_id = _get_value(hw_lst, 'network',
name.text, 'serial')
nic_id = nic_id.replace(':', '')
detect_utils.get_ethtool_status(hw_lst, name.text)
detect_utils.get_lld_status(hw_lst, name.text)
def detect_ipmi(hw_lst):
'Detect IPMI interfaces.'
modprobe("ipmi_smb")
modprobe("ipmi_si")
modprobe("ipmi_devintf")
if (os.path.exists('/dev/ipmi0')
or os.path.exists('/dev/ipmi/0')
or os.path.exists('/dev/ipmidev/0')):
for channel in range(0, 16):
status, _ = detect_utils.cmd(
'ipmitool channel info %d 2>&1 | grep -sq Volatile' % channel)
if status == 0:
hw_lst.append(('system', 'ipmi', 'channel', '%s' % channel))
break
status, output = detect_utils.cmd('ipmitool lan print')
if status == 0:
ipmi.parse_lan_info(output, hw_lst)
return True
# do we need a fake ipmi device for testing purpose ?
status, _ = detect_utils.cmd('grep -qi FAKEIPMI /proc/cmdline')
if status == 0:
# Yes ! So let's create a fake entry
hw_lst.append(('system', 'ipmi-fake', 'channel', '0'))
sys.stderr.write('Info: Added fake IPMI device\n')
return True
sys.stderr.write('Info: No IPMI device found\n')
return False
def detect_infiniband(hw_lst):
"""Detect Infiniband devices.
To detect if an IB device is present, we search for a pci device.
This pci device shall be from vendor Mellanox (15b3) from class 0280
Class 280 stands for a Network Controller while ethernet device are 0200.
"""
status, _ = detect_utils.cmd(
"lspci -d 15b3: -n|awk '{print $2}'|grep -q '0280'")
if status != 0:
sys.stderr.write('Info: No Infiniband device found\n')
return False
for ib_card in range(len(ib.ib_card_drv())):
card_type = ib.ib_card_drv()[ib_card]
ib_infos = ib.ib_global_info(card_type)
nb_ports = ib_infos['nb_ports']
hw_lst.append(('infiniband', 'card%i' % ib_card,
'card_type', card_type))
hw_lst.append(('infiniband', 'card%i' % ib_card,
'device_type', ib_infos['device_type']))
hw_lst.append(('infiniband', 'card%i' % ib_card,
'fw_version', ib_infos['fw_ver']))
hw_lst.append(('infiniband', 'card%i' % ib_card,
def get_hp_conrep(hwlst):
for i in hwlst:
if i[0:3] == ('system', 'product', 'vendor'):
if i[3] not in ['HPE', 'HP']:
return True, ""
output_file = next(tempfile._get_candidate_names())
status, output = cmd("hp-conrep --save -f {}".format(output_file))
if status != 0:
sys.stderr.write("Unable to run hp-conrep: %s\n" % output)
return False, ""
return_value = open(output_file).read()
os.remove(output_file)
return True, return_value
def modprobe(module):
'Load a kernel module using modprobe.'
status, _ = detect_utils.cmd('modprobe %s' % module)
if status == 0:
sys.stderr.write('Info: Probing %s failed\n' % module)