f4d17450 |
#
# Copyright (C) 2015 vmware inc.
#
# Author: Mahmoud Bassiouny <mbassiouny@vmware.com>
import subprocess
import os
class Device(object): |
bc583990 |
def __init__(self, model, path, size): |
f4d17450 |
self.model = model
self.path = path
self.size = size
@staticmethod
def refresh_devices(): |
00a5007f |
devices_list = subprocess.check_output(['lsblk', '-d', '-I', '8,259', '-n', '--output', 'NAME,SIZE,MODEL'], stderr=open(os.devnull, 'w')) |
bc583990 |
return Device.wrap_devices_from_list(devices_list) |
f4d17450 |
@staticmethod |
72832a72 |
def refresh_devices_bytes(): |
00a5007f |
devices_list = subprocess.check_output(['lsblk', '-d', '--bytes', '-I', '8,259', '-n', '--output', 'NAME,SIZE,MODEL'], stderr=open(os.devnull, 'w')) |
72832a72 |
return Device.wrap_devices_from_list(devices_list)
@staticmethod |
bc583990 |
def wrap_devices_from_list(list): |
f4d17450 |
devices = [] |
bc583990 |
deviceslines = list.splitlines()
for deviceline in deviceslines:
cols = deviceline.split(None, 2) |
09b7091f |
#skip Virtual NVDIMM from install list
if(cols[0].startswith("pmem")):
continue |
51ddc8dd |
model = "Unknown"
if(len(cols) >= 3):
model = cols[2] |
f4d17450 |
devices.append( |
51ddc8dd |
Device(model #Model |
bc583990 |
, '/dev/' + cols[0] #Path
, cols[1] #size
)) |
f4d17450 |
return devices |