Merge "Update helm charts for Minio"
[demo.git] / heat / vIMS / vellum.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: 2015-04-30
34
35 description: >
36   Clearwater Vellum 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   vellum_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   vellum_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
92 resources:
93
94   vellum_random_str:
95     type: OS::Heat::RandomString
96     properties:
97       length: 4
98
99   vellum_security_group:
100     type: OS::Neutron::SecurityGroup
101     properties:
102       description: security group
103       name:
104         str_replace:
105           template: pre_base_rand
106           params:
107             pre: vellum_sg_
108             base: { get_param: vnf_name }
109             rand: { get_resource: vellum_random_str }
110       rules: [
111         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 22, port_range_max: 22},
112         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 161, port_range_max: 162},
113         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 2380, port_range_max: 2380},
114         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 4000, port_range_max: 4000},
115         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 7253, port_range_max: 7253},
116         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 11211, port_range_max: 11211},
117         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 7000, port_range_max: 7000},
118         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 11311, port_range_max: 11311},
119         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 9160, port_range_max: 9160},
120         {remote_ip_prefix: 0.0.0.0/0, protocol: icmp}]
121
122   vellum_admin_port_0:
123     type: OS::Neutron::Port
124     properties:
125       name:
126         str_replace:
127           template: pre_base_rand
128           params:
129             pre: vellum_admin_port_0_
130             base:  { get_param: vnf_name }
131             rand: { get_resource: vellum_random_str }
132       network: { get_param: public_net_id }
133       security_groups: [{ get_resource: vellum_security_group }]
134
135   vellum_server_0:
136     type: OS::Nova::Server
137     properties:
138       name:
139         str_replace:
140           template: pre_base_rand
141           params:
142             pre: vellum_server_0_
143             base:  { get_param: vnf_name }
144             rand: { get_resource: vellum_random_str }
145       image: { get_param: vellum_image_name }
146       flavor: { get_param: vellum_flavor_name }
147       key_name: { get_param: key_name }
148       networks:
149         - port: { get_resource: vellum_admin_port_0 }
150       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }, vnf_name: { get_param: vnf_name }}
151       user_data_format: RAW
152       user_data:
153         str_replace:
154           params:
155             __repo_url__: { get_param: repo_url }
156             __zone__: { get_param: zone }
157             __dns_ip__: { get_param: dns_ip }
158             __dnssec_key__: { get_param: dnssec_key }
159             __etcd_ip__ : { get_param: etcd_ip }
160             __index__ : 0
161           template: |
162             #!/bin/bash
163
164             # Log all output to file.
165             exec > >(tee -a /var/log/clearwater-heat-vellum.log) 2>&1
166             set -x
167
168             # Configure the APT software source.
169             echo 'deb __repo_url__ binary/' > /etc/apt/sources.list.d/clearwater.list
170             curl -L http://repo.cw-ngv.com/repo_key | apt-key add -
171             apt-get update
172
173             # Get the public IP address from eth0
174             sudo apt-get install ipcalc
175             ADDR=`ip addr show eth0 | awk '/inet /{print $2}'`
176             PUBLIC_ADDR=`ipcalc -n -b $ADDR | awk '/Address:/{print $2}'`
177
178             # Configure /etc/clearwater/local_config.
179             mkdir -p /etc/clearwater
180             etcd_ip=__etcd_ip__
181             [ -n "$etcd_ip" ] || etcd_ip=$PUBLIC_ADDR
182             cat > /etc/clearwater/local_config << EOF
183             management_local_ip=$PUBLIC_ADDR
184             local_ip=$PUBLIC_ADDR
185             public_ip=$PUBLIC_ADDR
186             public_hostname=vellum-__index__.__zone__
187             etcd_cluster=$etcd_ip
188             EOF
189
190             # Now install the software.
191             DEBIAN_FRONTEND=noninteractive apt-get install vellum --yes --force-yes
192             DEBIAN_FRONTEND=noninteractive apt-get install clearwater-management --yes --force-yes
193
194             # Function to give DNS record type and IP address for specified IP address
195             ip2rr() {
196               if echo $1 | grep -q -e '[^0-9.]' ; then
197                 echo AAAA $1
198               else
199                 echo A $1
200               fi
201             }
202
203             # Update DNS
204             retries=0
205             while ! { nsupdate -y "__zone__:__dnssec_key__" -v << EOF
206             server __dns_ip__
207             update add vellum-__index__.__zone__. 30 $(ip2rr $PUBLIC_ADDR)
208             update add vellum.__zone__. 30 $(ip2rr $PUBLIC_ADDR)
209             send
210             EOF
211             } && [ $retries -lt 10 ]
212             do
213               retries=$((retries + 1))
214               echo 'nsupdate failed - retrying (retry '$retries')...'
215               sleep 5
216             done
217
218             # Use the DNS server.
219             echo 'nameserver __dns_ip__' > /etc/dnsmasq.resolv.conf
220             echo 'RESOLV_CONF=/etc/dnsmasq.resolv.conf' >> /etc/default/dnsmasq
221             service dnsmasq force-reload
222
223
224 outputs:
225   vellum_ip:
226     description: IP address in public network
227     value: { get_attr: [ vellum_server_0, networks, { get_param: public_net_id }, 0 ] }