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 Bono 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 | bono_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 | bono_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 (managment) |
| 71 | # bono_sig_security_group: |
| 72 | # type: string |
| 73 | # description: ID of security group for Bono nodes (signaling) |
| 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 | dns_ip: |
| 83 | type: string |
| 84 | description: IP address for DNS server on management network |
| 85 | dnssec_key: |
| 86 | type: string |
| 87 | description: DNSSEC private key (Base64-encoded) |
| 88 | constraints: |
| 89 | - allowed_pattern: "[0-9A-Za-z+/=]+" |
| 90 | description: Must be Base64-encoded |
| 91 | etcd_ip: |
| 92 | type: string |
| 93 | description: IP address of an existing member of the etcd cluster |
| 94 | default: "" |
| 95 | index: |
| 96 | type: number |
| 97 | description: Index of this Bono node in the Bono cluster |
| 98 | default: 0 |
| 99 | |
| 100 | resources: |
| 101 | server: |
| 102 | type: OS::Nova::Server |
| 103 | properties: |
| 104 | name: { str_replace: { params: { __index__: { get_param: index }, __zone__: { get_param: zone } }, template: bono-__index__.__zone__ } } |
| 105 | image: { get_param: bono_image_name } |
| 106 | flavor: { get_param: bono_flavor_name } |
| 107 | key_name: { get_param: key_name } |
| 108 | networks: |
| 109 | - network: { get_param: public_net_id } |
| 110 | metadata: {vnf_id: { get_param: vnf_id }, vf_module_id: { get_param: vf_module_id }} |
| 111 | user_data_format: RAW |
| 112 | user_data: |
| 113 | str_replace: |
| 114 | params: |
| 115 | __repo_url__: { get_param: repo_url } |
| 116 | __zone__: { get_param: zone } |
| 117 | __dns_ip__: { get_param: dns_ip } |
| 118 | __dnssec_key__: { get_param: dnssec_key } |
| 119 | __etcd_ip__ : { get_param: etcd_ip } |
| 120 | __index__ : { get_param: index } |
| 121 | template: | |
| 122 | #!/bin/bash |
| 123 | |
| 124 | # Log all output to file. |
| 125 | exec > >(tee -a /var/log/clearwater-heat-bono.log) 2>&1 |
| 126 | set -x |
| 127 | |
| 128 | # Configure the APT software source. |
| 129 | echo 'deb __repo_url__ binary/' > /etc/apt/sources.list.d/clearwater.list |
| 130 | curl -L http://repo.cw-ngv.com/repo_key | apt-key add - |
| 131 | apt-get update |
| 132 | |
| 133 | # Get the public IP address from eth0 |
| 134 | sudo apt-get install ipcalc |
| 135 | ADDR=`ip addr show eth0 | awk '/inet /{print $2}'` |
| 136 | PUBLIC_ADDR=`ipcalc -n -b $ADDR | awk '/Address:/{print $2}'` |
| 137 | |
| 138 | # Configure /etc/clearwater/local_config. |
| 139 | mkdir -p /etc/clearwater |
| 140 | etcd_ip=__etcd_ip__ |
| 141 | [ -n "$etcd_ip" ] || etcd_ip=$PUBLIC_ADDR |
| 142 | cat > /etc/clearwater/local_config << EOF |
| 143 | management_local_ip=$PUBLIC_ADDR |
| 144 | local_ip=$PUBLIC_ADDR |
| 145 | public_ip=$PUBLIC_ADDR |
| 146 | public_hostname=__index__.bono.__zone__ |
| 147 | etcd_cluster=$etcd_ip |
| 148 | EOF |
| 149 | |
| 150 | # Now install the software. |
| 151 | DEBIAN_FRONTEND=noninteractive apt-get install bono-node --yes --force-yes |
| 152 | DEBIAN_FRONTEND=noninteractive apt-get install clearwater-management --yes --force-yes |
| 153 | |
| 154 | # Function to give DNS record type and IP address for specified IP address |
| 155 | ip2rr() { |
| 156 | if echo $1 | grep -q -e '[^0-9.]' ; then |
| 157 | echo AAAA $1 |
| 158 | else |
| 159 | echo A $1 |
| 160 | fi |
| 161 | } |
| 162 | |
| 163 | # Update DNS |
| 164 | retries=0 |
| 165 | while ! { nsupdate -y "__zone__:__dnssec_key__" -v << EOF |
| 166 | server __dns_ip__ |
| 167 | update add bono-__index__.__zone__. 30 $(ip2rr $PUBLIC_ADDR) |
| 168 | update add __index__.bono.__zone__. 30 $(ip2rr $PUBLIC_ADDR) |
| 169 | update add __zone__. 30 $(ip2rr $PUBLIC_ADDR) |
| 170 | update add __zone__. 30 NAPTR 0 0 "s" "SIP+D2T" "" _sip._tcp.__zone__. |
| 171 | update add __zone__. 30 NAPTR 0 0 "s" "SIP+D2U" "" _sip._udp.__zone__. |
| 172 | update add _sip._tcp.__zone__. 30 SRV 0 0 5060 __index__.bono.__zone__. |
| 173 | update add _sip._udp.__zone__. 30 SRV 0 0 5060 __index__.bono.__zone__. |
| 174 | send |
| 175 | EOF |
| 176 | } && [ $retries -lt 10 ] |
| 177 | do |
| 178 | retries=$((retries + 1)) |
| 179 | echo 'nsupdate failed - retrying (retry '$retries')...' |
| 180 | sleep 5 |
| 181 | done |
| 182 | |
| 183 | # Use the DNS server. |
| 184 | echo 'nameserver __dns_ip__' > /etc/dnsmasq.resolv.conf |
| 185 | echo 'RESOLV_CONF=/etc/dnsmasq.resolv.conf' >> /etc/default/dnsmasq |
| 186 | service dnsmasq force-reload |
| 187 | |
| 188 | outputs: |
| 189 | public_ip: |
| 190 | description: IP address in public network |
| 191 | value: { get_attr: [ server, accessIPv4 ] } |