summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2016-11-29 06:05:39 -0600
committerDeepak Kodihalli <dkodihal@in.ibm.com>2016-12-08 12:40:07 -0600
commit8457f8218088954921dad41dcb94678141ec935f (patch)
tree58c4e2b05c2ce035bb5ca35a1bd46e0c52be3c6c
parentaabb33a07b512136af624f9be86b09a50a94aca2 (diff)
downloadopenpower-vpd-parser-8457f8218088954921dad41dcb94678141ec935f.tar.gz
openpower-vpd-parser-8457f8218088954921dad41dcb94678141ec935f.zip
inventory: write YAML parser
Write python-based parser for writefru.yaml. The parser generates writefru.hpp, which would have code to write to the inventory-manager the FRU VPD information, as described in writefru.yaml. Change-Id: I91776f808ef720e96c1b6fbd17e5f1edb93ea8f8 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rwxr-xr-xwritefru.mako.hpp91
-rwxr-xr-xwritefru.py18
2 files changed, 109 insertions, 0 deletions
diff --git a/writefru.mako.hpp b/writefru.mako.hpp
new file mode 100755
index 0000000..f7a2aa8
--- /dev/null
+++ b/writefru.mako.hpp
@@ -0,0 +1,91 @@
+## This file is a template. The comment below is emitted
+## into the rendered file; feel free to edit this file.
+// WARNING: Generated header. Do not edit!
+
+
+#pragma once
+
+#include <map>
+#include <iostream>
+#include "defines.hpp"
+#include "store.hpp"
+
+namespace openpower
+{
+namespace vpd
+{
+namespace inventory
+{
+
+using Inner = Parsed::mapped_type;
+using Outer = std::map<std::string, Inner>;
+
+// TODO: Remove once the call to inventory manager is added
+auto print = [](Outer&& object, const std::string& path)
+{
+ std::cout << "\n";
+ std::cout << path << "\n";
+ std::cout << "\n";
+ for(const auto& o : object)
+ {
+ std::cout << o.first << "\n";
+ for(const auto& i : o.second)
+ {
+ std::cout << i.first << " : " << i.second << "\n";
+ }
+ std::cout << "\n";
+ }
+};
+
+/** @brief API to write parsed VPD to inventory,
+ * for a specifc FRU
+ *
+ * @param [in] vpdStore - Store object containing
+ * parsed VPD
+ * @param [in] path - FRU object path
+ */
+template<Fru F>
+void writeFru(const Store& vpdStore, const std::string& path);
+
+% for key in fruDict.iterkeys():
+<%
+ fru = fruDict[key]
+%>\
+// Specialization of ${key}
+template<>
+void writeFru<Fru::${key}>(const Store& vpdStore,
+ const std::string& path)
+{
+ Outer object;
+
+ // Inventory manager needs object path, list of interface names to be
+ // implemented, and property:value pairs contained in said interfaces
+
+ % for interfaces, properties in fru.iteritems():
+<%
+ interface = interfaces.split(".")
+ intfName = interface[0] + interface[-1]
+%>\
+ Inner ${intfName};
+ % for name, value in properties.iteritems():
+ % if fru and interfaces and name and value:
+<%
+ record, keyword = value.split(",")
+%>\
+ ${intfName}["${name}"] =
+ vpdStore.get<Record::${record}, record::Keyword::${keyword}>();
+ % endif
+ % endfor
+ object.emplace("${interfaces}",
+ std::move(${intfName}));
+ % endfor
+
+ // TODO: Need integration with inventory manager, print serialized dbus
+ // object for now.
+ print(std::move(object), path);
+}
+
+% endfor
+} // namespace inventory
+} // namespace vpd
+} // namespace openpower
diff --git a/writefru.py b/writefru.py
new file mode 100755
index 0000000..97418ca
--- /dev/null
+++ b/writefru.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+import os
+import yaml
+from mako.template import Template
+
+if __name__ == '__main__':
+ script_dir = os.path.dirname(os.path.realpath(__file__))
+ with open(os.path.join(script_dir, 'writefru.yaml'), 'r') as fd:
+ yamlDict = yaml.safe_load(fd)
+
+ # Render the mako template
+ template = os.path.join(script_dir, 'writefru.mako.hpp')
+ t = Template(filename=template)
+ with open('writefru.hpp', 'w') as fd:
+ fd.write(
+ t.render(
+ fruDict=yamlDict))
OpenPOWER on IntegriCloud