~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-checkbox/bin/bmc_info

  • Committer: Tarmac
  • Author(s): Brendan Donegan
  • Date: 2013-06-03 11:12:58 UTC
  • mfrom: (2154.2.1 bug1185759)
  • Revision ID: tarmac-20130603111258-1b3m5ydvkf1accts
"[r=zkrynicki][bug=1185759][author=brendan-donegan] automatic merge by tarmac"

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
2
 
 
3
 
import sys
4
 
import shlex
5
 
from subprocess import check_output, CalledProcessError
6
 
 
7
 
def main():
8
 
    # First, we need to get output
9
 
    cmd = "ipmitool mc info"
10
 
    try:
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.",
14
 
              file=sys.stderr)
15
 
        return 1
16
 
    except CalledProcessError as e:
17
 
        print("Problem running %s.  Error was %s" % (cmd,e),file=sys.stderr)
18
 
        return 1
19
 
    result = result.split('\n')
20
 
 
21
 
    # We need some bits that are formatted oddly so we need to do some parsing
22
 
    data = {}
23
 
    for line in result:
24
 
        if ':' in line:
25
 
            key = line.split(':')[0].strip()
26
 
            value = line.split(':')[1].strip()
27
 
            data[key] = value
28
 
            last = (key, [value])
29
 
        else:
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]
36
 
 
37
 
    # Now print out what we care about:
38
 
    we_care_about = ['Manufacturer Name',
39
 
                     'Manufacturer ID',
40
 
                     'Product Name',
41
 
                     'Product ID',
42
 
                     'Firmware Revision',
43
 
                     'IPMI Version',
44
 
                     'Additional Device Support']
45
 
 
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)
53
 
        else:
54
 
            print(field.ljust(30),":",data[field])
55
 
            #print("{}:\t{}".format(field, data[field]))
56
 
 
57
 
    return 0
58
 
 
59
 
 
60
 
if __name__ == "__main__":
61
 
    sys.exit(main())