Parser Contributor Update 2: add shitao and lingli
[parser.git] / yang2tosca / tosca_transformer.xslt
1 <!-- Licensed under the Apache License, Version 2.0 (the "License");
2 you may not use this file except in compliance with the License.
3 You may obtain a copy of the License at
4    http://www.apache.org/licenses/LICENSE-2.0
5
6 Unless required by applicable law or agreed to in writing, software
7 distributed under the License is distributed on an "AS IS" BASIS,
8 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 See the License for the specific language governing permissions and limitations under the License.
10 -->
11 <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">
12 <xsl:output indent="no" method ="text"/>
13
14 <xsl:variable name="tosca_general">
15     <entry key="tosca_definitions_version">tosca_definitions_version:tosca_simple_yaml_1_0_0</entry>
16     <entry key="tosca_default_namespace">tosca_default_namespace:tosca_simple_yaml_1_0_0</entry>
17     <entry key="template_name">template_name:</entry>
18     <entry key="description">description:</entry>
19     <entry key="template_author">template_author:</entry>
20     <entry key="template_version">template_version:</entry>
21     <entry key="derived">derived_from:tosca.nodes.Root</entry>
22     <entry key="import">import:</entry>
23 </xsl:variable>
24 <xsl:variable name="nodeTypes">
25     <entry key="generalvdus">type:tosca.nodes.general.vdus</entry>
26     <entry key="compute">type:tosca.nodes.compute</entry>
27     <entry key="storage">type:tosca.nodes.block.Storage</entry>
28     <entry key="network">type:tosca.nodes.network</entry>
29     <entry key="security">type:tosca.nodes.security</entry>
30     <entry key="policy">type:tosca.nodes.policy</entry>
31 </xsl:variable>
32
33 <xsl:template match="ns:module">
34 <xsl:value-of select="concat(document('')//xsl:variable[@name='tosca_general']/entry[@key='tosca_definitions_version'] ,'&#x0A;')" />
35 <xsl:value-of select="concat(document('')//xsl:variable[@name='tosca_general']/entry[@key='description'],'&#x0A;&#x09;',ns:description/node()/text(),'&#x0A;')" />
36 <xsl:value-of select="concat(document('')//xsl:variable[@name='tosca_general']/entry[@key='import'],'&#x0A;&#x09;',ns:import/@module,'&#x0A;')" />
37 metadata:
38          ID:<xsl:value-of select="@name"/>
39          Vendor:<xsl:value-of select="ns:organization/node()/text()"/>
40
41 <xsl:for-each select="ns:container">
42 dsl_definitions:<xsl:for-each select="ns:list">
43         compute_props_host_<xsl:value-of select="@name"/>:<text disable-output-escaping="yes"><![CDATA[&]]>compute_props_host_</text><xsl:value-of select="@name"/>
44         <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"/>
45                  num_cpu:<xsl:value-of select="$num_cpu"/>
46                                     </xsl:if>
47                                         <xsl:if test="@name='memory'">
48                                                 <xsl:variable name="memory" select="ns:leaf/ns:type/ns:range/@value"/>
49                  mem_size:<xsl:value-of select="$memory"></xsl:value-of>
50                                                 </xsl:if>
51                                         </xsl:for-each>
52                         </xsl:if>
53                 </xsl:for-each>
54                 </xsl:for-each>
55 node_types:<xsl:for-each select="ns:list">
56         tosca.nodes.compute.<xsl:value-of select="@name"/>:
57                 derived_from:tosca.nodes.compute
58 </xsl:for-each>
59 topology_template:
60                 # a description of the topology template
61                 description:>
62                         <xsl:value-of select="ns:description/node()/text()"/>
63         inputs:
64                 storage_size:
65                         type:scalar-unit.size<xsl:for-each select="ns:list"><xsl:if test="@name = 'ellis'">
66                         <xsl:for-each select="ns:container"><xsl:if test="@name = 'resource'"><xsl:for-each select="ns:container"><xsl:if test="@name = 'disk'">
67                         default:<xsl:value-of select="ns:leaf/ns:type/ns:range/@value"/>
68                         description:<xsl:value-of select="ns:description/node()/text()"/>
69                         </xsl:if></xsl:for-each></xsl:if></xsl:for-each>
70                         </xsl:if></xsl:for-each>
71                 storage_location:
72                         type:string
73                         description:>
74                                 Block storage mount point (filesystem path).
75         node_templates:<xsl:for-each select="ns:list">
76                         <xsl:text>&#xa;&#x9;&#x9;</xsl:text>
77                         <xsl:value-of select="@name"/>:
78                         type:tosca.nodes.Compute
79                         capabilities:
80                                 os:
81                                         properties:
82                                                 architecture:
83                                                 type:
84                                                 distribution:
85                                                 version:
86                                 host:
87                                         properties:*compute_props_host_<xsl:value-of select="@name"/>
88                                 scalable:
89                                         properties:
90                                                 min_instances:<xsl:for-each select="ns:leaf"><xsl:if test="@name = 'instance-num'">
91                                                 <xsl:value-of select="ns:default/@value"/>
92                                                 </xsl:if></xsl:for-each>
93                                                 default_instances:<xsl:for-each select="ns:leaf"><xsl:if test="@name = 'instance-num'">
94                                                 <xsl:value-of select="ns:default/@value"/>
95                                                 </xsl:if></xsl:for-each>
96                         requirements:
97                                 - local_storage:
98                                         node:<xsl:value-of select="@name"/>_BlockStorage
99                                                 relationship:
100                                                         type:AttachesTo
101                                                         properties:
102                                                                 location:{ get_input:storage_location }
103                         interfaces:
104                                 Standard:<xsl:for-each select="ns:container">
105                                         <xsl:if test="@name = 'workflow-script'">
106                                 <xsl:for-each select="ns:leaf">
107                                         <xsl:choose>
108                                         <xsl:when test="@name = 'init'">
109                                         start:
110                                                 implementation:<xsl:value-of select="ns:default/@value"/>
111                                                         </xsl:when>
112                                         <xsl:when test="@name='terminate'">
113                                         delete:
114                                                 implementaion:<xsl:value-of select="ns:default/@value"/>
115                                         </xsl:when>
116                                         <xsl:when test="@name='graceful-shutdown'">
117                                         stop:
118                                                 implementaion:<xsl:value-of select="ns:default/@value"/>
119                                         </xsl:when>
120                                                         </xsl:choose>
121                                                  </xsl:for-each>
122                                                 </xsl:if>
123                                                 </xsl:for-each>
124                 <xsl:text>&#xa;&#x9;&#x9;</xsl:text>
125                 <xsl:variable name="vdu" select = "@name"/>
126                 <xsl:value-of select="$vdu"/>_BlockStorage:
127                         type:tosca.nodes.BlockStorage
128                         properties:
129                                 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">
130                                 <xsl:if test="@name='vnic'">
131                                                 <xsl:variable name="vnic" select="ns:leaf/ns:type/ns:range/@value"/>
132                                                 <xsl:call-template name="nic.loop">
133                                                 <xsl:with-param name="from" select="1"/>
134                                                 <xsl:with-param name="to" select="$vnic"/>
135                                                 </xsl:call-template>
136                                         </xsl:if>
137                                         </xsl:for-each>
138                 </xsl:if>
139                 </xsl:for-each>
140                 </xsl:for-each>
141 </xsl:for-each>
142 </xsl:template>
143 <xsl:template name="nic.loop">
144 <xsl:param name="from"/>
145     <xsl:param name="to"/>
146     <xsl:if test="$from &lt;= $to">
147     <xsl:text>&#xa;&#x9;</xsl:text>
148     <xsl:value-of select="../../../@name"/>_network<xsl:value-of select="$from"/>:
149                         type:tosca.nodes.network.Network
150                         properties:
151                         ip_version:4
152         <xsl:value-of select="../../@name"/>_port<xsl:value-of select="$from"/>:
153                         type:tosca.nodes.network.Port
154                         requirements:
155                                 - binding:
156                                         node:<xsl:value-of select="../../@name"/>
157                                 - link:
158                                          node:<xsl:value-of select="../../../@name"/>_network<xsl:value-of select="$from"/>
159                 <xsl:call-template name="nic.loop">
160                 <xsl:with-param name="from" select="$from + 1"/>
161                 <xsl:with-param name="to" select="$to"/>
162                 </xsl:call-template>
163 </xsl:if>
164 </xsl:template>
165 </xsl:stylesheet>