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 requests |
| 3 | import zipfile |
| 4 | from io import BytesIO |
| 5 | import os |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 6 | from collections import OrderedDict |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 7 | import shutil |
| 8 | import json |
| 9 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 10 | import xml.etree.ElementTree as ET |
| 11 | |
Sui Chen | 141d943 | 2022-02-03 22:01:27 -0800 | [diff] [blame] | 12 | VERSION = "DSP8010_2021.4" |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 13 | |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 14 | # To use a new schema, add to list and rerun tool |
| 15 | include_list = [ |
| 16 | 'AccountService', |
| 17 | 'ActionInfo', |
| 18 | 'Assembly', |
| 19 | 'AttributeRegistry', |
| 20 | 'Bios', |
Shantappa Teekappanavar | 9c929be | 2021-12-16 19:02:52 -0600 | [diff] [blame] | 21 | 'Cable', |
| 22 | 'CableCollection', |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 23 | 'Certificate', |
| 24 | 'CertificateCollection', |
| 25 | 'CertificateLocations', |
| 26 | 'CertificateService', |
| 27 | 'Chassis', |
| 28 | 'ChassisCollection', |
| 29 | 'ComputerSystem', |
| 30 | 'ComputerSystemCollection', |
| 31 | 'Drive', |
| 32 | 'DriveCollection', |
| 33 | 'EthernetInterface', |
| 34 | 'EthernetInterfaceCollection', |
| 35 | 'Event', |
| 36 | 'EventDestination', |
| 37 | 'EventDestinationCollection', |
| 38 | 'EventService', |
| 39 | 'IPAddresses', |
| 40 | 'JsonSchemaFile', |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 41 | 'JsonSchemaFileCollection', # redfish/v1/JsonSchemas |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 42 | 'LogEntry', |
| 43 | 'LogEntryCollection', |
| 44 | 'LogService', |
| 45 | 'LogServiceCollection', |
| 46 | 'Manager', |
| 47 | 'ManagerAccount', |
| 48 | 'ManagerAccountCollection', |
| 49 | 'ManagerCollection', |
Sui Chen | 2395251 | 2022-02-08 13:49:36 -0800 | [diff] [blame] | 50 | 'ManagerDiagnosticData', |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 51 | 'ManagerNetworkProtocol', |
| 52 | 'Memory', |
| 53 | 'MemoryCollection', |
| 54 | 'Message', |
| 55 | 'MessageRegistry', |
| 56 | 'MessageRegistryCollection', |
| 57 | 'MessageRegistryFile', |
| 58 | 'MessageRegistryFileCollection', |
| 59 | 'MetricDefinition', |
| 60 | 'MetricDefinitionCollection', |
| 61 | 'MetricReport', |
| 62 | 'MetricReportCollection', |
| 63 | 'MetricReportDefinition', |
| 64 | 'MetricReportDefinitionCollection', |
| 65 | 'OperatingConfig', |
| 66 | 'OperatingConfigCollection', |
| 67 | 'PCIeDevice', |
| 68 | 'PCIeDeviceCollection', |
| 69 | 'PCIeFunction', |
| 70 | 'PCIeFunctionCollection', |
sunitakx | 71b861b | 2022-01-18 11:05:05 +0000 | [diff] [blame] | 71 | 'PhysicalContext', |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 72 | 'Power', |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 73 | 'Privileges', # Used in Role |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 74 | 'Processor', |
| 75 | 'ProcessorCollection', |
| 76 | 'RedfishError', |
| 77 | 'RedfishExtensions', |
| 78 | 'Redundancy', |
| 79 | 'Resource', |
| 80 | 'Role', |
| 81 | 'RoleCollection', |
| 82 | 'Sensor', |
| 83 | 'SensorCollection', |
| 84 | 'ServiceRoot', |
| 85 | 'Session', |
| 86 | 'SessionCollection', |
| 87 | 'SessionService', |
| 88 | 'Settings', |
| 89 | 'SoftwareInventory', |
| 90 | 'SoftwareInventoryCollection', |
| 91 | 'Storage', |
| 92 | 'StorageCollection', |
| 93 | 'StorageController', |
| 94 | 'StorageControllerCollection', |
| 95 | 'Task', |
| 96 | 'TaskCollection', |
| 97 | 'TaskService', |
| 98 | 'TelemetryService', |
| 99 | 'Thermal', |
Lukasz Kazmierczak | 1b7e696 | 2021-08-02 13:40:27 +0200 | [diff] [blame] | 100 | 'Triggers', |
Lukasz Kazmierczak | 07148cf | 2021-08-02 11:08:53 +0200 | [diff] [blame] | 101 | 'TriggersCollection', |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 102 | 'UpdateService', |
| 103 | 'VLanNetworkInterfaceCollection', |
| 104 | 'VLanNetworkInterface', |
| 105 | 'VirtualMedia', |
| 106 | 'VirtualMediaCollection', |
| 107 | 'odata', |
| 108 | 'odata-v4', |
| 109 | 'redfish-error', |
| 110 | 'redfish-payload-annotations', |
| 111 | 'redfish-schema', |
| 112 | 'redfish-schema-v1', |
| 113 | ] |
| 114 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 115 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 116 | |
| 117 | proxies = { |
| 118 | 'https': os.environ.get("https_proxy", None) |
| 119 | } |
| 120 | |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 121 | r = requests.get( |
| 122 | 'https://www.dmtf.org/sites/default/files/standards/documents/' + |
| 123 | VERSION + |
| 124 | '.zip', |
| 125 | proxies=proxies) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 126 | |
| 127 | r.raise_for_status() |
| 128 | |
| 129 | static_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "static", |
| 130 | "redfish", "v1")) |
| 131 | |
| 132 | schema_path = os.path.join(static_path, "schema") |
| 133 | json_schema_path = os.path.join(static_path, "JsonSchemas") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 134 | metadata_index_path = os.path.join(static_path, "$metadata", "index.xml") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 135 | |
| 136 | zipBytesIO = BytesIO(r.content) |
| 137 | zip_ref = zipfile.ZipFile(zipBytesIO) |
| 138 | |
| 139 | # Remove the old files |
Szymon Dompke | d699cf9 | 2021-08-11 19:46:31 +0200 | [diff] [blame] | 140 | skip_prefixes = ('Oem') |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 141 | if os.path.exists(schema_path): |
Szymon Dompke | d699cf9 | 2021-08-11 19:46:31 +0200 | [diff] [blame] | 142 | files = [os.path.join(schema_path, f) for f in os.listdir(schema_path) |
| 143 | if not f.startswith(skip_prefixes)] |
James Feist | aee8d84 | 2018-09-10 16:07:40 -0700 | [diff] [blame] | 144 | for f in files: |
| 145 | os.remove(f) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 146 | if os.path.exists(json_schema_path): |
Szymon Dompke | d699cf9 | 2021-08-11 19:46:31 +0200 | [diff] [blame] | 147 | files = [os.path.join(json_schema_path, f) for f in |
| 148 | os.listdir(json_schema_path) if not f.startswith(skip_prefixes)] |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 149 | for f in files: |
| 150 | if (os.path.isfile(f)): |
| 151 | os.remove(f) |
| 152 | else: |
| 153 | shutil.rmtree(f) |
| 154 | os.remove(metadata_index_path) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 155 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 156 | if not os.path.exists(schema_path): |
| 157 | os.makedirs(schema_path) |
| 158 | if not os.path.exists(json_schema_path): |
| 159 | os.makedirs(json_schema_path) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 160 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 161 | with open(metadata_index_path, 'w') as metadata_index: |
| 162 | |
| 163 | metadata_index.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") |
| 164 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 165 | "<edmx:Edmx xmlns:edmx=" |
| 166 | "\"http://docs.oasis-open.org/odata/ns/edmx\"" |
| 167 | " Version=\"4.0\">\n") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 168 | |
| 169 | for zip_filepath in zip_ref.namelist(): |
Gunnar Mills | 60c922d | 2021-12-01 09:28:53 -0600 | [diff] [blame] | 170 | if zip_filepath.startswith('csdl/') and \ |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 171 | (zip_filepath != VERSION + "/csdl/") and \ |
Gunnar Mills | 60c922d | 2021-12-01 09:28:53 -0600 | [diff] [blame] | 172 | (zip_filepath != "csdl/"): |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 173 | filename = os.path.basename(zip_filepath) |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 174 | |
| 175 | # filename looks like Zone_v1.xml |
| 176 | filenamesplit = filename.split("_") |
| 177 | if filenamesplit[0] not in include_list: |
| 178 | print("excluding schema: " + filename) |
| 179 | continue |
| 180 | |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 181 | with open(os.path.join(schema_path, filename), 'wb') as schema_out: |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 182 | |
| 183 | metadata_index.write( |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 184 | " <edmx:Reference Uri=\"/redfish/v1/schema/" + |
| 185 | filename + |
| 186 | "\">\n") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 187 | |
| 188 | content = zip_ref.read(zip_filepath) |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 189 | content = content.replace(b'\r\n', b'\n') |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 190 | xml_root = ET.fromstring(content) |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 191 | edmx = "{http://docs.oasis-open.org/odata/ns/edmx}" |
Szymon Dompke | d699cf9 | 2021-08-11 19:46:31 +0200 | [diff] [blame] | 192 | edm = "{http://docs.oasis-open.org/odata/ns/edm}" |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 193 | for edmx_child in xml_root: |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 194 | if edmx_child.tag == edmx + "DataServices": |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 195 | for data_child in edmx_child: |
Szymon Dompke | d699cf9 | 2021-08-11 19:46:31 +0200 | [diff] [blame] | 196 | if data_child.tag == edm + "Schema": |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 197 | namespace = data_child.attrib["Namespace"] |
| 198 | if namespace.startswith("RedfishExtensions"): |
| 199 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 200 | " " |
| 201 | "<edmx:Include Namespace=\"" + |
| 202 | namespace + |
| 203 | "\" Alias=\"Redfish\"/>\n" |
| 204 | ) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 205 | |
| 206 | else: |
| 207 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 208 | " " |
| 209 | "<edmx:Include Namespace=\"" |
| 210 | + namespace + "\"/>\n" |
| 211 | ) |
| 212 | schema_out.write(content) |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 213 | metadata_index.write(" </edmx:Reference>\n") |
| 214 | |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 215 | metadata_index.write(" <edmx:DataServices>\n" |
| 216 | " <Schema " |
| 217 | "xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" " |
| 218 | "Namespace=\"Service\">\n" |
| 219 | " <EntityContainer Name=\"Service\" " |
| 220 | "Extends=\"ServiceRoot.v1_0_0.ServiceContainer\"/>\n" |
| 221 | " </Schema>\n" |
| 222 | " </edmx:DataServices>\n" |
| 223 | ) |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 224 | # 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] | 225 | # 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] | 226 | # don't update schemas very often, we just manually fix it. Need a |
| 227 | # permanent fix to the script. |
| 228 | metadata_index.write( |
| 229 | " <edmx:Reference Uri=\"/redfish/v1/schema/OemManager_v1.xml\">\n") |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 230 | metadata_index.write(" <edmx:Include Namespace=\"OemManager\"/>\n") |
| 231 | metadata_index.write(" </edmx:Reference>\n") |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 232 | |
| 233 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 234 | " <edmx:Reference Uri=\"" |
| 235 | "/redfish/v1/schema/OemComputerSystem_v1.xml\">\n") |
| 236 | metadata_index.write( |
| 237 | " <edmx:Include Namespace=\"OemComputerSystem\"/>\n") |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 238 | metadata_index.write(" </edmx:Reference>\n") |
| 239 | |
| 240 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 241 | " <edmx:Reference Uri=\"" |
| 242 | "/redfish/v1/schema/OemVirtualMedia_v1.xml\">\n") |
| 243 | metadata_index.write( |
| 244 | " <edmx:Include Namespace=\"OemVirtualMedia\"/>\n") |
| 245 | metadata_index.write( |
| 246 | " <edmx:Include Namespace=\"OemVirtualMedia.v1_0_0\"/>\n") |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 247 | metadata_index.write(" </edmx:Reference>\n") |
| 248 | |
| 249 | metadata_index.write( |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 250 | " <edmx:Reference Uri=\"" |
| 251 | "/redfish/v1/schema/OemAccountService_v1.xml\">\n") |
| 252 | metadata_index.write( |
| 253 | " <edmx:Include Namespace=\"OemAccountService\"/>\n") |
| 254 | metadata_index.write( |
| 255 | " <edmx:Include Namespace=\"OemAccountService.v1_0_0\"/>\n") |
Gunnar Mills | 2077899 | 2020-02-06 16:36:47 -0600 | [diff] [blame] | 256 | metadata_index.write(" </edmx:Reference>\n") |
| 257 | |
Ravi Teja | e7d68c3 | 2020-03-15 13:30:41 -0500 | [diff] [blame] | 258 | metadata_index.write( |
Sunitha Harish | 9dc5074 | 2020-05-11 00:10:20 -0500 | [diff] [blame] | 259 | " <edmx:Reference Uri=\"/redfish/v1/schema/OemSession_v1.xml\">\n") |
| 260 | metadata_index.write(" <edmx:Include Namespace=\"OemSession\"/>\n") |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 261 | metadata_index.write( |
| 262 | " <edmx:Include Namespace=\"OemSession.v1_0_0\"/>\n") |
Sunitha Harish | 9dc5074 | 2020-05-11 00:10:20 -0500 | [diff] [blame] | 263 | metadata_index.write(" </edmx:Reference>\n") |
| 264 | |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 265 | metadata_index.write("</edmx:Edmx>\n") |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 266 | |
| 267 | schema_files = {} |
| 268 | for zip_filepath in zip_ref.namelist(): |
Gunnar Mills | 60c922d | 2021-12-01 09:28:53 -0600 | [diff] [blame] | 269 | if zip_filepath.startswith(os.path.join('json-schema/')): |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 270 | filename = os.path.basename(zip_filepath) |
| 271 | filenamesplit = filename.split(".") |
Gunnar Mills | 349a2ac | 2021-01-20 22:29:16 -0600 | [diff] [blame] | 272 | |
| 273 | # exclude schemas again to save flash space |
| 274 | if filenamesplit[0] not in include_list: |
| 275 | continue |
| 276 | |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 277 | if len(filenamesplit) == 3: |
| 278 | thisSchemaVersion = schema_files.get(filenamesplit[0], None) |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 279 | if thisSchemaVersion is None: |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 280 | schema_files[filenamesplit[0]] = filenamesplit[1] |
| 281 | else: |
| 282 | # need to see if we're a newer version. |
| 283 | if list(map(int, filenamesplit[1][1:].split("_"))) > list(map( |
| 284 | int, thisSchemaVersion[1:].split("_"))): |
| 285 | schema_files[filenamesplit[0]] = filenamesplit[1] |
| 286 | |
| 287 | |
| 288 | for schema, version in schema_files.items(): |
| 289 | basename = schema + "." + version + ".json" |
Gunnar Mills | 60c922d | 2021-12-01 09:28:53 -0600 | [diff] [blame] | 290 | zip_filepath = os.path.join("json-schema", basename) |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 291 | schemadir = os.path.join(json_schema_path, schema) |
| 292 | os.makedirs(schemadir) |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 293 | location_json = OrderedDict() |
| 294 | location_json["Language"] = "en" |
| 295 | location_json["PublicationUri"] = ( |
| 296 | "http://redfish.dmtf.org/schemas/v1/" + schema + ".json") |
| 297 | location_json["Uri"] = ( |
Ed Tanous | 63faafa | 2019-01-03 14:09:56 -0800 | [diff] [blame] | 298 | "/redfish/v1/JsonSchemas/" + schema + "/" + schema + ".json") |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 299 | |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 300 | index_json = OrderedDict() |
Ed Tanous | f395daa | 2021-08-02 08:56:24 -0700 | [diff] [blame] | 301 | index_json["@odata.context"] = \ |
| 302 | "/redfish/v1/$metadata#JsonSchemaFile.JsonSchemaFile" |
Ed Tanous | 63faafa | 2019-01-03 14:09:56 -0800 | [diff] [blame] | 303 | index_json["@odata.id"] = "/redfish/v1/JsonSchemas/" + schema |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 304 | index_json["@odata.type"] = "#JsonSchemaFile.v1_0_2.JsonSchemaFile" |
| 305 | index_json["Name"] = schema + " Schema File" |
| 306 | index_json["Schema"] = "#" + schema + "." + schema |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 307 | index_json["Description"] = schema + " Schema File Location" |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 308 | index_json["Id"] = schema |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 309 | index_json["Languages"] = ["en"] |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 310 | index_json["Languages@odata.count"] = 1 |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 311 | index_json["Location"] = [location_json] |
Marri Devender Rao | d45d2d0 | 2019-01-21 10:11:34 -0600 | [diff] [blame] | 312 | index_json["Location@odata.count"] = 1 |
Ed Tanous | 118b1c7 | 2018-09-13 13:45:51 -0700 | [diff] [blame] | 313 | |
| 314 | with open(os.path.join(schemadir, "index.json"), 'w') as schema_file: |
| 315 | json.dump(index_json, schema_file, indent=4) |
| 316 | with open(os.path.join(schemadir, schema + ".json"), 'wb') as schema_file: |
Ed Tanous | cb10313 | 2019-10-08 11:34:22 -0700 | [diff] [blame] | 317 | 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] | 318 | |
| 319 | with open(os.path.join(json_schema_path, "index.json"), 'w') as index_file: |
Ed Tanous | 6f56d0c | 2019-05-03 17:15:41 -0700 | [diff] [blame] | 320 | members = [{"@odata.id": "/redfish/v1/JsonSchemas/" + schema} |
Ed Tanous | 683f727 | 2018-07-26 12:47:19 -0700 | [diff] [blame] | 321 | for schema in schema_files] |
| 322 | |
| 323 | members.sort(key=lambda x: x["@odata.id"]) |
| 324 | |
| 325 | indexData = OrderedDict() |
| 326 | |
| 327 | indexData["@odata.id"] = "/redfish/v1/JsonSchemas" |
| 328 | indexData["@odata.context"] = ("/redfish/v1/$metadata" |
| 329 | "#JsonSchemaFileCollection." |
| 330 | "JsonSchemaFileCollection") |
| 331 | indexData["@odata.type"] = ("#JsonSchemaFileCollection." |
| 332 | "JsonSchemaFileCollection") |
| 333 | indexData["Name"] = "JsonSchemaFile Collection" |
| 334 | indexData["Description"] = "Collection of JsonSchemaFiles" |
| 335 | indexData["Members@odata.count"] = len(schema_files) |
| 336 | indexData["Members"] = members |
| 337 | |
| 338 | json.dump(indexData, index_file, indent=2) |
| 339 | |
| 340 | zip_ref.close() |