Skip to content

Instantly share code, notes, and snippets.

@pcarver
Last active October 22, 2019 15:46
Show Gist options
  • Save pcarver/611f54f4cc02b8cf48d68edece12561b to your computer and use it in GitHub Desktop.
Save pcarver/611f54f4cc02b8cf48d68edece12561b to your computer and use it in GitHub Desktop.
Python script using IPMI to determine position of sleds in Nokia OpenEdge chassis
#!/usr/bin/env python3
import getpass
import ipaddress
from multiprocessing import Pool
import subprocess
pingcommand = 'ping -c 1 -w 1 %s'
sledcommand = 'ipmitool -H %s -U %s -P %s -I lanplus raw 0x30 0xe1 %d'
def run(command):
cmd = command.split(' ')
output = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return output.stdout.decode()
def getsledid(host):
if ' 0% packet loss' in run(pingcommand % host):
print('Sending IPMI to', host, ' (15 second timeout if host does not respond)')
try:
sledid = 0
bitposition = 0
for i in [123, 124, 125]:
bit = run(sledcommand % (host, userid, password, i)).split(' ')[2]
sledid += int(bit) * 2**bitposition
bitposition += 1
return 'Host %s is in sled position: %d\n' % (host,sledid)
except:
pass
userid = input('Enter BMC userid: ')
password = getpass.getpass('Enter BMC password: ')
subnet = input('Enter BMC subnet: ')
n = ipaddress.IPv4Network(subnet)
hosts = [str(h) for h in n.hosts()]
p = Pool(len(hosts))
ret = p.map(getsledid, hosts)
print(''.join([s for s in ret if s is not None]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment