def set_fields(cls, drive, data, context=None): try: if XML_NODE in data.keys(): if isinstance(data[XML_NODE], dict): if data[XML_NODE][XML_AT_ID].startswith(LSHW_DISK): data = data[XML_NODE] capabilities = data[LSHW_CAPABILITIES][LSHW_CAPABILITY] if not isinstance(capabilities, list): capabilities = [capabilities] for cap in capabilities: rpm_info = cap[XML_AT_ID].split(LSHW_RPM) if len(rpm_info) == DRIVE_RPM_DATA_SIZE: try: drive_hdparm = ShellCommand( "hdparm -I " + str(data[LSHW_LOGICALNAME]) + " | grep Rotation | cut -d':' -f2") drive_hdparm.execute() drive.rpm = int(drive_hdparm.get_stdout()) except ValueError: # unable to parse hdparm output - it returned "solid state drive" in "rotation" section drive.rpm = 0 if DISK_SSD_TYPE in data[XML_PRODUCT]: drive.type = DISK_SSD_TYPE del drive.rpm else: drive.type = DISK_HDD_TYPE drive.capacityGB = int( int(data[LSHW_SIZE][XML_HASH_TEXT]) / 1000**3) drive.physicalId = data[LSHW_PHYSID] drive.firmwareVersion = data[XML_VERSION] except (KeyError, TypeError): return None return drive
def set_fields(cls, drive, data, context=None): try: if XML_NODE in data.keys(): if isinstance(data[XML_NODE], dict): if data[XML_NODE][XML_AT_ID].startswith(LSHW_DISK): data = data[XML_NODE] capabilities = data[LSHW_CAPABILITIES][LSHW_CAPABILITY] if not isinstance(capabilities, list): capabilities = [capabilities] for cap in capabilities: rpm_info = cap[XML_AT_ID].split(LSHW_RPM) if len(rpm_info) == DRIVE_RPM_DATA_SIZE: try: drive_hdparm = ShellCommand("hdparm -I " + str(data[LSHW_LOGICALNAME]) + " | grep Rotation | cut -d':' -f2") drive_hdparm.execute() drive.rpm = int(drive_hdparm.get_stdout()) except ValueError: # unable to parse hdparm output - it returned "solid state drive" in "rotation" section drive.rpm = 0 if DISK_SSD_TYPE in data[XML_PRODUCT]: drive.type = DISK_SSD_TYPE del drive.rpm else: drive.type = DISK_HDD_TYPE drive.capacityGB = int(int(data[LSHW_SIZE][XML_HASH_TEXT]) / 1000 ** 3) drive.physicalId = data[LSHW_PHYSID] drive.firmwareVersion = data[XML_VERSION] except (KeyError, TypeError): return None return drive
def get_nic_mtu(nic): iplink = ShellCommand("ip link show " + nic) iplink.execute() try: mtu = iplink.get_stdout().split("mtu")[1] mtu = mtu.split(" ")[1] mtu = int(mtu) except IndexError, ValueError: return ""
def get_nic_mtu(nic): iplink = ShellCommand("ip link show " + nic) iplink.execute() try: mtu = iplink.get_stdout().split("mtu")[1] mtu = mtu.split(" ")[1] mtu = int(mtu) except IndexError, ValueError: return ""
def get_drives(cls, data): drives = [] for node in data: try: if node[XML_AT_ID].startswith(LSHW_SCSI): # find pci bus where disk is connected cmd = "udevadm info -q all -n " +\ str(node[XML_NODE][LSHW_LOGICALNAME]) +\ " | grep 'DEVPATH' | cut -d/ -f 4 " pci_bus_command = ShellCommand(cmd, []) pci_bus_command.execute() if pci_bus_command.get_exitcode() == EXIT_CODE_SUCCESS: node[ LSHW_PCI_STORAGE_CNTRL] = pci_bus_command.get_stdout( )[:-1] else: node[LSHW_PCI_STORAGE_CNTRL] = None drives.append(node) elif node[XML_AT_ID].startswith(LSHW_PCI): pci_list = node[XML_NODE] if not isinstance(pci_list, list): pci_list = [pci_list] for pci in pci_list: if pci[XML_AT_ID].startswith(LSHW_PCI): if isinstance(pci[XML_NODE], dict): if pci[XML_NODE][XML_AT_ID] == LSHW_STORAGE: resources = pci[XML_NODE][XML_NODE] if not isinstance(resources, list): resources = [resources] for disk in resources: if disk[XML_AT_ID].startswith( LSHW_DISK): disk[LSHW_PCI_STORAGE_CNTRL] = pci[ XML_NODE][LSHW_BUSINFO] drives.append(disk) elif isinstance(pci[XML_NODE], dict): for dev in pci[XML_NODE]: if isinstance(dev[XML_NODE], dict): if dev[XML_NODE][ XML_AT_ID] == LSHW_STORAGE: resources = dev[XML_NODE][XML_NODE] if not isinstance(resources, list): resources = [resources] for disk in resources: if disk[XML_AT_ID].startswith( LSHW_DISK): disk[ LSHW_PCI_STORAGE_CNTRL] = dev[ XML_NODE][ LSHW_BUSINFO] drives.append(disk) except KeyError: pass return drives
def read_location(): kernel_params = ShellCommand("cat /proc/cmdline") kernel_params.execute() location = Location() try: location_param = kernel_params.get_stdout().split("location=")[1] parsed_params = location_param.split(",") try: pod, rack, drawer, module, blade = parsed_params except ValueError: pod = "pod=0" rack, drawer, module, blade = parsed_params location = Location(pod.split("=")[1], rack.split("=")[1], drawer.split("=")[1], module.split("=")[1], blade.split("=")[1]) except IndexError, ValueError: pass
def get_drives(cls, data): drives = [] for node in data: try: if node[XML_AT_ID].startswith(LSHW_SCSI): # find pci bus where disk is connected cmd = "udevadm info -q all -n " +\ str(node[XML_NODE][LSHW_LOGICALNAME]) +\ " | grep 'DEVPATH' | cut -d/ -f 4 " pci_bus_command = ShellCommand(cmd, []) pci_bus_command.execute() if pci_bus_command.get_exitcode() == EXIT_CODE_SUCCESS: node[LSHW_PCI_STORAGE_CNTRL] = pci_bus_command.get_stdout()[:-1] else: node[LSHW_PCI_STORAGE_CNTRL] = None drives.append(node) elif node[XML_AT_ID].startswith(LSHW_PCI): pci_list = node[XML_NODE] if not isinstance(pci_list , list): pci_list = [pci_list] for pci in pci_list: if pci[XML_AT_ID].startswith(LSHW_PCI): if isinstance(pci[XML_NODE], dict): if pci[XML_NODE][XML_AT_ID] == LSHW_STORAGE: resources = pci[XML_NODE][XML_NODE] if not isinstance(resources , list): resources = [resources] for disk in resources: if disk[XML_AT_ID].startswith(LSHW_DISK): disk[LSHW_PCI_STORAGE_CNTRL] = pci[XML_NODE][LSHW_BUSINFO] drives.append(disk) elif isinstance(pci[XML_NODE], dict): for dev in pci[XML_NODE]: if isinstance(dev[XML_NODE], dict): if dev[XML_NODE][XML_AT_ID] == LSHW_STORAGE: resources = dev[XML_NODE][XML_NODE] if not isinstance(resources , list): resources = [resources] for disk in resources: if disk[XML_AT_ID].startswith(LSHW_DISK): disk[LSHW_PCI_STORAGE_CNTRL] = dev[XML_NODE][LSHW_BUSINFO] drives.append(disk) except KeyError: pass return drives
def get_lsusb_info(): lsusb = ShellCommand("lsusb") lsusb.execute() info = _parse_lsusb(lsusb.get_stdout()) return info
def get_udevadm_info(device): udevadm = ShellCommand("/sbin/udevadm info --query=property --name=" + device) udevadm.execute() info = Udevadm.parse_udevadm(udevadm.get_stdout()) return info
def get_ethtool_info(interface): ethtool = ShellCommand("ethtool " + interface) ethtool.execute() info = _parse_ehtool(ethtool.get_stdout()) return info
def prepare_data(cls, data): if data is None: lshw = ShellCommand("lshw -xml") lshw.execute() data = lshw.parse_output_xml_to_dict() return data
def get_ethtool_info(interface): ethtool = ShellCommand("ethtool " + interface) ethtool.execute() info = _parse_ehtool(ethtool.get_stdout()) return info
def prepare_data(cls, data): if data is None: lshw = ShellCommand("lshw -xml") lshw.execute() data = lshw.parse_output_xml_to_dict() return data
def get_lspci_info(): lspci = ShellCommand("lspci -n") lspci.execute() info = _parse_lspci(lspci.get_stdout()) return info
def get_lspci_info(): lspci = ShellCommand("lspci -n") lspci.execute() info = _parse_lspci(lspci.get_stdout()) return info
def _profile(type): dmi = ShellCommand("dmidecode") dmi.execute() info = _parse_dmi(dmi.get_stdout(), type) return info
def get_udevadm_info(device): udevadm = ShellCommand("/sbin/udevadm info --query=property --name=" + device) udevadm.execute() info = Udevadm.parse_udevadm(udevadm.get_stdout()) return info