5
from subprocess import check_output, CalledProcessError
8
# First, we need to get output
9
cmd = "ipmitool mc info"
11
result = check_output(shlex.split(cmd), universal_newlines=True)
12
except FileNotFoundError:
13
print("ipmitool was not found! Please install it and try again.",
16
except CalledProcessError as e:
17
print("Problem running %s. Error was %s" % (cmd,e),file=sys.stderr)
19
result = result.split('\n')
21
# We need some bits that are formatted oddly so we need to do some parsing
25
key = line.split(':')[0].strip()
26
value = line.split(':')[1].strip()
30
# since the last line we matched had a ':', it's key is likely the
31
# key for the next few lines that don't have a ':'
32
# This should keep adding items to our last key's list until we hit
33
# another line with a :, and we start the cycle over again.
34
last[1].append(line.strip())
35
data[last[0]] = last[1]
37
# Now print out what we care about:
38
we_care_about = ['Manufacturer Name',
44
'Additional Device Support']
46
for field in we_care_about:
47
if type(data[field]) is list:
48
# Sometimes the first item in the list is ''. This will remove it
49
data[field].remove('')
50
print(field.ljust(30),':',data[field].pop(0))
51
for item in data[field]:
52
print(' '.ljust(32),item)
54
print(field.ljust(30),":",data[field])
55
#print("{}:\t{}".format(field, data[field]))
60
if __name__ == "__main__":