Last active
December 14, 2016 20:30
-
-
Save dwlehman/653429ebb5af62721ab3f99997eb254b to your computer and use it in GitHub Desktop.
example code using libstoragemgmt to gather HBA RAID info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
import lsm | |
_hba_plugin_uris = ("hpsa://", "megaraid://") | |
HBAVolumeInfo = namedtuple('HBAVolumeInfo', ['system', 'nodes', 'raid_type', 'raid_stripe_size']) | |
""" lighweight data structure containing HBA RAID info: | |
system (str): descriptive name of HBA unit | |
nodes (list of str): list of device node paths for the volume | |
raid_type (int): one of the lsm.Volume.RAID_TYPE_* constants | |
raid_stripe_size (int): stripe size in bytes | |
""" | |
def get_volume_info(): | |
""" Return a list of namedtuples containing basic HBA RAID info. """ | |
volumes = [] | |
for uri in _hba_plugin_uris: | |
client = lsm.Client(uri) | |
systems = dict((s.id, s) for s in client.systems()) | |
for vol in client.volumes(): | |
nodes = lsm.LocalDisk.vpd83_search(vol.vpd83) | |
system = systems[vol.system_id] | |
caps = client.capabilities(system) | |
if caps.supported(lsm.Capabilities.VOLUME_RAID_INFO): | |
raid_info = client.volume_raid_info(vol) | |
else: | |
raid_info = [None, None, None, None] | |
volumes.append(HBAVolumeInfo(system.name, nodes, *raid_info[:2])) | |
return volumes | |
if __name__ == "__main__": | |
import pprint | |
pprint.pprint(get_volume_info()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment