diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2018-07-26 12:47:19 -0700 |
|---|---|---|
| committer | Ed Tanous <ed.tanous@intel.com> | 2018-09-17 16:25:06 +0000 |
| commit | 683f7276576dbf0bf7770570190f6b5b4e84d4c9 (patch) | |
| tree | 5ce732faa82e8360367006c510e9797bb7ee51d1 /scripts | |
| parent | cc340dd933d38095214a0eeb7c1ee77510bd30cd (diff) | |
| download | bmcweb-683f7276576dbf0bf7770570190f6b5b4e84d4c9.tar.gz bmcweb-683f7276576dbf0bf7770570190f6b5b4e84d4c9.zip | |
Implement JsonSchema endpoint
This patchset implements JsonSchema support, and automates our update
of the XML metadata, and Json schema files in the future by way of a
python script.
Change-Id: Iec6f580d10736678149db18d87be2f140b535be9
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/update_schemas.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py new file mode 100755 index 0000000..1fc5ca8 --- /dev/null +++ b/scripts/update_schemas.py @@ -0,0 +1,92 @@ +#!/usr/bin/python3 +import requests +import zipfile +from io import BytesIO +import os +from collections import defaultdict +from collections import OrderedDict +from distutils.version import StrictVersion +import shutil +import json + +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) + +proxies = { + 'https': os.environ.get("https_proxy", None) +} + +r = requests.get('https://www.dmtf.org/sites/default/files/standards/documents/' + 'DSP8010_2018.1.zip', proxies=proxies) + +r.raise_for_status() + +static_path = os.path.realpath(os.path.join(SCRIPT_DIR, "..", "static", + "redfish", "v1")) + +schema_path = os.path.join(static_path, "schema") +json_schema_path = os.path.join(static_path, "JsonSchemas") + +zipBytesIO = BytesIO(r.content) +zip_ref = zipfile.ZipFile(zipBytesIO) + +# Remove the old files +if os.path.exists(schema_path): + shutil.rmtree(schema_path) +if os.path.exists(json_schema_path): + shutil.rmtree(json_schema_path) +os.makedirs(schema_path) +os.makedirs(json_schema_path) + +for zip_filepath in zip_ref.namelist(): + + if zip_filepath.startswith('metadata/'): + filename = os.path.basename(zip_filepath) + with open(os.path.join(schema_path, filename), 'wb') as schema_file: + schema_file.write(zip_ref.read(zip_filepath)) + +schema_files = {} +for zip_filepath in zip_ref.namelist(): + if zip_filepath.startswith('json-schema/'): + filename = os.path.basename(zip_filepath) + filenamesplit = filename.split(".") + if len(filenamesplit) == 3: + thisSchemaVersion = schema_files.get(filenamesplit[0], None) + if thisSchemaVersion == None: + schema_files[filenamesplit[0]] = filenamesplit[1] + else: + # need to see if we're a newer version. + if list(map(int, filenamesplit[1][1:].split("_"))) > list(map( + int, thisSchemaVersion[1:].split("_"))): + schema_files[filenamesplit[0]] = filenamesplit[1] + + +for schema, version in schema_files.items(): + basename = schema + "." + version + ".json" + zip_filepath = os.path.join("json-schema", basename) + schemadir = os.path.join(json_schema_path, schema) + os.makedirs(schemadir) + with open(os.path.join(schemadir, "index.json"), 'wb') as schema_file: + schema_file.write(zip_ref.read(zip_filepath)) + +with open(os.path.join(json_schema_path, "index.json"), 'w') as index_file: + members = [{"@odata.id": "/redfish/v1/JsonSchemas/" + schema + "/"} + for schema in schema_files] + + members.sort(key=lambda x: x["@odata.id"]) + + indexData = OrderedDict() + + indexData["@odata.id"] = "/redfish/v1/JsonSchemas" + indexData["@odata.context"] = ("/redfish/v1/$metadata" + "#JsonSchemaFileCollection." + "JsonSchemaFileCollection") + indexData["@odata.type"] = ("#JsonSchemaFileCollection." + "JsonSchemaFileCollection") + indexData["Name"] = "JsonSchemaFile Collection" + indexData["Description"] = "Collection of JsonSchemaFiles" + indexData["Members@odata.count"] = len(schema_files) + indexData["Members"] = members + + json.dump(indexData, index_file, indent=2) + +zip_ref.close() |

