SHARE
TWEET

Untitled

a guest Oct 15th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import getpass
  4. import ipaddress
  5. import subprocess
  6.  
  7. pingcommand = 'ping -c 1 -w 1 %s'
  8. sledcommand = 'ipmitool -H %s -U %s -P %s -I lanplus raw 0x30 0xe1 %d'
  9.  
  10. def run(command):
  11.     cmd = command.split(' ')
  12.     output = subprocess.run(cmd, stdout=subprocess.PIPE)
  13.     return output.stdout.decode()
  14.  
  15. userid = input('Enter BMC userid: ')
  16. password = getpass.getpass('Enter BMC password: ')
  17. subnet = input('Enter BMC subnet: ')
  18. n = ipaddress.IPv4Network(subnet)
  19. summary = ''
  20.  
  21. for host in [str(h) for h in n.hosts()]:
  22.     if '0% packet loss' in run(pingcommand % host):
  23.         print('Sending IPMI to', host, '       (15 second timeout if host does not respond)')
  24.         try:
  25.             sledid = 0
  26.             bitposition = 0
  27.             for i in [123, 124, 125]: # Magic numbers to retrieve sled position as three single bits
  28.                bit =  run(sledcommand % (host, userid, password, i)).split(' ')[2]
  29.                sledid += int(bit) * 2**bitposition
  30.                bitposition += 1
  31.             summary += 'Host %s is in sled position: %d\n' % (host,sledid)
  32.         except:
  33.             continue
  34. print(summary)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top