Add more test for nested import list
[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 != 'connection-points') and (@name != 'internal-virtual-link')">
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"><xsl:if test="(@name != 'connection-points') and (@name != 'internal-virtual-link')">
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:for-each select="ns:container">
125                         <xsl:if test="@name = 'auto-scale-policies'">
126                         monitoring_policy:<xsl:for-each select="ns:list">
127                             name: <xsl:value-of select="ns:key/@value"/>
128                             parameters:<xsl:for-each select="../../ns:container"> <xsl:if test="@name = 'monitor-paras'">
129                             <xsl:text>&#xa;&#x9;&#x9;&#x9;&#x9;</xsl:text>
130                             <xsl:for-each select="ns:leaf-list">
131                             <xsl:for-each select="ns:type">
132                                 <xsl:for-each select="ns:enum">
133                                 <xsl:value-of select="@name"/>:
134                                 </xsl:for-each>
135                             </xsl:for-each>
136                             </xsl:for-each>    
137                             </xsl:if></xsl:for-each>    
138                             actions:<xsl:for-each select="ns:container"> <xsl:if test="@name = 'actions'">
139                             <xsl:text>&#xa;&#x9;&#x9;&#x9;&#x9;</xsl:text>
140                                 <xsl:for-each select="ns:list"> <xsl:value-of select="ns:key/@value"/>: <xsl:value-of select="ns:leaf/ns:type/ns:enum/@name"/> </xsl:for-each>
141                                 </xsl:if> </xsl:for-each>
142                                 </xsl:for-each></xsl:if></xsl:for-each>
143                 <xsl:text>&#xa;&#x9;&#x9;</xsl:text>
144                 <xsl:variable name="vdu" select = "@name"/>
145                 <xsl:value-of select="$vdu"/>_BlockStorage:
146                         type: tosca.nodes.BlockStorage
147                         properties:
148                                 size: { get_input:storage_size }</xsl:if></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">
149                                 <xsl:if test="@name='vnic'">
150                                                 <xsl:variable name="vnic" select="ns:leaf/ns:type/ns:range/@value"/>
151                                                 <xsl:call-template name="nic.loop">
152                                                 <xsl:with-param name="from" select="1"/>
153                                                 <xsl:with-param name="to" select="$vnic"/>
154                                                 </xsl:call-template>
155                                         </xsl:if>
156                                         </xsl:for-each>
157                 </xsl:if>
158                 </xsl:for-each>
159                 </xsl:for-each>
160                 <xsl:for-each select="ns:list">
161                 <xsl:if test="@name='connection-points'">
162                         <xsl:variable name="vnic" select="count(ns:leaf)"/>
163                         <xsl:call-template name="cp.loop">
164                         <xsl:with-param name="from" select="1"/>
165                         <xsl:with-param name="to" select="$vnic"/>
166                         </xsl:call-template>
167                 </xsl:if>
168                 </xsl:for-each>
169                 <xsl:for-each select="ns:list">
170                 <xsl:for-each select="ns:container"><xsl:if test="@name = 'resource'"><xsl:for-each select="ns:list"><xsl:if test="@name = 'network-interfaces'">
171                 
172                         <xsl:variable name="vnic" select="count(ns:choice/ns:case)"/>
173                         <xsl:call-template name="internalCP.loop">
174                         <xsl:with-param name="from" select="1"/>
175                         <xsl:with-param name="to" select="$vnic"/>
176                         </xsl:call-template>
177                 </xsl:if></xsl:for-each></xsl:if>
178                 </xsl:for-each>
179                 </xsl:for-each>
180                 <xsl:for-each select="ns:list">
181                 <xsl:if test="@name='internal-virtual-link'">
182                         <xsl:variable name="vnic" select="count(ns:leaf-list)"/>
183                         <xsl:call-template name="VL.loop">
184                         <xsl:with-param name="from" select="1"/>
185                         <xsl:with-param name="to" select="$vnic"/>
186                         </xsl:call-template>
187                 </xsl:if>
188                 </xsl:for-each>
189 </xsl:for-each>
190 </xsl:template>
191 <xsl:template name="nic.loop">
192 <xsl:param name="from"/>
193     <xsl:param name="to"/>
194     <xsl:if test="$from &lt;= $to">
195     <xsl:text>&#xa;&#x9;</xsl:text>
196     <xsl:value-of select="../../../@name"/>_network<xsl:value-of select="$from"/>:
197                         type:tosca.nodes.network.Network
198                         properties:
199                         ip_version:4
200         <xsl:value-of select="../../@name"/>_port<xsl:value-of select="$from"/>:
201                         type:tosca.nodes.network.Port
202                         requirements:
203                                 - binding:
204                                         node:<xsl:value-of select="../../@name"/>
205                                 - link:
206                                          node:<xsl:value-of select="../../../@name"/>_network<xsl:value-of select="$from"/>
207                 <xsl:call-template name="nic.loop">
208                 <xsl:with-param name="from" select="$from + 1"/>
209                 <xsl:with-param name="to" select="$to"/>
210                 </xsl:call-template>
211 </xsl:if>
212 </xsl:template>
213 <xsl:template name="cp.loop">
214 <xsl:param name="from"/>
215     <xsl:param name="to"/>
216     <xsl:if test="$from &lt;= $to">
217     <xsl:text>&#xa;&#x9;</xsl:text>
218                 <xsl:value-of select="ns:key/@value"/>:
219              #Endpoint for the VNF
220              type: tosca.nodes.nfv.CP
221              properties:
222                  type: 
223              requirements:
224                 <xsl:call-template name="cp.loop">
225                 <xsl:with-param name="from" select="$from + 1"/>
226                 <xsl:with-param name="to" select="$to"/>
227                 </xsl:call-template>
228 </xsl:if>
229 </xsl:template>
230
231 <xsl:template name="internalCP.loop">
232 <xsl:param name="from"/>
233     <xsl:param name="to"/>
234     <xsl:if test="$from &lt;= $to">
235     <xsl:text>&#xa;&#x9;</xsl:text>
236         CP<xsl:value-of select="$from"/>:
237             type: tosca.nodes.nfv.CP
238             properties:
239                 type:<xsl:value-of select="ns:choice/ns:case/ns:leaf/ns:type/@name"></xsl:value-of>
240             requirements:
241                - virtualLink:
242                    node: <xsl:value-of select="ns:choice/ns:case/ns:leaf/ns:type/ns:path/@value"/>
243                - virtualBinding:
244                    node: <xsl:value-of select="ns:choice/ns:case/ns:leaf/ns:type/ns:path/@value"/>
245             <xsl:call-template name="internalCP.loop">
246             <xsl:with-param name="from" select="$from + 1"/>
247             <xsl:with-param name="to" select="$to"/>
248             </xsl:call-template>
249 </xsl:if>
250 </xsl:template>
251
252 <xsl:template name="VL.loop">
253 <xsl:param name="from"/>
254     <xsl:param name="to"/>
255     <xsl:if test="$from &lt;= $to">
256     <xsl:text>&#xa;&#x9;</xsl:text>
257         VL<xsl:value-of select="$from"/>:
258             type: tosca.nodes.nfv.VL
259             properties:
260                 network_name:
261                 vendor:
262             capabilities:
263                 -virtualLink
264                  occurrences:
265             <xsl:call-template name="VL.loop">
266             <xsl:with-param name="from" select="$from + 1"/>
267             <xsl:with-param name="to" select="$to"/>
268             </xsl:call-template>
269 </xsl:if>
270 </xsl:template>
271 </xsl:stylesheet>