Compare commits

...

2 Commits

Author SHA1 Message Date
75744e0010
Get nvme devices inside /sys/block/ instead of /dev
All checks were successful
buildbot/multibuild_parent Build done.
buildbot/travis_bionic Build done.
2024-07-01 18:15:53 +05:30
2c19f2eefc
Added nvme details 2024-07-01 18:15:52 +05:30

View File

@ -30,6 +30,7 @@ class ServerData:
self.public_ip = self.get_public_ip()
self.dmidecode_data = self.parse_dmidecode_output()
self.hdparm_data = self.parse_hdparm_output()
self.nvme_data = self.parse_nvme_devices()
logging.basicConfig(level=logging.INFO)
def parse_dmidecode_output(self):
@ -103,8 +104,8 @@ class ServerData:
# Get the list of devices
try:
device_list = subprocess.check_output(['lsblk', '-d', '-o', 'NAME'], stderr=subprocess.STDOUT, universal_newlines=True).split()[1:]
except subprocess.CalledProcessError as e:
device_list = [device for device in os.listdir('/sys/block') if device.startswith('sd')]
except OSError as e:
logging.error("Failed to get device list: {}".format(e))
return devices
@ -135,6 +136,53 @@ class ServerData:
return devices
def parse_nvme_devices(self):
'''
Example nvme id-ctrl output:
NVME Identify Controller:
vid : 0x144d
ssvid : 0x144d
sn : S3RVNA0K502408F
mn : Samsung SSD 970 EVO Plus 1TB
fr : 2B2QEXM7
rab : 2
....
'''
devices = {}
# Check if nvme exists
if shutil.which('nvme') is None:
print("nvme not found")
return devices
# Get the list of nvme devices starting with 'nvme'
nvme_devices = [device for device in os.listdir('/sys/block') if device.startswith('nvme')]
for device in nvme_devices:
device_path = '/dev/' + device
try:
# Get the output of nvme id-ctrl command
output = subprocess.check_output(['nvme', 'id-ctrl', device_path], stderr=subprocess.STDOUT, universal_newlines=True)
except subprocess.CalledProcessError as e:
print(f"Failed to get nvme id-ctrl output for {device_path}: {e}")
continue
# Split the output into lines
lines = output.split('\n')
# Parse each line
device_info = {}
for line in lines:
if ':' in line:
key, value = line.split(':', 1)
device_info[key.strip()] = value.strip()
devices[device_path] = device_info
return devices
def get_ram_and_disk(self):
# RAM information
with open('/proc/meminfo', 'r') as f:
@ -254,9 +302,15 @@ class ServerData:
for device, details in self.hdparm_data.items():
sata_details.append("Device: {}, Model: {}, Serial: {}, Checksum: {}, Buffer Size: {}, Form Factor: {}".format(
device, details['model_number'], details['serial_number'], details['checksum'], details['buffer_size'], details['form_factor']))
# NVMe Storage media
nvme_details = []
for device, details in self.nvme_data.items():
nvme_details.append("Device: {}, Model: {}, Serial: {}, Firmware: {}".format(
device, details.get('mn', 'Unknown'), details.get('sn', 'Unknown'), details.get('fr', 'Unknown')))
note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM Details: {} ||| SATA Details {}".format(
chassis_model, chassis_serial, processor_model, processor_count, ' | '.join(ram_details), ' | '.join(sata_details))
note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM Details: {} ||| SATA Details {} ||| NVME Details {}".format(
chassis_model, chassis_serial, processor_model, processor_count, ' | '.join(ram_details), ' | '.join(sata_details), ' | '.join(nvme_details))
note_data = {
'note': note,