Skip to content

Instantly share code, notes, and snippets.

@moali87
Created August 10, 2015 15:57
Show Gist options
  • Select an option

  • Save moali87/c5586c621065f3626b02 to your computer and use it in GitHub Desktop.

Select an option

Save moali87/c5586c621065f3626b02 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import subprocess
def get_ipmi_ip():
grains = {}
grains['ipmi_ip'] = True
ipmiIpString = ('/usr/bin/ipmitool', 'lan', 'print', '1') #This will print out the full ipmitool lan print, not just the IP unfortunately
#['/usr/bin/ipmitool', 'lan', 'print', '|', 'awk', '"/IP Address /', '{ print $4 }"']
#"/usr/bin/ipmitool lan print | awk '/IP Address / { print $4 }'"
process = subprocess.Popen((ipmiIpString), stdout=subprocess.PIPE)
output = subprocess.check_output(('grep', 'IP Address'), stdin=process.stdout)
outputFormat1 = output.strip('\n').split(':')
outputFormat2 = outputFormat1[2].strip(" ")
grains['ipmi_ip'] = outputFormat2
return grains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment