summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-05-05 11:04:29 +0530
committerPatrick Williams <patrick@stwcx.xyz>2017-05-19 17:59:19 +0000
commitdd78a1d02fd1071a0a88e72a9add51795a9d0d28 (patch)
treedd657ec3127c0364bc5536b09910576fe3cc9328 /scripts
parent83527efebc74c906aa6e7ed3205703db48002619 (diff)
downloadphosphor-host-ipmid-dd78a1d02fd1071a0a88e72a9add51795a9d0d28.zip
phosphor-host-ipmid-dd78a1d02fd1071a0a88e72a9add51795a9d0d28.tar.gz
Write parser for inventory to sensor mapping yaml.
Write python-based parser for inventory-sensor.yaml. The parser generates inventory-sensor-gen.cpp, which is contains a map containing the inventory object path as key and the sensor related info as the value. Change-Id: Ib0e0f61f075b0ba777417a8032074c9b66b2eef7 Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/inventory-sensor.py60
-rw-r--r--scripts/inventorysensor.mako.cpp27
2 files changed, 87 insertions, 0 deletions
diff --git a/scripts/inventory-sensor.py b/scripts/inventory-sensor.py
new file mode 100755
index 0000000..77222f5
--- /dev/null
+++ b/scripts/inventory-sensor.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import yaml
+import argparse
+from mako.template import Template
+
+
+def generate_cpp(sensor_yaml, output_dir):
+ with open(os.path.join(script_dir, sensor_yaml), 'r') as f:
+ ifile = yaml.safe_load(f)
+ if not isinstance(ifile, dict):
+ ifile = {}
+
+ # Render the mako template
+
+ t = Template(filename=os.path.join(
+ script_dir,
+ "inventorysensor.mako.cpp"))
+
+ output_cpp = os.path.join(output_dir, "inventory-sensor-gen.cpp")
+ with open(output_cpp, 'w') as fd:
+ fd.write(t.render(sensorDict=ifile))
+
+
+def main():
+
+ valid_commands = {
+ 'generate-cpp': generate_cpp
+ }
+ parser = argparse.ArgumentParser(
+ description="Inventory Object to IPMI SensorID code generator")
+
+ parser.add_argument(
+ '-i', '--sensor_yaml', dest='sensor_yaml',
+ default='example.yaml', help='input sensor yaml file to parse')
+
+ parser.add_argument(
+ "-o", "--output-dir", dest="outputdir",
+ default=".",
+ help="output directory")
+
+ parser.add_argument(
+ 'command', metavar='COMMAND', type=str,
+ choices=valid_commands.keys(),
+ help='Command to run.')
+
+ args = parser.parse_args()
+
+ if (not (os.path.isfile(os.path.join(script_dir, args.sensor_yaml)))):
+ sys.exit("Can not find input yaml file " + args.sensor_yaml)
+
+ function = valid_commands[args.command]
+ function(args.sensor_yaml, args.outputdir)
+
+
+if __name__ == '__main__':
+ script_dir = os.path.dirname(os.path.realpath(__file__))
+ main()
diff --git a/scripts/inventorysensor.mako.cpp b/scripts/inventorysensor.mako.cpp
new file mode 100644
index 0000000..000f758
--- /dev/null
+++ b/scripts/inventorysensor.mako.cpp
@@ -0,0 +1,27 @@
+## This file is a template. The comment below is emitted
+## into the rendered file; feel free to edit this file.
+
+// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
+
+#include "types.hpp"
+using namespace ipmi::sensor;
+
+extern const InvObjectIDMap invSensors = {
+% for key in sensorDict.iterkeys():
+ % if key:
+{"${key}",
+ {
+<%
+ objectPath = sensorDict[key]
+ sensorID = objectPath["sensorID"]
+ sensorType = objectPath["sensorType"]
+ eventReadingType = objectPath["eventReadingType"]
+ offset = objectPath["offset"]
+%>
+ ${sensorID},${sensorType},${eventReadingType},${offset}
+ }
+},
+ % endif
+% endfor
+};
+
OpenPOWER on IntegriCloud