forked from yongseokoh/nvme_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvme_list.py
executable file
·45 lines (33 loc) · 1.22 KB
/
nvme_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import subprocess
import json
import nvme_simulation as nv_simul
def print_nvme_list(json_data):
for device in json_data['Devices']:
print('DevicePath %s' %device['DevicePath'])
print('Firmware %s' %device['Firmware'])
print('Index %s' %device['Index'])
print('ModelNumber %s' %device['ModelNumber'])
print('ProductName %s' %device['ProductName'])
print('SerialNumber %s' %device['SerialNumber'])
print('UsedBytes %s' %device['UsedBytes'])
print('MaximumLBA %s' %device['MaximumLBA'])
print('PhysicalSize %s' %device['PhysicalSize'])
print('SectorSize %s' %device['SectorSize'])
def get_nvme_list():
if nv_simul.NVME_SIMULATION == 0:
proc = subprocess.Popen("nvme list %s -o json",
shell=True,
stdout=subprocess.PIPE,
encoding='utf-8')
err = proc.wait()
(stdout, stderr) = proc.communicate()
json_data = json.loads(stdout)
else:
json_data = nv_simul.gen_simulation_nvme_list()
#print(type(json_data))
#print(json_data)
print_nvme_list(json_data)
return json_data
if __name__ == '__main__':
nvme_list_json = get_nvme_list("/dev/nvme0")
print(nvme_list_json)