Last active
October 25, 2019 10:23
-
-
Save tracernz/174eaaedb1810cefa6a374b40b43187b to your computer and use it in GitHub Desktop.
quick hax script to turn identification led on disk bay connected to mpt2sas HBA from disk serial no.
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
#!/usr/bin/env python3 | |
import re | |
import subprocess | |
import sys | |
def main(): | |
if len(sys.argv) != 2: | |
print(f'Usage: {sys.argv[0]} <serial>', file=sys.stderr) | |
return 1 | |
serial = sys.argv[1] | |
proc = subprocess.run(['sas2ircu', 'LIST'], encoding='UTF-8', stdout=subprocess.PIPE) | |
if proc.returncode != 0: | |
return proc.returncode | |
adaptors = [] | |
for m in re.finditer('Index.+?(?P<index>[0-9]+)', proc.stdout, re.DOTALL): | |
adaptors.append(m.group('index')) | |
print(f'Found adaptors {", ".join([str(i) for i in adaptors])}') | |
enclosure, slot = None, None | |
for adp in adaptors: | |
proc = subprocess.run(['sas2ircu', str(adp), 'DISPLAY'], encoding='UTF-8', stdout=subprocess.PIPE) | |
for group in proc.stdout.split('Device is a Hard disk'): | |
m = re.search(f'Enclosure #\s+:\s+(?P<enclosure>[0-9]+)\s+Slot #\s+:\s+(?P<slot>[0-9]+).+?Serial No\s+:\s+{re.escape(serial)}\n', group, re.DOTALL) | |
if m is not None: | |
adaptor, enclosure, slot = adp, m.group('enclosure'), m.group('slot') | |
print(f'Found disk on adaptor {adaptor} in enclosure {enclosure} at slot {slot}') | |
break | |
if enclosure is not None: | |
break | |
if enclosure is None or slot is None: | |
print('Disk not found!', file=sys.stderr) | |
return 1 | |
print('Turning LED on:') | |
cmd = f'sas2ircu {adaptor} LOCATE {enclosure}:{slot} ON' | |
print(cmd) | |
proc = subprocess.run(cmd.split(' '), stdout=subprocess.PIPE) | |
if proc.returncode != 0: | |
return proc.returncode | |
input('LED turned on, press enter when done...') | |
print('\nTurning turn LED off:') | |
cmd = f'sas2ircu {adaptor} LOCATE {enclosure}:{slot} OFF' | |
print(cmd) | |
proc = subprocess.run(cmd.split(' '), stdout=subprocess.PIPE) | |
if proc.returncode != 0: | |
return proc.returncode | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment