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, _ = 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 = cmd('ipmitool lan print') if status == 0: ipmi.parse_lan_info(output, hw_lst) else: # do we need a fake ipmi device for testing purpose ? status, _ = 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 else: sys.stderr.write('Info: No IPMI device found\n') return False
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, _ = 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 = 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, _ = 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_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, _ = 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 = cmd("ipmitool lan print") if status == 0: ipmi.parse_lan_info(output, hw_lst) else: # do we need a fake ipmi device for testing purpose ? status, _ = 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 else: sys.stderr.write("Info: No IPMI device found\n") return False
def ib_port_info(card_drv, port): """Return port infos of a IB card_drv in a python dict. :param card_drv: a card device ID (e.g. mlx4_0) :param port: the port number (e.g. 1) :returns: a list containing information on the port """ port_infos = {} ret, port_desc = cmd('ibstat %s %i' % (card_drv, port)) if ret == 0: for line in port_desc.split('\n'): re_state = re.search('State: (.*)', line) if re_state is not None: port_infos['state'] = re_state.group(1) re_phy_state = re.search('State: (.*)', line) if re_phy_state is not None: port_infos['physical_state'] = re_phy_state.group(1) re_rate = re.search('Rate: (.*)', line) if re_rate is not None: port_infos['rate'] = re_rate.group(1) re_blid = re.search('Base lid: (.*)', line) if re_blid is not None: port_infos['base_lid'] = re_blid.group(1) re_lmc = re.search('LMC: (.*)', line) if re_lmc is not None: port_infos['lmc'] = re_lmc.group(1) re_smlid = re.search('SM lid: (.*)', line) if re_smlid is not None: port_infos['sm_lid'] = re_smlid.group(1) re_pguid = re.search('Port GUID: (.*)', line) if re_pguid is not None: port_infos['port_guid'] = re_pguid.group(1) return port_infos
def ib_global_info(card_drv): """Return global info of a IB card in a python dict. :param card_drv: a card device ID (e.g. mlx4_0) :returns: a list containing information on the card device """ 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: global_card_info['node_guid'] = re_node_guid.group(1) re_sys_guid = re.search('System image GUID: (.*)', line) if re_sys_guid is not None: global_card_info['sys_guid'] = re_sys_guid.group(1) return global_card_info
def _main(options): 'Command line entry point.' hrdw = [] detect_areca(hrdw) detect_hpa(hrdw) detect_megacli(hrdw) detect_disks(hrdw) if not detect_system(hrdw): sys.exit(1) detect_ipmi(hrdw) detect_infiniband(hrdw) detect_temperatures(hrdw) detect_utils.get_ddr_timing(hrdw) detect_utils.ipmi_sdr(hrdw) detect_rtc_clock(hrdw) _, output = cmd("dmesg") parse_dmesg(hrdw, output) bios_hp.dump_hp_bios(hrdw) if "benchmark_cpu" in options: bm_cpu.cpu_perf(hrdw) if "benchmark_mem" in options: bm_mem.mem_perf(hrdw) if "benchmark_disk" in options: bm_disk.disk_perf(hrdw, destructive=options['benchmark_disk_destructive']) hrdw = clean_tuples(hrdw) if "human" in options.keys(): pprint.pprint(hrdw) else: print(json.dumps(hrdw))
def ib_card_drv(): '''Return an array of IB device (ex: ['mlx4_0']).''' ret, output = cmd('ibstat -l') if ret == 0: return output.split('\n') else: return []
def _main(options): 'Command line entry point.' hrdw = [] detect_hpa(hrdw) detect_megacli(hrdw) detect_disks(hrdw) if not detect_system(hrdw): sys.exit(1) detect_ipmi(hrdw) detect_infiniband(hrdw) detect_temperatures(hrdw) detect_utils.get_ddr_timing(hrdw) detect_utils.ipmi_sdr(hrdw) _, output = cmd("dmesg") parse_dmesg(hrdw, output) if "benchmark_cpu" in options: bm_cpu.cpu_perf(hrdw) if "benchmark_mem" in options: bm_mem.mem_perf(hrdw) if "benchmark_disk" in options: bm_disk.disk_perf(hrdw, destructive=options['benchmark_disk_destructive']) if "human" in options.keys(): pprint.pprint(hrdw) else: print(json.dumps(hrdw))
def ib_port_info(card_drv, port): '''Return port infos of a IB card_drv in a python dict. Take in argument the card_drv name and the port number (ex: mlx4_0,1). ''' port_infos = {} ret, port_desc = cmd('ibstat %s %i' % (card_drv, port)) if ret == 0: for line in port_desc.split('\n'): re_state = re.search('State: (.*)', line) if re_state is not None: port_infos['state'] = re_state.group(1) re_phy_state = re.search('State: (.*)', line) if re_phy_state is not None: port_infos['physical_state'] = re_phy_state.group(1) re_rate = re.search('Rate: (.*)', line) if re_rate is not None: port_infos['rate'] = re_rate.group(1) re_blid = re.search('Base lid: (.*)', line) if re_blid is not None: port_infos['base_lid'] = re_blid.group(1) re_lmc = re.search('LMC: (.*)', line) if re_lmc is not None: port_infos['lmc'] = re_lmc.group(1) re_smlid = re.search('SM lid: (.*)', line) if re_smlid is not None: port_infos['sm_lid'] = re_smlid.group(1) re_pguid = re.search('Port GUID: (.*)', line) if re_pguid is not None: port_infos['port_guid'] = re_pguid.group(1) return port_infos
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: global_card_info['node_guid'] = re_node_guid.group(1) re_sys_guid = re.search('System image GUID: (.*)', line) if re_sys_guid is not None: global_card_info['sys_guid'] = re_sys_guid.group(1) return global_card_info
def ib_port_info(card_drv, port): """Return port infos of a IB card_drv in a python dict. Take in argument the card_drv name and the port number (ex: mlx4_0,1). """ port_infos = {} ret, port_desc = cmd("ibstat %s %i" % (card_drv, port)) if ret == 0: for line in port_desc.split("\n"): re_state = re.search("State: (.*)", line) if re_state is not None: port_infos["state"] = re_state.group(1) re_phy_state = re.search("State: (.*)", line) if re_phy_state is not None: port_infos["physical_state"] = re_phy_state.group(1) re_rate = re.search("Rate: (.*)", line) if re_rate is not None: port_infos["rate"] = re_rate.group(1) re_blid = re.search("Base lid: (.*)", line) if re_blid is not None: port_infos["base_lid"] = re_blid.group(1) re_lmc = re.search("LMC: (.*)", line) if re_lmc is not None: port_infos["lmc"] = re_lmc.group(1) re_smlid = re.search("SM lid: (.*)", line) if re_smlid is not None: port_infos["sm_lid"] = re_smlid.group(1) re_pguid = re.search("Port GUID: (.*)", line) if re_pguid is not None: port_infos["port_guid"] = re_pguid.group(1) return port_infos
def ib_card_drv(): """Return an array of IB device (ex: ['mlx4_0']).""" ret, output = cmd("ibstat -l") if ret == 0: return output.split("\n") else: return []
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: global_card_info["node_guid"] = re_node_guid.group(1) re_sys_guid = re.search("System image GUID: (.*)", line) if re_sys_guid is not None: global_card_info["sys_guid"] = re_sys_guid.group(1) return global_card_info
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 []
def setup_user(channel, username, password): 'Setup an IPMI user.' sys.stderr.write('Info: ipmi_setup_user: Setting user="******", ' 'password="******" on channel %s\n' % (username, password, channel)) cmd('ipmitool user set name 1 %s' % username) cmd('ipmitool user set password 1 %s' % password) cmd('ipmitool user priv 1 4 %s' % channel) cmd('ipmitool user enable') state, _ = cmd('ipmitool user test 1 16 %s' % password) if state == 0: sys.stderr.write('Info: ipmi_setup_user: Setting user successful !\n') sys.stderr.write('Err: ipmi_setup_user: Setting user failed !\n') return False
def setup_user(channel, username, password): 'Setup an IPMI user.' sys.stderr.write('Info: ipmi_setup_user: Setting user="******", ' 'password="******" on channel %s\n' % (username, password, channel)) cmd('ipmitool user set name 1 %s' % username) cmd('ipmitool user set password 1 %s' % password) cmd('ipmitool user priv 1 4 %s' % channel) cmd('ipmitool user enable') state, _ = cmd('ipmitool user test 1 16 %s' % password) if state == 0: sys.stderr.write('Info: ipmi_setup_user: Setting user successful !\n') else: sys.stderr.write('Err: ipmi_setup_user: Setting user failed !\n') return False
def get_hp_conrep(hrdw): for i in hrdw: if i[0:3] == ('system', 'product', 'vendor'): if i[3] not in ['HPE', 'HP']: return True, "" output_file = tempfile.TemporaryFile() 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 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 detect_infiniband(hw_lst): '''Detect Infiniband devinces. To detect if an IB device is present, we search for a pci device. This pci device shall be from vendor Mellanox (15b3) form class 0280 Class 280 stands for a Network Controller while ethernet device are 0200. ''' status, _ = cmd("lspci -d 15b3: -n|awk '{print $2}'|grep -q '0280'") if status == 0: ib_card = 0 for devices in range(ib_card, len(ib.ib_card_drv())): card_type = ib.ib_card_drv()[devices] 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, 'hw_version', ib_infos['hw_ver'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'nb_ports', nb_ports)) hw_lst.append(('infiniband', 'card%i' % ib_card, 'sys_guid', ib_infos['sys_guid'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'node_guid', ib_infos['node_guid'])) for port in range(1, int(nb_ports) + 1): ib_port_infos = ib.ib_port_info(card_type, port) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'state', ib_port_infos['state'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'physical_state', ib_port_infos['physical_state'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'rate', ib_port_infos['rate'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'base_lid', ib_port_infos['base_lid'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'lmc', ib_port_infos['lmc'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'sm_lid', ib_port_infos['sm_lid'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'port_guid', ib_port_infos['port_guid'])) return True else: sys.stderr.write('Info: No Infiniband device found\n') return False
def parse_dmesg(hrdw): """Run dmesg and parse the output.""" _, output = 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 _main(options): 'Command line entry point.' hrdw = [] detect_hpa(hrdw) detect_megacli(hrdw) detect_disks(hrdw) detect_system(hrdw) detect_ipmi(hrdw) detect_infiniband(hrdw) detect_temperatures(hrdw) detect_utils.get_ddr_timing(hrdw) detect_utils.ipmi_sdr(hrdw) status, output = cmd("dmesg") parse_dmesg(hrdw, output) if "human" in options.keys(): pprint.pprint(hrdw) else: print(json.dumps(hrdw))
def detect_infiniband(hw_lst): """Detect Infiniband devinces. To detect if an IB device is present, we search for a pci device. This pci device shall be from vendor Mellanox (15b3) form class 0280 Class 280 stands for a Network Controller while ethernet device are 0200. """ status, _ = cmd("lspci -d 15b3: -n|awk '{print $2}'|grep -q '0280'") if status == 0: ib_card = 0 for devices in range(ib_card, len(ib.ib_card_drv())): card_type = ib.ib_card_drv()[devices] 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, "hw_version", ib_infos["hw_ver"])) hw_lst.append(("infiniband", "card%i" % ib_card, "nb_ports", nb_ports)) hw_lst.append(("infiniband", "card%i" % ib_card, "sys_guid", ib_infos["sys_guid"])) hw_lst.append(("infiniband", "card%i" % ib_card, "node_guid", ib_infos["node_guid"])) for port in range(1, int(nb_ports) + 1): ib_port_infos = ib.ib_port_info(card_type, port) hw_lst.append(("infiniband", "card%i_port%i" % (ib_card, port), "state", ib_port_infos["state"])) hw_lst.append( ("infiniband", "card%i_port%i" % (ib_card, port), "physical_state", ib_port_infos["physical_state"]) ) hw_lst.append(("infiniband", "card%i_port%i" % (ib_card, port), "rate", ib_port_infos["rate"])) hw_lst.append(("infiniband", "card%i_port%i" % (ib_card, port), "base_lid", ib_port_infos["base_lid"])) hw_lst.append(("infiniband", "card%i_port%i" % (ib_card, port), "lmc", ib_port_infos["lmc"])) hw_lst.append(("infiniband", "card%i_port%i" % (ib_card, port), "sm_lid", ib_port_infos["sm_lid"])) hw_lst.append( ("infiniband", "card%i_port%i" % (ib_card, port), "port_guid", ib_port_infos["port_guid"]) ) return True else: sys.stderr.write("Info: No Infiniband device found\n") return False
def main(): """Command line entry point.""" os.environ["LANG"] = "en_US.UTF-8" args = parse_args(sys.argv[1:]) hrdw = [] detect_areca(hrdw) detect_hpa(hrdw) detect_megacli(hrdw) detect_disks(hrdw) if not detect_system(hrdw): sys.exit(1) detect_ipmi(hrdw) detect_infiniband(hrdw) detect_temperatures(hrdw) detect_utils.get_ddr_timing(hrdw) detect_utils.ipmi_sdr(hrdw) detect_rtc_clock(hrdw) _, output = cmd("dmesg") parse_dmesg(hrdw, output) bios_hp.dump_hp_bios(hrdw) if args.benchmark: if 'cpu' in args.benchmark: bm_cpu.cpu_perf(hrdw) if 'mem' in args.benchmark: bm_mem.mem_perf(hrdw) if 'disk' in args.benchmark: bm_disk.disk_perf(hrdw, destructive=args.benchmark_disk_destructive) hrdw = clean_tuples(hrdw) if args.human: pprint.pprint(hrdw) else: print(json.dumps(hrdw))
def dump_hp_bios(hw_lst, output=None): def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None, transform=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: txt = elt[0].attrib[attrib] else: txt = elt[0].text if transform: txt = transform(txt) hw_lst.append((sys_cls, sys_type, sys_subtype, txt)) return txt return None # handle output injection for testing purpose if output: root = ET.fromstring(output) else: 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 xml = ET.parse(output_file) os.remove(output_file) root = xml.getroot().iter("Section") for child in root: hw_lst.append(('hp', 'bios', child.attrib['name'], child.text)) return True
def diskperfs(names): return dict((name, parse_hdparm_output(cmd('hdparm -t /dev/%s' % name))) for name in names)
def detect_system(hw_lst, output=None): 'Detect system characteristics from the output of lshw.' def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None, transform=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: txt = elt[0].attrib[attrib] else: txt = elt[0].text if transform: txt = transform(txt) hw_lst.append((sys_cls, sys_type, sys_subtype, txt)) return txt return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd('lshw -xml') if status == 0: mobo_id = '' nic_id = '' xml = ET.fromstring(output) find_element(xml, "./node/serial", 'serial') find_element(xml, "./node/product", 'name') find_element(xml, "./node/vendor", 'vendor') find_element(xml, "./node/version", 'version') uuid = get_uuid(hw_lst) if uuid: # If we have an uuid, we shall check if it's part of a # known list of broken uuid # If so let's delete the uuid instead of reporting a stupid thing if uuid in ['Not']: uuid = '' else: hw_lst.append(('system', 'product', 'uuid', uuid)) for elt in xml.findall(".//node[@id='core']"): name = elt.find('physid') if name is not None: find_element(elt, 'product', 'name', 'motherboard', 'system') find_element(elt, 'vendor', 'vendor', 'motherboard', 'system') find_element(elt, 'version', 'version', 'motherboard', 'system') find_element(elt, 'serial', 'serial', 'motherboard', 'system') mobo_id = _get_value(hw_lst, 'system', 'motherboard', 'serial') for elt in xml.findall(".//node[@id='firmware']"): name = elt.find('physid') if name is not None: find_element(elt, 'version', 'version', 'bios', 'firmware') find_element(elt, 'date', 'date', 'bios', 'firmware') find_element(elt, 'vendor', 'vendor', 'bios', 'firmware') bank_count = 0 for elt in xml.findall(".//node[@class='memory']"): if not elt.attrib['id'].startswith('memory'): continue try: location = re.search('memory(:.*)', elt.attrib['id']).group(1) except AttributeError: location = '' name = elt.find('physid') if name is not None: find_element(elt, 'size', 'size', 'total', 'memory') for bank_list in elt.findall(".//node[@id]"): if 'bank:' in bank_list.get('id'): bank_count = bank_count + 1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get('id'))): bank_id = bank_list.get('id').replace( "bank:", "bank" + location + ":") find_element(bank, 'size', 'size', bank_id, 'memory') find_element(bank, 'clock', 'clock', bank_id, 'memory') find_element(bank, 'description', 'description', bank_id, 'memory') find_element(bank, 'vendor', 'vendor', bank_id, 'memory') find_element(bank, 'product', 'product', bank_id, 'memory') find_element(bank, 'serial', 'serial', bank_id, 'memory') find_element(bank, 'slot', 'slot', bank_id, 'memory') if bank_count > 0: hw_lst.append(('memory', 'banks', 'count', str(bank_count))) for elt in xml.findall(".//node[@class='network']"): name = elt.find('logicalname') if name is not None: find_element(elt, 'businfo', 'businfo', name.text, 'network') find_element(elt, 'vendor', 'vendor', name.text, 'network') find_element(elt, 'product', 'product', name.text, 'network') find_element(elt, "configuration/setting[@id='firmware']", 'firmware', name.text, 'network', 'value') find_element(elt, 'size', 'size', name.text, 'network') ipv4 = find_element(elt, "configuration/setting[@id='ip']", 'ipv4', name.text, 'network', 'value') if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl( sock, SIOCGIFNETMASK, struct.pack('256s', name.text.encode('utf-8')))[20:24]) hw_lst.append( ('network', name.text, 'ipv4-netmask', netmask)) cidr = get_cidr(netmask) hw_lst.append( ('network', name.text, 'ipv4-cidr', cidr)) net = (ipaddress.IPv4Interface( '%s/%s' % (ipv4, cidr)).network.network_address) hw_lst.append( ('network', name.text, 'ipv4-network', str(net))) except Exception as excpt: sys.stderr.write('unable to get info for %s: %s\n' % (name.text, str(excpt))) find_element(elt, "configuration/setting[@id='link']", 'link', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='driver']", '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 = 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) fix_bad_serial(hw_lst, uuid, mobo_id, nic_id) else: sys.stderr.write("Unable to run lshw: %s\n" % output) return False get_cpus(hw_lst) osvendor_cmd = detect_utils.output_lines("lsb_release -is") for line in osvendor_cmd: hw_lst.append(('system', 'os', 'vendor', line.rstrip('\n').strip())) osinfo_cmd = detect_utils.output_lines("lsb_release -ds | tr -d '\"'") for line in osinfo_cmd: hw_lst.append(('system', 'os', 'version', line.rstrip('\n').strip())) uname_cmd = detect_utils.output_lines("uname -r") for line in uname_cmd: hw_lst.append( ('system', 'kernel', 'version', line.rstrip('\n').strip())) arch_cmd = detect_utils.output_lines("uname -i") for line in arch_cmd: hw_lst.append(('system', 'kernel', 'arch', line.rstrip('\n').strip())) cmdline_cmd = detect_utils.output_lines("cat /proc/cmdline") for line in cmdline_cmd: hw_lst.append( ('system', 'kernel', 'cmdline', line.rstrip('\n').strip())) return True
def modprobe(module): 'Load a kernel module using modprobe.' status, _ = cmd('modprobe %s' % module) if status == 0: sys.stderr.write('Info: Probing %s failed\n' % module)
def detect_system(hw_lst, output=None): "Detect system characteristics from the output of lshw." socket_count = 0 def find_element(xml, xml_spec, sys_subtype, sys_type="product", sys_cls="system", attrib=None, transform=None): "Lookup an xml element and populate hw_lst when found." elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: txt = elt[0].attrib[attrib] else: txt = elt[0].text if transform: txt = transform(txt) hw_lst.append((sys_cls, sys_type, sys_subtype, txt)) return txt return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd("lshw -xml") if status == 0: mobo_id = "" nic_id = "" xml = ET.fromstring(output) find_element(xml, "./node/serial", "serial") find_element(xml, "./node/product", "name") find_element(xml, "./node/vendor", "vendor") find_element(xml, "./node/version", "version") uuid = get_uuid() if uuid: # If we have an uuid, we shall check if it's part of a # known list of broken uuid # If so let's delete the uuid instead of reporting a stupid thing if uuid in ["Not"]: uuid = "" else: hw_lst.append(("system", "product", "uuid", uuid)) for elt in xml.findall(".//node[@id='core']"): name = elt.find("physid") if name is not None: find_element(elt, "product", "name", "motherboard", "system") find_element(elt, "vendor", "vendor", "motherboard", "system") find_element(elt, "version", "version", "motherboard", "system") find_element(elt, "serial", "serial", "motherboard", "system") mobo_id = _get_value(hw_lst, "system", "motherboard", "serial") for elt in xml.findall(".//node[@id='firmware']"): name = elt.find("physid") if name is not None: find_element(elt, "version", "version", "bios", "firmware") find_element(elt, "date", "date", "bios", "firmware") find_element(elt, "vendor", "vendor", "bios", "firmware") bank_count = 0 for elt in xml.findall(".//node[@class='memory']"): if not elt.attrib["id"].startswith("memory"): continue try: location = re.search("memory(:.*)", elt.attrib["id"]).group(1) except AttributeError: location = "" name = elt.find("physid") if name is not None: find_element(elt, "size", "size", "total", "memory") for bank_list in elt.findall(".//node[@id]"): if "bank:" in bank_list.get("id"): bank_count = bank_count + 1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get("id"))): bank_id = bank_list.get("id").replace("bank:", "bank" + location + ":") find_element(bank, "size", "size", bank_id, "memory") find_element(bank, "clock", "clock", bank_id, "memory") find_element(bank, "description", "description", bank_id, "memory") find_element(bank, "vendor", "vendor", bank_id, "memory") find_element(bank, "product", "product", bank_id, "memory") find_element(bank, "serial", "serial", bank_id, "memory") find_element(bank, "slot", "slot", bank_id, "memory") if bank_count > 0: hw_lst.append(("memory", "banks", "count", str(bank_count))) for elt in xml.findall(".//node[@class='network']"): name = elt.find("logicalname") if name is not None: find_element(elt, "businfo", "businfo", name.text, "network") find_element(elt, "vendor", "vendor", name.text, "network") find_element(elt, "product", "product", name.text, "network") find_element(elt, "configuration/setting[@id='firmware']", "firmware", name.text, "network", "value") find_element(elt, "size", "size", name.text, "network") ipv4 = find_element(elt, "configuration/setting[@id='ip']", "ipv4", name.text, "network", "value") if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl(sock, SIOCGIFNETMASK, struct.pack("256s", name.text.encode("utf-8")))[20:24] ) hw_lst.append(("network", name.text, "ipv4-netmask", netmask)) cidr = get_cidr(netmask) hw_lst.append(("network", name.text, "ipv4-cidr", cidr)) hw_lst.append( ("network", name.text, "ipv4-network", "%s" % IPNetwork("%s/%s" % (ipv4, cidr)).network) ) except Exception as excpt: sys.stderr.write("unable to get info for %s: %s\n" % (name.text, str(excpt))) find_element(elt, "configuration/setting[@id='link']", "link", name.text, "network", "value") find_element(elt, "configuration/setting[@id='driver']", "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 = 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) for elt in xml.findall(".//node[@class='processor']"): name = elt.find("physid") if name is not None: hw_lst.append(("cpu", "physical_%s" % (socket_count), "physid", name.text)) find_element(elt, "product", "product", "physical_%s" % socket_count, "cpu") find_element(elt, "vendor", "vendor", "physical_%s" % socket_count, "cpu") find_element(elt, "version", "version", "physical_%s" % socket_count, "cpu") find_element(elt, "size", "frequency", "physical_%s" % socket_count, "cpu") find_element(elt, "clock", "clock", "physical_%s" % socket_count, "cpu") find_element( elt, "configuration/setting[@id='cores']", "cores", "physical_%s" % socket_count, "cpu", "value" ) find_element( elt, "configuration/setting[@id='enabledcores']", "enabled_cores", "physical_%s" % socket_count, "cpu", "value", ) find_element( elt, "configuration/setting[@id='threads']", "threads", "physical_%s" % socket_count, "cpu", "value" ) elt_cap = elt.findall("capabilities/capability") cpu_flags = "" for cap in elt_cap: for element in cap.items(): cpu_flags = "%s %s" % (cpu_flags, element[1].strip()) hw_lst.append(("cpu", "physical_%s" % (socket_count), "flags", cpu_flags.strip())) socket_count = socket_count + 1 fix_bad_serial(hw_lst, uuid, mobo_id, nic_id) else: sys.stderr.write("Unable to run lshw: %s\n" % output) return False hw_lst.append(("cpu", "physical", "number", str(socket_count))) status, output = detect_utils.cmd("nproc") if status == 0: hw_lst.append(("cpu", "logical", "number", str(output).strip())) osvendor_cmd = detect_utils.output_lines("lsb_release -is") for line in osvendor_cmd: hw_lst.append(("system", "os", "vendor", line.rstrip("\n").strip())) osinfo_cmd = detect_utils.output_lines("lsb_release -ds | tr -d '\"'") for line in osinfo_cmd: hw_lst.append(("system", "os", "version", line.rstrip("\n").strip())) uname_cmd = detect_utils.output_lines("uname -r") for line in uname_cmd: hw_lst.append(("system", "kernel", "version", line.rstrip("\n").strip())) arch_cmd = detect_utils.output_lines("uname -i") for line in arch_cmd: hw_lst.append(("system", "kernel", "arch", line.rstrip("\n").strip())) cmdline_cmd = detect_utils.output_lines("cat /proc/cmdline") for line in cmdline_cmd: hw_lst.append(("system", "kernel", "cmdline", line.rstrip("\n").strip())) return True
def setup_network(channel, ipv4, netmask, gateway, vlan_id=-1): 'Define the network of an IPMI interface.' sys.stderr.write('Info: ipmi_setup_network: Setting network ip="%s", ' 'netmask="%s", gateway="%s", vland_id="%d" on ' 'channel %s\n' % (ipv4, netmask, gateway, vlan_id, channel)) # NOTE (leseb): assuming you're missing an argument # and this already happened # ipmitool always returns 0 and prompt the valid values... cmd('ipmitool lan set %s ipsrc static' % channel) cmd('ipmitool lan set %s ipaddr %s' % (channel, ipv4)) cmd('ipmitool lan set %s netmask %s' % (channel, netmask)) cmd('ipmitool lan set %s defgw ipaddr %s' % (channel, gateway)) cmd('ipmitool lan set %s arp respond on' % channel) if vlan_id >= 0: cmd('ipmitool lan set %s vlan id %d' % (channel, vlan_id)) else: cmd('ipmitool lan set %s vlan id off' % channel) # We need to restart the bmc to insure the setup is properly done restart_bmc()
def restart_bmc(): 'Restart a BMC card.' sys.stderr.write('Info: Restarting IPMI BMC\n') cmd('ipmitool bmc reset cold')
def detect_system(hw_lst, output=None): 'Detect system characteristics from the output of lshw.' socket_count = 0 def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None, transform=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: txt = elt[0].attrib[attrib] else: txt = elt[0].text if transform: txt = transform(txt) hw_lst.append((sys_cls, sys_type, sys_subtype, txt)) return txt return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd('lshw -xml') if status == 0: xml = ET.fromstring(output) find_element(xml, "./node/serial", 'serial') find_element(xml, "./node/product", 'name') find_element(xml, "./node/vendor", 'vendor') find_element(xml, "./node/version", 'version') uuid = get_uuid() if uuid: # If we have an uuid, let's manage a quirk list of stupid # serial numbers TYAN or Supermicro are known to provide # dirty serial numbers In that case, let's use the uuid # instead for i in hw_lst: if 'system' in i[0] and 'product' in i[1] and 'serial' in i[2]: # Does the current serial number is part of the quirk list if i[3] in ['0123456789']: # Let's delete the stupid SN and use the UUID instead hw_lst.remove(i) hw_lst.append(('system', 'product', 'serial', uuid)) break hw_lst.append(('system', 'product', 'uuid', uuid)) for elt in xml.findall(".//node[@id='core']"): name = elt.find('physid') if name is not None: find_element(elt, 'product', 'name', 'motherboard', 'system') find_element(elt, 'vendor', 'vendor', 'motherboard', 'system') find_element(elt, 'version', 'version', 'motherboard', 'system') find_element(elt, 'serial', 'serial', 'motherboard', 'system') for elt in xml.findall(".//node[@id='firmware']"): name = elt.find('physid') if name is not None: find_element(elt, 'version', 'version', 'bios', 'firmware') find_element(elt, 'date', 'date', 'bios', 'firmware') find_element(elt, 'vendor', 'vendor', 'bios', 'firmware') bank_count = 0 for elt in xml.findall(".//node[@class='memory']"): if not elt.attrib['id'].startswith('memory'): continue try: location = re.search('memory(:.*)', elt.attrib['id']).group(1) except AttributeError: location = '' name = elt.find('physid') if name is not None: find_element(elt, 'size', 'size', 'total', 'memory') for bank_list in elt.findall(".//node[@id]"): if 'bank:' in bank_list.get('id'): bank_count = bank_count + 1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get('id'))): bank_id = bank_list.get('id').replace( "bank:", "bank" + location + ":") find_element(bank, 'size', 'size', bank_id, 'memory') find_element(bank, 'clock', 'clock', bank_id, 'memory') find_element(bank, 'description', 'description', bank_id, 'memory') find_element(bank, 'vendor', 'vendor', bank_id, 'memory') find_element(bank, 'product', 'product', bank_id, 'memory') find_element(bank, 'serial', 'serial', bank_id, 'memory') find_element(bank, 'slot', 'slot', bank_id, 'memory') if bank_count > 0: hw_lst.append(('memory', 'banks', 'count', str(bank_count))) for elt in xml.findall(".//node[@class='network']"): name = elt.find('logicalname') if name is not None: find_element(elt, 'businfo', 'businfo', name.text, 'network') find_element(elt, 'vendor', 'vendor', name.text, 'network') find_element(elt, 'product', 'product', name.text, 'network') find_element(elt, "configuration/setting[@id='firmware']", 'firmware', name.text, 'network', 'value') find_element(elt, 'size', 'size', name.text, 'network') ipv4 = find_element(elt, "configuration/setting[@id='ip']", 'ipv4', name.text, 'network', 'value') if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl( sock, SIOCGIFNETMASK, struct.pack('256s', name.text.encode('utf-8')))[20:24]) hw_lst.append( ('network', name.text, 'ipv4-netmask', netmask)) cidr = get_cidr(netmask) hw_lst.append( ('network', name.text, 'ipv4-cidr', cidr)) hw_lst.append( ('network', name.text, 'ipv4-network', "%s" % IPNetwork('%s/%s' % (ipv4, cidr)).network)) except Exception as excpt: sys.stderr.write('unable to get info for %s: %s\n' % (name.text, str(excpt))) find_element(elt, "configuration/setting[@id='link']", 'link', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='driver']", '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 = 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()) detect_utils.get_ethtool_status(hw_lst, name.text) detect_utils.get_lld_status(hw_lst, name.text) for elt in xml.findall(".//node[@class='processor']"): name = elt.find('physid') if name is not None: hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'physid', name.text)) find_element(elt, 'product', 'product', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'vendor', 'vendor', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'version', 'version', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'size', 'frequency', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'clock', 'clock', 'physical_%s' % socket_count, 'cpu') find_element(elt, "configuration/setting[@id='cores']", 'cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='enabledcores']", 'enabled_cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='threads']", 'threads', 'physical_%s' % socket_count, 'cpu', 'value') elt_cap = elt.findall("capabilities/capability") cpu_flags = "" for cap in elt_cap: for element in cap.items(): cpu_flags = "%s %s" % (cpu_flags, element[1].strip()) hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'flags', cpu_flags.strip())) socket_count = socket_count + 1 else: sys.stderr.write("Unable to run lshw: %s\n" % output) hw_lst.append(('cpu', 'physical', 'number', str(socket_count))) status, output = detect_utils.cmd('nproc') if status == 0: hw_lst.append(('cpu', 'logical', 'number', str(output).strip())) osvendor_cmd = detect_utils.output_lines("lsb_release -is") for line in osvendor_cmd: hw_lst.append(('system', 'os', 'vendor', line.rstrip('\n').strip())) osinfo_cmd = detect_utils.output_lines("lsb_release -ds | tr -d '\"'") for line in osinfo_cmd: hw_lst.append(('system', 'os', 'version', line.rstrip('\n').strip())) uname_cmd = detect_utils.output_lines("uname -r") for line in uname_cmd: hw_lst.append( ('system', 'kernel', 'version', line.rstrip('\n').strip())) arch_cmd = detect_utils.output_lines("uname -i") for line in arch_cmd: hw_lst.append(('system', 'kernel', 'arch', line.rstrip('\n').strip())) cmdline_cmd = detect_utils.output_lines("cat /proc/cmdline") for line in cmdline_cmd: hw_lst.append( ('system', 'kernel', 'cmdline', line.rstrip('\n').strip()))
def detect_system(hw_lst, output=None): 'Detect system characteristics from the output of lshw.' socket_count = 0 def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None, transform=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: txt = elt[0].attrib[attrib] else: txt = elt[0].text if transform: txt = transform(txt) hw_lst.append((sys_cls, sys_type, sys_subtype, txt)) return txt return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd('lshw -xml') if status == 0: mobo_id = '' nic_id = '' xml = ET.fromstring(output) find_element(xml, "./node/serial", 'serial') find_element(xml, "./node/product", 'name') find_element(xml, "./node/vendor", 'vendor') find_element(xml, "./node/version", 'version') uuid = get_uuid() if uuid: # If we have an uuid, we shall check if it's part of a # known list of broken uuid # If so let's delete the uuid instead of reporting a stupid thing if uuid in ['Not']: uuid = '' else: hw_lst.append(('system', 'product', 'uuid', uuid)) for elt in xml.findall(".//node[@id='core']"): name = elt.find('physid') if name is not None: find_element(elt, 'product', 'name', 'motherboard', 'system') find_element(elt, 'vendor', 'vendor', 'motherboard', 'system') find_element(elt, 'version', 'version', 'motherboard', 'system') find_element(elt, 'serial', 'serial', 'motherboard', 'system') mobo_id = _get_value(hw_lst, 'system', 'motherboard', 'serial') for elt in xml.findall(".//node[@id='firmware']"): name = elt.find('physid') if name is not None: find_element(elt, 'version', 'version', 'bios', 'firmware') find_element(elt, 'date', 'date', 'bios', 'firmware') find_element(elt, 'vendor', 'vendor', 'bios', 'firmware') bank_count = 0 for elt in xml.findall(".//node[@class='memory']"): if not elt.attrib['id'].startswith('memory'): continue try: location = re.search('memory(:.*)', elt.attrib['id']).group(1) except AttributeError: location = '' name = elt.find('physid') if name is not None: find_element(elt, 'size', 'size', 'total', 'memory') for bank_list in elt.findall(".//node[@id]"): if 'bank:' in bank_list.get('id'): bank_count = bank_count + 1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get('id'))): bank_id = bank_list.get('id').replace("bank:", "bank" + location + ":") find_element(bank, 'size', 'size', bank_id, 'memory') find_element(bank, 'clock', 'clock', bank_id, 'memory') find_element(bank, 'description', 'description', bank_id, 'memory') find_element(bank, 'vendor', 'vendor', bank_id, 'memory') find_element(bank, 'product', 'product', bank_id, 'memory') find_element(bank, 'serial', 'serial', bank_id, 'memory') find_element(bank, 'slot', 'slot', bank_id, 'memory') if bank_count > 0: hw_lst.append(('memory', 'banks', 'count', str(bank_count))) for elt in xml.findall(".//node[@class='network']"): name = elt.find('logicalname') if name is not None: find_element(elt, 'businfo', 'businfo', name.text, 'network') find_element(elt, 'vendor', 'vendor', name.text, 'network') find_element(elt, 'product', 'product', name.text, 'network') find_element(elt, "configuration/setting[@id='firmware']", 'firmware', name.text, 'network', 'value') find_element(elt, 'size', 'size', name.text, 'network') ipv4 = find_element(elt, "configuration/setting[@id='ip']", 'ipv4', name.text, 'network', 'value') if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl( sock, SIOCGIFNETMASK, struct.pack('256s', name.text.encode('utf-8')))[20:24]) hw_lst.append( ('network', name.text, 'ipv4-netmask', netmask)) cidr = get_cidr(netmask) hw_lst.append( ('network', name.text, 'ipv4-cidr', cidr)) hw_lst.append( ('network', name.text, 'ipv4-network', "%s" % IPNetwork('%s/%s' % (ipv4, cidr)).network)) except Exception as excpt: sys.stderr.write('unable to get info for %s: %s\n' % (name.text, str(excpt))) find_element(elt, "configuration/setting[@id='link']", 'link', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='driver']", '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 = 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) for elt in xml.findall(".//node[@class='processor']"): name = elt.find('physid') if name is not None: hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'physid', name.text)) find_element(elt, 'product', 'product', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'vendor', 'vendor', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'version', 'version', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'size', 'frequency', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'clock', 'clock', 'physical_%s' % socket_count, 'cpu') find_element(elt, "configuration/setting[@id='cores']", 'cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='enabledcores']", 'enabled_cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='threads']", 'threads', 'physical_%s' % socket_count, 'cpu', 'value') elt_cap = elt.findall("capabilities/capability") cpu_flags = "" for cap in elt_cap: for element in cap.items(): cpu_flags = "%s %s" % (cpu_flags, element[1].strip()) hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'flags', cpu_flags.strip())) socket_count = socket_count + 1 fix_bad_serial(hw_lst, uuid, mobo_id, nic_id) else: sys.stderr.write("Unable to run lshw: %s\n" % output) return False hw_lst.append(('cpu', 'physical', 'number', str(socket_count))) status, output = detect_utils.cmd('nproc') if status == 0: hw_lst.append(('cpu', 'logical', 'number', str(output).strip())) osvendor_cmd = detect_utils.output_lines("lsb_release -is") for line in osvendor_cmd: hw_lst.append(('system', 'os', 'vendor', line.rstrip('\n').strip())) osinfo_cmd = detect_utils.output_lines("lsb_release -ds | tr -d '\"'") for line in osinfo_cmd: hw_lst.append(('system', 'os', 'version', line.rstrip('\n').strip())) uname_cmd = detect_utils.output_lines("uname -r") for line in uname_cmd: hw_lst.append(('system', 'kernel', 'version', line.rstrip('\n').strip())) arch_cmd = detect_utils.output_lines("uname -i") for line in arch_cmd: hw_lst.append(('system', 'kernel', 'arch', line.rstrip('\n').strip())) cmdline_cmd = detect_utils.output_lines("cat /proc/cmdline") for line in cmdline_cmd: hw_lst.append(('system', 'kernel', 'cmdline', line.rstrip('\n').strip())) return True
def ib_card_drv(): '''Return an array of IB device (ex: ['mlx4_0']).''' return [cmd('ibstat -l')]
def restart_bmc(): """Restart a BMC card.""" sys.stderr.write('Info: Restarting IPMI BMC\n') detect_utils.cmd('ipmitool bmc reset cold')
def modprobe(module): "Load a kernel module using modprobe." status, _ = cmd("modprobe %s" % module) if status == 0: sys.stderr.write("Info: Probing %s failed\n" % module)