Add vIMS heat template in demo repository
[demo.git] / heat / vIMS / bono.yaml
1 # Project Clearwater - IMS in the Cloud
2 # Copyright (C) 2015  Metaswitch Networks Ltd
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version, along with the "Special Exception" for use of
8 # the program along with SSL, set forth below. This program is distributed
9 # in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE.  See the GNU General Public License for more
12 # details. You should have received a copy of the GNU General Public
13 # License along with this program.  If not, see
14 # <http://www.gnu.org/licenses/>.
15 #
16 # The author can be reached by email at clearwater@metaswitch.com or by
17 # post at Metaswitch Networks Ltd, 100 Church St, Enfield EN2 6BQ, UK
18 #
19 # Special Exception
20 # Metaswitch Networks Ltd  grants you permission to copy, modify,
21 # propagate, and distribute a work formed by combining OpenSSL with The
22 # Software, or a work derivative of such a combination, even if such
23 # copying, modification, propagation, or distribution would otherwise
24 # violate the terms of the GPL. You must comply with the GPL in all
25 # respects for all of the code used other than OpenSSL.
26 # "OpenSSL" means OpenSSL toolkit software distributed by the OpenSSL
27 # Project and licensed under the OpenSSL Licenses, or a work based on such
28 # software and licensed under the OpenSSL Licenses.
29 # "OpenSSL Licenses" means the OpenSSL License and Original SSLeay License
30 # under which the OpenSSL Project distributes the OpenSSL toolkit software,
31 # as those licenses appear in the file LICENSE-OPENSSL.
32
33 heat_template_version: 2014-10-16
34
35 description: >
36   Clearwater Bono node
37
38 parameters:
39   vnf_name:
40     type: string
41     label: VNF ID
42     description: The VNF name provided by ONAP
43   vnf_id:
44     type: string
45     label: VNF ID
46     description: The VNF ID provided by ONAP
47   vf_module_id:
48     type: string
49     label: VNF module ID
50     description: The VNF module ID provided by ONAP
51   public_net_id:
52     type: string
53     description: ID of public network
54     constraints:
55       - custom_constraint: neutron.network
56         description: Must be a valid network ID
57   bono_flavor_name:
58     type: string
59     description: Flavor to use
60     constraints:
61       - custom_constraint: nova.flavor
62         description: Must be a valid flavor name
63   bono_image_name:
64     type: string
65     description: Name of image to use
66   key_name:
67     type: string
68     description: Name of keypair to assign
69     constraints:
70       - custom_constraint: nova.keypair
71         description: Must be a valid keypair name
72   repo_url:
73     type: string
74     description: URL for Clearwater repository
75   zone:
76     type: string
77     description: DNS zone
78   dns_ip:
79     type: string
80     description: IP address for DNS server on management network
81   dnssec_key:
82     type: string
83     description: DNSSEC private key (Base64-encoded)
84     constraints:
85       - allowed_pattern: "[0-9A-Za-z+/=]+"
86         description: Must be Base64-encoded
87   etcd_ip:
88     type: string
89     description: IP address of an existing member of the etcd cluster
90
91 resources:
92
93   bono_random_str:
94     type: OS::Heat::RandomString
95     properties:
96       length: 4
97
98   bono_Sec_Grp:
99     type: OS::Neutron::SecurityGroup
100     properties:
101       description: security group
102       name:
103         str_replace:
104           template: pre_base_rand
105           params:
106             pre: bono_sg_
107             base: { get_param: vnf_name }
108             rand: { get_resource: bono_random_str }
109       rules: [
110         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 22, port_range_max: 22},
111         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 161, port_range_max: 162},
112         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 2380, port_range_max: 2380},
113         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 4000, port_range_max: 4000},
114         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 3478, port_range_max: 3478},
115         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 3478, port_range_max: 3478},
116         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 5060, port_range_max: 5060},
117         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 5060, port_range_max: 5060},
118         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 5062, port_range_max: 5062},
119         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 32768, port_range_max: 65535},
120         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 5058, port_range_max: 5058},
121         {remote_ip_prefix: 0.0.0.0/0, protocol: icmp}]
122
123   bono_admin_port_0:
124     type: OS::Neutron::Port
125     properties:
126       name:
127         str_replace:
128           template: pre_base_rand
129           params:
130             pre: bono_admin_
131             base: { get_param: vnf_name }
132             rand: { get_resource: bono_random_str }
133       network: { get_param: public_net_id }
134       security_groups: [{ get_resource: bono_Sec_Grp }]
135
136   bono_server_0:
137     type: OS::Nova::Server
138     properties:
139       name:
140         str_replace:
141           template: pre_base_rand
142           params:
143             pre: bono_
144             base: { get_param: vnf_name }
145             rand: { get_resource: bono_random_str }
146       image: { get_param: bono_image_name }
147       flavor: { get_param: bono_flavor_name }
148       key_name: { get_param: key_name }
149       networks:
150         - port: { get_resource: bono_admin_port_0 }
151       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }, vnf_name: { get_param: vnf_name }}
152       user_data_format: RAW
153       user_data:
154         str_replace:
155           params:
156             __repo_url__: { get_param: repo_url }
157             __zone__: { get_param: zone }
158             __dns_ip__: { get_param: dns_ip }
159             __dnssec_key__: { get_param: dnssec_key }
160             __etcd_ip__ : { get_param: etcd_ip }
161             __index__ : 0
162
163           template: |
164             #!/bin/bash
165
166             # Log all output to file.
167             exec > >(tee -a /var/log/clearwater-heat-bono.log) 2>&1
168             set -x
169
170             # Configure the APT software source.
171             echo 'deb __repo_url__ binary/' > /etc/apt/sources.list.d/clearwater.list
172             curl -L http://repo.cw-ngv.com/repo_key | apt-key add -
173             apt-get update
174
175             # Get the public IP address from eth0
176             sudo apt-get install ipcalc
177             ADDR=`ip addr show eth0 | awk '/inet /{print $2}'`
178             PUBLIC_ADDR=`ipcalc -n -b $ADDR | awk '/Address:/{print $2}'`
179
180             # Configure /etc/clearwater/local_config.
181             mkdir -p /etc/clearwater
182             etcd_ip=__etcd_ip__
183             [ -n "$etcd_ip" ] || etcd_ip=$PUBLIC_ADDR
184             cat > /etc/clearwater/local_config << EOF
185             management_local_ip=$PUBLIC_ADDR
186             local_ip=$PUBLIC_ADDR
187             public_ip=$PUBLIC_ADDR
188             public_hostname=__index__.bono.__zone__
189             etcd_cluster=$etcd_ip
190             EOF
191
192             # Now install the software.
193             DEBIAN_FRONTEND=noninteractive apt-get install bono restund --yes --force-yes
194             DEBIAN_FRONTEND=noninteractive apt-get install clearwater-management --yes --force-yes
195
196             # Function to give DNS record type and IP address for specified IP address
197             ip2rr() {
198               if echo $1 | grep -q -e '[^0-9.]' ; then
199                 echo AAAA $1
200               else
201                 echo A $1
202               fi
203             }
204
205             # Update DNS
206             retries=0
207             while ! { nsupdate -y "__zone__:__dnssec_key__" -v << EOF
208             server __dns_ip__
209             update add bono-__index__.__zone__. 30 $(ip2rr $PUBLIC_ADDR)
210             update add __index__.bono.__zone__. 30 $(ip2rr $PUBLIC_ADDR)
211             update add __zone__. 30 $(ip2rr $PUBLIC_ADDR)
212             update add __zone__. 30 NAPTR 0 0 "s" "SIP+D2T" "" _sip._tcp.__zone__.
213             update add __zone__. 30 NAPTR 0 0 "s" "SIP+D2U" "" _sip._udp.__zone__.
214             update add _sip._tcp.__zone__. 30 SRV 0 0 5060 __index__.bono.__zone__.
215             update add _sip._udp.__zone__. 30 SRV 0 0 5060 __index__.bono.__zone__.
216             send
217             EOF
218             } && [ $retries -lt 10 ]
219             do
220               retries=$((retries + 1))
221               echo 'nsupdate failed - retrying (retry '$retries')...'
222               sleep 5
223             done
224
225             # Use the DNS server.
226             echo 'nameserver __dns_ip__' > /etc/dnsmasq.resolv.conf
227             echo 'RESOLV_CONF=/etc/dnsmasq.resolv.conf' >> /etc/default/dnsmasq
228             service dnsmasq force-reload
229
230
231 outputs:
232   bono_ip:
233     description: IP address in public network
234     value: { get_attr: [ bono_server_0, networks, { get_param: public_net_id }, 0 ] }