blob: a5aa2225e5c7ce8d56537899f7542222e46dc91a [file] [log] [blame]
#!/usr/bin/env python3
import yaml
import argparse
entityIds = {
'dimm': 32,
'core': 208,
'cpu': 3,
'gpu': 216,
'gpu_mem': 217,
'tpm': 3,
'state/host0': 33, # Different interfaces using different entity ID
# and this requires extra fix.
# {'state/host0', 34},
# {'state/host0', 35},
'turbo': 3,
'fan': 29,
'vdd_temp': 218,
'power': 10,
'voltage': 10,
'current': 10,
'temperature/pcie': 35,
'temperature/ambient': 64,
'occ': 210,
'control/volatile': 33,
}
extraIds = {
'RebootPolicy': 33,
'Progress': 34,
'RebootAttempts': 34,
'OperatingSystem.Status': 35
}
def openYaml(f):
return yaml.load(open(f))
def saveYaml(y, f):
yaml.dump(y, open(f, "w"))
def getEntityId(p, i):
for k, v in entityIds.items():
if k in p:
if k == 'state/host0':
# get id from extraIds
for ek, ev in extraIds.items():
if ek in i:
return ev
raise Exception("Unable to find entity id:", p, i)
else:
return v
raise Exception('Unable to find entity id:', p)
# Global entity instances
entityInstances = {}
def getEntityInstance(id):
instanceId = entityInstances.get(id, 0)
instanceId = instanceId + 1
entityInstances[id] = instanceId
print("EntityId:", id, "InstanceId:", instanceId)
return instanceId
def main():
parser = argparse.ArgumentParser(
description='Yaml tool for updating ipmi sensor yaml config')
parser.add_argument('-i', '--input', required=True, dest='input',
help='The ipmi sensor yaml config')
parser.add_argument('-o', '--output', required=True, dest='output',
help='The output yaml file')
parser.add_argument('-r', '--rpt', dest='rpt',
help='The .rpt file generated by op-build')
parser.add_argument('-e', '--entity', action='store_true',
help='Fix entities')
args = parser.parse_args()
args = vars(args)
if args['input'] is None or args['output'] is None:
parser.print_help()
exit(1)
# TODO: read rtp and generate the whole config yaml
# if args['rpt']:
# pass
y = openYaml(args['input'])
if args['entity']:
# Fix entities
for i in y:
path = y[i]['path']
intf = list(y[i]['interfaces'].keys())[0]
entityId = getEntityId(path, intf)
y[i]['entityID'] = entityId
y[i]['entityInstance'] = getEntityInstance(entityId)
print(y[i]['path'], "id:", entityId,
"instance:", y[i]['entityInstance'])
saveYaml(y, args['output'])
if __name__ == "__main__":
main()