This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
sprout.yaml
258 lines (238 loc) · 10.2 KB
/
sprout.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# Copyright (C) Metaswitch Networks 2017
# If license terms are provided to you in a COPYING file in the root directory
# of the source code repository by which you are accessing this code, then
# the license outlined in that COPYING file applies to your use.
# Otherwise no rights are granted except for those provided to you by
# Metaswitch Networks in a separate written agreement.
heat_template_version: 2013-05-23
description: >
Clearwater Sprout node
parameters:
public_mgmt_net_id:
type: string
description: ID of public management network
constraints:
- custom_constraint: neutron.network
description: Must be a valid network ID
private_mgmt_net_id:
type: string
description: ID of private management network
constraints:
- custom_constraint: neutron.network
description: Must be a valid network ID
public_sig_net_id:
type: string
description: ID of public signaling network
constraints:
- custom_constraint: neutron.network
description: Must be a valid network ID
private_sig_net_id:
type: string
description: ID of private signaling network
constraints:
- custom_constraint: neutron.network
description: Must be a valid network ID
private_sig_net_cidr:
type: string
description: Private signaling network address (CIDR notation)
default: 192.168.1.0/24
private_sig_net_gateway:
type: string
description: Private signaling network gateway address
default: 192.168.1.254
flavor:
type: string
description: Flavor to use
constraints:
- custom_constraint: nova.flavor
description: Must be a valid flavor name
image:
type: string
description: Name of image to use
constraints:
- custom_constraint: glance.image
description: Must be a valid image name
key_name:
type: string
description: Name of keypair to assign
constraints:
- custom_constraint: nova.keypair
description: Must be a valid keypair name
base_mgmt_security_group:
type: string
description: ID of base security group for all Clearwater nodes (management)
sprout_sig_outbound_security_group:
type: string
description: ID of security group for Sprout nodes outbound traffic (signaling)
sprout_sig_inbound_security_group:
type: string
description: ID of security group for Sprout nodes inbound traffic (signaling)
repo_url:
type: string
description: URL for Clearwater repository
default: http://repo.cw-ngv.com/stable
zone:
type: string
description: DNS zone
default: example.com
dns_mgmt_ip:
type: string
description: IP address for DNS server on management network
dns_sig_ip:
type: string
description: IP address for DNS server on signaling network
dnssec_key:
type: string
description: DNSSEC private key (Base64-encoded)
constraints:
- allowed_pattern: "[0-9A-Za-z+/=]+"
description: Must be Base64-encoded
etcd_ip:
type: string
description: IP address of an existing member of the etcd cluster
default: ""
index:
type: number
description: Index of this Sprout node in the Sprout cluster
default: 0
resources:
mgmt_port:
type: OS::Neutron::Port
properties:
# Specify the network ID by string to work around OpenStack issues - see https://github.com/Metaswitch/clearwater-heat/issues/18.
network_id: { str_replace: { params: { x: { get_param: private_mgmt_net_id } }, template: x } }
security_groups:
- { get_param: base_mgmt_security_group }
mgmt_floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_mgmt_net_id }
port_id: { get_resource: mgmt_port }
sig_port:
type: OS::Neutron::Port
properties:
# Specify the network ID by string to work around OpenStack issues - see https://github.com/Metaswitch/clearwater-heat/issues/18.
network_id: { str_replace: { params: { x: { get_param: private_sig_net_id } }, template: x } }
security_groups:
- { get_param: sprout_sig_outbound_security_group }
- { get_param: sprout_sig_inbound_security_group }
server:
type: OS::Nova::Server
properties:
name: { str_replace: { params: { __index__: { get_param: index }, __zone__: { get_param: zone } }, template: sprout-__index__.__zone__ } }
image: { get_param: image }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
networks:
- port: { get_resource: mgmt_port }
- port: { get_resource: sig_port }
user_data_format: RAW
user_data:
str_replace:
params:
__repo_url__: { get_param: repo_url }
__zone__: { get_param: zone }
__public_mgmt_ip__: { get_attr: [ mgmt_floating_ip, floating_ip_address ] }
__private_mgmt_ip__: { get_attr: [ mgmt_port, fixed_ips, 0, ip_address ] }
__private_sig_ip__: { get_attr: [ sig_port, fixed_ips, 0, ip_address ] }
__private_sig_cidr__: { get_param: private_sig_net_cidr }
__private_sig_gateway__: { get_param: private_sig_net_gateway }
__dns_mgmt_ip__: { get_param: dns_mgmt_ip }
__dns_sig_ip__: { get_param: dns_sig_ip }
__dnssec_key__: { get_param: dnssec_key }
__etcd_ip__ : { get_param: etcd_ip }
__index__ : { get_param: index }
template: |
#!/bin/bash
# Log all output to file.
exec > >(tee -a /var/log/clearwater-heat-sprout.log) 2>&1
set -x
# Set up the signaling network namespace on each boot by creating an init file and
# linking to it from runlevel 2 and 3
cat >/etc/init.d/signaling_namespace <<EOF
#!/bin/bash
# Create the signaling namespace and configure its interfaces.
set -e
# Exit if the namespace is already set up.
ip netns list | grep -q signaling && exit 0
# eth1 is the signaling interface (and eth0 is the management interface).
# We need to set eth1 up manually - only eth0 is automatically configured via DHCP.
ip netns add signaling
ip link set eth1 netns signaling
ip netns exec signaling ip link set dev lo up
ip netns exec signaling ip addr add __private_sig_ip__/$(echo __private_sig_cidr__ | cut -d / -f 2) dev eth1
ip netns exec signaling ip link set dev eth1 up
ip netns exec signaling ip route add default via __private_sig_gateway__
EOF
chmod a+x /etc/init.d/signaling_namespace
ln -s /etc/init.d/signaling_namespace /etc/rc2.d/S01signaling_namespace
ln -s /etc/init.d/signaling_namespace /etc/rc3.d/S01signaling_namespace
# Also set up the signaling namespace now.
/etc/init.d/signaling_namespace
# Configure the APT software source.
echo 'deb __repo_url__ binary/' > /etc/apt/sources.list.d/clearwater.list
curl -L http://repo.cw-ngv.com/repo_key | apt-key add -
apt-get update
# Configure /etc/clearwater/local_config.
mkdir -p /etc/clearwater
etcd_ip=__etcd_ip__
[ -n "$etcd_ip" ] || etcd_ip=__private_mgmt_ip__
cat > /etc/clearwater/local_config << EOF
signaling_namespace=signaling
signaling_dns_server=__dns_sig_ip__
management_local_ip=__private_mgmt_ip__
local_ip=__private_sig_ip__
public_ip=__private_sig_ip__
public_hostname=__index__.sprout.__zone__
etcd_cluster=$etcd_ip
EOF
# Now install the software.
DEBIAN_FRONTEND=noninteractive apt-get install sprout --yes --force-yes
DEBIAN_FRONTEND=noninteractive apt-get install clearwater-management --yes --force-yes
# Function to give DNS record type and IP address for specified IP address
ip2rr() {
if echo $1 | grep -q -e '[^0-9.]' ; then
echo AAAA $1
else
echo A $1
fi
}
# Update DNS
retries=0
while ! { nsupdate -y "__zone__:__dnssec_key__" -v << EOF
server __dns_mgmt_ip__
update add sprout-__index__.__zone__. 30 $(ip2rr __public_mgmt_ip__)
update add __index__.sprout.__zone__. 30 $(ip2rr __private_sig_ip__)
update add sprout.__zone__. 30 $(ip2rr __private_sig_ip__)
update add scscf.sprout.__zone__. 30 $(ip2rr __private_sig_ip__)
update add icscf.sprout.__zone__. 30 $(ip2rr __private_sig_ip__)
update add sprout.__zone__. 30 NAPTR 0 0 "s" "SIP+D2T" "" _sip._tcp.sprout.__zone__.
update add _sip._tcp.sprout.__zone__. 30 SRV 0 0 5054 __index__.sprout.__zone__.
update add icscf.sprout.__zone__. 30 NAPTR 0 0 "s" "SIP+D2T" "" _sip._tcp.icscf.sprout.__zone__.
update add _sip._tcp.icscf.sprout.__zone__. 30 SRV 0 0 5052 __index__.sprout.__zone__.
update add scscf.sprout.__zone__. 30 NAPTR 0 0 "s" "SIP+D2T" "" _sip._tcp.scscf.sprout.__zone__.
update add _sip._tcp.scscf.sprout.__zone__. 30 SRV 0 0 5054 __index__.sprout.__zone__.
send
EOF
} && [ $retries -lt 10 ]
do
retries=$((retries + 1))
echo 'nsupdate failed - retrying (retry '$retries')...'
sleep 5
done
# Use the DNS server.
echo 'nameserver __dns_mgmt_ip__' > /etc/dnsmasq.resolv.conf
echo 'RESOLV_CONF=/etc/dnsmasq.resolv.conf' >> /etc/default/dnsmasq
mkdir -p /etc/netns/signaling
echo 'nameserver __dns_sig_ip__' > /etc/netns/signaling/resolv.conf
service dnsmasq force-reload
outputs:
public_mgmt_ip:
description: IP address in public (management) network
value: { get_attr: [ mgmt_floating_ip, floating_ip_address ] }
private_mgmt_ip:
description: IP address in private signaling network
value: { get_attr: [ mgmt_port, fixed_ips, 0, ip_address ] }
private_sig_ip:
description: IP address in private signaling network
value: { get_attr: [ sig_port, fixed_ips, 0, ip_address ] }