summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJason M. Bills <jason.m.bills@linux.intel.com>2019-03-27 12:03:59 -0700
committerEd Tanous <ed.tanous@intel.com>2019-05-08 19:08:00 +0000
commit70304cb594859b3862eeecc0a16c8e6e9a126530 (patch)
treea8372c36d4a7d1fa419d66d191751652bf213043 /scripts
parentaf8f791296511553e11643d0bbbd80dfe9cd30e3 (diff)
downloadbmcweb-70304cb594859b3862eeecc0a16c8e6e9a126530.tar.gz
bmcweb-70304cb594859b3862eeecc0a16c8e6e9a126530.zip
Remove the static Base Message Registry file
This change removes the static Base Message Registry file and replaces it with a compile-time structure. A script is used to pull the Base Message Registry file from the DMTF and parse it into the .hpp structure. Tested: Verified that after running the script, I can get the same Redfish data back from the existing endpoints without using the static files. Change-Id: Ide3c61ecff62801c06619d5c3edc2229c945d8e7 Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/parse_registries.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
new file mode 100644
index 0000000..d9d6cf3
--- /dev/null
+++ b/scripts/parse_registries.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python3
+import requests
+import zipfile
+from io import BytesIO
+import os
+from collections import defaultdict
+from collections import OrderedDict
+from distutils.version import StrictVersion
+import shutil
+import json
+import glob
+import subprocess
+
+import xml.etree.ElementTree as ET
+
+REGISTRY_HEADER = '''/*
+// Copyright (c) 2019 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+/****************************************************************
+ * This is an auto-generated header which contains definitions
+ * for Redfish DMTF defined messages.
+ ***************************************************************/
+#pragma once
+#include <registries.hpp>
+
+namespace redfish::message_registries::{}
+{{
+
+const std::array registry = {{
+'''
+
+SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
+
+include_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "redfish-core", "include"))
+
+proxies = {
+ 'https': os.environ.get("https_proxy", None)
+}
+
+base_file = requests.get('https://redfish.dmtf.org/registries/Base.1.4.0.json', proxies=proxies)
+base_file.raise_for_status()
+base_json = json.loads(base_file.text)
+base_path = os.path.join(include_path, "base_message_registry.hpp")
+
+files = [(base_path, base_json, "base")]
+
+# Remove the old files
+for file, json, namespace in files:
+ try:
+ os.remove(file)
+ except:
+ print("{} not found".format(file))
+
+ with open(file, 'w') as registry:
+ registry.write(REGISTRY_HEADER.format(namespace))
+ for messageId, message in sorted(json["Messages"].items()):
+ registry.write("MessageEntry{")
+ registry.write("\"{}\",".format(messageId))
+ registry.write("{")
+ registry.write(".description = \"{}\",".format(message["Description"]))
+ registry.write(".message = \"{}\",".format(message["Message"]))
+ registry.write(".severity = \"{}\",".format(message["Severity"]))
+ registry.write(".numberOfArgs = {},".format(message["NumberOfArgs"]))
+ registry.write(".paramTypes = {")
+ paramTypes = message.get("ParamTypes")
+ if paramTypes:
+ for paramType in paramTypes:
+ registry.write("\"{}\",".format(paramType))
+ registry.write("},")
+ registry.write(".resolution = \"{}\",".format(message["Resolution"]))
+ registry.write("}},")
+ registry.write("};}\n")
+ subprocess.check_call(["clang-format", "-i", file])
OpenPOWER on IntegriCloud