summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/documentation-example.rst76
-rw-r--r--docs/index.rst24
-rw-r--r--yang2tosca/tosca_transformer.xslt165
-rw-r--r--yang2tosca/tosca_translator.py62
4 files changed, 327 insertions, 0 deletions
diff --git a/docs/documentation-example.rst b/docs/documentation-example.rst
new file mode 100644
index 0000000..ebd80e4
--- /dev/null
+++ b/docs/documentation-example.rst
@@ -0,0 +1,76 @@
+.. two dots create a comment. please leave this logo at the top of each of your rst files.
+
+How to create documentation for your OPNFV project
+==================================================
+
+this is the directory structure of the docs/ directory that can be found in the root of your project directory
+
+.. code-block:: bash
+
+ ./yourfolder_name1/file_name1.rst
+ ./yourfolder_nameN/file_nameX.rst
+ ./documentation-example.rst
+ ./index.rst
+
+To create your own documentation, Create any number of directories (depending on your need) and place in each of them an index.rst.
+This index file must refence your other rst files.
+
+* Here is an example index.rst
+
+.. code-block:: bash
+
+ Example Documentation table of contents
+ =======================================
+
+ Contents:
+
+ .. toctree::
+ :numbered:
+ :maxdepth: 4
+
+ documentation-example.rst
+
+ Indices and tables
+ ==================
+
+ * :ref:`search`
+
+ Revision: _sha1_
+
+ Build date: |today|
+
+
+The Sphinx Build
+================
+
+When you push documentation changes to gerrit a jenkins job will create html documentation.
+
+* Verify Jobs
+For verify jobs a link to the documentation will show up as a comment in gerrit for you to see the result.
+
+* Merge jobs
+
+Once you are happy with the look of your documentation you can submit the patchset the merge job will copy the output of each documentation directory to http://artifacts.opnfv.org/$project/docs/$name_of_your_folder/index.html
+
+Here are some quick examples of how to use rst markup
+
+This is a headline::
+
+ here is some code, note that it is indented
+
+links are easy to add: Here is a link to sphinx, the tool that we are using to generate documetation http://sphinx-doc.org/
+
+* Bulleted Items
+
+ **this will be bold**
+
+.. code-block:: bash
+
+ echo "Heres is a code block with bash syntax highlighting"
+
+
+Leave these at the bottom of each of your documents they are used internally
+
+Revision: _sha1_
+
+Build date: |today|
diff --git a/docs/index.rst b/docs/index.rst
new file mode 100644
index 0000000..4e10cf3
--- /dev/null
+++ b/docs/index.rst
@@ -0,0 +1,24 @@
+.. OPNFV Parser documentation, created by
+ sphinx-quickstart.
+ You can adapt this file completely to your liking, but it should at least
+ contain the root `toctree` directive.
+
+Example Documentation table of contents
+=======================================
+
+Contents:
+
+.. toctree::
+ :numbered:
+ :maxdepth: 4
+
+ documentation-example.rst
+
+Indices and tables
+==================
+
+* :ref:`search`
+
+Revision: _sha1_
+
+Build date: |today|
diff --git a/yang2tosca/tosca_transformer.xslt b/yang2tosca/tosca_transformer.xslt
new file mode 100644
index 0000000..c8953ac
--- /dev/null
+++ b/yang2tosca/tosca_transformer.xslt
@@ -0,0 +1,165 @@
+<!-- Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+-->
+<xsl:stylesheet version="1.0" xmlns:ns="urn:ietf:params:xml:ns:yang:yin:1" xmlns:y="urn:ietf:params:xml:ns:yang:ietf-vdus" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="t">
+<xsl:output indent="no" method ="text"/>
+
+<xsl:variable name="tosca_general">
+ <entry key="tosca_definitions_version">tosca_definitions_version:tosca_simple_yaml_1_0_0</entry>
+ <entry key="tosca_default_namespace">tosca_default_namespace:tosca_simple_yaml_1_0_0</entry>
+ <entry key="template_name">template_name:</entry>
+ <entry key="description">description:</entry>
+ <entry key="template_author">template_author:</entry>
+ <entry key="template_version">template_version:</entry>
+ <entry key="derived">derived_from:tosca.nodes.Root</entry>
+ <entry key="import">import:</entry>
+</xsl:variable>
+<xsl:variable name="nodeTypes">
+ <entry key="generalvdus">type:tosca.nodes.general.vdus</entry>
+ <entry key="compute">type:tosca.nodes.compute</entry>
+ <entry key="storage">type:tosca.nodes.block.Storage</entry>
+ <entry key="network">type:tosca.nodes.network</entry>
+ <entry key="security">type:tosca.nodes.security</entry>
+ <entry key="policy">type:tosca.nodes.policy</entry>
+</xsl:variable>
+
+<xsl:template match="ns:module">
+<xsl:value-of select="concat(document('')//xsl:variable[@name='tosca_general']/entry[@key='tosca_definitions_version'] ,'&#x0A;')" />
+<xsl:value-of select="concat(document('')//xsl:variable[@name='tosca_general']/entry[@key='description'],'&#x0A;&#x09;',ns:description/node()/text(),'&#x0A;')" />
+<xsl:value-of select="concat(document('')//xsl:variable[@name='tosca_general']/entry[@key='import'],'&#x0A;&#x09;',ns:import/@module,'&#x0A;')" />
+metadata:
+ ID:<xsl:value-of select="@name"/>
+ Vendor:<xsl:value-of select="ns:organization/node()/text()"/>
+
+<xsl:for-each select="ns:container">
+dsl_definitions:<xsl:for-each select="ns:list">
+ compute_props_host_<xsl:value-of select="@name"/>:<text disable-output-escaping="yes"><![CDATA[&]]>compute_props_host_</text><xsl:value-of select="@name"/>
+ <xsl:for-each select="ns:container"><xsl:if test="@name = 'resource'"><xsl:for-each select="ns:container"><xsl:if test="@name = 'cpu'"><xsl:variable name="num_cpu" select="ns:leaf/ns:type/ns:range/@value"/>
+ num_cpu:<xsl:value-of select="$num_cpu"/>
+ </xsl:if>
+ <xsl:if test="@name='memory'">
+ <xsl:variable name="memory" select="ns:leaf/ns:type/ns:range/@value"/>
+ mem_size:<xsl:value-of select="$memory"></xsl:value-of>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:for-each>
+node_types:<xsl:for-each select="ns:list">
+ tosca.nodes.compute.<xsl:value-of select="@name"/>:
+ derived_from:tosca.nodes.compute
+</xsl:for-each>
+topology_template:
+ # a description of the topology template
+ description:>
+ <xsl:value-of select="ns:description/node()/text()"/>
+ inputs:
+ storage_size:
+ type:scalar-unit.size<xsl:for-each select="ns:list"><xsl:if test="@name = 'ellis'">
+ <xsl:for-each select="ns:container"><xsl:if test="@name = 'resource'"><xsl:for-each select="ns:container"><xsl:if test="@name = 'disk'">
+ default:<xsl:value-of select="ns:leaf/ns:type/ns:range/@value"/>
+ description:<xsl:value-of select="ns:description/node()/text()"/>
+ </xsl:if></xsl:for-each></xsl:if></xsl:for-each>
+ </xsl:if></xsl:for-each>
+ storage_location:
+ type:string
+ description:>
+ Block storage mount point (filesystem path).
+ node_templates:<xsl:for-each select="ns:list">
+ <xsl:text>&#xa;&#x9;&#x9;</xsl:text>
+ <xsl:value-of select="@name"/>:
+ type:tosca.nodes.Compute
+ capabilities:
+ os:
+ properties:
+ architecture:
+ type:
+ distribution:
+ version:
+ host:
+ properties:*compute_props_host_<xsl:value-of select="@name"/>
+ scalable:
+ properties:
+ min_instances:<xsl:for-each select="ns:leaf"><xsl:if test="@name = 'instance-num'">
+ <xsl:value-of select="ns:default/@value"/>
+ </xsl:if></xsl:for-each>
+ default_instances:<xsl:for-each select="ns:leaf"><xsl:if test="@name = 'instance-num'">
+ <xsl:value-of select="ns:default/@value"/>
+ </xsl:if></xsl:for-each>
+ requirements:
+ - local_storage:
+ node:<xsl:value-of select="@name"/>_BlockStorage
+ relationship:
+ type:AttachesTo
+ properties:
+ location:{ get_input:storage_location }
+ interfaces:
+ Standard:<xsl:for-each select="ns:container">
+ <xsl:if test="@name = 'workflow-script'">
+ <xsl:for-each select="ns:leaf">
+ <xsl:choose>
+ <xsl:when test="@name = 'init'">
+ start:
+ implementation:<xsl:value-of select="ns:default/@value"/>
+ </xsl:when>
+ <xsl:when test="@name='terminate'">
+ delete:
+ implementaion:<xsl:value-of select="ns:default/@value"/>
+ </xsl:when>
+ <xsl:when test="@name='graceful-shutdown'">
+ stop:
+ implementaion:<xsl:value-of select="ns:default/@value"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:text>&#xa;&#x9;&#x9;</xsl:text>
+ <xsl:variable name="vdu" select = "@name"/>
+ <xsl:value-of select="$vdu"/>_BlockStorage:
+ type:tosca.nodes.BlockStorage
+ properties:
+ size:{ get_input:storage_size }</xsl:for-each><xsl:for-each select="ns:list"><xsl:for-each select="ns:container"><xsl:if test="@name = 'resource'"><xsl:for-each select="ns:container">
+ <xsl:if test="@name='vnic'">
+ <xsl:variable name="vnic" select="ns:leaf/ns:type/ns:range/@value"/>
+ <xsl:call-template name="nic.loop">
+ <xsl:with-param name="from" select="1"/>
+ <xsl:with-param name="to" select="$vnic"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:for-each>
+</xsl:for-each>
+</xsl:template>
+<xsl:template name="nic.loop">
+<xsl:param name="from"/>
+ <xsl:param name="to"/>
+ <xsl:if test="$from &lt;= $to">
+ <xsl:text>&#xa;&#x9;</xsl:text>
+ <xsl:value-of select="../../../@name"/>_network<xsl:value-of select="$from"/>:
+ type:tosca.nodes.network.Network
+ properties:
+ ip_version:4
+ <xsl:value-of select="../../@name"/>_port<xsl:value-of select="$from"/>:
+ type:tosca.nodes.network.Port
+ requirements:
+ - binding:
+ node:<xsl:value-of select="../../@name"/>
+ - link:
+ node:<xsl:value-of select="../../../@name"/>_network<xsl:value-of select="$from"/>
+ <xsl:call-template name="nic.loop">
+ <xsl:with-param name="from" select="$from + 1"/>
+ <xsl:with-param name="to" select="$to"/>
+ </xsl:call-template>
+</xsl:if>
+</xsl:template>
+</xsl:stylesheet>
diff --git a/yang2tosca/tosca_translator.py b/yang2tosca/tosca_translator.py
new file mode 100644
index 0000000..afbb3a1
--- /dev/null
+++ b/yang2tosca/tosca_translator.py
@@ -0,0 +1,62 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+import getopt
+import argparse
+from lxml import etree
+
+
+def tosca_translator(file_name):
+ if os.path.exists(file_name):
+ var = file_name
+ file_format = var.split('.')
+ if len(file_format) == 2:
+ if file_format[1] == 'yaml' or file_format[1] == 'yang':
+ print("Its a yaml file")
+ os.system('pyang -f yin '+var + ' -o ' + file_format[0]+'.xml')
+ elif file_format[1] == 'xml':
+ print ("Its a "+file_format[1]+" file")
+
+ else:
+ print ("File format not supported exiting script.")
+ exit()
+ else:
+ print ("File format not supported exiting script.")
+ exit()
+ tree = etree.parse(file_format[0]+'.xml')
+
+ doc = tree.getroot()
+
+ xslt_root = etree.parse('tosca_transformer.xslt')
+
+ transform = etree.XSLT(xslt_root)
+
+ result_tree = transform(doc)
+ output_file = file_format[0]+'_tosca.yaml'
+
+ f = open(output_file, "w")
+ f.write(str(result_tree))
+ f.close()
+ print ("TOSCA file generated with name "+output_file)
+ else:
+ print ("File does not exist, exiting the script")
+ exit()
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(add_help=True)
+ parser.add_argument('-n', '--filename', dest='filename', required=True,
+ help='Please enter the YANG file name: ')
+ args = parser.parse_args()
+ file_name = str(args.filename)
+ tosca_translator(file_name)