blob: 8cd37e6311c8848f5b4e77142798d77fb012d9fe [file] [log] [blame]
Nan Zhou313c1b72022-03-25 11:47:55 -07001#!/usr/bin/env python3
Ed Tanous683f7272018-07-26 12:47:19 -07002import requests
3import zipfile
4from io import BytesIO
5import os
Ed Tanous683f7272018-07-26 12:47:19 -07006from collections import OrderedDict
Ed Tanous683f7272018-07-26 12:47:19 -07007import shutil
8import json
9
Ed Tanous118b1c72018-09-13 13:45:51 -070010import xml.etree.ElementTree as ET
11
Sui Chen141d9432022-02-03 22:01:27 -080012VERSION = "DSP8010_2021.4"
Ed Tanouscb103132019-10-08 11:34:22 -070013
Ed Tanous81d523a2022-05-25 12:00:51 -070014WARNING = '''/****************************************************************
15 * READ THIS WARNING FIRST
16 * This is an auto-generated header which contains definitions
17 * for Redfish DMTF defined schemas.
18 * DO NOT modify this registry outside of running the
19 * update_schemas.py script. The definitions contained within
20 * this file are owned by DMTF. Any modifications to these files
21 * should be first pushed to the relevant registry in the DMTF
22 * github organization.
23 ***************************************************************/'''
24
Gunnar Mills349a2ac2021-01-20 22:29:16 -060025# To use a new schema, add to list and rerun tool
26include_list = [
27 'AccountService',
28 'ActionInfo',
29 'Assembly',
30 'AttributeRegistry',
31 'Bios',
Shantappa Teekappanavar9c929be2021-12-16 19:02:52 -060032 'Cable',
33 'CableCollection',
Gunnar Mills349a2ac2021-01-20 22:29:16 -060034 'Certificate',
35 'CertificateCollection',
36 'CertificateLocations',
37 'CertificateService',
38 'Chassis',
39 'ChassisCollection',
40 'ComputerSystem',
41 'ComputerSystemCollection',
42 'Drive',
43 'DriveCollection',
44 'EthernetInterface',
45 'EthernetInterfaceCollection',
46 'Event',
47 'EventDestination',
48 'EventDestinationCollection',
49 'EventService',
50 'IPAddresses',
51 'JsonSchemaFile',
Ed Tanousf395daa2021-08-02 08:56:24 -070052 'JsonSchemaFileCollection', # redfish/v1/JsonSchemas
Gunnar Mills349a2ac2021-01-20 22:29:16 -060053 'LogEntry',
54 'LogEntryCollection',
55 'LogService',
56 'LogServiceCollection',
57 'Manager',
58 'ManagerAccount',
59 'ManagerAccountCollection',
60 'ManagerCollection',
Sui Chen23952512022-02-08 13:49:36 -080061 'ManagerDiagnosticData',
Gunnar Mills349a2ac2021-01-20 22:29:16 -060062 'ManagerNetworkProtocol',
63 'Memory',
64 'MemoryCollection',
65 'Message',
66 'MessageRegistry',
67 'MessageRegistryCollection',
68 'MessageRegistryFile',
69 'MessageRegistryFileCollection',
70 'MetricDefinition',
71 'MetricDefinitionCollection',
72 'MetricReport',
73 'MetricReportCollection',
74 'MetricReportDefinition',
75 'MetricReportDefinitionCollection',
76 'OperatingConfig',
77 'OperatingConfigCollection',
78 'PCIeDevice',
79 'PCIeDeviceCollection',
80 'PCIeFunction',
81 'PCIeFunctionCollection',
sunitakx71b861b2022-01-18 11:05:05 +000082 'PhysicalContext',
Ed Tanous08eca732022-06-09 14:32:18 -070083 'PCIeSlots',
Gunnar Mills349a2ac2021-01-20 22:29:16 -060084 'Power',
Ed Tanousf395daa2021-08-02 08:56:24 -070085 'Privileges', # Used in Role
Gunnar Mills349a2ac2021-01-20 22:29:16 -060086 'Processor',
87 'ProcessorCollection',
88 'RedfishError',
89 'RedfishExtensions',
90 'Redundancy',
91 'Resource',
92 'Role',
93 'RoleCollection',
94 'Sensor',
95 'SensorCollection',
96 'ServiceRoot',
97 'Session',
98 'SessionCollection',
99 'SessionService',
100 'Settings',
101 'SoftwareInventory',
102 'SoftwareInventoryCollection',
103 'Storage',
104 'StorageCollection',
105 'StorageController',
106 'StorageControllerCollection',
107 'Task',
108 'TaskCollection',
109 'TaskService',
110 'TelemetryService',
111 'Thermal',
Lukasz Kazmierczak1b7e6962021-08-02 13:40:27 +0200112 'Triggers',
Lukasz Kazmierczak07148cf2021-08-02 11:08:53 +0200113 'TriggersCollection',
Gunnar Mills349a2ac2021-01-20 22:29:16 -0600114 'UpdateService',
115 'VLanNetworkInterfaceCollection',
116 'VLanNetworkInterface',
117 'VirtualMedia',
118 'VirtualMediaCollection',
119 'odata',
120 'odata-v4',
121 'redfish-error',
122 'redfish-payload-annotations',
123 'redfish-schema',
124 'redfish-schema-v1',
125]
126
Ed Tanous683f7272018-07-26 12:47:19 -0700127SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
128
129proxies = {
130 'https': os.environ.get("https_proxy", None)
131}
132
Ed Tanouscb103132019-10-08 11:34:22 -0700133r = requests.get(
134 'https://www.dmtf.org/sites/default/files/standards/documents/' +
135 VERSION +
136 '.zip',
137 proxies=proxies)
Ed Tanous683f7272018-07-26 12:47:19 -0700138
139r.raise_for_status()
140
Ed Tanous81d523a2022-05-25 12:00:51 -0700141
Ed Tanous683f7272018-07-26 12:47:19 -0700142static_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "static",
143 "redfish", "v1"))
144
Ed Tanous81d523a2022-05-25 12:00:51 -0700145
146cpp_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "redfish-core",
147 "include"))
148
149
Ed Tanous683f7272018-07-26 12:47:19 -0700150schema_path = os.path.join(static_path, "schema")
151json_schema_path = os.path.join(static_path, "JsonSchemas")
Ed Tanous118b1c72018-09-13 13:45:51 -0700152metadata_index_path = os.path.join(static_path, "$metadata", "index.xml")
Ed Tanous683f7272018-07-26 12:47:19 -0700153
154zipBytesIO = BytesIO(r.content)
155zip_ref = zipfile.ZipFile(zipBytesIO)
156
157# Remove the old files
Szymon Dompked699cf92021-08-11 19:46:31 +0200158skip_prefixes = ('Oem')
Ed Tanous683f7272018-07-26 12:47:19 -0700159if os.path.exists(schema_path):
Szymon Dompked699cf92021-08-11 19:46:31 +0200160 files = [os.path.join(schema_path, f) for f in os.listdir(schema_path)
161 if not f.startswith(skip_prefixes)]
James Feistaee8d842018-09-10 16:07:40 -0700162 for f in files:
163 os.remove(f)
Ed Tanous683f7272018-07-26 12:47:19 -0700164if os.path.exists(json_schema_path):
Szymon Dompked699cf92021-08-11 19:46:31 +0200165 files = [os.path.join(json_schema_path, f) for f in
166 os.listdir(json_schema_path) if not f.startswith(skip_prefixes)]
Ed Tanous118b1c72018-09-13 13:45:51 -0700167 for f in files:
168 if (os.path.isfile(f)):
169 os.remove(f)
170 else:
171 shutil.rmtree(f)
172os.remove(metadata_index_path)
Ed Tanous683f7272018-07-26 12:47:19 -0700173
Ed Tanous118b1c72018-09-13 13:45:51 -0700174if not os.path.exists(schema_path):
175 os.makedirs(schema_path)
176if not os.path.exists(json_schema_path):
177 os.makedirs(json_schema_path)
Ed Tanous683f7272018-07-26 12:47:19 -0700178
Ed Tanous118b1c72018-09-13 13:45:51 -0700179with open(metadata_index_path, 'w') as metadata_index:
180
181 metadata_index.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
182 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700183 "<edmx:Edmx xmlns:edmx="
184 "\"http://docs.oasis-open.org/odata/ns/edmx\""
185 " Version=\"4.0\">\n")
Ed Tanous118b1c72018-09-13 13:45:51 -0700186
187 for zip_filepath in zip_ref.namelist():
Gunnar Mills60c922d2021-12-01 09:28:53 -0600188 if zip_filepath.startswith('csdl/') and \
Ed Tanousf395daa2021-08-02 08:56:24 -0700189 (zip_filepath != VERSION + "/csdl/") and \
Gunnar Mills60c922d2021-12-01 09:28:53 -0600190 (zip_filepath != "csdl/"):
Ed Tanous118b1c72018-09-13 13:45:51 -0700191 filename = os.path.basename(zip_filepath)
Gunnar Mills349a2ac2021-01-20 22:29:16 -0600192
193 # filename looks like Zone_v1.xml
194 filenamesplit = filename.split("_")
195 if filenamesplit[0] not in include_list:
196 print("excluding schema: " + filename)
197 continue
198
Ed Tanousf395daa2021-08-02 08:56:24 -0700199 with open(os.path.join(schema_path, filename), 'wb') as schema_out:
Ed Tanous118b1c72018-09-13 13:45:51 -0700200
201 metadata_index.write(
Ed Tanouscb103132019-10-08 11:34:22 -0700202 " <edmx:Reference Uri=\"/redfish/v1/schema/" +
203 filename +
204 "\">\n")
Ed Tanous118b1c72018-09-13 13:45:51 -0700205
206 content = zip_ref.read(zip_filepath)
Ed Tanouscb103132019-10-08 11:34:22 -0700207 content = content.replace(b'\r\n', b'\n')
Ed Tanous118b1c72018-09-13 13:45:51 -0700208 xml_root = ET.fromstring(content)
Ed Tanousf395daa2021-08-02 08:56:24 -0700209 edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
Szymon Dompked699cf92021-08-11 19:46:31 +0200210 edm = "{http://docs.oasis-open.org/odata/ns/edm}"
Ed Tanous118b1c72018-09-13 13:45:51 -0700211 for edmx_child in xml_root:
Ed Tanousf395daa2021-08-02 08:56:24 -0700212 if edmx_child.tag == edmx + "DataServices":
Ed Tanous118b1c72018-09-13 13:45:51 -0700213 for data_child in edmx_child:
Szymon Dompked699cf92021-08-11 19:46:31 +0200214 if data_child.tag == edm + "Schema":
Ed Tanous118b1c72018-09-13 13:45:51 -0700215 namespace = data_child.attrib["Namespace"]
216 if namespace.startswith("RedfishExtensions"):
217 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700218 " "
219 "<edmx:Include Namespace=\"" +
220 namespace +
221 "\" Alias=\"Redfish\"/>\n"
222 )
Ed Tanous118b1c72018-09-13 13:45:51 -0700223
224 else:
225 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700226 " "
227 "<edmx:Include Namespace=\""
228 + namespace + "\"/>\n"
229 )
230 schema_out.write(content)
Ed Tanous118b1c72018-09-13 13:45:51 -0700231 metadata_index.write(" </edmx:Reference>\n")
232
Ed Tanousf395daa2021-08-02 08:56:24 -0700233 metadata_index.write(" <edmx:DataServices>\n"
234 " <Schema "
235 "xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" "
236 "Namespace=\"Service\">\n"
237 " <EntityContainer Name=\"Service\" "
238 "Extends=\"ServiceRoot.v1_0_0.ServiceContainer\"/>\n"
239 " </Schema>\n"
240 " </edmx:DataServices>\n"
241 )
Ed Tanouscb103132019-10-08 11:34:22 -0700242 # TODO:Issue#32 There's a bug in the script that currently deletes this
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500243 # schema (because it's an OEM schema). Because it's the only six, and we
Ed Tanouscb103132019-10-08 11:34:22 -0700244 # don't update schemas very often, we just manually fix it. Need a
245 # permanent fix to the script.
246 metadata_index.write(
247 " <edmx:Reference Uri=\"/redfish/v1/schema/OemManager_v1.xml\">\n")
Marri Devender Raod45d2d02019-01-21 10:11:34 -0600248 metadata_index.write(" <edmx:Include Namespace=\"OemManager\"/>\n")
249 metadata_index.write(" </edmx:Reference>\n")
Gunnar Mills20778992020-02-06 16:36:47 -0600250
251 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700252 " <edmx:Reference Uri=\""
253 "/redfish/v1/schema/OemComputerSystem_v1.xml\">\n")
254 metadata_index.write(
255 " <edmx:Include Namespace=\"OemComputerSystem\"/>\n")
Gunnar Mills20778992020-02-06 16:36:47 -0600256 metadata_index.write(" </edmx:Reference>\n")
257
258 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700259 " <edmx:Reference Uri=\""
260 "/redfish/v1/schema/OemVirtualMedia_v1.xml\">\n")
261 metadata_index.write(
262 " <edmx:Include Namespace=\"OemVirtualMedia\"/>\n")
263 metadata_index.write(
264 " <edmx:Include Namespace=\"OemVirtualMedia.v1_0_0\"/>\n")
Gunnar Mills20778992020-02-06 16:36:47 -0600265 metadata_index.write(" </edmx:Reference>\n")
266
267 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700268 " <edmx:Reference Uri=\""
269 "/redfish/v1/schema/OemAccountService_v1.xml\">\n")
270 metadata_index.write(
271 " <edmx:Include Namespace=\"OemAccountService\"/>\n")
272 metadata_index.write(
273 " <edmx:Include Namespace=\"OemAccountService.v1_0_0\"/>\n")
Gunnar Mills20778992020-02-06 16:36:47 -0600274 metadata_index.write(" </edmx:Reference>\n")
275
Ravi Tejae7d68c32020-03-15 13:30:41 -0500276 metadata_index.write(
Sunitha Harish9dc50742020-05-11 00:10:20 -0500277 " <edmx:Reference Uri=\"/redfish/v1/schema/OemSession_v1.xml\">\n")
278 metadata_index.write(" <edmx:Include Namespace=\"OemSession\"/>\n")
Ed Tanousf395daa2021-08-02 08:56:24 -0700279 metadata_index.write(
280 " <edmx:Include Namespace=\"OemSession.v1_0_0\"/>\n")
Sunitha Harish9dc50742020-05-11 00:10:20 -0500281 metadata_index.write(" </edmx:Reference>\n")
282
Ed Tanous118b1c72018-09-13 13:45:51 -0700283 metadata_index.write("</edmx:Edmx>\n")
Ed Tanous683f7272018-07-26 12:47:19 -0700284
285schema_files = {}
286for zip_filepath in zip_ref.namelist():
Gunnar Mills60c922d2021-12-01 09:28:53 -0600287 if zip_filepath.startswith(os.path.join('json-schema/')):
Ed Tanous683f7272018-07-26 12:47:19 -0700288 filename = os.path.basename(zip_filepath)
289 filenamesplit = filename.split(".")
Gunnar Mills349a2ac2021-01-20 22:29:16 -0600290
291 # exclude schemas again to save flash space
292 if filenamesplit[0] not in include_list:
293 continue
294
Ed Tanous683f7272018-07-26 12:47:19 -0700295 if len(filenamesplit) == 3:
296 thisSchemaVersion = schema_files.get(filenamesplit[0], None)
Ed Tanouscb103132019-10-08 11:34:22 -0700297 if thisSchemaVersion is None:
Ed Tanous683f7272018-07-26 12:47:19 -0700298 schema_files[filenamesplit[0]] = filenamesplit[1]
299 else:
300 # need to see if we're a newer version.
301 if list(map(int, filenamesplit[1][1:].split("_"))) > list(map(
302 int, thisSchemaVersion[1:].split("_"))):
303 schema_files[filenamesplit[0]] = filenamesplit[1]
304
305
306for schema, version in schema_files.items():
307 basename = schema + "." + version + ".json"
Gunnar Mills60c922d2021-12-01 09:28:53 -0600308 zip_filepath = os.path.join("json-schema", basename)
Ed Tanous683f7272018-07-26 12:47:19 -0700309 schemadir = os.path.join(json_schema_path, schema)
310 os.makedirs(schemadir)
Ed Tanous118b1c72018-09-13 13:45:51 -0700311
Ed Tanous118b1c72018-09-13 13:45:51 -0700312 with open(os.path.join(schemadir, schema + ".json"), 'wb') as schema_file:
Ed Tanouscb103132019-10-08 11:34:22 -0700313 schema_file.write(zip_ref.read(zip_filepath).replace(b'\r\n', b'\n'))
Ed Tanous683f7272018-07-26 12:47:19 -0700314
Ed Tanous81d523a2022-05-25 12:00:51 -0700315with open(os.path.join(cpp_path, "schemas.hpp"), 'w') as hpp_file:
316 hpp_file.write(
317 "#pragma once\n"
318 "{WARNING}\n"
319 "// clang-format off\n"
320 "\n"
321 "namespace redfish\n"
322 "{{\n"
323 " constexpr std::array schemas {{\n"
324 .format(
325 WARNING=WARNING))
326 for schema_file in schema_files:
327 hpp_file.write(" \"{}\",\n".format(schema_file))
Ed Tanous683f7272018-07-26 12:47:19 -0700328
Ed Tanous81d523a2022-05-25 12:00:51 -0700329 hpp_file.write(
330 " };\n"
331 "}\n"
332 )
Ed Tanous683f7272018-07-26 12:47:19 -0700333
334zip_ref.close()