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