diff --git a/tools/redfish-gen/redfish_gen/property.py b/tools/redfish-gen/redfish_gen/property.py index d3a6361a..4e023bba 100644 --- a/tools/redfish-gen/redfish_gen/property.py +++ b/tools/redfish-gen/redfish_gen/property.py @@ -155,7 +155,7 @@ def resolve_property_spec(prop_spec, global_spec, recursive=True): ref_spec = Property.__resolve_spec_by_ref(urlparse(ref)) recursive_spec = ref_spec if ref_spec is not None else global_spec return Property.resolve_property_spec(definition, recursive_spec) - RedfishSchema.extract_schemas(properties) + RedfishSchema.expand_schema_properties(properties) return definition def value(self): diff --git a/tools/redfish-gen/redfish_gen/redfish_base.py b/tools/redfish-gen/redfish_gen/redfish_base.py index 74b936bb..737cf811 100644 --- a/tools/redfish-gen/redfish_gen/redfish_base.py +++ b/tools/redfish-gen/redfish_gen/redfish_base.py @@ -1,13 +1,12 @@ ## SPDX-License-Identifier: Apache-2.0 ## Copyright (C) 2023, KNS Group LLC (YADRO) +import yaml import json -from shutil import copy -from os import path, makedirs, walk +from os import path, makedirs from xml.dom import minidom from .globals import __RFG_PATH__ -from .globals import __WWW_PATH__ class RedfishBase: """ @@ -15,37 +14,120 @@ class RedfishBase: Contains all common methods for RedfishNode and RedfishSchema classes. """ + def __init__(self, standard: str, schema_name, version) -> None: + """ + Construct base object. + """ + if standard != "redfish" and standard != "redfish/swordfish": + raise Exception("API Standard \"%s\" in not supported" % standard) + self._standard = standard + self._schema_name = schema_name + if self._schema_name is None: + raise ValueError("Node config: require field 'Schema'") + self._schema_version = version[1:] if version is not None and version.startswith("v") else version + + def standard(self): + return self._standard + + def schema_id(self): + return self._schema_name + + def version(self): + if self._schema_version: + return "v" + self._schema_version.replace(".", "_") + return None + + def is_oem(self): + return self._schema_name.startswith("Oem") + + def _load_openapi(self): + data = RedfishBase._load_bundle_file(self.standard(), self._schema_file_openapi()) + return yaml.safe_load(data) + + def _load_schema_json(self): + """ + Loads json schema from file with version, like "Power.v1_7_6.json". + """ + filename = self._schema_file_json_with_ver() + if filename is not None: + data = RedfishBase._load_bundle_file(self.standard(), filename) + return json.loads(data) + return None + + def _load_schema_spec_json(self): + """ + Loads json schema spec from file without version, like "Power.json". + """ + data = RedfishBase._load_bundle_file(self.standard(), self._schema_spec_file_json()) + return json.loads(data) + + def _schema_file_json_with_ver(self): + filename = self._schema_file_with_ver() + if filename is not None: + return "json-schema/" + filename + ".json" + return filename + + def _schema_file_with_ver(self): + if self._schema_version: + return self.schema_id() + "." + self.version() + return None + + def _schema_spec_file_json(self): + return "json-schema/" + self.schema_id() + ".json" + + def _schema_file_openapi(self): + return "openapi/" + self.schema_id() + ".yaml" + + def _schema_file_csdl(self): + return "csdl/" + self.schema_id() + "_v1.xml" + @staticmethod - def redfish_version(): - return "v1" + def _load_csdl_file(standard: str, relativename): + """ + Load CSDL schema from file from schemas budle subdir. + """ + data = RedfishBase._load_bundle_file(standard, relativename) + return minidom.parseString(data) @staticmethod - def _json_schemas_relative_dir(): - return "JsonSchemas" + def _load_bundle_file(standard: str, filename: str, schema_path=__RFG_PATH__): + """ + Helper method to load file content from schemas bundle subdirs. + """ + fullpath = path.join(schema_path, RedfishBase._bundle_relative_path(standard), filename) + return RedfishBase._load_file_fullpath(fullname=fullpath) @staticmethod - def _load_file_fullpath(fullname): - with open(fullname) as f: - data = f.read() - return data + def _load_json_file(fullname): + """ + Separate method to load json schema from any file. + """ + data = RedfishBase._load_file_fullpath(fullname) + return json.loads(data) @staticmethod - def _load_file(fullname, schema_path=__RFG_PATH__): - file_path = path.join(schema_path, fullname) - with open(file_path) as f: + def _load_file_fullpath(fullname): + """ + Reads any file content. + """ + with open(fullname) as f: data = f.read() return data @staticmethod - def _load_bundle_file(fullname): - file_path = path.join("assets", "schemas", "bundle", fullname) - return RedfishBase._load_file(file_path) - - @staticmethod - def _load_csdl_file(fullname): - data = RedfishBase._load_bundle_file(fullname) - return minidom.parseString(data) - + def _write_file(destdir, filename, content): + """ + Create dirs if not exist and writes file content. + """ + if not path.isdir(destdir): + makedirs(destdir, exist_ok=True) + filename = path.join(destdir, filename) + if isinstance(content, str): + with open(filename, "w") as file: + file.writelines(content) + else: + with open(filename, "wb") as file: + file.write(content) @staticmethod def _version_from_filename(filename): @@ -64,44 +146,70 @@ def schema_and_version_from(filename): return parts[0], None @staticmethod - def write_file(destdir, filename, content): - if not path.isdir(destdir): - makedirs(destdir, exist_ok=True) - filename = path.join(destdir, filename) - if isinstance(content, str): - with open(filename, "w") as file: - file.writelines(content) + def _json_full_filename(schema, srcdir=__RFG_PATH__): + fromname = RedfishBase._map_json_schema_file(schema.schema_id()) + from_name_version = fromname + if schema._schema_version is not None: + from_name_version += ".v" + schema._schema_version + return path.join( + srcdir, + RedfishBase._bundle_relative_path(schema._standard), + "json-schema", + from_name_version + ".json") + + @staticmethod + def _schema_file_csdl_by_name(schema_id): + return schema_id + "_" + RedfishBase.redfish_version() + ".xml" + + @staticmethod + def _map_json_schema_file(basename): + schemas_map = RedfishBase._json_schema_file_map() + if basename in schemas_map: + return schemas_map[basename] else: - with open(filename, "wb") as file: - file.write(content) + return basename - def __init__(self, standard: str, schema_name, version) -> None: - if standard != "redfish" and standard != "redfish/swordfish": - raise Exception("API Standard \"%s\" in not supported" % standard) - self._standard = standard - self._schema_name = schema_name - if self._schema_name is None: - raise ValueError("Node config: require field 'Schema'") - self._schema_version = version[1:] if version is not None and version.startswith("v") else version + @staticmethod + def _json_schema_file_map(): + return { "RedfishExtensions": "redfish-schema" } - def standard(self): - return self._standard - def schema_id(self): - return self._schema_name + @staticmethod + def _json_full_path(standard: str): + return path.join(RedfishBase._bundle_full_path(standard), "json-schema") - def version(self): - if self._schema_version: - return "v" + self._schema_version.replace(".", "_") - return None + @staticmethod + def _bundle_full_path(standard: str, srcdir=__RFG_PATH__): + return path.join(srcdir, RedfishBase._bundle_relative_path(standard)) - def _available_schema(self): - if self.schema is not None: - return self.schema - return self.schema_spec + @staticmethod + def _bundle_csdl_full_path(standard: str, srcdir=__RFG_PATH__): + if "swordfish" in standard: + # bundle/scdl-schema for SNI Swordfish bundle zip + return path.join(srcdir, RedfishBase._bundle_relative_path(standard), "csdl-schema") + else: + # bundle/scdl for DMTF bundle zip + return path.join(srcdir, RedfishBase._bundle_relative_path(standard), "csdl") - def is_oem(self): - return self._schema_name.startswith("Oem") + @staticmethod + def _bundle_relative_path(standard: str): + if "swordfish" in standard: + return path.join("assets", "schemas", "swordfish", "bundle") + else: + return path.join("assets", "schemas", "bundle") + + @staticmethod + def _oem_full_path(srcdir=__RFG_PATH__): + return path.join(srcdir, "assets", "oem") - def get_json_schema(self): - return self.schema + @staticmethod + def redfish_version(): + return "v1" + + @staticmethod + def _json_schemas_relative_dir(): + return "JsonSchemas" + + @staticmethod + def _formatting_classname(classname): + return str("Redfish" + classname[0].upper() + classname[1:]) diff --git a/tools/redfish-gen/redfish_gen/redfish_node.py b/tools/redfish-gen/redfish_gen/redfish_node.py index a620b6ce..0f216a76 100644 --- a/tools/redfish-gen/redfish_gen/redfish_node.py +++ b/tools/redfish-gen/redfish_gen/redfish_node.py @@ -1,13 +1,8 @@ ## SPDX-License-Identifier: Apache-2.0 ## Copyright (C) 2022, KNS Group LLC (YADRO) -import yaml -import json -from xml.dom import minidom - from .redfish_base import RedfishBase from .property import OemFragment, Property -from .globals import __RFG_PATH__ from .node_parameter import NodeParameter, StaticNodeParameter @@ -38,43 +33,6 @@ def build(parent=None, **kwargs): else: raise ValueError("Invalid config definition") - def __load_openapi(self): - data = self._load_bundle_file(self.__schema_file_openapi()) - return yaml.safe_load(data) - - def __load_schema_json(self): - file = self.__schema_file_json() - if file is not None: - return json.loads(self._load_bundle_file(file)) - return file - - def __load_schema_spec_json(self): - data = self._load_bundle_file(self.__schema_spec_file_json()) - return json.loads(data) - - def __schema_file(self): - if self._schema_version: - return self._schema_name + "." + self.version() - return None - - def __schema_spec_file(self): - return self._schema_name - - def __schema_file_json(self): - filename = self.__schema_file() - if filename is not None: - return "json-schema/" + filename + ".json" - return filename - - def __schema_spec_file_json(self): - return "json-schema/" + self.__schema_spec_file() + ".json" - - def __schema_file_openapi(self): - return "openapi/" + self.__schema_spec_file() + ".yaml" - - def __schema_file_csdl(self): - return "csdl/" + self._schema_name + "_v1.xml" - def __build_id(self): segment = "/%s%s" % (self.uri_prefix(), self._segment) parent = self._parent.id() if self._parent is not None else "/redfish" @@ -92,10 +50,10 @@ def __init__(self, parent, segment, **kwargs): self.__build_id() self._y = kwargs # Load resourses - self.openapi = self.__load_openapi() - self.schema_spec = self.__load_schema_spec_json() - self.schema = self.__load_schema_json() - self.csdl = RedfishBase._load_csdl_file(self.__schema_file_csdl()) + self.openapi = self._load_openapi() + self.schema_spec = self._load_schema_spec_json() + self.schema = self._load_schema_json() + self.csdl = RedfishBase._load_csdl_file(self.standard(), self._schema_file_csdl()) def is_dynamic(self): return False @@ -135,12 +93,13 @@ def __schema_spec_node(self): definitions = self.schema_spec["definitions"] if self._schema_name in definitions: return definitions[self._schema_name] - raise Exception("Redfish JSON schema '" + self.__schema_spec_file_json() + raise Exception("Redfish JSON schema '" + self._schema_spec_file_json() + "' is corrupted") - @staticmethod - def __formatting_classname(classname): - return str("Redfish" + classname[0].upper() + classname[1:]) + def __available_schema(self): + if self.schema is not None: + return self.schema + return self.schema_spec # Public def name(self): @@ -156,7 +115,7 @@ def __get_field_from_schema_spec_node(self, field): elif field in node["anyOf"][1]: return node["anyOf"][1][field] raise Exception("Redfish JSON schema '" - + self.__schema_spec_file_json() + "' is corrupted") + + self._schema_spec_file_json() + "' is corrupted") def description(self): return self.__get_field_from_schema_spec_node("description") @@ -173,10 +132,10 @@ def id(self): return self._id def odata_type(self): - return self._available_schema()["title"] + return self.__available_schema()["title"] def classname(self): - return RedfishNode.__formatting_classname(self._classname) + return RedfishBase._formatting_classname(self._classname) def def_filename(self): return self._classname @@ -229,9 +188,9 @@ def childs(self): if not isinstance(ref["Node"], list) and not isinstance(ref["Node"], str): raise ValueError("Node key must be a list or a string") if isinstance(ref["Node"], str): - r.append(RedfishNode.__formatting_classname(ref["Node"])) + r.append(RedfishBase._formatting_classname(ref["Node"])) elif isinstance(ref["Node"], list): - r += [RedfishNode.__formatting_classname(v) + r += [RedfishBase._formatting_classname(v) for v in ref["Node"]] except Exception: pass @@ -252,11 +211,11 @@ def reference(self): ref["Field"] = ref["Node"] if isinstance(ref["Node"], list): ref_class_list = [ - RedfishNode.__formatting_classname(n) for n in ref["Node"]] + RedfishBase._formatting_classname(n) for n in ref["Node"]] ref_class = "ListReferences<%s>" % ",".join(ref_class_list) ref['Type'] = 'List' else: - ref_class = "IdReference<%s>" % RedfishNode.__formatting_classname( + ref_class = "IdReference<%s>" % RedfishBase._formatting_classname( ref["Node"]) ref['Type'] = 'Object' ref["Classname"] = ref_class @@ -275,7 +234,7 @@ def __check_properties_definition(self, source: str) -> bool: def _properties_expand(self, source: str): if not self.__check_properties_definition(source): return [] - return Property.build(source, self.schema_id(), self._available_schema(), self.__get()["Properties"]) + return Property.build(source, self.schema_id(), self.__available_schema(), self.__get()["Properties"]) def links(self): return self._properties_expand("Links") diff --git a/tools/redfish-gen/redfish_gen/redfish_schema.py b/tools/redfish-gen/redfish_gen/redfish_schema.py index bca7b009..59a12c50 100644 --- a/tools/redfish-gen/redfish_gen/redfish_schema.py +++ b/tools/redfish-gen/redfish_gen/redfish_schema.py @@ -7,7 +7,6 @@ from xml.dom import minidom from .redfish_base import RedfishBase -from .globals import __RFG_PATH__ from .globals import __WWW_PATH__ class RedfishSchema(RedfishBase): @@ -17,6 +16,8 @@ class RedfishSchema(RedfishBase): required information to prepare schema file """ + REDFISH_CSDL_BUNDLE_URL = "http://docs.oasis-open.org/odata/ns/edmx" + schemas = {} # Instances factory @@ -37,8 +38,8 @@ def __init__(self, standard: str, schema_name, version, resolved, schema_json) - if schema_json is not None: self.schema = schema_json else: - filename = self.__json_full_filename() - self.schema = RedfishSchema.load_json(filename) + filename = RedfishBase._json_full_filename(self) + self.schema = RedfishBase._load_json_file(filename) def schema_and_version(self): if self._schema_version: @@ -49,30 +50,13 @@ def schema_and_version(self): def resolved(self): return self._resolved + def get_json_schema(self): + return self.schema + @staticmethod def redfish_v1_relative_path(standard: str): return path.join(standard, RedfishBase.redfish_version()) - @staticmethod - def extract_schemas(properties: dict, deep = 0): - """ - Interates properties recusively to find all inner schema references. - """ - if deep == 10: - raise Exception("Unadle to find all inner schemas in properties, max deep recusion reached: %s" % str(deep)) - if properties is not None: - for prop in properties.values(): - if "anyOf" in prop: - for ref in prop["anyOf"]: - if "$ref" in ref: - RedfishSchema.__add_schema_by_ref_json(ref["$ref"]) - if "items" in prop: - prop = prop["items"] - if "$ref" in prop: - RedfishSchema.__add_schema_by_ref_json(prop["$ref"]) - if "properties" in prop: - RedfishSchema.extract_schemas(prop["properties"], deep + 1) - @staticmethod def __add_schema_by_ref_json(schema_ref): """ @@ -130,6 +114,9 @@ def __add_schema(standard: str, schema_name: str, schema_version: str): @staticmethod def generate_all_schema(): + """ + Main method to generate all schemas. + """ schemaIndexDoc, rootElement = RedfishSchema.__create_csdl_scheme_index() jsonSchemas = [] RedfishSchema.__prepare_additional_schemas() @@ -140,9 +127,12 @@ def generate_all_schema(): @staticmethod def __prepare_additional_schemas(): - # add requred redfish schemas + """ + Adds schemas required by the Redfish Sevice Validator. + """ additionalRequiredSchemas = { - "RedfishExtensions": "redfish" # or, maybe, "redfish/swordfish" + # : ("redfish" or "redfish/swordfish") + "RedfishExtensions": "redfish" } for schemaName in sorted(additionalRequiredSchemas): if schemaName not in RedfishSchema.schemas: @@ -153,7 +143,11 @@ def __prepare_additional_schemas(): print("Warning: additional scheme already added: \"%s\"" % schemaName) @staticmethod - def __prepare_oem_schemas(jsondir=path.join(__RFG_PATH__, "assets", "schemas", "bundle", "json-schema")): + def __prepare_oem_schemas(): + """ + Finds files by the "Oem*.json" mask and adds to common schemas list. + """ + jsondir = RedfishBase._json_full_path(standard="redfish") for root, _, files in (next(walk(jsondir)),): for file in files: if file.startswith("Oem") and file.endswith(".json"): @@ -161,12 +155,16 @@ def __prepare_oem_schemas(jsondir=path.join(__RFG_PATH__, "assets", "schemas", " _, schemaVersion = RedfishBase.schema_and_version_from(file) # Add Oem*.json schemas only with version if path.isfile(filename) and schemaVersion is not None: - json_spec = RedfishSchema.load_json(filename) - RedfishSchema.extract_schemas(json_spec) + json_spec = RedfishSchema._load_json_file(filename) + RedfishSchema.expand_schema_properties(json_spec) RedfishSchema.__add_schema_by_ref_json(filename) @staticmethod def __resolve_remaining_schemas(): + """ + Runs over added schemas and resolve they in cycle + until new ones will be resolved. + """ resolve_iterations = 10 while resolve_iterations > 0: resolve_iterations -= 1 @@ -184,16 +182,34 @@ def __resolve_remaining_schemas(): def __resolve(schema): json = schema.get_json_schema() if "definitions" in json: - RedfishSchema.extract_schemas(json["definitions"]) + RedfishSchema.expand_schema_properties(json["definitions"]) schema._resolved = True + @staticmethod + def expand_schema_properties(properties: dict, deep = 0): + """ + Iterates properties recusively to find all inner schema properties and references. + """ + if deep == 10: + raise Exception("Unadle to find all inner schemas in properties, max deep recusion reached: %s" % str(deep)) + if properties is not None: + for prop in properties.values(): + if "anyOf" in prop: + for ref in prop["anyOf"]: + if "$ref" in ref: + RedfishSchema.__add_schema_by_ref_json(ref["$ref"]) + if "items" in prop: + prop = prop["items"] + if "$ref" in prop: + RedfishSchema.__add_schema_by_ref_json(prop["$ref"]) + if "properties" in prop: + RedfishSchema.expand_schema_properties(prop["properties"], deep + 1) + @staticmethod def __build_result_schemas(schemaIndexDoc, rootElement, jsonSchemas): keys = sorted(RedfishSchema.schemas) for key in keys: schema = RedfishSchema.schemas[key] - if not schema.resolved(): - RedfishSchema.__resolve(schema) print(" - Generating Redfish scheme file: " + schema.schema_and_version()) RedfishSchema.__copy_schema_scdl_from_assets(schema) RedfishSchema.__add_index_refs_part(schema.standard(), schema.schema_id(), schemaIndexDoc, rootElement) @@ -204,9 +220,9 @@ def __build_result_schemas(schemaIndexDoc, rootElement, jsonSchemas): @staticmethod def __create_csdl_scheme_index(): domImpl = minidom.getDOMImplementation() - csdlDocument = domImpl.createDocument("http://docs.oasis-open.org/odata/ns/edmx", "edmx:Edmx", None) # TODO replace Url with variable + csdlDocument = domImpl.createDocument(RedfishSchema.REDFISH_CSDL_BUNDLE_URL, "edmx:Edmx", None) rootElement = csdlDocument.documentElement - rootElement.setAttributeNS("xmls", "xmlns:edmx", "http://docs.oasis-open.org/odata/ns/edmx") # TODO replace Url with variable + rootElement.setAttributeNS("xmls", "xmlns:edmx", RedfishSchema.REDFISH_CSDL_BUNDLE_URL) rootElement.setAttribute("Version", "4.0") return csdlDocument, rootElement @@ -215,7 +231,7 @@ def __build_indexes(schemaIndexDoc, rootElement, jsonSchemas): # Generate "/redfish/v1/$metadata/index.xml" csdlSchemeIndex = schemaIndexDoc.toprettyxml(encoding="utf-8") csdlOutDir = path.join(__WWW_PATH__, RedfishSchema.redfish_v1_relative_path("redfish"), "$metadata") - RedfishBase.write_file(csdlOutDir, "index.xml", csdlSchemeIndex) + RedfishBase._write_file(csdlOutDir, "index.xml", csdlSchemeIndex) # Generate "/redfish/v1/JsonSchemas/index.json" RedfishSchema.__generate_json_index("redfish", jsonSchemas) @@ -227,10 +243,10 @@ def __add_schema_by_name(standard: str, schemaName): @staticmethod def __add_index_refs_part(standard: str, schema_name: str, csdlIndexDoc, csdlIndexRoot, scdlOemDir = ""): referenceElement = csdlIndexDoc.createElement('edmx:Reference') - uri = path.join(RedfishSchema.redfish_v1_relative_path(standard), "schema", RedfishSchema.__schema_file_csdl_by_name(schema_name)) \ + uri = path.join(RedfishSchema.redfish_v1_relative_path(standard), "schema", RedfishSchema._schema_file_csdl_by_name(schema_name)) \ if len(scdlOemDir) == 0 else path.join(scdlOemDir, schema_name + "_" + RedfishBase.redfish_version() + ".xml") csdlPath = path.join(__WWW_PATH__, uri) - csdl = RedfishBase._load_csdl_file(csdlPath) + csdl = RedfishBase._load_csdl_file(standard, csdlPath) referenceElement.setAttribute("Uri", "/" + uri) for schema in csdl.getElementsByTagName("Schema"): schemaNamespace = schema.getAttribute("Namespace") @@ -242,18 +258,18 @@ def __add_index_refs_part(standard: str, schema_name: str, csdlIndexDoc, csdlInd csdlIndexRoot.appendChild(referenceElement) @staticmethod - def __copy_schema_scdl_from_assets(schema, srcdir=__RFG_PATH__, destdir=__WWW_PATH__): - """ Copying scheme file prevents re-formatting XML """ + def __copy_schema_scdl_from_assets(schema, destdir=__WWW_PATH__): + """ + Copying scheme file prevents re-formatting XML. + """ if schema.is_oem(): fromfile = path.join( - srcdir, - RedfishSchema.__oem_relative_path(), - RedfishSchema.__schema_file_csdl_by_name(schema.schema_id())) + RedfishBase._oem_full_path(), + RedfishBase._schema_file_csdl_by_name(schema.schema_id())) else: fromfile = path.join( - srcdir, - RedfishSchema.__bundle_csdl_relative_path(schema.standard()), - RedfishSchema.__schema_file_csdl_by_name(schema.schema_id())) + RedfishBase._bundle_csdl_full_path(schema.standard()), + RedfishBase._schema_file_csdl_by_name(schema.schema_id())) todir = path.join( destdir, schema.standard(), @@ -263,11 +279,11 @@ def __copy_schema_scdl_from_assets(schema, srcdir=__RFG_PATH__, destdir=__WWW_PA makedirs(todir, exist_ok=True) tofile = path.join( todir, - RedfishSchema.__schema_file_csdl_by_name(schema.schema_id())) + RedfishBase._schema_file_csdl_by_name(schema.schema_id())) copy(fromfile, tofile) @staticmethod - def __copy_schema_json_file_from_assets(schema, srcdir=__RFG_PATH__, destdir=__WWW_PATH__): + def __copy_schema_json_file_from_assets(schema, destdir=__WWW_PATH__): """ Copy json schema file from the "redfish" and "redfish/swordfish" bundles to the destination diretory. @@ -281,7 +297,7 @@ def __copy_schema_json_file_from_assets(schema, srcdir=__RFG_PATH__, destdir=__W """ schemaNameVer = schema.schema_and_version() - fromfile = schema.__json_full_filename() + fromfile = RedfishBase._json_full_filename(schema) toname = schema.schema_id() redfishdir = path.join( schema.standard(), @@ -309,21 +325,12 @@ def __copy_schema_json_file_from_assets(schema, srcdir=__RFG_PATH__, destdir=__W RedfishSchema.__write_json_subindex(schema.standard(), redfishdir, schema.schema_id()) return redfishdir - def __json_full_filename(self, srcdir=__RFG_PATH__): - fromname = RedfishSchema.__map_json_schema_file(self.schema_id()) - from_name_version = fromname - if self._schema_version is not None: - from_name_version += ".v" + self._schema_version - return path.join( - srcdir, - RedfishSchema.bundle_relative_path(self._standard), - "json-schema", - from_name_version + ".json") - @staticmethod def __generate_json_index(standard: str, json_schemas): + """ + Generates "/redfish/v1/JsonSchemas/index.json". + """ json_schema_index = RedfishSchema.__create_json_schema_index(standard) - # Generate "/redfish/v1/JsonSchemas/index.json" for schema_id in json_schemas: RedfishSchema.__add_json_scheme_index_member(json_schema_index, schema_id) json_schema_index["Members@odata.count"] = len(json_schema_index["Members"]) @@ -333,13 +340,13 @@ def __generate_json_index(standard: str, json_schemas): RedfishBase.redfish_version(), "JsonSchemas" ) - RedfishBase.write_file(json_out_dir, "index.json", content) + RedfishBase._write_file(json_out_dir, "index.json", content) @staticmethod def __write_json_subindex(standard: str, relative_schema_path, schema_spec_name, destdir = __WWW_PATH__): content = RedfishSchema.__generate_json_schema_index(standard, schema_spec_name, relative_schema_path) fullpath = path.join(destdir, relative_schema_path) - RedfishBase.write_file(fullpath, "index.json", content) + RedfishBase._write_file(fullpath, "index.json", content) @staticmethod def __create_json_schema_index(standard: str): @@ -363,7 +370,7 @@ def __add_json_scheme_index_member(index_dict, schema_path): @staticmethod def __generate_json_schema_index(standard: str, schema_spec_name, relative_schema_path): - template = RedfishSchema.__generate_json_schema_index_template() + template = RedfishSchema.__json_schema_index_template() template = template.replace("{name}", schema_spec_name) template = template.replace("{relativeSchemaPath}", relative_schema_path) template = template.replace("{JsonSchemas}", RedfishBase._json_schemas_relative_dir()) @@ -372,7 +379,7 @@ def __generate_json_schema_index(standard: str, schema_spec_name, relative_schem return template @staticmethod - def __generate_json_schema_index_template(): + def __json_schema_index_template(): return '''{ "@odata.context": "/{standard}/{v}/$metadata#JsonSchemaFile.JsonSchemaFile", "@odata.id": "/{standard}/{v}/{JsonSchemas}/{name}", @@ -396,12 +403,9 @@ def __generate_json_schema_index_template(): }''' @staticmethod - def __find_latest_version_schema_in_json(standartd: str, schema_id, srcdir=__RFG_PATH__): - json_bundle_path = path.join( - srcdir, - RedfishSchema.bundle_relative_path(standartd), - "json-schema") - schema_id = RedfishSchema.__map_json_schema_file(schema_id) + def __find_latest_version_schema_in_json(standard: str, schema_id): + json_bundle_path = RedfishBase._json_full_path(standard) + schema_id = RedfishSchema._map_json_schema_file(schema_id) newest_name = schema_id newest_double_ver = 0 for _, _, files in (next(walk(json_bundle_path)),): @@ -413,35 +417,6 @@ def __find_latest_version_schema_in_json(standartd: str, schema_id, srcdir=__RFG newest_double_ver = current_double_ver return RedfishBase._version_from_filename(newest_name) - @staticmethod - def __schema_file_csdl_by_name(schema_id): - return schema_id + "_" + RedfishBase.redfish_version() + ".xml" - - @staticmethod - def __bundle_csdl_relative_path(standard: str): - if "swordfish" in standard: - # bundle/scdl-schema for SNI Swordfish bundle zip - return path.join(RedfishSchema.bundle_relative_path(standard), "csdl-schema") - else: - # bundle/scdl for DMTF bundle zip - return path.join(RedfishSchema.bundle_relative_path(standard), "csdl") - - @staticmethod - def bundle_relative_path(standard: str): - if "swordfish" in standard: - return path.join("assets", "schemas", "swordfish", "bundle") - else: - return path.join("assets", "schemas", "bundle") - - @staticmethod - def __oem_relative_path(): - return path.join("assets", "oem") - - @staticmethod - def load_json(fullname): - data = RedfishSchema._load_file_fullpath(fullname) - return json.loads(data) - @staticmethod def __version_to_double(schema_spec): parts = schema_spec.split(".") @@ -453,18 +428,6 @@ def __version_to_double(schema_spec): return int(ver_parts[1]) + 0.00000001 return 0 - @staticmethod - def __map_json_schema_file(basename): - schemas_map = RedfishSchema.__json_schema_file_map() - if basename in schemas_map: - return schemas_map[basename] - else: - return basename - - @staticmethod - def __json_schema_file_map(): - return { "RedfishExtensions": "redfish-schema" } - @staticmethod def __fix_to_dot_version(filename): """