Skip to content

Instantly share code, notes, and snippets.

@dwlehman
Last active December 14, 2016 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwlehman/653429ebb5af62721ab3f99997eb254b to your computer and use it in GitHub Desktop.
Save dwlehman/653429ebb5af62721ab3f99997eb254b to your computer and use it in GitHub Desktop.
example code using libstoragemgmt to gather HBA RAID info
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