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(): |
9072ba9a |
devices_list = subprocess.check_output(['lsblk', '-d', '-I', '8,179,259', '-n', |
c533b308 |
'--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(): |
c533b308 |
devices_list = subprocess.check_output(['lsblk', '-d', '--bytes', '-I', |
9072ba9a |
'8,179,259', '-n', '--output', 'NAME,SIZE,MODEL'], |
c533b308 |
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 |
a672bd24 |
colstr = cols[0].decode() |
c533b308 |
if colstr.startswith("pmem"): |
09b7091f |
continue |
51ddc8dd |
model = "Unknown" |
c533b308 |
if len(cols) >= 3: |
a672bd24 |
model = cols[2].decode() |
f4d17450 |
devices.append( |
c533b308 |
Device(model #Model
, '/dev/' + cols[0].decode() #Path
, cols[1].decode() #size
)) |
f4d17450 |
|
a672bd24 |
return devices |