f4d17450 | #! /usr/bin/python2 # # 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(): |
68b5f74a | 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 |
bc583990 | def wrap_devices_from_list(list): |
f4d17450 | devices = [] |
bc583990 | deviceslines = list.splitlines() for deviceline in deviceslines: cols = deviceline.split(None, 2) |
f4d17450 | devices.append( |
bc583990 | Device(cols[2] #Model , '/dev/' + cols[0] #Path , cols[1] #size )) |
f4d17450 | return devices |