blob: 80208ad20240fad0e7963589992c55ffe251ab02 [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 Tanous27747912022-09-23 12:50:08 -070014WARNING = """/****************************************************************
Ed Tanous81d523a2022-05-25 12:00:51 -070015 * 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.
Ed Tanous27747912022-09-23 12:50:08 -070023 ***************************************************************/"""
Ed Tanous81d523a2022-05-25 12:00:51 -070024
Gunnar Mills349a2ac2021-01-20 22:29:16 -060025# To use a new schema, add to list and rerun tool
26include_list = [
Ed Tanous27747912022-09-23 12:50:08 -070027 "AccountService",
28 "ActionInfo",
29 "Assembly",
30 "AttributeRegistry",
31 "Bios",
32 "Cable",
33 "CableCollection",
34 "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",
52 "JsonSchemaFileCollection", # redfish/v1/JsonSchemas
53 "LogEntry",
54 "LogEntryCollection",
55 "LogService",
56 "LogServiceCollection",
57 "Manager",
58 "ManagerAccount",
59 "ManagerAccountCollection",
60 "ManagerCollection",
61 "ManagerDiagnosticData",
62 "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",
82 "PhysicalContext",
83 "PCIeSlots",
84 "Power",
85 "Privileges", # Used in Role
86 "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",
112 "ThermalSubsystem",
113 "Triggers",
114 "TriggersCollection",
115 "UpdateService",
116 "VLanNetworkInterfaceCollection",
117 "VLanNetworkInterface",
118 "VirtualMedia",
119 "VirtualMediaCollection",
120 "odata",
121 "odata-v4",
122 "redfish-error",
123 "redfish-payload-annotations",
124 "redfish-schema",
125 "redfish-schema-v1",
Gunnar Mills349a2ac2021-01-20 22:29:16 -0600126]
127
Ed Tanous683f7272018-07-26 12:47:19 -0700128SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
129
Ed Tanous27747912022-09-23 12:50:08 -0700130proxies = {"https": os.environ.get("https_proxy", None)}
Ed Tanous683f7272018-07-26 12:47:19 -0700131
Ed Tanouscb103132019-10-08 11:34:22 -0700132r = requests.get(
Ed Tanous27747912022-09-23 12:50:08 -0700133 "https://www.dmtf.org/sites/default/files/standards/documents/"
134 + VERSION
135 + ".zip",
136 proxies=proxies,
137)
Ed Tanous683f7272018-07-26 12:47:19 -0700138
139r.raise_for_status()
140
Ed Tanous81d523a2022-05-25 12:00:51 -0700141
Ed Tanous27747912022-09-23 12:50:08 -0700142static_path = os.path.realpath(
143 os.path.join(SCRIPT_DIR, "..", "static", "redfish", "v1")
144)
Ed Tanous683f7272018-07-26 12:47:19 -0700145
Ed Tanous81d523a2022-05-25 12:00:51 -0700146
Ed Tanous27747912022-09-23 12:50:08 -0700147cpp_path = os.path.realpath(
148 os.path.join(SCRIPT_DIR, "..", "redfish-core", "include")
149)
Ed Tanous81d523a2022-05-25 12:00:51 -0700150
151
Ed Tanous683f7272018-07-26 12:47:19 -0700152schema_path = os.path.join(static_path, "schema")
153json_schema_path = os.path.join(static_path, "JsonSchemas")
Ed Tanous118b1c72018-09-13 13:45:51 -0700154metadata_index_path = os.path.join(static_path, "$metadata", "index.xml")
Ed Tanous683f7272018-07-26 12:47:19 -0700155
156zipBytesIO = BytesIO(r.content)
157zip_ref = zipfile.ZipFile(zipBytesIO)
158
159# Remove the old files
Ed Tanous27747912022-09-23 12:50:08 -0700160skip_prefixes = "Oem"
Ed Tanous683f7272018-07-26 12:47:19 -0700161if os.path.exists(schema_path):
Ed Tanous27747912022-09-23 12:50:08 -0700162 files = [
163 os.path.join(schema_path, f)
164 for f in os.listdir(schema_path)
165 if not f.startswith(skip_prefixes)
166 ]
James Feistaee8d842018-09-10 16:07:40 -0700167 for f in files:
168 os.remove(f)
Ed Tanous683f7272018-07-26 12:47:19 -0700169if os.path.exists(json_schema_path):
Ed Tanous27747912022-09-23 12:50:08 -0700170 files = [
171 os.path.join(json_schema_path, f)
172 for f in os.listdir(json_schema_path)
173 if not f.startswith(skip_prefixes)
174 ]
Ed Tanous118b1c72018-09-13 13:45:51 -0700175 for f in files:
Ed Tanous27747912022-09-23 12:50:08 -0700176 if os.path.isfile(f):
Ed Tanous118b1c72018-09-13 13:45:51 -0700177 os.remove(f)
178 else:
179 shutil.rmtree(f)
180os.remove(metadata_index_path)
Ed Tanous683f7272018-07-26 12:47:19 -0700181
Ed Tanous118b1c72018-09-13 13:45:51 -0700182if not os.path.exists(schema_path):
183 os.makedirs(schema_path)
184if not os.path.exists(json_schema_path):
185 os.makedirs(json_schema_path)
Ed Tanous683f7272018-07-26 12:47:19 -0700186
Ed Tanous27747912022-09-23 12:50:08 -0700187with open(metadata_index_path, "w") as metadata_index:
Ed Tanous118b1c72018-09-13 13:45:51 -0700188
Ed Tanous27747912022-09-23 12:50:08 -0700189 metadata_index.write('<?xml version="1.0" encoding="UTF-8"?>\n')
Ed Tanous118b1c72018-09-13 13:45:51 -0700190 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700191 "<edmx:Edmx xmlns:edmx="
Ed Tanous27747912022-09-23 12:50:08 -0700192 '"http://docs.oasis-open.org/odata/ns/edmx"'
193 ' Version="4.0">\n'
194 )
Ed Tanous118b1c72018-09-13 13:45:51 -0700195
196 for zip_filepath in zip_ref.namelist():
Ed Tanous27747912022-09-23 12:50:08 -0700197 if (
198 zip_filepath.startswith("csdl/")
199 and (zip_filepath != VERSION + "/csdl/")
200 and (zip_filepath != "csdl/")
201 ):
Ed Tanous118b1c72018-09-13 13:45:51 -0700202 filename = os.path.basename(zip_filepath)
Gunnar Mills349a2ac2021-01-20 22:29:16 -0600203
204 # filename looks like Zone_v1.xml
205 filenamesplit = filename.split("_")
206 if filenamesplit[0] not in include_list:
207 print("excluding schema: " + filename)
208 continue
209
Ed Tanous27747912022-09-23 12:50:08 -0700210 with open(os.path.join(schema_path, filename), "wb") as schema_out:
Ed Tanous118b1c72018-09-13 13:45:51 -0700211
212 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700213 ' <edmx:Reference Uri="/redfish/v1/schema/'
214 + filename
215 + '">\n'
216 )
Ed Tanous118b1c72018-09-13 13:45:51 -0700217
218 content = zip_ref.read(zip_filepath)
Ed Tanous27747912022-09-23 12:50:08 -0700219 content = content.replace(b"\r\n", b"\n")
Ed Tanous118b1c72018-09-13 13:45:51 -0700220 xml_root = ET.fromstring(content)
Ed Tanousf395daa2021-08-02 08:56:24 -0700221 edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
Szymon Dompked699cf92021-08-11 19:46:31 +0200222 edm = "{http://docs.oasis-open.org/odata/ns/edm}"
Ed Tanous118b1c72018-09-13 13:45:51 -0700223 for edmx_child in xml_root:
Ed Tanousf395daa2021-08-02 08:56:24 -0700224 if edmx_child.tag == edmx + "DataServices":
Ed Tanous118b1c72018-09-13 13:45:51 -0700225 for data_child in edmx_child:
Szymon Dompked699cf92021-08-11 19:46:31 +0200226 if data_child.tag == edm + "Schema":
Ed Tanous118b1c72018-09-13 13:45:51 -0700227 namespace = data_child.attrib["Namespace"]
228 if namespace.startswith("RedfishExtensions"):
229 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700230 " "
Ed Tanous27747912022-09-23 12:50:08 -0700231 '<edmx:Include Namespace="'
232 + namespace
233 + '" Alias="Redfish"/>\n'
Ed Tanousf395daa2021-08-02 08:56:24 -0700234 )
Ed Tanous118b1c72018-09-13 13:45:51 -0700235
236 else:
237 metadata_index.write(
Ed Tanousf395daa2021-08-02 08:56:24 -0700238 " "
Ed Tanous27747912022-09-23 12:50:08 -0700239 '<edmx:Include Namespace="'
240 + namespace
241 + '"/>\n'
Ed Tanousf395daa2021-08-02 08:56:24 -0700242 )
243 schema_out.write(content)
Ed Tanous118b1c72018-09-13 13:45:51 -0700244 metadata_index.write(" </edmx:Reference>\n")
245
Ed Tanous27747912022-09-23 12:50:08 -0700246 metadata_index.write(
247 " <edmx:DataServices>\n"
248 " <Schema "
249 'xmlns="http://docs.oasis-open.org/odata/ns/edm" '
250 'Namespace="Service">\n'
251 ' <EntityContainer Name="Service" '
252 'Extends="ServiceRoot.v1_0_0.ServiceContainer"/>\n'
253 " </Schema>\n"
254 " </edmx:DataServices>\n"
255 )
Ed Tanouscb103132019-10-08 11:34:22 -0700256 # TODO:Issue#32 There's a bug in the script that currently deletes this
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500257 # schema (because it's an OEM schema). Because it's the only six, and we
Ed Tanouscb103132019-10-08 11:34:22 -0700258 # don't update schemas very often, we just manually fix it. Need a
259 # permanent fix to the script.
260 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700261 ' <edmx:Reference Uri="/redfish/v1/schema/OemManager_v1.xml">\n'
262 )
263 metadata_index.write(' <edmx:Include Namespace="OemManager"/>\n')
Marri Devender Raod45d2d02019-01-21 10:11:34 -0600264 metadata_index.write(" </edmx:Reference>\n")
Gunnar Mills20778992020-02-06 16:36:47 -0600265
266 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700267 ' <edmx:Reference Uri="'
268 '/redfish/v1/schema/OemComputerSystem_v1.xml">\n'
269 )
Ed Tanousf395daa2021-08-02 08:56:24 -0700270 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700271 ' <edmx:Include Namespace="OemComputerSystem"/>\n'
272 )
Gunnar Mills20778992020-02-06 16:36:47 -0600273 metadata_index.write(" </edmx:Reference>\n")
274
275 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700276 ' <edmx:Reference Uri="'
277 '/redfish/v1/schema/OemVirtualMedia_v1.xml">\n'
278 )
Ed Tanousf395daa2021-08-02 08:56:24 -0700279 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700280 ' <edmx:Include Namespace="OemVirtualMedia"/>\n'
281 )
Ed Tanousf395daa2021-08-02 08:56:24 -0700282 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700283 ' <edmx:Include Namespace="OemVirtualMedia.v1_0_0"/>\n'
284 )
Gunnar Mills20778992020-02-06 16:36:47 -0600285 metadata_index.write(" </edmx:Reference>\n")
286
287 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700288 ' <edmx:Reference Uri="'
289 '/redfish/v1/schema/OemAccountService_v1.xml">\n'
290 )
Ed Tanousf395daa2021-08-02 08:56:24 -0700291 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700292 ' <edmx:Include Namespace="OemAccountService"/>\n'
293 )
Ed Tanousf395daa2021-08-02 08:56:24 -0700294 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700295 ' <edmx:Include Namespace="OemAccountService.v1_0_0"/>\n'
296 )
Gunnar Mills20778992020-02-06 16:36:47 -0600297 metadata_index.write(" </edmx:Reference>\n")
298
Ravi Tejae7d68c32020-03-15 13:30:41 -0500299 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700300 ' <edmx:Reference Uri="/redfish/v1/schema/OemSession_v1.xml">\n'
301 )
302 metadata_index.write(' <edmx:Include Namespace="OemSession"/>\n')
Ed Tanousf395daa2021-08-02 08:56:24 -0700303 metadata_index.write(
Ed Tanous27747912022-09-23 12:50:08 -0700304 ' <edmx:Include Namespace="OemSession.v1_0_0"/>\n'
305 )
Sunitha Harish9dc50742020-05-11 00:10:20 -0500306 metadata_index.write(" </edmx:Reference>\n")
307
Ed Tanous118b1c72018-09-13 13:45:51 -0700308 metadata_index.write("</edmx:Edmx>\n")
Ed Tanous683f7272018-07-26 12:47:19 -0700309
310schema_files = {}
311for zip_filepath in zip_ref.namelist():
Ed Tanous27747912022-09-23 12:50:08 -0700312 if zip_filepath.startswith(os.path.join("json-schema/")):
Ed Tanous683f7272018-07-26 12:47:19 -0700313 filename = os.path.basename(zip_filepath)
314 filenamesplit = filename.split(".")
Gunnar Mills349a2ac2021-01-20 22:29:16 -0600315
316 # exclude schemas again to save flash space
317 if filenamesplit[0] not in include_list:
318 continue
319
Ed Tanous683f7272018-07-26 12:47:19 -0700320 if len(filenamesplit) == 3:
321 thisSchemaVersion = schema_files.get(filenamesplit[0], None)
Ed Tanouscb103132019-10-08 11:34:22 -0700322 if thisSchemaVersion is None:
Ed Tanous683f7272018-07-26 12:47:19 -0700323 schema_files[filenamesplit[0]] = filenamesplit[1]
324 else:
325 # need to see if we're a newer version.
Ed Tanous27747912022-09-23 12:50:08 -0700326 if list(map(int, filenamesplit[1][1:].split("_"))) > list(
327 map(int, thisSchemaVersion[1:].split("_"))
328 ):
Ed Tanous683f7272018-07-26 12:47:19 -0700329 schema_files[filenamesplit[0]] = filenamesplit[1]
Ed Tanous852432a2022-07-07 14:32:37 -0700330 else:
331 # Unversioned schema include directly. Invent a version so it can
332 # still be sorted against
333 schema_files[filenamesplit[0]] = "v0_0_0"
Ed Tanous683f7272018-07-26 12:47:19 -0700334
335for schema, version in schema_files.items():
Ed Tanous852432a2022-07-07 14:32:37 -0700336 basename = schema
337 if version != "v0_0_0":
338 basename += "." + version
339 basename += ".json"
340
Gunnar Mills60c922d2021-12-01 09:28:53 -0600341 zip_filepath = os.path.join("json-schema", basename)
Ed Tanous683f7272018-07-26 12:47:19 -0700342 schemadir = os.path.join(json_schema_path, schema)
343 os.makedirs(schemadir)
Ed Tanous118b1c72018-09-13 13:45:51 -0700344
Ed Tanous27747912022-09-23 12:50:08 -0700345 with open(os.path.join(schemadir, schema + ".json"), "wb") as schema_file:
346 schema_file.write(zip_ref.read(zip_filepath).replace(b"\r\n", b"\n"))
Ed Tanous683f7272018-07-26 12:47:19 -0700347
Ed Tanous27747912022-09-23 12:50:08 -0700348with open(os.path.join(cpp_path, "schemas.hpp"), "w") as hpp_file:
Ed Tanous81d523a2022-05-25 12:00:51 -0700349 hpp_file.write(
350 "#pragma once\n"
351 "{WARNING}\n"
352 "// clang-format off\n"
353 "\n"
354 "namespace redfish\n"
355 "{{\n"
Ed Tanous27747912022-09-23 12:50:08 -0700356 " constexpr std::array schemas {{\n".format(WARNING=WARNING)
Ed Tanous81d523a2022-05-25 12:00:51 -0700357 )
Ed Tanous27747912022-09-23 12:50:08 -0700358 for schema_file in schema_files:
359 hpp_file.write(' "{}",\n'.format(schema_file))
360
361 hpp_file.write(" };\n" "}\n")
Ed Tanous683f7272018-07-26 12:47:19 -0700362
363zip_ref.close()