def get_pci_info(ns): """ Prints tabular data of PCI devices info. """ result = [('PCI Devices:', '')] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: pci_dev = get_all_instances(ns, 'LMI_PCIDevice') pci_br = get_all_instances(ns, 'LMI_PCIBridge') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing PCI related classes. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] pci = pci_dev + pci_br pci.sort(key=lambda x: x.DeviceID) if not pci: result += [(' N/A', 'No PCI Device was detected on the system.')] tf.produce_output(result) return [] result += get_pci_list(ns, pci) if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_motherboard_info(ns): """ Prints tabular data of motherboard info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Baseboard') if i: model = '' if i.Manufacturer: model += i.Manufacturer if i.Model: if model: model += ' ' model += i.Model result += [('Motherboard:', model)] else: if STANDALONE: result += [(get_colored_string( 'warning:', YELLOW_COLOR ), 'LMI_Baseboard instance is missing. This usually means that the server is virtual machine.' )] except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_Baseboard. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) result = [] try: i = get_single_instance(ns, 'LMI_BIOSElement') if i and i.Name: result += [('BIOS:', i.Name)] else: result += [('BIOS:', 'N/A')] except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing LMI_BIOSElement class. Openlmi-hardware package is probably out-dated.' )] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_system_info(ns): """ Prints tabular data of system info, from the ``LMI_Chassis`` instance. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Chassis') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_Chassis. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] if i.Model and i.ProductName: model = '%s (%s)' % (i.Model, i.ProductName) elif i.Model: model = i.Model elif i.ProductName: model = i.ProductName else: model = 'N/A' if i.Manufacturer: model = '%s %s' % (i.Manufacturer, model) virt = getattr(i, 'VirtualMachine', None) if virt is None: virt = 'N/A. You are probably using old openlmi-hardware package on the server.' elif not virt: virt = 'N/A' result += [('Chassis Type:', ns.LMI_Chassis.ChassisPackageTypeValues.value_name( i.ChassisPackageType)), ('Model:', model), ('Serial Number:', i.SerialNumber), ('Asset Tag:', i.Tag), ('Virtual Machine:', virt)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_motherboard_info(ns): """ Prints tabular data of motherboard info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Baseboard') if i: model = '' if i.Manufacturer: model += i.Manufacturer if i.Model: if model: model += ' ' model += i.Model result += [('Motherboard:', model)] else: if STANDALONE: result += [(get_colored_string('warning:', YELLOW_COLOR), 'LMI_Baseboard instance is missing. This usually means that the server is virtual machine.')] except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_Baseboard. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) result = [] try: i = get_single_instance(ns, 'LMI_BIOSElement') if i and i.Name: result += [('BIOS:', i.Name)] else: result += [('BIOS:', 'N/A')] except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing LMI_BIOSElement class. Openlmi-hardware package is probably out-dated.')] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_system_info(ns): """ Prints tabular data of system info, from the ``LMI_Chassis`` instance. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Chassis') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_Chassis. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] if i.Model and i.ProductName: model = '%s (%s)' % (i.Model, i.ProductName) elif i.Model: model = i.Model elif i.ProductName: model = i.ProductName else: model = 'N/A' if i.Manufacturer: model = '%s %s' % (i.Manufacturer, model) virt = getattr(i, 'VirtualMachine', None) if virt is None: virt = 'N/A. You are probably using old openlmi-hardware package on the server.' elif not virt: virt = 'N/A' result += [ ('Chassis Type:', ns.LMI_Chassis.ChassisPackageTypeValues.value_name( i.ChassisPackageType)), ('Model:', model), ('Serial Number:', i.SerialNumber), ('Asset Tag:', i.Tag), ('Virtual Machine:', virt)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_system_info(ns): """ Prints tabular data of all general system information. """ tf = TableFormatter(stdout, 0, True) tf.print_host(get_hostname(ns)) try: get_hwinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_storageinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_osinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_langinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_selinuxinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_servicesinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_networkinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) return []
def get_system_info(ns): """ Prints tabular data of all general system information. """ tf = TableFormatter(stdout, 0, True) tf.print_host(get_hostname(ns)) try: get_hwinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_storageinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_osinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_langinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_selinuxinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_servicesinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_networkinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) return []
def get_all_info(ns): """ Prints tabular data of all available info. """ global STANDALONE STANDALONE = False tf = TableFormatter(stdout, 0, True) tf.print_host(get_hostname(ns)) try: get_system_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_motherboard_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_cpu_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_memory_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_pci_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_disks_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) STANDALONE = True return []
def get_all_info(ns): """ Prints tabular data of all available info. """ global STANDALONE STANDALONE = False tf = TableFormatter(stdout, 0, True) tf.print_host(get_hostname(ns)) try: get_system_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_motherboard_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_cpu_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_memory_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_pci_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_disks_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) STANDALONE = True return []
def get_cpu_info(ns): """ Prints tabular data of processor info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: cpus = get_all_instances(ns, 'LMI_Processor') cpu_caps = get_all_instances(ns, 'LMI_ProcessorCapabilities') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing CPU related classes. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] cores = 0 threads = 0 for i in cpu_caps: cores += i.NumberOfProcessorCores threads += i.NumberOfHardwareThreads result += [ ('CPU:', cpus[0].Name), ('Topology:', '%d cpu(s), %d core(s), %d thread(s)' % \ (len(cpus), cores, threads)), ('Max Freq:', '%d MHz' % cpus[0].MaxClockSpeed), ('Arch:', cpus[0].Architecture)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_cpu_info(ns): """ Prints tabular data of processor info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: cpus = get_all_instances(ns, 'LMI_Processor') cpu_caps = get_all_instances(ns, 'LMI_ProcessorCapabilities') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing CPU related classes. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] cores = 0 threads = 0 for i in cpu_caps: cores += i.NumberOfProcessorCores threads += i.NumberOfHardwareThreads result += [ ('CPU:', cpus[0].Name), ('Topology:', '%d cpu(s), %d core(s), %d thread(s)' % \ (len(cpus), cores, threads)), ('Max Freq:', '%d MHz' % cpus[0].MaxClockSpeed), ('Arch:', cpus[0].Architecture)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_disks_info(ns): """ Prints tabular data of disk info. """ result = [('Disks:', '')] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: hdds = get_all_instances(ns, 'LMI_DiskDrive') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing LMI_DiskDrive class. Openlmi-hardware package is probably out-dated.' )] tf.produce_output(result) return [] if not hdds: result += [(' N/A', 'No disk was detected on the system.')] tf.produce_output(result) return [] for hdd in hdds: phys_hdds = hdd.associators(ResultClass='LMI_DiskPhysicalPackage') fws = hdd.associators(ResultClass='LMI_DiskDriveSoftwareIdentity') if phys_hdds and phys_hdds[0].Model: model = phys_hdds[0].Model else: model = 'N/A' if phys_hdds[0].Manufacturer \ and not model.startswith(phys_hdds[0].Manufacturer): man_model = '%s %s' % (phys_hdds[0].Manufacturer, model) else: man_model = model if fws[0].VersionString: fw = fws[0].VersionString else: fw = 'N/A' form_factor_dict = { 3: '5.25"', 4: '3.5"', 5: '2.5"', 6: '1.8"', } if hdd.FormFactor in form_factor_dict: form_factor = form_factor_dict[hdd.FormFactor] else: form_factor = 'N/A' if hdd.RPM != 0xffffffff: rpm = hdd.RPM else: rpm = 'N/A' if hdd.DiskType == 2: disk_type = 'HDD' elif hdd.DiskType == 3: disk_type = 'SSD' else: disk_type = 'N/A' status_to_color = { 'OK': GREEN_COLOR, 'Unknown': YELLOW_COLOR, 'Predictive Failure': RED_COLOR, } if hdd.OperationalStatus: smart = ns.LMI_DiskDrive.OperationalStatusValues.value_name( hdd.OperationalStatus[0]) smart = get_colored_string(smart, status_to_color[smart]) else: smart = get_colored_string('Unknown', YELLOW_COLOR) temp = getattr(hdd, 'Temperature', None) if temp: temp_str = '%d' % temp else: temp_str = 'N/A' temp_str += u' °C' if hdd.Name != hdd.DeviceID and hdd.Name != model: result += [(' %s' % hdd.DeviceID, hdd.Name)] else: result += [(' %s' % hdd.DeviceID, '')] result += [(' Model:', man_model), (' Firmware:', fw), (' Capacity:', format_memory_size(hdd.Capacity)), (' Form Factor:', form_factor), (' HDD/SSD:', disk_type), (' RPM:', rpm), (' SMART Status:', smart), (' Temperature:', temp_str)] tf.produce_output(result) result = [EMPTY_LINE] tf.produce_output(result) return []
def get_memory_info(ns): """ Prints tabular data of memory info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: memory = get_single_instance(ns, 'LMI_Memory') phys_memory = get_all_instances(ns, 'LMI_PhysicalMemory') memory_slots = get_all_instances(ns, 'LMI_MemorySlot') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing memory related classes. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] size = format_memory_size(memory.NumberOfBlocks) slots = '' if phys_memory: slots += '%d' % len(phys_memory) else: slots += 'N/A' slots += ' used, ' if memory_slots: slots += '%d' % len(memory_slots) else: slots += 'N/A' slots += ' total' modules = [] if phys_memory: for m in phys_memory: module = format_memory_size(m.Capacity) if m.MemoryType: module += ', %s' % \ ns.LMI_PhysicalMemory.MemoryTypeValues.value_name(m.MemoryType) if m.FormFactor: module += ' (%s)' % \ ns.LMI_PhysicalMemory.FormFactorValues.value_name( m.FormFactor) if m.ConfiguredMemoryClockSpeed: module += ', %d MHz' % m.ConfiguredMemoryClockSpeed if m.Manufacturer: module += ', %s' % m.Manufacturer if m.BankLabel: module += ', %s' % m.BankLabel if not modules: modules.append(('Modules:', module)) else: modules.append(('', module)) if not modules: modules.append(('Modules:', 'N/A')) result += [('Memory:', size)] result += modules result += [('Slots:', slots)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_disks_info(ns): """ Prints tabular data of disk info. """ result = [('Disks:', '')] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: hdds = get_all_instances(ns, 'LMI_DiskDrive') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing LMI_DiskDrive class. Openlmi-hardware package is probably out-dated.')] tf.produce_output(result) return [] if not hdds: result += [(' N/A', 'No disk was detected on the system.')] tf.produce_output(result) return [] for hdd in hdds: phys_hdds = hdd.associators( AssocClass='LMI_DiskDriveRealizes', ResultClass='LMI_DiskPhysicalPackage') fws = hdd.associators( AssocClass='LMI_DiskDriveElementSoftwareIdentity', ResultClass='LMI_DiskDriveSoftwareIdentity') if phys_hdds and phys_hdds[0].Model: model = phys_hdds[0].Model else: model = 'N/A' if phys_hdds[0].Manufacturer \ and not model.startswith(phys_hdds[0].Manufacturer): man_model = '%s %s' % (phys_hdds[0].Manufacturer, model) else: man_model = model if fws[0].VersionString: fw = fws[0].VersionString else: fw = 'N/A' form_factor_dict = { 3: '5.25"', 4: '3.5"', 5: '2.5"', 6: '1.8"',} if hdd.FormFactor in form_factor_dict: form_factor = form_factor_dict[hdd.FormFactor] else: form_factor = 'N/A' if hdd.RPM != 0xffffffff: rpm = hdd.RPM else: rpm = 'N/A' if hdd.DiskType == 2: disk_type = 'HDD' elif hdd.DiskType == 3: disk_type = 'SSD' else: disk_type = 'N/A' status_to_color = { 'OK': GREEN_COLOR, 'Unknown': YELLOW_COLOR, 'Predictive Failure': RED_COLOR,} if hdd.OperationalStatus: smart = ns.LMI_DiskDrive.OperationalStatusValues.value_name( hdd.OperationalStatus[0]) smart = get_colored_string(smart, status_to_color[smart]) else: smart = get_colored_string('Unknown', YELLOW_COLOR) temp = getattr(hdd, 'Temperature', None) if temp: temp_str = '%d' % temp else: temp_str = 'N/A' temp_str += u' °C' if hdd.Name != hdd.DeviceID and hdd.Name != model: result += [(' %s' % hdd.DeviceID, hdd.Name)] else: result += [(' %s' % hdd.DeviceID, '')] result += [(' Model:', man_model), (' Firmware:', fw), (' Capacity:', format_memory_size(hdd.Capacity)), (' Form Factor:', form_factor), (' HDD/SSD:', disk_type), (' RPM:', rpm), (' SMART Status:', smart), (' Temperature:', temp_str)] tf.produce_output(result) result = [EMPTY_LINE] tf.produce_output(result) return []
def get_memory_info(ns): """ Prints tabular data of memory info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: memory = get_single_instance(ns, 'LMI_Memory') phys_memory = get_all_instances(ns, 'LMI_PhysicalMemory') memory_slots = get_all_instances(ns, 'LMI_MemorySlot') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing memory related classes. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] size = format_memory_size(memory.NumberOfBlocks) slots = '' if phys_memory: slots += '%d' % len(phys_memory) else: slots += 'N/A' slots += ' used, ' if memory_slots: slots += '%d' % len(memory_slots) else: slots += 'N/A' slots += ' total' modules = [] if phys_memory: for m in phys_memory: module = format_memory_size(m.Capacity) if m.MemoryType: module += ', %s' % \ ns.LMI_PhysicalMemory.MemoryTypeValues.value_name(m.MemoryType) if m.FormFactor: module += ' (%s)' % \ ns.LMI_PhysicalMemory.FormFactorValues.value_name( m.FormFactor) if m.ConfiguredMemoryClockSpeed: module += ', %d MHz' % m.ConfiguredMemoryClockSpeed if m.Manufacturer: module += ', %s' % m.Manufacturer if m.BankLabel: module += ', %s' % m.BankLabel if not modules: modules.append(('Modules:', module)) else: modules.append(('', module)) if not modules: modules.append(('Modules:', 'N/A')) result += [('Memory:', size)] result += modules result += [('Slots:', slots)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []