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