Created
May 12, 2015 22:00
-
-
Save moloney/2c20fa4b8e67fee8a01e to your computer and use it in GitHub Desktop.
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
# Provides access to Mellanox 'mstflint' program which can be used to manage | |
# the firmware on their Infiniband cards. | |
from subprocess import check_output as _check_output | |
from subprocess import CalledProcessError | |
from salt.utils.decorators import depends | |
try: | |
_check_output(['which', 'mstflint']) | |
HAS_MSTFLINT = True | |
except CalledProcessError as e: | |
HAS_MSTFLINT = False | |
@depends(HAS_MSTFLINT) | |
def query(image_file=None, pci_bus_id=None): | |
'''Query the device and firmware info from either a PCI device or a | |
firmware image file. | |
Example: | |
salt '*' mstflint.query image_file=fw.bin | |
salt '*' mstflint.query pci_bus_id="'81:00.00'" | |
''' | |
if pci_bus_id is not None: | |
if image_file is not None: | |
raise ValueError("Can not specify both a 'pci_bus_id' and a " | |
"'image_file'") | |
print pci_bus_id | |
print type(pci_bus_id) | |
out_str = _check_output(['mstflint', '-d', pci_bus_id, 'query']) | |
elif image_file is not None: | |
out_str = _check_output(['mstflint', '-i', image_file, 'query']) | |
else: | |
raise ValueError("Must specify one of: 'pci_bus_id' or 'image_file'.") | |
out_dict = odict | |
for line in out_str.split('\n'): | |
toks = line.split(':') | |
if len(toks) < 2: | |
continue | |
out_dict[toks[0]] = ':'.join(toks[1:]) | |
return out_dict | |
def _check_compat(image_file, pci_bus_id): | |
img_res = query(image_file=image_file) | |
dev_res = query(pci_bus_id=pci_bus_id) | |
return img_res['PSID'] == dev_res['PSID'] | |
@depends(HAS_MSTFLINT) | |
def burn(image_file, pci_bus_id): | |
'''Burn the firmware in the 'image_file' to the device with the given | |
'pci_bus_id'. | |
Example: | |
salt '*' mstflint.burn fw.bin "'81:00.00'" | |
''' | |
if not _check_compat(image_file, pci_bus_id): | |
raise ValueError("The image is not compatible with this device.") | |
_check_output(['mstflint', '-d', pci_bus_id, '-i', image_file, 'burn']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment