Commit 1e0e3f47 by Gunnar Billung-Meyer

change schema to 1.4.0

parent 8fbc13c6

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

# CSDL-to-JSON-Convertor
The CSDL-to-JSON-Convertor is a **Python 3** application, with which JSON schema files can be generated from CSDL files. It is part of the [Redfish-Tools](https://github.com/DMTF/Redfish-Tools).
## Usage
The application can be started by running the **service.py** with Python 3.
One can adapt the **csdl2json.cmd** file in the **scripts** folder to conveniently run this application on a Windows system.
### Parameters
#### --directory
This parameter specifies the source folder, which contains the CSDL schema files.
#### --outdir
This parameter points to the folder where the JSON schema files will be generated in.
# CSDL to JSON Converter
Copyright 2017 Distributed Management Task Force, Inc. All rights reserved.
## About
The CSDL to JSON Converter is a python3 tool which processes Redfish CSDL files and converts them to the Redfish JSON Schema format.
## Usage
Ensure that the machine running the tool has a python 3 install.
Example: `python3 csdl-to-json.py --input <CSDL-Dir> --output <JSON-Dir> --config <Config-File>`
The tool will process all files found in the folder specified by the *input* argument. It will convert the contents of the files to create JSON Schema files and save them to the folder specified by the *output* argument; the [Operation section](#operation) describes this process in more detail. There are some control parameters that are read in from the JSON file specified by the *config* argument; the [Config File section](#config-file) describes the contents of the file.
### Options
```
usage: csdl-to-json.py [-h] --input INPUT --output OUTPUT [--config CONFIG]
[--overwrite OVERWRITE]
A tool used to convert Redfish CSDL files to Redfish JSON Schema files
required arguments:
--input INPUT, -I INPUT
The folder containing the CSDL files to convert
--output OUTPUT, -O OUTPUT
The folder to write the converted JSON files
optional arguments:
-h, --help show this help message and exit
--config CONFIG, -C CONFIG
The configuration file containing definitions for
various links and user strings
--overwrite OVERWRITE, -W OVERWRITE
Overwrite the versioned files in the output directory
if they already exist (default is True)
```
### Config File
The config file can contain up to five parameters; parameters not defined will have a default value in the tool:
* Copyright: The copyright string to include in the JSON Schema files
* RedfishSchema: A pointer to the Redfish extensions to JSON Schema
* ODataSchema: A pointer to the OData extensions to JSON Schema
* Location: A pointer to the web folder where the resulting JSON Schema files will be published
* ResourceLocation: A pointer to the web folder where the core Resource_v1.xml file can be found
Sample File and Default Values:
```
{
"Copyright": "Copyright 2014-2017 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright",
"RedfishSchema": "http://redfish.dmtf.org/schemas/v1/redfish-schema.v1_2_0.json",
"ODataSchema": "http://redfish.dmtf.org/schemas/v1/odata.4.0.0.json",
"Location": "http://redfish.dmtf.org/schemas/v1/",
"ResourceLocation": "http://redfish.dmtf.org/schemas/v1/"
}
```
## Operation
The tool makes several assumptions about the format of the Redfish CSDL files:
* Each file that defines a resource follows the Redfish model for inheritance by copy; other than the base *Resource* definition, each resource definition is contained in one file
* Any referenced external namespaces have proper *Include* statements found at the top of the CSL file
* All annotations have their expected facets filled; for example, the OData.Description annotation must use the *String=* facet
* All namespaces follow the Redfish defined format where a namespace is either unversioned, or is in the form *name.vX_Y_Z*
* If a reference is made to another CSDL file, its JSON Schema file will be in the same folder
Before any translation is done, the tool will attempt to locate the Resource_v1.xml schema. This is to cache properties for base definitions that all resources use. The tool will first check to see if the file exists in the input directory; if it doesn't exist there, it will access the remote location for the file.
Once the Resource_v1.xml definitions are cached, the tool loops on all files ending in ".xml" in the input directory. For every namespace found in the file, it will generate a corresponding ".json" file in the following manner:
* For EntityType and ComplexType definitions...
* ... that are in an unversioned namespace and are marked as abstract have a definition that contains an "anyOf" statement in the unversioned JSON Schema that points to all versioned definitions
* ... that are in an unversioned namespace and are not marked as abstract have their definition translated only to the unversioned JSON Schema file
* ... that are in a versioned namespace have their definitions translated to that version of the JSON Schema file, and newer JSON Schema files
* Action definitions...
* ... that are in an unversioned namespace are translated to all versioned JSON Schema files
* ... that are in a versioned namespace have their definitions translated to that version of the JSON Schema file, and newer JSON Schema files
* EnumType and TypeDefinition definitions...
* ... that are in an unversioned namespace are translated to the unversioned JSON Schema file
* ... that are in a versioned namespace have their definitions translated to that version of the JSON Schema file, and newer JSON Schema files
#!/usr/bin/python
# Copyright Notice:
# Copyright 2016 Distributed Management Task Force, Inc. All rights reserved.
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tools/LICENSE.md
"""
CSDL to JSON Convertor utilities
"""
import http.client
import os
class Utilities:
#########################################################################################################
# Name: show_interactive_mode #
# Description: #
# Displays a form for input. #
# This method should be called when there is an error or user wants to generate the JSON #
# in an interactive fashion #
#########################################################################################################
@staticmethod
def show_interactive_mode(error):
result = "Content-type: text/html\n"
result += "\n"
result += "<HTML>\n"
result += " <HEAD>\n"
result += " <TITLE>\n"
result += " CSDL to JSON Convertor\n"
result += " </TITLE>\n"
result += " </HEAD>\n"
result += " <BODY>\n"
result += " <H1>CSDL to JSON Convertor</H1>\n"
if error is not None:
result += "Error: "
result += error
result += "\n"
result += " <H2>Overview</H2>\n"
result += " <p> This service converts OData CSDL metadata files to JSON Schema equivalents.\n"
result += " <H2>Usage</H2>\n"
result += " <p> This service can be used in interactive mode or command mode.\n"
result += " <H3>Interactive Mode</H3>\n"
result += " <p> You are currently using the service's interactive mode.\n"
result += " From here, you can use the form below to request conversion of a CSDL metadata file\n"
result += " Simply type or paste the URL of the target CSDL Metadata file into the textbox and click Convert\n"
result += " <H3>Command Mode</H3>\n"
result += " <p> Make an HTTP GET request against a URL of the following form: <b>http://<i>service</i>?url=<i>URL</i>#<i>type</i></b>.\n"
result += " Here, <b><i>service</i></b> is the URL to this service (your browser's current address), <b><i>URL</i></b> is the URL of the CSDL Metadata and <b><i>type</i></b> is the type for which to return a JSON Schema representation.\n"
result += " Make sure you accept the <b>application/json</b> content type.\n"
result += " <FORM target=\"service.py\">\n"
result += " URL: <input name=\"url\" type=\"text\" size=\"100\" /> \n"
result += " <input name=\"submitBtn\" type=\"submit\" value=\"Convert\" />\n"
result += " </FORM>\n"
result += " </BODY>\n"
result += "</HTML>\n"
return result
#################################################################
# Name: open_url #
# Description: #
# Opens the target file and extracts data from it. #
#################################################################
@staticmethod
def open_url(url, directory):
#temp hack to always open from file
if( url.find("OData") < 0 ):
decoded = Utilities.open_as_file(url, directory)
return decoded
# TODO: handle cases where URL is malformed
try:
connections = {}
hostStart = url.find("//")
prefix = url[:hostStart]
hostStop = url.find("/", hostStart + 2)
hostname = url[hostStart + 2 : hostStop]
resname = url[hostStop :]
if hostname in connections.keys():
conn = connections[hostname]
else:
conn = http.client.HTTPConnection(hostname)
connections[hostname] = conn
conn.request("GET", resname)
response = conn.getresponse()
data = response.read()
decoded = data.decode("utf-8")
if response.status != 200:
decoded = Utilities.open_as_file(url, directory)
except:
decoded = Utilities.open_as_file(url, directory)
return decoded
#################################################################
# Name: open_as_file #
# Description: #
# Opens the target file and extracts data from it. #
#################################################################
@staticmethod
def open_as_file(url, directory):
try:
filelocation = url.rfind("/")
if(filelocation > 0):
filename=url[filelocation+1:]
else:
filename=url
if(len(directory) > 0 ):
filename = directory + os.path.sep + filename
metafile = open(filename)
decoded = metafile.read()
except:
decoded = ""
#print("failed to open " + url + " as " + filename)
return decoded
#################################################################
# Name: indent #
# Description: #
# Enumeration for various scenarios #
#################################################################
@staticmethod
def indent(depth) :
return " " * depth
{
"Copyright": "Copyright 2014-2017 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright",
"RedfishSchema": "http://redfish.dmtf.org/schemas/v1/redfish-schema.v1_3_0.json",
"ODataSchema": "http://redfish.dmtf.org/schemas/v1/odata.v4_0_1.json",
"Location": "http://redfish.dmtf.org/schemas/v1/",
"ResourceLocation": "http://redfish.dmtf.org/schemas/v1/"
}
[http://redfish.dmtf.org/schemas/swordfish/v1/HostedStorageServices_v1.xml]
typename = HostedStorageServices.HostedStorageServices
Alias = HostedStorageServices
TypeType = EntityType
StubRef = http://redfish.dmtf.org/schemas/swordfish/v1/HostedStorageServices.json#/definitions/HostedStorageServices
Name = HostedStorageServices
Namespace = HostedStorageServices
JsonUrl = http://redfish.dmtf.org/schemas/swordfish/v1/HostedStorageServices.json
BaseType = Resource.v1_0_0.ResourceCollection
[http://redfish.dmtf.org/schemas/swordfish/v1/StorageSystemCollection_v1.xml]
typename = StorageSystemCollection.StorageSystemCollection
Alias = StorageSystemCollection
TypeType = EntityType
StubRef = http://redfish.dmtf.org/schemas/swordfish/v1/StorageSystemCollection.json#/definitions/StorageSystemCollection
Name = StorageSystemCollection
Namespace = StorageSystemCollection
JsonUrl = http://redfish.dmtf.org/schemas/swordfish/v1/StorageSystemCollection.json
BaseType = Resource.v1_0_0.ResourceCollection
[http://redfish.dmtf.org/schemas/swordfish/v1/StorageServiceCollection_v1.xml]
typename = StorageServiceCollection.StorageServiceCollection
Alias = StorageServiceCollection
TypeType = EntityType
StubRef = http://redfish.dmtf.org/schemas/swordfish/v1/StorageServiceCollection.json#/definitions/StorageServiceCollection
Name = StorageServiceCollection
Namespace = StorageServiceCollection
JsonUrl = http://redfish.dmtf.org/schemas/swordfish/v1/StorageServiceCollection.json
BaseType = Resource.v1_0_0.ResourceCollection
<?xml version="1.0" encoding="UTF-8"?>
<!---->
<!--################################################################################ -->
<!--# Copyright 2017-2019 christmann informationstechnik + medien GmbH & Co. KG -->
<!--################################################################################ -->
<!---->
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/errata03/csd01/complete/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Namespace="Org.OData.Core.V1" Alias="OData" />
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/Resource_v1.xml">
<edmx:Include Namespace="Resource.v1_0_0" />
</edmx:Reference>
<edmx:Reference Uri="Backplane_v1.xml">
<edmx:Include Namespace="Backplane" />
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="BackplaneCollection">
<EntityType Name="BackplaneCollection" BaseType="Resource.v1_0_0.ResourceCollection">
<NavigationProperty Name="Members" Type="Collection(Backplane.Backplane)">
<Annotation Term="OData.Permissions" EnumMember="OData.Permissions/Read" />
<Annotation Term="OData.Description" String="Contains the members of this collection." />
<Annotation Term="OData.AutoExpandReferences" />
</NavigationProperty>
</EntityType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
<?xml version="1.0" encoding="UTF-8"?>
<!---->
<!--################################################################################ -->
<!--# Copyright 2017-2019 christmann informationstechnik + medien GmbH & Co. KG -->
<!--################################################################################ -->
<!---->
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/errata03/csd01/complete/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Namespace="Org.OData.Core.V1" Alias="OData" />
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/RedfishExtensions_v1.xml">
<edmx:Include Namespace="RedfishExtensions.v1_0_0" Alias="Redfish"/>
<edmx:Include Namespace="Validation.v1_0_0" Alias="Validation"/>
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/Resource_v1.xml">
<edmx:Include Namespace="Resource"/>
<edmx:Include Namespace="Resource.v1_0_0" />
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/Chassis_v1.xml">
<edmx:Include Namespace="Chassis"/>
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/ComputerSystemCollection_v1.xml">
<edmx:Include Namespace="ComputerSystemCollection"/>
</edmx:Reference>
<edmx:Reference Uri="PCIeDeviceCollection_v1.xml">
<edmx:Include Namespace="PCIeDeviceCollection"/>
</edmx:Reference>
<edmx:Reference Uri="PCIeSwitchCollection_v1.xml">
<edmx:Include Namespace="PCIeSwitchCollection"/>
</edmx:Reference>
<edmx:Reference Uri="BaseboardCollection_v1.xml">
<edmx:Include Namespace="BaseboardCollection"/>
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Backplane">
<EntityType Name="Backplane" BaseType="Resource.v1_0_0.Resource">
<Annotation Term="OData.Description" String="This is the schema definition for the Backplane resource." />
<Annotation Term="OData.LongDescription" String="This is the schema definition for the Backplane resource. It represents the properties of a Backplane." />
</EntityType>
</Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Backplane.v0_1_0">
<EntityType Name="Backplane" BaseType="Backplane.Backplane">
<Property Name="Status" Type="Resource.Status" />
<Property Name="Links" Type="Backplane.v0_1_0.Links" Nullable="false">
<Annotation Term="OData.Permissions" EnumMember="OData.Permission/Read"/>
<Annotation Term="OData.Description" String="The links object contains the links to other resources that are related to this resource."/>
</Property>
<Property Name="BackplaneType" Type="Backplane.v0_1_0.BackplaneType">
<Annotation Term="OData.Permissions" EnumMember="OData.Permissions/Read"/>
<Annotation Term="OData.Description" String="The type of the Backplane."/>
</Property>
<NavigationProperty Name="Baseboards" Type="BaseboardCollection.BaseboardCollection" Nullable="false">
<Annotation Term="OData.Permissions" EnumMember="OData.Permission/Read"/>
<Annotation Term="OData.Description" String="This is a link to a collection of Baseboards this Backplane is connected to."/>
<Annotation Term="OData.LongDescription" String="This object shall only contain a reference to a collection of resources that comply to the Baseboard schema."/>
<Annotation Term="OData.AutoExpandReferences"/>
</NavigationProperty>
<NavigationProperty Name="PCIeSwitches" Type="PCIeSwitchCollection.PCIeSwitchCollection" Nullable="false">
<Annotation Term="OData.Permissions" EnumMember="OData.Permission/Read"/>
<Annotation Term="OData.Description" String="This is a link to a collection of PCIeSwitches hosted on this Backplane."/>
<Annotation Term="OData.LongDescription" String="This object shall only contain a reference to a collection of resources that comply to the PCIeSwitch schema."/>
<Annotation Term="OData.AutoExpandReferences"/>
</NavigationProperty>
<NavigationProperty Name="Chassis" Type="Chassis.Chassis" Nullable="false">
<Annotation Term="OData.Permissions" EnumMember="OData.Permission/Read"/>
<Annotation Term="OData.Description" String="The Chassis hosting this Backplane"/>
<Annotation Term="OData.LongDescription" String="This object shall only contain a reference that complies to the Chassis schema."/>
<Annotation Term="OData.AutoExpandReferences"/>
</NavigationProperty>
</EntityType>
<ComplexType Name="Links" BaseType="Resource.Links">
<NavigationProperty Name="ComputerSystems" Type="ComputerSystemCollection.ComputerSystemCollection" Nullable="false">
<Annotation Term="OData.Permissions" EnumMember="OData.Permission/Read"/>
<Annotation Term="OData.Description" String="This is a link to a collection of ComputerSystems hosted on the Baseboards connected to this Backplane."/>
<Annotation Term="OData.LongDescription" String="This object shall only contain a reference to a collection of resources that comply to the ComputerSystem schema."/>
<Annotation Term="OData.AutoExpandReferences"/>
</NavigationProperty>
<NavigationProperty Name="PCIeDevices" Type="PCIeDeviceCollection.PCIeDeviceCollection" Nullable="false">
<Annotation Term="OData.Permissions" EnumMember="OData.Permission/Read"/>
<Annotation Term="OData.Description" String="This is a link to a collection of PCIeDevices hosted on the Baseboards connected to this Backplane."/>
<Annotation Term="OData.LongDescription" String="This object shall only contain a reference to a collection of resources that comply to the PCIeDevice schema."/>
<Annotation Term="OData.AutoExpandReferences"/>
</NavigationProperty>
</ComplexType>
<EnumType Name="BackplaneType">
<Member Name="Ethernet">
<Annotation Term="OData.Description" String="This Backplane provides the infrastructure for ethernet communication."/>
</Member>
<Member Name="PCIe">
<Annotation Term="OData.Description" String="This Backplane provides the infrastructure for PCIe communication."/>
</Member>
</EnumType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
<?xml version="1.0" encoding="UTF-8"?>
<!---->
<!--################################################################################ -->
<!--# Copyright 2017-2019 christmann informationstechnik + medien GmbH & Co. KG -->
<!--################################################################################ -->
<!---->
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/errata03/csd01/complete/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Namespace="Org.OData.Core.V1" Alias="OData" />
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/Resource_v1.xml">
<edmx:Include Namespace="Resource.v1_0_0" />
</edmx:Reference>
<edmx:Reference Uri="Baseboard_v1.xml">
<edmx:Include Namespace="Baseboard" />
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="BaseboardCollection">
<EntityType Name="BaseboardCollection" BaseType="Resource.v1_0_0.ResourceCollection">
<NavigationProperty Name="Members" Type="Collection(Baseboard.Baseboard)">
<Annotation Term="OData.Permissions" EnumMember="OData.Permissions/Read" />
<Annotation Term="OData.Description" String="Contains the members of this collection." />
<Annotation Term="OData.AutoExpandReferences" />
</NavigationProperty>
</EntityType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
<?xml version="1.0" encoding="UTF-8"?>
<!---->
<!--################################################################################ -->
<!--# Copyright 2017-2019 christmann informationstechnik + medien GmbH & Co. KG -->
<!--################################################################################ -->
<!---->
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/errata03/csd01/complete/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Namespace="Org.OData.Core.V1" Alias="OData" />
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/RedfishExtensions_v1.xml">
<edmx:Include Namespace="RedfishExtensions.v1_0_0" Alias="Redfish"/>
<edmx:Include Namespace="Validation.v1_0_0" Alias="Validation"/>
</edmx:Reference>
<edmx:Reference Uri="http://redfish.dmtf.org/schemas/v1/Resource_v1.xml">