Last active
December 11, 2016 07:52
-
-
Save evanfoster/58fab001b66b59fad83f8d5683abc852 to your computer and use it in GitHub Desktop.
Quick script to show which slots have modules installed and give some info about each module. Requires root, Python >= 2.6 (works with 3), and dmidecode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import subprocess | |
class MemoryBank(object): | |
def __repr__(self): | |
if self.is_populated: | |
return_string = """Bank Location: {0} | |
Location: {8} | |
Populated: {1} | |
Size: {2} | |
Manufacturer: {3} | |
Type: {4} | |
Speed: {5} | |
Serial Number: {6} | |
Part Number: {7} | |
""".format(self.bank_location, self.is_populated, self.size, self.manufacturer, self.type, self.speed, | |
self.serial_number, self.part_number, self.location) | |
else: | |
return_string = """Bank Location: {0} | |
Location: {2} | |
Populated: {1} | |
""".format(self.bank_location, self.is_populated, self.location) | |
return return_string | |
def __init__(self, bank_list): | |
self.bank_list = bank_list | |
self.bank_location = self.search_filter_list(r'\tBank Locator: ', bank_list)[0].string.split(' ')[-1] | |
self.location = self.search_filter_list(r'\tLocator: ', bank_list)[0].string.split(' ')[-1] | |
self.is_populated = self.is_module_installed() | |
if self.is_populated: | |
self.size = self.search_filter_list(r'\tSize: ', bank_list)[0].string.split(':')[-1].strip() | |
self.manufacturer = self.search_filter_list(r'\tManufacturer: ', bank_list)[0].string.split(':')[-1].strip() | |
self.type = self.search_filter_list(r'\tType: ', bank_list)[0].string.split(':')[-1].strip() | |
self.speed = self.search_filter_list(r'\tSpeed: ', bank_list)[0].string.split(':')[-1].strip() | |
self.serial_number = self.search_filter_list(r'\tSerial Number: ', bank_list)[0].string.split(':')[ | |
-1].strip() | |
self.part_number = self.search_filter_list(r'\tPart Number: ', bank_list)[0].string.split(':')[-1].strip() | |
def is_module_installed(self): | |
form_factor_search = self.search_filter_list(r'\tForm Factor: .*DIMM.*', self.bank_list) | |
size_search = self.search_filter_list(r'\tSize: [0-9]+', self.bank_list) | |
if len(form_factor_search) > 0 and len(size_search) > 0: | |
return True | |
else: | |
return False | |
def search_filter_list(self, pattern, list_to_search): | |
return list(filter(None, [re.search(pattern, item) for item in list_to_search])) | |
dmidecode_output = subprocess.Popen(['dmidecode', '-t', '17'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8') | |
dmidecode_output = re.split('Handle 0x', dmidecode_output) | |
dmidecode_output.pop(0) | |
linified = [line.splitlines() for line in dmidecode_output] | |
memory_objects = [MemoryBank(line) for line in linified] | |
for memory_object in memory_objects: | |
print(memory_object) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment