Add vIMS heat template in demo repository
[demo.git] / heat / vIMS / ellis.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 Ellis 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   ellis_name_0:
58       type: string
59       description: Name of server to use
60   ellis_flavor_name:
61     type: string
62     description: Flavor to use
63     constraints:
64       - custom_constraint: nova.flavor
65         description: Must be a valid flavor name
66   ellis_image_name:
67     type: string
68     description: Name of image to use
69   key_name:
70     type: string
71     description: Name of keypair to assign
72     constraints:
73       - custom_constraint: nova.keypair
74         description: Must be a valid keypair name
75   repo_url:
76     type: string
77     description: URL for Clearwater repository
78   zone:
79     type: string
80     description: DNS zone
81   dn_range_start:
82     type: string
83     description: First directory number in pool
84     constraints:
85       - allowed_pattern: "[0-9]+"
86         description: Must be numeric
87   dn_range_length:
88     type: string
89     description: Number of directory numbers to add to pool
90     constraints:
91       - allowed_pattern: "[0-9]+"
92         description: Must be numeric
93   dns_ip:
94     type: string
95     description: IP address for DNS server
96   dnssec_key:
97     type: string
98     description: DNSSEC private key (Base64-encoded)
99     constraints:
100       - allowed_pattern: "[0-9A-Za-z+/=]+"
101         description: Must be Base64-encoded
102   etcd_ip:
103     type: string
104     description: IP address of an existing member of the etcd cluster
105
106 resources:
107
108   ellis_random_str:
109     type: OS::Heat::RandomString
110     properties:
111       length: 4
112
113   ellis_security_group:
114     type: OS::Neutron::SecurityGroup
115     properties:
116       description: security group
117       name:
118         str_replace:
119           template: pre_base_rand
120           params:
121             pre: ellis_sg_
122             base: { get_param: vnf_name }
123             rand: { get_resource: ellis_random_str }
124       rules: [
125         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 22, port_range_max: 22},
126         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 161, port_range_max: 162},
127         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 2380, port_range_max: 2380},
128         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 4000, port_range_max: 4000},
129         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 80, port_range_max: 80},
130         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 443, port_range_max: 443},
131         {remote_ip_prefix: 0.0.0.0/0, protocol: icmp}]
132
133   ellis_admin_port_0:
134     type: OS::Neutron::Port
135     properties:
136       name:
137         str_replace:
138           template: pre_base_rand
139           params:
140             pre: ellis_admin_port_0_
141             base: { get_param: vnf_name }
142             rand: { get_resource: ellis_random_str }
143       network: { get_param: public_net_id }
144       security_groups: [{ get_resource: ellis_security_group }]
145
146   ellis_server_0:
147     type: OS::Nova::Server
148     properties:
149       name:
150         str_replace:
151           template: pre_base_rand
152           params:
153             pre: ellis_server_0_
154             base: { get_param: vnf_name }
155             rand: { get_resource: ellis_random_str }
156       image: { get_param: ellis_image_name }
157       flavor: { get_param: ellis_flavor_name }
158       key_name: { get_param: key_name }
159       networks:
160         - port: { get_resource: ellis_admin_port_0 }
161       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }, vnf_name: { get_param: vnf_name }}
162       user_data_format: RAW
163       user_data:
164         str_replace:
165           params:
166             __repo_url__: { get_param: repo_url }
167             __zone__: { get_param: zone }
168             __dn_range_start__: { get_param: dn_range_start }
169             __dn_range_length__: { get_param: dn_range_length }
170             __dns_ip__: { get_param: dns_ip }
171             __dnssec_key__: { get_param: dnssec_key }
172             __etcd_ip__ : { get_param: etcd_ip }
173             __index__ : 0
174           template: |
175             #!/bin/bash
176
177             # Log all output to file.
178             exec > >(tee -a /var/log/clearwater-heat-ellis.log) 2>&1
179             set -x
180
181             # Configure the APT software source.
182             echo 'deb __repo_url__ binary/' > /etc/apt/sources.list.d/clearwater.list
183             curl -L http://repo.cw-ngv.com/repo_key | apt-key add -
184             apt-get update
185
186             # Get the public IP address from eth0
187             sudo apt-get install ipcalc
188             ADDR=`ip addr show eth0 | awk '/inet /{print $2}'`
189             PUBLIC_ADDR=`ipcalc -n -b $ADDR | awk '/Address:/{print $2}'`
190
191             # Configure /etc/clearwater/local_config.  Add xdms_hostname here to use Homer's management
192             # hostname instead of signaling.  This will override shared_config.  This works around
193             # https://github.com/Metaswitch/ellis/issues/153.
194             mkdir -p /etc/clearwater
195             etcd_ip=__etcd_ip__
196             [ -n "$etcd_ip" ] || etcd_ip=$PUBLIC_ADDR
197             cat > /etc/clearwater/local_config << EOF
198             local_ip=$PUBLIC_ADDR
199             public_ip=$PUBLIC_ADDR
200             public_hostname=ellis-__index__.__zone__
201             etcd_cluster=$etcd_ip
202             xdms_hostname=homer-0.__zone__:7888
203             EOF
204
205             # Now install the software.
206             DEBIAN_FRONTEND=noninteractive apt-get install ellis --yes --force-yes
207             DEBIAN_FRONTEND=noninteractive apt-get install clearwater-management --yes --force-yes
208
209             # Wait until etcd is up and running before uploading the shared_config
210             /usr/share/clearwater/clearwater-etcd/scripts/wait_for_etcd
211
212             # Configure and upload /etc/clearwater/shared_config.
213             cat > /etc/clearwater/shared_config << EOF
214             # Deployment definitions
215             home_domain=__zone__
216             sprout_hostname=sprout.__zone__
217             sprout_registration_store=vellum.__zone__
218             hs_hostname=hs.__zone__:8888
219             hs_provisioning_hostname=hs.__zone__:8889
220             sprout_impi_store=vellum.__zone__
221             homestead_impu_store=vellum.__zone__
222             ralf_hostname=ralf.__zone__:10888
223             ralf_session_store=vellum.__zone__
224             xdms_hostname=homer.__zone__:7888
225             chronos_hostname=vellum.__zone__
226             cassandra_hostname=vellum.__zone__
227
228             # Email server configuration
229             smtp_smarthost=localhost
230             smtp_username=username
231             smtp_password=password
232             email_recovery_sender=clearwater@example.org
233
234             # Keys
235             signup_key=secret
236             turn_workaround=secret
237             ellis_api_key=secret
238             ellis_cookie_key=secret
239             EOF
240             sudo /usr/share/clearwater/clearwater-config-manager/scripts/upload_shared_config
241
242             # Allocate a pool of numbers to assign to users.  Before we do this,
243             # restart clearwater-infrastructure to make sure that
244             # local_settings.py runs to pick up the configuration changes.
245             service clearwater-infrastructure restart
246             service ellis stop
247             /usr/share/clearwater/ellis/env/bin/python /usr/share/clearwater/ellis/src/metaswitch/ellis/tools/create_numbers.py --start __dn_range_start__ --count __dn_range_length__
248
249             # Function to give DNS record type and IP address for specified IP address
250             ip2rr() {
251               if echo $1 | grep -q -e '[^0-9.]' ; then
252                 echo AAAA $1
253               else
254                 echo A $1
255               fi
256             }
257
258             # Update DNS
259             retries=0
260             while ! { nsupdate -y "__zone__:__dnssec_key__" -v << EOF
261             server __dns_ip__
262             update add ellis-__index__.__zone__. 30 $(ip2rr $PUBLIC_ADDR)
263             update add ellis.__zone__. 30 $(ip2rr $PUBLIC_ADDR)
264             send
265             EOF
266             } && [ $retries -lt 10 ]
267             do
268               retries=$((retries + 1))
269               echo 'nsupdate failed - retrying (retry '$retries')...'
270               sleep 5
271             done
272
273             # Use the DNS server.
274             echo 'nameserver __dns_ip__' > /etc/dnsmasq.resolv.conf
275             echo 'RESOLV_CONF=/etc/dnsmasq.resolv.conf' >> /etc/default/dnsmasq
276             service dnsmasq force-reload
277
278
279 outputs:
280   ellis_ip:
281     description: IP address in public network
282     value: { get_attr: [ ellis_server_0, networks, { get_param: public_net_id }, 0 ] }