Merge "Update helm charts for Minio"
[demo.git] / heat / vIMS / dns.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   DNS server exposing dynamic DNS using DNSSEC
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   dns_name_0:
58       type: string
59       description: Name of server to use
60   dns_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   dns_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   zone:
76     type: string
77     description: DNS zone
78   dnssec_key:
79     type: string
80     description: DNSSEC private key (Base64-encoded)
81
82 resources:
83
84   dns_random_str:
85     type: OS::Heat::RandomString
86     properties:
87       length: 4
88
89   dns_security_group:
90     type: OS::Neutron::SecurityGroup
91     properties:
92       description: security group
93       name:
94         str_replace:
95           template: pre_base_rand
96           params:
97             pre: dns_sg_
98             base: { get_param: vnf_name }
99             rand: { get_resource: dns_random_str }
100       rules: [
101         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 22, port_range_max: 22},
102         {remote_ip_prefix: 0.0.0.0/0, protocol: tcp, port_range_min: 53, port_range_max: 53},
103         {remote_ip_prefix: 0.0.0.0/0, protocol: udp, port_range_min: 53, port_range_max: 53},
104         {remote_ip_prefix: 0.0.0.0/0, protocol: icmp}]
105
106   dns_admin_port_0:
107     type: OS::Neutron::Port
108     properties:
109       name:
110         str_replace:
111           template: base_rand
112           params:
113             base: dns_admin_port_0
114             rand: { get_resource: dns_random_str }
115       network: { get_param: public_net_id }
116       security_groups: [{ get_resource: dns_security_group }]
117
118   dns_server_0:
119     type: OS::Nova::Server
120     properties:
121       name:
122         str_replace:
123           template: pre_base_rand
124           params:
125             pre: dns_server_0_
126             base: { get_param: vnf_name }
127             rand: { get_resource: dns_random_str }
128       image: { get_param: dns_image_name }
129       flavor: { get_param: dns_flavor_name }
130       key_name: { get_param: key_name }
131       networks:
132         - port: { get_resource: dns_admin_port_0 }
133       metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }, vnf_name: { get_param: vnf_name }}
134       user_data_format: RAW
135       user_data:
136         str_replace:
137           params:
138             __zone__: { get_param: zone }
139             __dnssec_key__: { get_param: dnssec_key }
140           template: |
141             #!/bin/bash
142
143             # Log all output to file.
144             exec > >(tee -a /var/log/clearwater-heat-dns.log) 2>&1
145             set -x
146
147             # Install BIND.
148             apt-get update
149             DEBIAN_FRONTEND=noninteractive apt-get install bind9 --yes
150
151             # Get the IP address from eth0
152             sudo apt-get install ipcalc
153             ADDR=`ip addr show eth0 | awk '/inet /{print $2}'`
154             PUBLIC_ADDR=`ipcalc -n -b $ADDR | awk '/Address:/{print $2}'`
155
156             # Update BIND configuration with the specified zone and key.
157             cat >> /etc/bind/named.conf.local << EOF
158             key __zone__. {properties
159               algorithm "HMAC-MD5";
160               secret "__dnssec_key__";
161             };
162
163             zone "__zone__" IN {
164               type master;
165               file "/var/lib/bind/db.__zone__";
166               allow-update {
167                 key __zone__.;
168               };
169             };
170             EOF
171
172             # Function to give DNS record type and IP address for specified IP address
173             ip2rr() {
174               if echo $1 | grep -q -e '[^0-9.]' ; then
175                 echo AAAA $1
176               else
177                 echo A $1
178               fi
179             }
180
181             # Create basic zone configuration.
182             cat > /var/lib/bind/db.__zone__ << EOF
183             \$ORIGIN __zone__.
184             \$TTL 1h
185             @ IN SOA ns admin\@__zone__. ( $(date +%Y%m%d%H) 1d 2h 1w 30s )
186             @ NS ns
187             ns $(ip2rr $PUBLIC_ADDR)
188             EOF
189             chown root:bind /var/lib/bind/db.__zone__
190
191             # Now that BIND configuration is correct, kick it to reload.
192             service bind9 reload
193
194
195 outputs:
196   dns_ip:
197     description: IP address of DNS server
198     value: { get_attr: [ dns_server_0, networks, { get_param: public_net_id }, 0 ] }
199   zone:
200     description: DNS zone
201     value: { get_param: zone }
202   dnssec_key:
203     description: DNSSEC private key (Base64-encoded)
204     value: { get_param: dnssec_key }