Prevent package installation failures in VNFs
[demo.git] / heat / vFWCL / vFWSNK / base_vfw.yaml
1 ##########################################################################
2 #
3 #==================LICENSE_START==========================================
4 #
5 #
6 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #        http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #==================LICENSE_END============================================
20 #
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 #
23 ##########################################################################
24
25 heat_template_version: 2013-05-23
26
27 description: Heat template that deploys vFirewall Closed Loop demo app (vFW and vSink) for ONAP
28
29 ##############
30 #            #
31 # PARAMETERS #
32 #            #
33 ##############
34
35 parameters:
36   image_name:
37     type: string
38     label: Image name or ID
39     description: Image to be used for compute instance
40   flavor_name:
41     type: string
42     label: Flavor
43     description: Type of instance (flavor) to be used
44   public_net_id:
45     type: string
46     label: Public network name or ID
47     description: Public network that enables remote connection to VNF
48   unprotected_private_net_id:
49     type: string
50     label: Unprotected private network name or ID
51     description: Private network that connects vPacketGenerator with vFirewall
52   unprotected_private_subnet_id:
53     type: string
54     label: Unprotected private subnetwork name or ID
55     description: Private subnetwork of the protected network
56   unprotected_private_net_cidr:
57     type: string
58     label: Unprotected private network CIDR
59     description: The CIDR of the unprotected private network
60   protected_private_net_id:
61     type: string
62     label: Protected private network name or ID
63     description: Private network that connects vFirewall with vSink
64   protected_private_subnet_id:
65     type: string
66     label: Protected private subnetwork name or ID
67     description: Private subnetwork of the unprotected network
68   protected_private_net_cidr:
69     type: string
70     label: Protected private network CIDR
71     description: The CIDR of the protected private network
72   onap_private_net_id:
73     type: string
74     label: ONAP management network name or ID
75     description: Private network that connects ONAP components and the VNF
76   onap_private_subnet_id:
77     type: string
78     label: ONAP management sub-network name or ID
79     description: Private sub-network that connects ONAP components and the VNF
80   onap_private_net_cidr:
81     type: string
82     label: ONAP private network CIDR
83     description: The CIDR of the protected private network
84   vfw_private_ip_0:
85     type: string
86     label: vFirewall private IP address towards the unprotected network
87     description: Private IP address that is assigned to the vFirewall to communicate with the vPacketGenerator
88   vfw_private_ip_1:
89     type: string
90     label: vFirewall private IP address towards the protected network
91     description: Private IP address that is assigned to the vFirewall to communicate with the vSink
92   vfw_private_ip_2:
93     type: string
94     label: vFirewall private IP address towards the ONAP management network
95     description: Private IP address that is assigned to the vFirewall to communicate with ONAP components
96   vpg_private_ip_0:
97     type: string
98     label: vPacketGenerator private IP address towards the unprotected network
99     description: Private IP address that is assigned to the vPacketGenerator to communicate with the vFirewall
100   vsn_private_ip_0:
101     type: string
102     label: vSink private IP address towards the protected network
103     description: Private IP address that is assigned to the vSink to communicate with the vFirewall
104   vsn_private_ip_1:
105     type: string
106     label: vSink private IP address towards the ONAP management network
107     description: Private IP address that is assigned to the vSink to communicate with ONAP components
108   vfw_name_0:
109     type: string
110     label: vFirewall name
111     description: Name of the vFirewall
112   vsn_name_0:
113     type: string
114     label: vSink name
115     description: Name of the vSink
116   vnf_id:
117     type: string
118     label: VNF ID
119     description: The VNF ID is provided by ONAP
120   vf_module_id:
121     type: string
122     label: vFirewall module ID
123     description: The vFirewall Module ID is provided by ONAP
124   dcae_collector_ip:
125     type: string
126     label: DCAE collector IP address
127     description: IP address of the DCAE collector
128   dcae_collector_port:
129     type: string
130     label: DCAE collector port
131     description: Port of the DCAE collector
132   key_name:
133     type: string
134     label: Key pair name
135     description: Public/Private key pair name
136   pub_key:
137     type: string
138     label: Public key
139     description: Public key to be installed on the compute instance
140   install_script_version:
141     type: string
142     label: Installation script version number
143     description: Version number of the scripts that install the vFW demo app
144   demo_artifacts_version:
145     type: string
146     label: Artifacts version used in demo vnfs
147     description: Artifacts (jar, tar.gz) version used in demo vnfs
148   nexus_artifact_repo:
149     type: string
150     description: Root URL for the Nexus repository for Maven artifacts.
151     default: "https://nexus.onap.org"
152   cloud_env:
153     type: string
154     label: Cloud environment
155     description: Cloud environment (e.g., openstack, rackspace)
156   sec_group:
157     type: string
158     description: ONAP Security Group
159
160 #############
161 #           #
162 # RESOURCES #
163 #           #
164 #############
165
166 resources:
167   random-str:
168     type: OS::Heat::RandomString
169     properties:
170       length: 4
171
172   my_keypair:
173     type: OS::Nova::KeyPair
174     properties:
175       name:
176         str_replace:
177           template: base_rand
178           params:
179             base: { get_param: key_name }
180             rand: { get_resource: random-str }
181       public_key: { get_param: pub_key }
182       save_private_key: false
183
184   unprotected_private_network:
185     type: OS::Neutron::Net
186     properties:
187       name: { get_param: unprotected_private_net_id }
188
189   unprotected_private_subnet:
190     type: OS::Neutron::Subnet
191     properties:
192       name: { get_param: unprotected_private_subnet_id }
193       network_id: { get_resource: unprotected_private_network }
194       cidr: { get_param: unprotected_private_net_cidr }
195
196   protected_private_network:
197     type: OS::Neutron::Net
198     properties:
199       name: { get_param: protected_private_net_id }
200
201   protected_private_subnet:
202     type: OS::Neutron::Subnet
203     properties:
204       name: { get_param: protected_private_subnet_id }
205       network_id: { get_resource: protected_private_network }
206       cidr: { get_param: protected_private_net_cidr }
207
208   # Virtual Firewall instantiation
209   vfw_private_0_port:
210     type: OS::Neutron::Port
211     properties:
212       network: { get_resource: unprotected_private_network }
213       fixed_ips: [{"subnet": { get_resource: unprotected_private_subnet }, "ip_address": { get_param: vfw_private_ip_0 }}]
214       security_groups:
215       - { get_param: sec_group }
216
217   vfw_private_1_port:
218     type: OS::Neutron::Port
219     properties:
220       allowed_address_pairs: [{ "ip_address": { get_param: vpg_private_ip_0 }}]
221       network: { get_resource: protected_private_network }
222       fixed_ips: [{"subnet": { get_resource: protected_private_subnet }, "ip_address": { get_param: vfw_private_ip_1 }}]
223       security_groups:
224       - { get_param: sec_group }
225
226   vfw_private_2_port:
227     type: OS::Neutron::Port
228     properties:
229       network: { get_param: onap_private_net_id }
230       fixed_ips: [{"subnet": { get_param: onap_private_subnet_id }, "ip_address": { get_param: vfw_private_ip_2 }}]
231       security_groups:
232       - { get_param: sec_group }
233
234   vfw_0:
235     type: OS::Nova::Server
236     properties:
237       image: { get_param: image_name }
238       flavor: { get_param: flavor_name }
239       name: { get_param: vfw_name_0 }
240       key_name: { get_resource: my_keypair }
241       networks:
242         - network: { get_param: public_net_id }
243         - port: { get_resource: vfw_private_0_port }
244         - port: { get_resource: vfw_private_1_port }
245         - port: { get_resource: vfw_private_2_port }
246       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }}
247       user_data_format: RAW
248       user_data:
249         str_replace:
250           params:
251             __dcae_collector_ip__ : { get_param: dcae_collector_ip }
252             __dcae_collector_port__ : { get_param: dcae_collector_port }
253             __demo_artifacts_version__ : { get_param: demo_artifacts_version }
254             __install_script_version__ : { get_param: install_script_version }
255             __vfw_private_ip_0__ : { get_param: vfw_private_ip_0 }
256             __vfw_private_ip_1__ : { get_param: vfw_private_ip_1 }
257             __vfw_private_ip_2__ : { get_param: vfw_private_ip_2 }
258             __unprotected_private_net_cidr__ : { get_param: unprotected_private_net_cidr }
259             __protected_private_net_cidr__ : { get_param: protected_private_net_cidr }
260             __onap_private_net_cidr__ : { get_param: onap_private_net_cidr }
261             __cloud_env__ : { get_param: cloud_env }
262             __nexus_artifact_repo__: { get_param: nexus_artifact_repo }
263           template: |
264             #!/bin/bash
265
266             # Create configuration files
267             mkdir /opt/config
268             echo "__dcae_collector_ip__" > /opt/config/dcae_collector_ip.txt
269             echo "__dcae_collector_port__" > /opt/config/dcae_collector_port.txt
270             echo "__demo_artifacts_version__" > /opt/config/demo_artifacts_version.txt
271             echo "__install_script_version__" > /opt/config/install_script_version.txt
272             echo "__vfw_private_ip_0__" > /opt/config/vfw_private_ip_0.txt
273             echo "__vfw_private_ip_1__" > /opt/config/vfw_private_ip_1.txt
274             echo "__vfw_private_ip_2__" > /opt/config/vfw_private_ip_2.txt
275             echo "__unprotected_private_net_cidr__" > /opt/config/unprotected_private_net_cidr.txt
276             echo "__protected_private_net_cidr__" > /opt/config/protected_private_net_cidr.txt
277             echo "__onap_private_net_cidr__" > /opt/config/onap_private_net_cidr.txt
278             echo "__cloud_env__" > /opt/config/cloud_env.txt
279             echo "__nexus_artifact_repo__" > /opt/config/nexus_artifact_repo.txt
280
281             # Download and run install script
282             apt-get update
283             apt-get -y install unzip
284             if [[ "__install_script_version__" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
285             curl -k -L "__nexus_artifact_repo__/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vfw&a=vfw-scripts&e=zip&v=__install_script_version__" -o /opt/vfw-scripts-__install_script_version__.zip
286             unzip -j /opt/vfw-scripts-__install_script_version__.zip -d /opt v_firewall_install.sh
287             cd /opt
288             chmod +x v_firewall_install.sh
289             ./v_firewall_install.sh
290
291
292   # Virtual Sink instantiation
293   vsn_private_0_port:
294     type: OS::Neutron::Port
295     properties:
296       network: { get_resource: protected_private_network }
297       fixed_ips: [{"subnet": { get_resource: protected_private_subnet }, "ip_address": { get_param: vsn_private_ip_0 }}]
298       security_groups:
299       - { get_param: sec_group }
300
301   vsn_private_1_port:
302     type: OS::Neutron::Port
303     properties:
304       network: { get_param: onap_private_net_id }
305       fixed_ips: [{"subnet": { get_param: onap_private_subnet_id }, "ip_address": { get_param: vsn_private_ip_1 }}]
306       security_groups:
307       - { get_param: sec_group }
308
309   vsn_0:
310     type: OS::Nova::Server
311     properties:
312       image: { get_param: image_name }
313       flavor: { get_param: flavor_name }
314       name: { get_param: vsn_name_0 }
315       key_name: { get_resource: my_keypair }
316       networks:
317         - network: { get_param: public_net_id }
318         - port: { get_resource: vsn_private_0_port }
319         - port: { get_resource: vsn_private_1_port }
320       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }}
321       user_data_format: RAW
322       user_data:
323         str_replace:
324           params:
325             __protected_net_gw__: { get_param: vfw_private_ip_1 }
326             __unprotected_net__: { get_param: unprotected_private_net_cidr }
327             __install_script_version__ : { get_param: install_script_version }
328             __vsn_private_ip_0__ : { get_param: vsn_private_ip_0 }
329             __vsn_private_ip_1__ : { get_param: vsn_private_ip_1 }
330             __protected_private_net_cidr__ : { get_param: protected_private_net_cidr }
331             __onap_private_net_cidr__ : { get_param: onap_private_net_cidr }
332             __cloud_env__ : { get_param: cloud_env }
333             __nexus_artifact_repo__: { get_param: nexus_artifact_repo }
334           template: |
335             #!/bin/bash
336
337             # Create configuration files
338             mkdir /opt/config
339             echo "__protected_net_gw__" > /opt/config/protected_net_gw.txt
340             echo "__unprotected_net__" > /opt/config/unprotected_net.txt
341             echo "__install_script_version__" > /opt/config/install_script_version.txt
342             echo "__vsn_private_ip_0__" > /opt/config/vsn_private_ip_0.txt
343             echo "__vsn_private_ip_1__" > /opt/config/vsn_private_ip_1.txt
344             echo "__protected_private_net_cidr__" > /opt/config/protected_private_net_cidr.txt
345             echo "__onap_private_net_cidr__" > /opt/config/onap_private_net_cidr.txt
346             echo "__cloud_env__" > /opt/config/cloud_env.txt
347             echo "__nexus_artifact_repo__" > /opt/config/nexus_artifact_repo.txt
348
349             # Download and run install script
350             apt-get update
351             apt-get -y install unzip
352             if [[ "__install_script_version__" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
353             curl -k -L "__nexus_artifact_repo__/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vfw&a=vfw-scripts&e=zip&v=__install_script_version__" -o /opt/vfw-scripts-__install_script_version__.zip
354             unzip -j /opt/vfw-scripts-__install_script_version__.zip -d /opt v_sink_install.sh
355             cd /opt
356             chmod +x v_sink_install.sh
357             ./v_sink_install.sh