DR695H | 96c1f6f | 2017-08-17 17:13:48 -0400 | [diff] [blame^] | 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: 2013-05-23 |
| 34 | |
| 35 | description: > |
| 36 | Clearwater Ellis node |
| 37 | |
| 38 | parameters: |
| 39 | vnf_id: |
| 40 | type: string |
| 41 | label: VNF ID |
| 42 | description: The VNF ID provided by ONAP |
| 43 | vf_module_id: |
| 44 | type: string |
| 45 | label: VNF module ID |
| 46 | description: The VNF module ID provided by ONAP |
| 47 | public_net_id: |
| 48 | type: string |
| 49 | description: ID of public network |
| 50 | constraints: |
| 51 | - custom_constraint: neutron.network |
| 52 | description: Must be a valid network ID |
| 53 | ellis_flavor_name: |
| 54 | type: string |
| 55 | description: Flavor to use |
| 56 | constraints: |
| 57 | - custom_constraint: nova.flavor |
| 58 | description: Must be a valid flavor name |
| 59 | ellis_image_name: |
| 60 | type: string |
| 61 | description: Name of image to use |
| 62 | key_name: |
| 63 | type: string |
| 64 | description: Name of keypair to assign |
| 65 | constraints: |
| 66 | - custom_constraint: nova.keypair |
| 67 | description: Must be a valid keypair name |
| 68 | # base_mgmt_security_group: |
| 69 | # type: string |
| 70 | # description: ID of base security group for all Clearwater nodes (management) |
| 71 | # ellis_mgmt_security_group: |
| 72 | # type: string |
| 73 | # description: ID of security group for Ellis nodes (management) |
| 74 | repo_url: |
| 75 | type: string |
| 76 | description: URL for Clearwater repository |
| 77 | default: http://repo.cw-ngv.com/stable |
| 78 | zone: |
| 79 | type: string |
| 80 | description: DNS zone |
| 81 | default: example.com |
| 82 | dn_range_start: |
| 83 | type: string |
| 84 | description: First directory number in pool |
| 85 | default: "6505550000" |
| 86 | constraints: |
| 87 | - allowed_pattern: "[0-9]+" |
| 88 | description: Must be numeric |
| 89 | dn_range_length: |
| 90 | type: string |
| 91 | description: Number of directory numbers to add to pool |
| 92 | default: "1000" |
| 93 | constraints: |
| 94 | - allowed_pattern: "[0-9]+" |
| 95 | description: Must be numeric |
| 96 | dns_ip: |
| 97 | type: string |
| 98 | description: IP address for DNS server |
| 99 | dnssec_key: |
| 100 | type: string |
| 101 | description: DNSSEC private key (Base64-encoded) |
| 102 | constraints: |
| 103 | - allowed_pattern: "[0-9A-Za-z+/=]+" |
| 104 | description: Must be Base64-encoded |
| 105 | etcd_ip: |
| 106 | type: string |
| 107 | description: IP address of an existing member of the etcd cluster |
| 108 | default: "" |
| 109 | index: |
| 110 | type: number |
| 111 | description: Index of this Ellis node in the Ellis cluster |
| 112 | default: 0 |
| 113 | |
| 114 | resources: |
| 115 | server: |
| 116 | type: OS::Nova::Server |
| 117 | properties: |
| 118 | name: { str_replace: { params: { __index__: { get_param: index }, __zone__: { get_param: zone } }, template: ellis-__index__.__zone__ } } |
| 119 | image: { get_param: ellis_image_name } |
| 120 | flavor: { get_param: ellis_flavor_name } |
| 121 | key_name: { get_param: key_name } |
| 122 | networks: |
| 123 | - network: { get_param: public_net_id } |
| 124 | metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }} |
| 125 | user_data_format: RAW |
| 126 | user_data: |
| 127 | str_replace: |
| 128 | params: |
| 129 | __repo_url__: { get_param: repo_url } |
| 130 | __zone__: { get_param: zone } |
| 131 | __dn_range_start__: { get_param: dn_range_start } |
| 132 | __dn_range_length__: { get_param: dn_range_length } |
| 133 | __dns_ip__: { get_param: dns_ip } |
| 134 | __dnssec_key__: { get_param: dnssec_key } |
| 135 | __etcd_ip__ : { get_param: etcd_ip } |
| 136 | __index__ : { get_param: index } |
| 137 | template: | |
| 138 | #!/bin/bash |
| 139 | |
| 140 | # Log all output to file. |
| 141 | exec > >(tee -a /var/log/clearwater-heat-ellis.log) 2>&1 |
| 142 | set -x |
| 143 | |
| 144 | # Configure the APT software source. |
| 145 | echo 'deb __repo_url__ binary/' > /etc/apt/sources.list.d/clearwater.list |
| 146 | curl -L http://repo.cw-ngv.com/repo_key | apt-key add - |
| 147 | apt-get update |
| 148 | |
| 149 | # Get the public IP address from eth0 |
| 150 | sudo apt-get install ipcalc |
| 151 | ADDR=`ip addr show eth0 | awk '/inet /{print $2}'` |
| 152 | PUBLIC_ADDR=`ipcalc -n -b $ADDR | awk '/Address:/{print $2}'` |
| 153 | |
| 154 | # Configure /etc/clearwater/local_config. Add xdms_hostname here to use Homer's management |
| 155 | # hostname instead of signaling. This will override shared_config. This works around |
| 156 | # https://github.com/Metaswitch/ellis/issues/153. |
| 157 | mkdir -p /etc/clearwater |
| 158 | etcd_ip=__etcd_ip__ |
| 159 | [ -n "$etcd_ip" ] || etcd_ip=$PUBLIC_ADDR |
| 160 | cat > /etc/clearwater/local_config << EOF |
| 161 | local_ip=$PUBLIC_ADDR |
| 162 | public_ip=$PUBLIC_ADDR |
| 163 | public_hostname=ellis-__index__.__zone__ |
| 164 | etcd_cluster=$etcd_ip |
| 165 | xdms_hostname=homer-0.__zone__:7888 |
| 166 | EOF |
| 167 | |
| 168 | # Now install the software. |
| 169 | DEBIAN_FRONTEND=noninteractive apt-get install ellis-node --yes --force-yes |
| 170 | DEBIAN_FRONTEND=noninteractive apt-get install clearwater-management --yes --force-yes |
| 171 | |
| 172 | # Wait until etcd is up and running before uploading the shared_config |
| 173 | /usr/share/clearwater/clearwater-etcd/scripts/wait_for_etcd |
| 174 | |
| 175 | # Configure and upload /etc/clearwater/shared_config. |
| 176 | cat > /etc/clearwater/shared_config << EOF |
| 177 | # Deployment definitions |
| 178 | home_domain=__zone__ |
| 179 | sprout_hostname=sprout.__zone__ |
| 180 | hs_hostname=hs.__zone__:8888 |
| 181 | hs_provisioning_hostname=hs-prov.__zone__:8889 |
| 182 | ralf_hostname=ralf.__zone__:10888 |
| 183 | xdms_hostname=homer.__zone__:7888 |
| 184 | sprout_registration_store=sprout.__zone__ |
| 185 | ralf_session_store=ralf.__zone__ |
| 186 | |
| 187 | upstream_port=0 |
| 188 | |
| 189 | # Email server configuration |
| 190 | smtp_smarthost=localhost |
| 191 | smtp_username=username |
| 192 | smtp_password=password |
| 193 | email_recovery_sender=clearwater@example.org |
| 194 | |
| 195 | # Keys |
| 196 | signup_key=secret |
| 197 | turn_workaround=secret |
| 198 | ellis_api_key=secret |
| 199 | ellis_cookie_key=secret |
| 200 | EOF |
| 201 | sudo /usr/share/clearwater/clearwater-config-manager/scripts/upload_shared_config |
| 202 | |
| 203 | # Allocate a pool of numbers to assign to users. Before we do this, |
| 204 | # restart clearwater-infrastructure to make sure that |
| 205 | # local_settings.py runs to pick up the configuration changes. |
| 206 | service clearwater-infrastructure restart |
| 207 | service ellis stop |
| 208 | /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__ |
| 209 | |
| 210 | # Function to give DNS record type and IP address for specified IP address |
| 211 | ip2rr() { |
| 212 | if echo $1 | grep -q -e '[^0-9.]' ; then |
| 213 | echo AAAA $1 |
| 214 | else |
| 215 | echo A $1 |
| 216 | fi |
| 217 | } |
| 218 | |
| 219 | # Update DNS |
| 220 | retries=0 |
| 221 | while ! { nsupdate -y "__zone__:__dnssec_key__" -v << EOF |
| 222 | server __dns_ip__ |
| 223 | update add ellis-__index__.__zone__. 30 $(ip2rr $PUBLIC_ADDR) |
| 224 | update add ellis.__zone__. 30 $(ip2rr $PUBLIC_ADDR) |
| 225 | send |
| 226 | EOF |
| 227 | } && [ $retries -lt 10 ] |
| 228 | do |
| 229 | retries=$((retries + 1)) |
| 230 | echo 'nsupdate failed - retrying (retry '$retries')...' |
| 231 | sleep 5 |
| 232 | done |
| 233 | |
| 234 | # Use the DNS server. |
| 235 | echo 'nameserver __dns_ip__' > /etc/dnsmasq.resolv.conf |
| 236 | echo 'RESOLV_CONF=/etc/dnsmasq.resolv.conf' >> /etc/default/dnsmasq |
| 237 | service dnsmasq force-reload |
| 238 | |
| 239 | outputs: |
| 240 | public_ip: |
| 241 | description: IP address in public network |
| 242 | value: { get_attr: [ server, accessIPv4 ] } |