Nan Zhou | 313c1b7 | 2022-03-25 11:47:55 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 2 | import os |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 3 | import shutil |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 4 | import xml.etree.ElementTree as ET |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 5 | import zipfile |
| 6 | from collections import OrderedDict, defaultdict |
| 7 | from io import BytesIO |
| 8 | |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 9 | import generate_schema_enums |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame^] | 10 | import requests |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 11 | |
Asmitha Karunanithi | 009c645 | 2022-09-22 01:07:59 -0500 | [diff] [blame] | 12 | VERSION = "DSP8010_2022.2" |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 13 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 14 | WARNING = """/**************************************************************** |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 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. |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 23 | ***************************************************************/""" |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 24 | |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 25 | # To use a new schema, add to list and rerun tool |
| 26 | include_list = [ |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 27 | "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", |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 44 | "EnvironmentMetrics", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 45 | "EthernetInterface", |
| 46 | "EthernetInterfaceCollection", |
| 47 | "Event", |
| 48 | "EventDestination", |
| 49 | "EventDestinationCollection", |
| 50 | "EventService", |
George Liu | 1a7b377 | 2022-09-29 09:29:18 +0800 | [diff] [blame] | 51 | "Fan", |
| 52 | "FanCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 53 | "IPAddresses", |
| 54 | "JsonSchemaFile", |
| 55 | "JsonSchemaFileCollection", # redfish/v1/JsonSchemas |
| 56 | "LogEntry", |
| 57 | "LogEntryCollection", |
| 58 | "LogService", |
| 59 | "LogServiceCollection", |
| 60 | "Manager", |
| 61 | "ManagerAccount", |
| 62 | "ManagerAccountCollection", |
| 63 | "ManagerCollection", |
| 64 | "ManagerDiagnosticData", |
| 65 | "ManagerNetworkProtocol", |
| 66 | "Memory", |
| 67 | "MemoryCollection", |
| 68 | "Message", |
| 69 | "MessageRegistry", |
| 70 | "MessageRegistryCollection", |
| 71 | "MessageRegistryFile", |
| 72 | "MessageRegistryFileCollection", |
| 73 | "MetricDefinition", |
| 74 | "MetricDefinitionCollection", |
| 75 | "MetricReport", |
| 76 | "MetricReportCollection", |
| 77 | "MetricReportDefinition", |
| 78 | "MetricReportDefinitionCollection", |
| 79 | "OperatingConfig", |
| 80 | "OperatingConfigCollection", |
| 81 | "PCIeDevice", |
| 82 | "PCIeDeviceCollection", |
| 83 | "PCIeFunction", |
| 84 | "PCIeFunctionCollection", |
| 85 | "PhysicalContext", |
| 86 | "PCIeSlots", |
| 87 | "Power", |
Chicago Duan | fe9bd2d | 2022-09-30 18:03:05 +0800 | [diff] [blame] | 88 | "PowerSubsystem", |
| 89 | "PowerSupply", |
| 90 | "PowerSupplyCollection", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 91 | "Privileges", # Used in Role |
| 92 | "Processor", |
| 93 | "ProcessorCollection", |
| 94 | "RedfishError", |
| 95 | "RedfishExtensions", |
| 96 | "Redundancy", |
| 97 | "Resource", |
| 98 | "Role", |
| 99 | "RoleCollection", |
| 100 | "Sensor", |
| 101 | "SensorCollection", |
| 102 | "ServiceRoot", |
| 103 | "Session", |
| 104 | "SessionCollection", |
| 105 | "SessionService", |
| 106 | "Settings", |
| 107 | "SoftwareInventory", |
| 108 | "SoftwareInventoryCollection", |
| 109 | "Storage", |
| 110 | "StorageCollection", |
| 111 | "StorageController", |
| 112 | "StorageControllerCollection", |
| 113 | "Task", |
| 114 | "TaskCollection", |
| 115 | "TaskService", |
| 116 | "TelemetryService", |
| 117 | "Thermal", |
George Liu | f1240b4 | 2022-10-28 17:26:15 +0800 | [diff] [blame] | 118 | "ThermalMetrics", |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 119 | "ThermalSubsystem", |
| 120 | "Triggers", |
| 121 | "TriggersCollection", |
| 122 | "UpdateService", |
| 123 | "VLanNetworkInterfaceCollection", |
| 124 | "VLanNetworkInterface", |
| 125 | "VirtualMedia", |
| 126 | "VirtualMediaCollection", |
| 127 | "odata", |
| 128 | "odata-v4", |
| 129 | "redfish-error", |
| 130 | "redfish-payload-annotations", |
| 131 | "redfish-schema", |
| 132 | "redfish-schema-v1", |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 133 | ] |
| 134 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 135 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 136 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 137 | proxies = {"https": os.environ.get("https_proxy", None)} |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 138 | |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 139 | r = requests.get( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 140 | "https://www.dmtf.org/sites/default/files/standards/documents/" |
| 141 | + VERSION |
| 142 | + ".zip", |
| 143 | proxies=proxies, |
| 144 | ) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 145 | |
| 146 | r.raise_for_status() |
| 147 | |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 148 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 149 | static_path = os.path.realpath( |
| 150 | os.path.join(SCRIPT_DIR, "..", "static", "redfish", "v1") |
| 151 | ) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 152 | |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 153 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 154 | cpp_path = os.path.realpath( |
| 155 | os.path.join(SCRIPT_DIR, "..", "redfish-core", "include") |
| 156 | ) |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 157 | |
| 158 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 159 | schema_path = os.path.join(static_path, "schema") |
| 160 | json_schema_path = os.path.join(static_path, "JsonSchemas") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 161 | metadata_index_path = os.path.join(static_path, "$metadata", "index.xml") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 162 | |
| 163 | zipBytesIO = BytesIO(r.content) |
| 164 | zip_ref = zipfile.ZipFile(zipBytesIO) |
| 165 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 166 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 167 | class SchemaVersion: |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame^] | 168 | """ |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 169 | A Python class for sorting Redfish schema versions. Allows sorting Redfish |
| 170 | versions in the way humans expect, by comparing version strings as lists |
| 171 | (ie 0_2_0 comes before 0_10_0) in the way humans expect. It does case |
| 172 | insensitive schema name comparisons |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame^] | 173 | """ |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 174 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 175 | def __init__(self, key): |
| 176 | key = str.casefold(key) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 177 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 178 | split_tup = key.split(".") |
| 179 | self.version_pieces = [split_tup[0]] |
| 180 | if len(split_tup) < 2: |
| 181 | return |
| 182 | version = split_tup[1] |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 183 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 184 | if version.startswith("v"): |
| 185 | version = version[1:] |
| 186 | if any(char.isdigit() for char in version): |
Patrick Williams | fd06b30 | 2022-12-12 10:39:42 -0600 | [diff] [blame^] | 187 | self.version_pieces.extend([int(x) for x in version.split("_")]) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 188 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 189 | def __lt__(self, other): |
| 190 | return self.version_pieces < other.version_pieces |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 191 | |
| 192 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 193 | # Remove the old files |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 194 | skip_prefixes = "Oem" |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 195 | if os.path.exists(schema_path): |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 196 | files = [ |
| 197 | os.path.join(schema_path, f) |
| 198 | for f in os.listdir(schema_path) |
| 199 | if not f.startswith(skip_prefixes) |
| 200 | ] |
James Feist | aee8d84 | 2018-09-10 16:07:40 -0700 | [diff] [blame] | 201 | for f in files: |
| 202 | os.remove(f) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 203 | if os.path.exists(json_schema_path): |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 204 | files = [ |
| 205 | os.path.join(json_schema_path, f) |
| 206 | for f in os.listdir(json_schema_path) |
| 207 | if not f.startswith(skip_prefixes) |
| 208 | ] |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 209 | for f in files: |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 210 | if os.path.isfile(f): |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 211 | os.remove(f) |
| 212 | else: |
| 213 | shutil.rmtree(f) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 214 | try: |
| 215 | os.remove(metadata_index_path) |
| 216 | except FileNotFoundError: |
| 217 | pass |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 218 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 219 | if not os.path.exists(schema_path): |
| 220 | os.makedirs(schema_path) |
| 221 | if not os.path.exists(json_schema_path): |
| 222 | os.makedirs(json_schema_path) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 223 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 224 | csdl_filenames = [] |
| 225 | json_schema_files = defaultdict(list) |
| 226 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 227 | for zip_file in zip_ref.infolist(): |
| 228 | if zip_file.is_dir(): |
| 229 | continue |
| 230 | if zip_file.filename.startswith("csdl/"): |
| 231 | csdl_filenames.append(os.path.basename(zip_file.filename)) |
| 232 | elif zip_file.filename.startswith("json-schema/"): |
| 233 | filename = os.path.basename(zip_file.filename) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 234 | filenamesplit = filename.split(".") |
| 235 | # exclude schemas again to save flash space |
| 236 | if filenamesplit[0] not in include_list: |
| 237 | continue |
| 238 | json_schema_files[filenamesplit[0]].append(filename) |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 239 | elif zip_file.filename.startswith("openapi/"): |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 240 | pass |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 241 | elif zip_file.filename.startswith("dictionaries/"): |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 242 | pass |
| 243 | |
| 244 | # sort the json files by version |
| 245 | for key, value in json_schema_files.items(): |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 246 | value.sort(key=SchemaVersion, reverse=True) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 247 | |
| 248 | # Create a dictionary ordered by schema name |
| 249 | json_schema_files = OrderedDict( |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 250 | sorted(json_schema_files.items(), key=lambda x: SchemaVersion(x[0])) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 251 | ) |
| 252 | |
Ed Tanous | 204c376 | 2022-12-12 09:50:09 -0800 | [diff] [blame] | 253 | csdl_filenames.sort(key=SchemaVersion) |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 254 | with open(metadata_index_path, "w") as metadata_index: |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 255 | metadata_index.write('<?xml version="1.0" encoding="UTF-8"?>\n') |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 256 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 257 | "<edmx:Edmx xmlns:edmx=" |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 258 | '"http://docs.oasis-open.org/odata/ns/edmx"' |
| 259 | ' Version="4.0">\n' |
| 260 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 261 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 262 | for filename in csdl_filenames: |
| 263 | # filename looks like Zone_v1.xml |
| 264 | filenamesplit = filename.split("_") |
| 265 | if filenamesplit[0] not in include_list: |
| 266 | print("excluding schema: " + filename) |
| 267 | continue |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 268 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 269 | with open(os.path.join(schema_path, filename), "wb") as schema_out: |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 270 | metadata_index.write( |
| 271 | ' <edmx:Reference Uri="/redfish/v1/schema/' |
| 272 | + filename |
| 273 | + '">\n' |
| 274 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 275 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 276 | content = zip_ref.read(os.path.join("csdl", filename)) |
| 277 | content = content.replace(b"\r\n", b"\n") |
| 278 | xml_root = ET.fromstring(content) |
| 279 | edmx = "{http://docs.oasis-open.org/odata/ns/edmx}" |
| 280 | edm = "{http://docs.oasis-open.org/odata/ns/edm}" |
| 281 | for edmx_child in xml_root: |
| 282 | if edmx_child.tag == edmx + "DataServices": |
| 283 | for data_child in edmx_child: |
| 284 | if data_child.tag == edm + "Schema": |
| 285 | namespace = data_child.attrib["Namespace"] |
| 286 | if namespace.startswith("RedfishExtensions"): |
| 287 | metadata_index.write( |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 288 | ' <edmx:Include Namespace="' |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 289 | + namespace |
| 290 | + '" Alias="Redfish"/>\n' |
| 291 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 292 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 293 | else: |
| 294 | metadata_index.write( |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 295 | ' <edmx:Include Namespace="' |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 296 | + namespace |
| 297 | + '"/>\n' |
| 298 | ) |
| 299 | schema_out.write(content) |
| 300 | metadata_index.write(" </edmx:Reference>\n") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 301 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 302 | metadata_index.write( |
| 303 | " <edmx:DataServices>\n" |
| 304 | " <Schema " |
| 305 | 'xmlns="http://docs.oasis-open.org/odata/ns/edm" ' |
| 306 | 'Namespace="Service">\n' |
| 307 | ' <EntityContainer Name="Service" ' |
| 308 | 'Extends="ServiceRoot.v1_0_0.ServiceContainer"/>\n' |
| 309 | " </Schema>\n" |
| 310 | " </edmx:DataServices>\n" |
| 311 | ) |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 312 | # TODO:Issue#32 There's a bug in the script that currently deletes this |
Asmitha Karunanithi | d337bb7 | 2020-09-21 10:34:02 -0500 | [diff] [blame] | 313 | # schema (because it's an OEM schema). Because it's the only six, and we |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 314 | # don't update schemas very often, we just manually fix it. Need a |
| 315 | # permanent fix to the script. |
| 316 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 317 | ' <edmx:Reference Uri="/redfish/v1/schema/OemManager_v1.xml">\n' |
| 318 | ) |
| 319 | metadata_index.write(' <edmx:Include Namespace="OemManager"/>\n') |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 320 | metadata_index.write(" </edmx:Reference>\n") |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 321 | |
| 322 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 323 | ' <edmx:Reference Uri="' |
| 324 | '/redfish/v1/schema/OemComputerSystem_v1.xml">\n' |
| 325 | ) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 326 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 327 | ' <edmx:Include Namespace="OemComputerSystem"/>\n' |
| 328 | ) |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 329 | metadata_index.write(" </edmx:Reference>\n") |
| 330 | |
| 331 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 332 | ' <edmx:Reference Uri="' |
| 333 | '/redfish/v1/schema/OemVirtualMedia_v1.xml">\n' |
| 334 | ) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 335 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 336 | ' <edmx:Include Namespace="OemVirtualMedia"/>\n' |
| 337 | ) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 338 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 339 | ' <edmx:Include Namespace="OemVirtualMedia.v1_0_0"/>\n' |
| 340 | ) |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 341 | metadata_index.write(" </edmx:Reference>\n") |
| 342 | |
| 343 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 344 | ' <edmx:Reference Uri="' |
| 345 | '/redfish/v1/schema/OemAccountService_v1.xml">\n' |
| 346 | ) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 347 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 348 | ' <edmx:Include Namespace="OemAccountService"/>\n' |
| 349 | ) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 350 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 351 | ' <edmx:Include Namespace="OemAccountService.v1_0_0"/>\n' |
| 352 | ) |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 353 | metadata_index.write(" </edmx:Reference>\n") |
| 354 | |
Ravi Teja | e7d68c3 | 2020-03-15 13:30:41 -0500 | [diff] [blame] | 355 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 356 | ' <edmx:Reference Uri="/redfish/v1/schema/OemSession_v1.xml">\n' |
| 357 | ) |
| 358 | metadata_index.write(' <edmx:Include Namespace="OemSession"/>\n') |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 359 | metadata_index.write( |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 360 | ' <edmx:Include Namespace="OemSession.v1_0_0"/>\n' |
| 361 | ) |
Sunitha Harish | 9dc5074 | 2020-05-11 00:10:20 -0500 | [diff] [blame] | 362 | metadata_index.write(" </edmx:Reference>\n") |
| 363 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 364 | metadata_index.write("</edmx:Edmx>\n") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 365 | |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 366 | |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 367 | for schema, version in json_schema_files.items(): |
| 368 | zip_filepath = os.path.join("json-schema", version[0]) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 369 | schemadir = os.path.join(json_schema_path, schema) |
| 370 | os.makedirs(schemadir) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 371 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 372 | with open(os.path.join(schemadir, schema + ".json"), "wb") as schema_file: |
| 373 | schema_file.write(zip_ref.read(zip_filepath).replace(b"\r\n", b"\n")) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 374 | |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 375 | with open(os.path.join(cpp_path, "schemas.hpp"), "w") as hpp_file: |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 376 | hpp_file.write( |
| 377 | "#pragma once\n" |
| 378 | "{WARNING}\n" |
| 379 | "// clang-format off\n" |
Ed Tanous | 3d69fed | 2022-09-26 20:10:42 -0700 | [diff] [blame] | 380 | "#include <array>\n" |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 381 | "\n" |
| 382 | "namespace redfish\n" |
| 383 | "{{\n" |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 384 | " constexpr std::array schemas {{\n".format(WARNING=WARNING) |
Ed Tanous | 81d523a | 2022-05-25 12:00:51 -0700 | [diff] [blame] | 385 | ) |
Ed Tanous | 8b56455 | 2022-09-23 12:03:18 -0700 | [diff] [blame] | 386 | for schema_file in json_schema_files: |
Ed Tanous | 2774791 | 2022-09-23 12:50:08 -0700 | [diff] [blame] | 387 | hpp_file.write(' "{}",\n'.format(schema_file)) |
| 388 | |
Patrick Williams | dfa3fdc | 2022-12-07 07:14:21 -0600 | [diff] [blame] | 389 | hpp_file.write(" };\n}\n") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 390 | |
| 391 | zip_ref.close() |
Ed Tanous | 0ec8b83 | 2022-03-14 14:56:47 -0700 | [diff] [blame] | 392 | |
| 393 | generate_schema_enums.main() |