openubmc-bingo 0.5.240__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of openubmc-bingo might be problematic. Click here for more details.
- bmcgo/__init__.py +12 -0
- bmcgo/bmcgo.py +22 -0
- bmcgo/bmcgo_config.py +176 -0
- bmcgo/cli/__init__.py +10 -0
- bmcgo/cli/cli.py +584 -0
- bmcgo/codegen/__init__.py +14 -0
- bmcgo/codegen/c/__init__.py +9 -0
- bmcgo/codegen/c/annotation.py +52 -0
- bmcgo/codegen/c/argument.py +42 -0
- bmcgo/codegen/c/codegen.py +153 -0
- bmcgo/codegen/c/comment.py +22 -0
- bmcgo/codegen/c/ctype_defination.py +353 -0
- bmcgo/codegen/c/helper.py +87 -0
- bmcgo/codegen/c/interface.py +63 -0
- bmcgo/codegen/c/method.py +82 -0
- bmcgo/codegen/c/property.py +180 -0
- bmcgo/codegen/c/renderer.py +21 -0
- bmcgo/codegen/c/signal.py +64 -0
- bmcgo/codegen/c/template/client.c.mako +145 -0
- bmcgo/codegen/c/template/client.h.mako +36 -0
- bmcgo/codegen/c/template/interface.c.mako +0 -0
- bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
- bmcgo/codegen/c/template/micro_component.c.mako +32 -0
- bmcgo/codegen/c/template/public.c.mako +228 -0
- bmcgo/codegen/c/template/public.h.mako +128 -0
- bmcgo/codegen/c/template/server.c.mako +104 -0
- bmcgo/codegen/c/template/server.h.mako +36 -0
- bmcgo/codegen/lua/.lua-format +7 -0
- bmcgo/codegen/lua/Makefile +101 -0
- bmcgo/codegen/lua/__init__.py +9 -0
- bmcgo/codegen/lua/codegen.py +171 -0
- bmcgo/codegen/lua/proto/Makefile +87 -0
- bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
- bmcgo/codegen/lua/proto/types.proto +52 -0
- bmcgo/codegen/lua/script/check_intfs.py +161 -0
- bmcgo/codegen/lua/script/dto/__init__.py +11 -0
- bmcgo/codegen/lua/script/dto/exception.py +53 -0
- bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
- bmcgo/codegen/lua/script/dto/options.py +33 -0
- bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
- bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
- bmcgo/codegen/lua/script/dto/url_route.py +195 -0
- bmcgo/codegen/lua/script/gen_db_json.py +444 -0
- bmcgo/codegen/lua/script/gen_depends.py +89 -0
- bmcgo/codegen/lua/script/gen_entry.py +263 -0
- bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
- bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
- bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
- bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
- bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
- bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
- bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
- bmcgo/codegen/lua/script/gen_schema.py +302 -0
- bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
- bmcgo/codegen/lua/script/loader/__init__.py +11 -0
- bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
- bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
- bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
- bmcgo/codegen/lua/script/lua_format.py +62 -0
- bmcgo/codegen/lua/script/mds_util.py +385 -0
- bmcgo/codegen/lua/script/merge_model.py +330 -0
- bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
- bmcgo/codegen/lua/script/proto_loader.py +47 -0
- bmcgo/codegen/lua/script/proto_plugin.py +140 -0
- bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
- bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
- bmcgo/codegen/lua/script/render_utils/base.py +25 -0
- bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
- bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
- bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
- bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
- bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
- bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
- bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
- bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
- bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
- bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
- bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
- bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
- bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
- bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
- bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
- bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
- bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
- bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
- bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
- bmcgo/codegen/lua/script/template.py +166 -0
- bmcgo/codegen/lua/script/types_pb2.py +516 -0
- bmcgo/codegen/lua/script/utils.py +663 -0
- bmcgo/codegen/lua/script/validate.py +80 -0
- bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
- bmcgo/codegen/lua/templates/Makefile +114 -0
- bmcgo/codegen/lua/templates/apps/Makefile +261 -0
- bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
- bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
- bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
- bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
- bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
- bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
- bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
- bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
- bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
- bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
- bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
- bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
- bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
- bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
- bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
- bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
- bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
- bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
- bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
- bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
- bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
- bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
- bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
- bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
- bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
- bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
- bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
- bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
- bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
- bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
- bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
- bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
- bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
- bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
- bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
- bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
- bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
- bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
- bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
- bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
- bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
- bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
- bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
- bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
- bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
- bmcgo/component/__init__.py +10 -0
- bmcgo/component/analysis/analysis.py +183 -0
- bmcgo/component/analysis/build_deps.py +165 -0
- bmcgo/component/analysis/data_deps.py +333 -0
- bmcgo/component/analysis/dep-rules.json +912 -0
- bmcgo/component/analysis/dep_node.py +110 -0
- bmcgo/component/analysis/intf_deps.py +163 -0
- bmcgo/component/analysis/intf_validation.py +254 -0
- bmcgo/component/analysis/rule.py +211 -0
- bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
- bmcgo/component/analysis/sr_validation.py +391 -0
- bmcgo/component/build.py +222 -0
- bmcgo/component/component_dt_version_parse.py +348 -0
- bmcgo/component/component_helper.py +114 -0
- bmcgo/component/coverage/__init__.py +11 -0
- bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
- bmcgo/component/coverage/incremental_cov.py +464 -0
- bmcgo/component/deploy.py +110 -0
- bmcgo/component/gen.py +169 -0
- bmcgo/component/package_info.py +236 -0
- bmcgo/component/template/conanbase.py.mako +278 -0
- bmcgo/component/template/conanfile.deploy.py.mako +40 -0
- bmcgo/component/test.py +947 -0
- bmcgo/errors.py +119 -0
- bmcgo/frame.py +217 -0
- bmcgo/functional/__init__.py +10 -0
- bmcgo/functional/analysis.py +96 -0
- bmcgo/functional/bmc_studio_action.py +98 -0
- bmcgo/functional/check.py +185 -0
- bmcgo/functional/conan_index_build.py +251 -0
- bmcgo/functional/config.py +332 -0
- bmcgo/functional/csr_build.py +724 -0
- bmcgo/functional/deploy.py +263 -0
- bmcgo/functional/diff.py +235 -0
- bmcgo/functional/fetch.py +235 -0
- bmcgo/functional/full_component.py +391 -0
- bmcgo/functional/maintain.py +381 -0
- bmcgo/functional/new.py +166 -0
- bmcgo/functional/schema_valid.py +111 -0
- bmcgo/functional/simple_sign.py +104 -0
- bmcgo/functional/upgrade.py +78 -0
- bmcgo/ipmigen/__init__.py +13 -0
- bmcgo/ipmigen/ctype_defination.py +82 -0
- bmcgo/ipmigen/ipmigen.py +309 -0
- bmcgo/ipmigen/template/cmd.c.mako +366 -0
- bmcgo/ipmigen/template/ipmi.c.mako +25 -0
- bmcgo/ipmigen/template/ipmi.h.mako +51 -0
- bmcgo/logger.py +176 -0
- bmcgo/misc.py +117 -0
- bmcgo/target/app.yml +17 -0
- bmcgo/target/install_sdk.yml +15 -0
- bmcgo/target/personal.yml +53 -0
- bmcgo/target/publish.yml +45 -0
- bmcgo/tasks/__init__.py +11 -0
- bmcgo/tasks/download_buildtools_hm.py +124 -0
- bmcgo/tasks/misc.py +15 -0
- bmcgo/tasks/task.py +354 -0
- bmcgo/tasks/task_build_conan.py +714 -0
- bmcgo/tasks/task_build_rootfs_img.py +595 -0
- bmcgo/tasks/task_buildgppbin.py +88 -0
- bmcgo/tasks/task_buildhpm_ext4.py +82 -0
- bmcgo/tasks/task_create_interface_config.py +122 -0
- bmcgo/tasks/task_download_buildtools.py +99 -0
- bmcgo/tasks/task_download_dependency.py +72 -0
- bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
- bmcgo/tasks/task_packet_to_supporte.py +87 -0
- bmcgo/tasks/task_prepare.py +105 -0
- bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
- bmcgo/utils/__init__.py +10 -0
- bmcgo/utils/buffer.py +128 -0
- bmcgo/utils/combine_json_schemas.py +170 -0
- bmcgo/utils/component_post.py +54 -0
- bmcgo/utils/component_version_check.py +86 -0
- bmcgo/utils/config.py +1067 -0
- bmcgo/utils/fetch_component_code.py +232 -0
- bmcgo/utils/install_manager.py +61 -0
- bmcgo/utils/installations/__init__.py +10 -0
- bmcgo/utils/installations/base_installer.py +70 -0
- bmcgo/utils/installations/install_consts.py +30 -0
- bmcgo/utils/installations/install_plans/bingo.yml +11 -0
- bmcgo/utils/installations/install_workflow.py +50 -0
- bmcgo/utils/installations/installers/apt_installer.py +177 -0
- bmcgo/utils/installations/installers/pip_installer.py +46 -0
- bmcgo/utils/installations/version_util.py +100 -0
- bmcgo/utils/mapping_config_patch.py +443 -0
- bmcgo/utils/perf_analysis.py +114 -0
- bmcgo/utils/tools.py +704 -0
- bmcgo/worker.py +417 -0
- openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
- openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
- openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
- openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
- openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
from utils import Utils
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MdbRegister:
|
|
18
|
+
JSON_TYPE_TO_LUA = {
|
|
19
|
+
"S8": "integer",
|
|
20
|
+
"U8": "integer",
|
|
21
|
+
"S16": "integer",
|
|
22
|
+
"U16": "integer",
|
|
23
|
+
"S32": "integer",
|
|
24
|
+
"U32": "integer",
|
|
25
|
+
"S64": "integer",
|
|
26
|
+
"U64": "integer",
|
|
27
|
+
"Double": "number",
|
|
28
|
+
"String": "string",
|
|
29
|
+
"Boolean": "boolean",
|
|
30
|
+
"Array": "message",
|
|
31
|
+
"Binary": "string"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
JSON_TYPE_TO_DBUS = {
|
|
35
|
+
"S8": "y",
|
|
36
|
+
"U8": "y",
|
|
37
|
+
"S16": "n",
|
|
38
|
+
"U16": "q",
|
|
39
|
+
"S32": "i",
|
|
40
|
+
"U32": "u",
|
|
41
|
+
"S64": "x",
|
|
42
|
+
"U64": "t",
|
|
43
|
+
"Double": "d",
|
|
44
|
+
"String": "s",
|
|
45
|
+
"Boolean": "b",
|
|
46
|
+
"Binary": "ay"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def transform_types(prop_data, trans_map):
|
|
51
|
+
if isinstance(prop_data, int):
|
|
52
|
+
return False, 'i'
|
|
53
|
+
elif isinstance(prop_data, str):
|
|
54
|
+
return False, 's'
|
|
55
|
+
if "baseType" in prop_data:
|
|
56
|
+
if prop_data["baseType"] == "Struct" or prop_data["baseType"] == "Enum" \
|
|
57
|
+
or prop_data["baseType"] == "Dictionary":
|
|
58
|
+
return False, prop_data["$ref"].replace("#/defs/", "")
|
|
59
|
+
elif prop_data["baseType"] == "Array":
|
|
60
|
+
return True, prop_data["items"]["$ref"].replace("#/defs/", "")
|
|
61
|
+
elif prop_data["baseType"].endswith("[]"):
|
|
62
|
+
return True, trans_map[prop_data["baseType"][0:-2]]
|
|
63
|
+
else:
|
|
64
|
+
return False, trans_map[prop_data["baseType"]]
|
|
65
|
+
return False, prop_data["$ref"].replace("#/defs/", "")
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def readonly_json(prop_data):
|
|
69
|
+
return str(prop_data.get("readOnly", False)).lower()
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def get_name(intf):
|
|
73
|
+
intfs = intf.split(".")
|
|
74
|
+
if intfs[-1] == "Default":
|
|
75
|
+
return intfs[-2] + intfs[-1]
|
|
76
|
+
return intfs[-1]
|
|
77
|
+
|
|
78
|
+
@staticmethod
|
|
79
|
+
def force_to_colon(path):
|
|
80
|
+
return path.replace("${", ":").replace("}", "")
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def get_method_description(intf_name, method_data):
|
|
84
|
+
pattern = r'^bmc\..*\.(Debug|Release)\..*$'
|
|
85
|
+
if not re.match(pattern, intf_name):
|
|
86
|
+
return ""
|
|
87
|
+
if "displayDescription" in method_data:
|
|
88
|
+
return ', [=[' + method_data["displayDescription"] + ']=]'
|
|
89
|
+
return ""
|
|
90
|
+
|
|
91
|
+
def recover_path(self, class_name, class_require):
|
|
92
|
+
class_data = class_require[class_name]
|
|
93
|
+
path = self.force_to_colon(class_data['path'])
|
|
94
|
+
if 'parent' not in class_data['data']:
|
|
95
|
+
return path
|
|
96
|
+
return path.replace(':parent/', self.recover_path(class_data['data']['parent'], class_require) + ':parent/')
|
|
97
|
+
|
|
98
|
+
def get_path(self, class_name, class_require):
|
|
99
|
+
path = self.recover_path(class_name, class_require)
|
|
100
|
+
return Utils.deduplicate_path(self, path)
|
|
101
|
+
|
|
102
|
+
def is_dbus_base_type(self, name):
|
|
103
|
+
return name in self.JSON_TYPE_TO_DBUS.values()
|
|
104
|
+
|
|
105
|
+
def get_types_in_defs(self, defs, struct):
|
|
106
|
+
is_dict = False
|
|
107
|
+
if "key" in defs[struct] and "value" in defs[struct]:
|
|
108
|
+
is_dict = True
|
|
109
|
+
dbus_types = "a{" if is_dict else "("
|
|
110
|
+
for prop in defs[struct].values():
|
|
111
|
+
if isinstance(prop, int):
|
|
112
|
+
return 'i'
|
|
113
|
+
elif isinstance(prop, str):
|
|
114
|
+
return 's'
|
|
115
|
+
repeated, dbus_type = self.transform_types(
|
|
116
|
+
prop, self.JSON_TYPE_TO_DBUS)
|
|
117
|
+
dbus_types += "a" if repeated else ""
|
|
118
|
+
dbus_types += (
|
|
119
|
+
dbus_type
|
|
120
|
+
if self.is_dbus_base_type(dbus_type)
|
|
121
|
+
else self.get_types_in_defs(defs, dbus_type)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return dbus_types + ("}" if is_dict else ")")
|
|
125
|
+
|
|
126
|
+
def do_type_to_lua_json(self, prop_data):
|
|
127
|
+
repeated, lua_type = self.transform_types(
|
|
128
|
+
prop_data, self.JSON_TYPE_TO_LUA)
|
|
129
|
+
return lua_type + "[]" if repeated else lua_type
|
|
130
|
+
|
|
131
|
+
def do_type_to_dbus_json(self, root, prop):
|
|
132
|
+
dbus_types = ""
|
|
133
|
+
repeated, dbus_type = self.transform_types(
|
|
134
|
+
prop, self.JSON_TYPE_TO_DBUS)
|
|
135
|
+
dbus_types += "a" if repeated else ""
|
|
136
|
+
dbus_types += (
|
|
137
|
+
dbus_type
|
|
138
|
+
if self.is_dbus_base_type(dbus_type)
|
|
139
|
+
else self.get_types_in_defs(root["defs"], dbus_type)
|
|
140
|
+
)
|
|
141
|
+
return dbus_types
|
|
142
|
+
|
|
143
|
+
def do_types_to_dbus_json(self, root, struct_data, name):
|
|
144
|
+
dbus_types = ""
|
|
145
|
+
if name not in struct_data:
|
|
146
|
+
return dbus_types
|
|
147
|
+
|
|
148
|
+
for prop in struct_data[name].values():
|
|
149
|
+
repeated, dbus_type = self.transform_types(
|
|
150
|
+
prop, self.JSON_TYPE_TO_DBUS)
|
|
151
|
+
dbus_types += "a" if repeated else ""
|
|
152
|
+
dbus_types += (
|
|
153
|
+
dbus_type
|
|
154
|
+
if self.is_dbus_base_type(dbus_type)
|
|
155
|
+
else self.get_types_in_defs(root["defs"], dbus_type)
|
|
156
|
+
)
|
|
157
|
+
return dbus_types
|
|
158
|
+
|
|
159
|
+
def convert_dict_to_lua_table(self, msg, ):
|
|
160
|
+
string = '{\n'
|
|
161
|
+
i = 1
|
|
162
|
+
for (prop, value) in msg.items():
|
|
163
|
+
if prop == "pattern":
|
|
164
|
+
string += "['" + prop + "'] = [=[" + value + "]=],\n"
|
|
165
|
+
elif prop == "validator":
|
|
166
|
+
string += "['" + prop + "'] = " + value + ",\n"
|
|
167
|
+
else:
|
|
168
|
+
string += "['" + prop + "'] = " + \
|
|
169
|
+
self.convert_to_lua(value) + ",\n"
|
|
170
|
+
i += 1
|
|
171
|
+
return string + '}'
|
|
172
|
+
|
|
173
|
+
def convert_to_lua(self, value):
|
|
174
|
+
if isinstance(value, str):
|
|
175
|
+
return "'" + value + "'"
|
|
176
|
+
elif isinstance(value, bool):
|
|
177
|
+
return 'true' if value else 'false'
|
|
178
|
+
elif isinstance(value, int) or isinstance(value, float):
|
|
179
|
+
return str(value)
|
|
180
|
+
elif isinstance(value, dict):
|
|
181
|
+
return self.convert_dict_to_lua_table(value)
|
|
182
|
+
elif isinstance(value, list):
|
|
183
|
+
string = "{"
|
|
184
|
+
for val in value:
|
|
185
|
+
string += self.convert_to_lua(val) + ","
|
|
186
|
+
string += "}"
|
|
187
|
+
return string
|
|
188
|
+
raise Exception("值类型无效")
|
|
189
|
+
|
|
190
|
+
def default_json(self, prop_data):
|
|
191
|
+
if 'default' not in prop_data:
|
|
192
|
+
return 'nil'
|
|
193
|
+
|
|
194
|
+
default_val = prop_data['default']
|
|
195
|
+
|
|
196
|
+
if 'baseType' not in prop_data:
|
|
197
|
+
return self.convert_to_lua(default_val)
|
|
198
|
+
|
|
199
|
+
if prop_data['baseType'] == 'Enum':
|
|
200
|
+
return 'utils.unpack_enum(true, E' + prop_data['$ref'].replace('#/defs/', '') + "." + default_val + ")"
|
|
201
|
+
|
|
202
|
+
if prop_data['baseType'] == 'Array' and \
|
|
203
|
+
'baseType' in prop_data['items'] and prop_data['items']['baseType'] == 'Enum':
|
|
204
|
+
result = []
|
|
205
|
+
for default in default_val:
|
|
206
|
+
result.append('utils.unpack_enum(true, E' +
|
|
207
|
+
prop_data['items']['$ref'].replace('#/defs/', '') + "." + default + ")")
|
|
208
|
+
return '{' + ",".join(result) + '}'
|
|
209
|
+
|
|
210
|
+
return self.convert_to_lua(default_val)
|
|
211
|
+
|
|
212
|
+
def options_json(self, prop_data):
|
|
213
|
+
if 'options' not in prop_data:
|
|
214
|
+
return 'nil'
|
|
215
|
+
return self.convert_to_lua(prop_data['options'])
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
from dto.options import Options
|
|
14
|
+
from render_utils.base import Base
|
|
15
|
+
from render_utils.factory import Factory
|
|
16
|
+
from render_utils.utils_message_lua import UtilsMessageLua
|
|
17
|
+
from render_utils.validate_lua import ValidateLua
|
|
18
|
+
from render_utils.mdb_register import MdbRegister
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MessageUtils(Base, ValidateLua, UtilsMessageLua, MdbRegister):
|
|
22
|
+
def __init__(self, data: dict, options: Options):
|
|
23
|
+
super().__init__(data, options)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Factory().register("message.lua.mako", MessageUtils)
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
4
|
+
# openUBMC is licensed under Mulan PSL v2.
|
|
5
|
+
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
6
|
+
# You may obtain a copy of Mulan PSL v2 at:
|
|
7
|
+
# http://license.coscl.org.cn/MulanPSL2
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
9
|
+
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
10
|
+
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
11
|
+
# See the Mulan PSL v2 for more details.
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
from utils import Utils
|
|
16
|
+
from dto.options import Options
|
|
17
|
+
from render_utils.base import Base
|
|
18
|
+
from render_utils.factory import Factory
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MessagesLuaUtils(Base, Utils):
|
|
22
|
+
LOG_MAP = {
|
|
23
|
+
"OK": "log.INFO",
|
|
24
|
+
"Warning": "log.WARN",
|
|
25
|
+
"Critical": "log.ERROR"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def __init__(self, data: dict, options: Options):
|
|
29
|
+
super().__init__(data, options=options)
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def match_placeholders(msg):
|
|
33
|
+
return sorted(set(int(v) for v in re.findall(r"%(\d+)", msg)))
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def format_hex(data):
|
|
37
|
+
return "0x%02X" % data
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def format(msg):
|
|
41
|
+
return re.sub(r"%(\d+)", r"%s", re.sub(r'%\D', lambda x: '%%' + x.group(0)[1:], msg))
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def get_app_name(code):
|
|
45
|
+
name = code.split(".")
|
|
46
|
+
if name == -1:
|
|
47
|
+
return code
|
|
48
|
+
return name[1]
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def get_http_response(root, err):
|
|
52
|
+
ret = -1
|
|
53
|
+
if 'HttpStatusCode' in err:
|
|
54
|
+
ret = err['HttpStatusCode']
|
|
55
|
+
elif 'HttpStatusCode' in root:
|
|
56
|
+
ret = root['HttpStatusCode']
|
|
57
|
+
if ret == -1: # 没有配置则返回nil
|
|
58
|
+
return 'nil'
|
|
59
|
+
return str(ret)
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def get_redfish_response(root, err):
|
|
63
|
+
if 'RedfishResponse' in err and len(err['RedfishResponse']) > 0:
|
|
64
|
+
return "\"{}\"".format(err['RedfishResponse'])
|
|
65
|
+
if 'RedfishResponse' in root and len(root['RedfishResponse']) > 0:
|
|
66
|
+
return "\"{}\"".format(root['RedfishResponse'])
|
|
67
|
+
return 'nil'
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def ret_check_ipmi(res):
|
|
71
|
+
generic_completion_codes = [
|
|
72
|
+
0x00,
|
|
73
|
+
0xC0,
|
|
74
|
+
0xC1,
|
|
75
|
+
0xC2,
|
|
76
|
+
0xC3,
|
|
77
|
+
0xC4,
|
|
78
|
+
0xC5,
|
|
79
|
+
0xC6,
|
|
80
|
+
0xC7,
|
|
81
|
+
0xC8,
|
|
82
|
+
0xC9,
|
|
83
|
+
0xCA,
|
|
84
|
+
0xCB,
|
|
85
|
+
0xCC,
|
|
86
|
+
0xCD,
|
|
87
|
+
0xCE,
|
|
88
|
+
0xCF,
|
|
89
|
+
0xD0,
|
|
90
|
+
0xD1,
|
|
91
|
+
0xD2,
|
|
92
|
+
0xD3,
|
|
93
|
+
0xD4,
|
|
94
|
+
0xD5,
|
|
95
|
+
0xD6,
|
|
96
|
+
0xFF,
|
|
97
|
+
]
|
|
98
|
+
device_specific_codes = range(0x01, 0x7E + 1)
|
|
99
|
+
command_specific_codes = range(0x80, 0xBE + 1)
|
|
100
|
+
if res == -1: # 没有配置则返回nil
|
|
101
|
+
return "nil"
|
|
102
|
+
valid = res in generic_completion_codes or res in device_specific_codes \
|
|
103
|
+
or res in command_specific_codes
|
|
104
|
+
if not valid: # 不在规定的返回码范围中则抛错
|
|
105
|
+
raise Exception("无效的 ipmi 响应: 0x%02X" % res)
|
|
106
|
+
return "0x%02X" % res
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def get_ipmi_response(err):
|
|
110
|
+
res = 0
|
|
111
|
+
if "IpmiCompletionCode" in err:
|
|
112
|
+
res = int(err["IpmiCompletionCode"], 16)
|
|
113
|
+
|
|
114
|
+
return MessagesLuaUtils.ret_check_ipmi(res)
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def get_backtrace_level(root, err):
|
|
118
|
+
ret = 0
|
|
119
|
+
if "TraceDepth" in err:
|
|
120
|
+
ret = err["TraceDepth"]
|
|
121
|
+
elif "TraceDepth" in root:
|
|
122
|
+
ret = root["TraceDepth"]
|
|
123
|
+
if ret > 5: # 层级不超过5层
|
|
124
|
+
return 5
|
|
125
|
+
return ret
|
|
126
|
+
|
|
127
|
+
@staticmethod
|
|
128
|
+
def get_severity_err(err):
|
|
129
|
+
if "Severity" in err and err["Severity"] in MessagesLuaUtils.LOG_MAP:
|
|
130
|
+
return MessagesLuaUtils.LOG_MAP.get(err["Severity"])
|
|
131
|
+
return "log.DEBUG" # 不在log_map映射表中则默认返回debug
|
|
132
|
+
|
|
133
|
+
@staticmethod
|
|
134
|
+
def get_severity(root, err):
|
|
135
|
+
if 'Severity' in err and err['Severity'] in MessagesLuaUtils.LOG_MAP:
|
|
136
|
+
return MessagesLuaUtils.LOG_MAP.get(err['Severity'])
|
|
137
|
+
if 'Severity' in root and root['Severity'] in MessagesLuaUtils.LOG_MAP:
|
|
138
|
+
return MessagesLuaUtils.LOG_MAP.get(root['Severity'])
|
|
139
|
+
return 'log.DEBUG' # 不在log_map映射表中则默认返回debug
|
|
140
|
+
|
|
141
|
+
def error_params(self, err):
|
|
142
|
+
params = self.params(err["Message"])
|
|
143
|
+
if len(params) == 0:
|
|
144
|
+
return ""
|
|
145
|
+
return f", {params}"
|
|
146
|
+
|
|
147
|
+
def params(self, msg):
|
|
148
|
+
placeholders = self.match_placeholders(msg)
|
|
149
|
+
if len(placeholders) == 0:
|
|
150
|
+
return ""
|
|
151
|
+
elif len(placeholders) != placeholders[len(placeholders) - 1]:
|
|
152
|
+
raise RuntimeError("无效错误信息: `{}`, 无法匹配到占位符".format(msg))
|
|
153
|
+
return ", ".join(["val" + str(v) for v in placeholders])
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
Factory().register("messages.lua.mako", MessagesLuaUtils)
|