summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2017-04-11 13:52:54 -0500
committerMatt Spinler <spinler@us.ibm.com>2017-04-27 10:04:00 -0500
commitd08dbe27c2de978b0c4a65c678e678f3260470c0 (patch)
tree2a00a3989a4d9f039b9e60df4a5bc5fdb5bdc5a0
parent57352a312680c62f231f9c4496b636bad10ef743 (diff)
downloadphosphor-fan-presence-d08dbe27c2de978b0c4a65c678e678f3260470c0.tar.gz
phosphor-fan-presence-d08dbe27c2de978b0c4a65c678e678f3260470c0.zip
Fan control: Python script framework
The basics of a python script that will generate the fan zone data structures for the fan control code from zone and fan yaml files using a mako template. Change-Id: I1d92dc55c2b6dd986e5aaae0d3440ef85cbe79c0 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rwxr-xr-xcontrol/gen-fan-zone-defs.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py
new file mode 100755
index 0000000..806b484
--- /dev/null
+++ b/control/gen-fan-zone-defs.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+"""
+This script reads in fan definition and zone definition YAML
+files and generates a set of structures for use by the fan control code.
+"""
+
+import os
+import sys
+import yaml
+from argparse import ArgumentParser
+from mako.template import Template
+
+#Note: Condition is a TODO
+tmpl = '''/* This is a generated file. */
+#include "manager.hpp"
+
+using namespace phosphor::fan::control;
+
+const std::vector<ZoneGroup> Manager::_zoneLayouts
+{
+%for zone_group in zones:
+ std::make_tuple(
+ std::vector<Condition>{},
+ std::vector<ZoneDefinition>{
+ %for zone in zone_group['zones']:
+ std::make_tuple(${zone['num']},
+ ${zone['initial_speed']},
+ std::vector<FanDefinition>{
+ %for fan in zone['fans']:
+ std::make_tuple("${fan['name']}",
+ std::vector<std::string>{
+ %for sensor in fan['sensors']:
+ "${sensor}",
+ %endfor
+ }
+ ),
+ %endfor
+ }
+ ),
+ %endfor
+ }
+ ),
+%endfor
+};
+'''
+
+if __name__ == '__main__':
+ parser = ArgumentParser(
+ description="Phosphor fan zone definition parser")
+
+ parser.add_argument('-z', '--zone_yaml', dest='zone_yaml',
+ default="example/zones.yaml",
+ help='fan zone definitional yaml')
+ parser.add_argument('-f', '--fan_yaml', dest='fan_yaml',
+ default="example/fans.yaml",
+ help='fan definitional yaml')
+ parser.add_argument('-o', '--output_dir', dest='output_dir',
+ default=".",
+ help='output directory')
+ args = parser.parse_args()
+
+ if not args.zone_yaml or not args.fan_yaml:
+ parser.print_usage()
+ sys.exit(-1)
+
+ with open(args.zone_yaml, 'r') as zone_input:
+ zone_data = yaml.safe_load(zone_input) or {}
+
+ with open(args.fan_yaml, 'r') as fan_input:
+ fan_data = yaml.safe_load(fan_input) or {}
+
+ #Fill in with using zone_data and fan_data with next commit
+ zone_data = []
+
+ output_file = os.path.join(args.output_dir, "fan_zone_defs.cpp")
+ with open(output_file, 'w') as output:
+ output.write(Template(tmpl).render(zones=zone_data))
OpenPOWER on IntegriCloud