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