summaryrefslogtreecommitdiffstats
path: root/control/gen-fan-zone-defs.py
blob: 806b4844c1583e371197a240f968a17c07863192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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