diff options
author | Patrick Venture <venture@google.com> | 2017-12-22 14:03:06 -0800 |
---|---|---|
committer | Tom Joseph <tomjoseph@in.ibm.com> | 2018-01-17 15:05:57 +0000 |
commit | c01edf283dca792d1eecedd5c03b69b7eebb6f23 (patch) | |
tree | 4fab333c768b575412a513ec59988d5f546769c8 /scripts | |
parent | a1adb0777e370103ab9f3e7f8788f74975c69897 (diff) | |
download | phosphor-host-ipmid-c01edf283dca792d1eecedd5c03b69b7eebb6f23.tar.gz phosphor-host-ipmid-c01edf283dca792d1eecedd5c03b69b7eebb6f23.zip |
multiple-channel configuration via yaml
Handles converting a yaml file mapping IPMI
channel to ethernet device and using this instead of
a hard-coded map.
Change-Id: Iedfe7cb52a2d0663b9c8a0f6f9d37fe733b63a58
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/channel-example.yaml | 6 | ||||
-rwxr-xr-x | scripts/channel_gen.py | 60 | ||||
-rw-r--r-- | scripts/writechannel.mako.cpp | 20 |
3 files changed, 86 insertions, 0 deletions
diff --git a/scripts/channel-example.yaml b/scripts/channel-example.yaml new file mode 100644 index 0000000..819f251 --- /dev/null +++ b/scripts/channel-example.yaml @@ -0,0 +1,6 @@ +# Channel Number (must be unique) is the key +1: + # ifName the ethernet device name (used in the dbus path) + ifName: eth0 +2: + ifName: eth1 diff --git a/scripts/channel_gen.py b/scripts/channel_gen.py new file mode 100755 index 0000000..77fbd2e --- /dev/null +++ b/scripts/channel_gen.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(interface_yaml, output_dir): + with open(os.path.join(script_dir, interface_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, + "writechannel.mako.cpp")) + + output_cpp = os.path.join(output_dir, "channel-gen.cpp") + with open(output_cpp, 'w') as fd: + fd.write(t.render(interfaceDict=ifile)) + + +def main(): + + valid_commands = { + 'generate-cpp': generate_cpp + } + parser = argparse.ArgumentParser( + description="IPMI ethernet interface parser and code generator") + + parser.add_argument( + '-i', '--interface_yaml', dest='interface_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.interface_yaml)))): + sys.exit("Can not find input yaml file " + args.interface_yaml) + + function = valid_commands[args.command] + function(args.interface_yaml, args.outputdir) + + +if __name__ == '__main__': + script_dir = os.path.dirname(os.path.realpath(__file__)) + main() diff --git a/scripts/writechannel.mako.cpp b/scripts/writechannel.mako.cpp new file mode 100644 index 0000000..922611a --- /dev/null +++ b/scripts/writechannel.mako.cpp @@ -0,0 +1,20 @@ +## 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" + +namespace ipmi +{ +namespace network +{ + +extern const ChannelEthMap ethdevices = { +% for channel,channelInfo in interfaceDict.iteritems(): + {${channel},"${channelInfo['ifName']}"}, +% endfor +}; + +} // namespace network +} // namespace ipmi + |