Lusheng Ji | c38ca2f | 2017-09-11 20:11:29 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START========================================== |
| 4 | # =================================================================== |
| 5 | # Copyright © 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | # =================================================================== |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # ============LICENSE_END============================================ |
| 19 | # |
| 20 | # ECOMP and OpenECOMP are trademarks |
| 21 | # and service marks of AT&T Intellectual Property. |
| 22 | # |
| 23 | |
| 24 | # URLs for artifacts needed for installation |
| 25 | DESIGTYPES={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml |
| 26 | DESIGPLUG={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/plugins/dnsdesig-1.0.0-py27-none-any.wgn |
| 27 | SSHKEYTYPES={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/sshkeyshare/sshkey_types.yaml |
| 28 | SSHKEYPLUG={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/plugins/sshkeyshare-1.0.0-py27-none-any.wgn |
| 29 | OSPLUGINZIP=https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/1.4.zip |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 30 | OSPLUGINWGN=https://github.com/cloudify-cosmo/cloudify-openstack-plugin/releases/download/2.2.0/cloudify_openstack_plugin-2.2.0-py27-none-linux_x86_64-centos-Core.wgn |
| 31 | |
Lusheng Ji | c38ca2f | 2017-09-11 20:11:29 +0000 | [diff] [blame] | 32 | |
| 33 | # Make sure ssh doesn't prompt for new host or choke on a new host with an IP it's seen before |
| 34 | SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" |
| 35 | STARTDIR=$(pwd) |
| 36 | |
| 37 | SSHUSER=centos |
| 38 | PVTKEY=./config/key |
| 39 | INPUTS=./config/inputs.yaml |
| 40 | |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 41 | if [ "$LOCATION" = "" ] |
Lusheng Ji | c38ca2f | 2017-09-11 20:11:29 +0000 | [diff] [blame] | 42 | then |
| 43 | echo 'Environment variable LOCATION not set. Should be set to location ID for this installation.' |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | set -e |
| 48 | set -x |
| 49 | |
| 50 | # Docker workaround for SSH key |
| 51 | # In order for the container to be able to access the key when it's mounted from the Docker host, |
| 52 | # the key file has to be world-readable. But ssh itself will not work with a private key that's world readable. |
| 53 | # So we make a copy and change permissions on the copy. |
| 54 | # NB -- the key on the Docker host has to be world-readable, which means that, from the host machine, you |
| 55 | # can't use it with ssh. It needs to be a world-readable COPY. |
| 56 | PVTKEY=./key600 |
| 57 | cp ./config/key ${PVTKEY} |
| 58 | chmod 600 ${PVTKEY} |
| 59 | |
| 60 | # Create a virtual environment |
| 61 | virtualenv dcaeinstall |
| 62 | source dcaeinstall/bin/activate |
| 63 | |
| 64 | # Install Cloudify |
| 65 | pip install cloudify==3.4.0 |
| 66 | |
| 67 | # Install the Cloudify OpenStack plugin |
| 68 | wget -qO- ${OSPLUGINZIP} > openstack.zip |
| 69 | pip install openstack.zip |
| 70 | |
| 71 | # Spin up a VM |
| 72 | |
| 73 | # Get the Designate and SSH key type files and plugins |
| 74 | mkdir types |
| 75 | wget -qO- ${DESIGTYPES} > types/dns_types.yaml |
| 76 | wget -qO- ${SSHKEYTYPES} > types/sshkey_types.yaml |
| 77 | |
| 78 | wget -O dnsdesig.wgn ${DESIGPLUG} |
| 79 | wget -O sshkeyshare.wgn ${SSHKEYPLUG} |
| 80 | |
| 81 | wagon install -s dnsdesig.wgn |
| 82 | wagon install -s sshkeyshare.wgn |
| 83 | |
| 84 | ## Fix up the inputs file to get the private key locally |
| 85 | sed -e "s#key_filename:.*#key_filename: $PVTKEY#" < ${INPUTS} > /tmp/local_inputs |
| 86 | |
| 87 | # Now install the VM |
| 88 | # Don't exit on error after this point--keep container running so we can do uninstalls after a failure |
| 89 | set +e |
| 90 | if wget -P ./blueprints/ {{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases }}/blueprints/centos_vm.yaml; then |
| 91 | echo "Succeeded in getting the newest centos_vm.yaml" |
| 92 | else |
| 93 | echo "Failed to update centos_vm.yaml, using default version" |
| 94 | fi |
| 95 | set -e |
| 96 | cfy local init --install-plugins -p ./blueprints/centos_vm.yaml -i /tmp/local_inputs -i "datacenter=$LOCATION" |
| 97 | cfy local execute -w install --task-retries=10 |
| 98 | PUBIP=$(cfy local outputs | grep -Po '"public_ip": "\K.*?(?=")') |
| 99 | |
| 100 | |
| 101 | ## It's probably not completely ready when the installation finish, so wait |
| 102 | sleep 180 |
| 103 | |
| 104 | echo "Installing Cloudify Manager on ${PUBIP}." |
| 105 | |
| 106 | PVTIP=$(ssh $SSHOPTS -i "$PVTKEY" "$SSHUSER"@"$PUBIP" 'echo PVTIP=`curl --silent http://169.254.169.254/2009-04-04/meta-data/local-ipv4`' | grep PVTIP | sed 's/PVTIP=//') |
| 107 | if [ "$PVTIP" = "" ] |
| 108 | then |
| 109 | echo Cannot access specified machine at $PUBIP using supplied credentials |
| 110 | # Don't exit--keep the container up so we can uninstall the VM and supporting entities |
| 111 | while true |
| 112 | do |
| 113 | sleep 300 |
| 114 | done |
| 115 | fi |
| 116 | |
| 117 | |
| 118 | # Copy private key onto Cloudify Manager VM |
| 119 | PVTKEYPATH=$(cat ${INPUTS} | grep "key_filename" | cut -d "'" -f2) |
| 120 | PVTKEYNAME=$(basename $PVTKEYPATH) |
| 121 | PVTKEYDIR=$(dirname $PVTKEYPATH) |
| 122 | scp $SSHOPTS -i $PVTKEY $PVTKEY $SSHUSER@$PUBIP:/tmp/$PVTKEYNAME |
| 123 | ssh -t $SSHOPTS -i $PVTKEY $SSHUSER@$PUBIP sudo mkdir -p $PVTKEYDIR |
| 124 | ssh -t $SSHOPTS -i $PVTKEY $SSHUSER@$PUBIP sudo mv /tmp/$PVTKEYNAME $PVTKEYPATH |
| 125 | |
| 126 | ESMAGIC=$(uuidgen -r) |
| 127 | WORKDIR=$HOME/cmtmp |
| 128 | BSDIR=$WORKDIR/cmbootstrap |
| 129 | PVTKEY2=$BSDIR/id_rsa.cfybootstrap |
| 130 | TMPBASE=$WORKDIR/tmp |
| 131 | TMPDIR=$TMPBASE/lib |
| 132 | SRCS=$WORKDIR/srcs.tar |
| 133 | TOOL=$WORKDIR/tool.py |
| 134 | rm -rf $WORKDIR |
| 135 | mkdir -p $BSDIR $TMPDIR/cloudify/wheels $TMPDIR/cloudify/sources $TMPDIR/manager |
| 136 | chmod 700 $WORKDIR |
| 137 | cp "$PVTKEY" $PVTKEY2 |
| 138 | cat >$TOOL <<!EOF |
| 139 | #!/usr/local/bin/python |
| 140 | # |
| 141 | import yaml |
| 142 | import sys |
| 143 | bsdir = sys.argv[1] |
| 144 | with open(bsdir + '/simple-manager-blueprint-inputs.yaml', 'r') as f: |
| 145 | inpyaml = yaml.load(f) |
| 146 | with open(bsdir + '/simple-manager-blueprint.yaml', 'r') as f: |
| 147 | bpyaml = yaml.load(f) |
| 148 | for param, value in bpyaml['inputs'].items(): |
| 149 | if value.has_key('default') and not inpyaml.has_key(param): |
| 150 | inpyaml[param] = value['default'] |
| 151 | print inpyaml['manager_resources_package'] |
| 152 | !EOF |
| 153 | |
| 154 | # |
| 155 | # Try to disable attempt to download virtualenv when not needed |
| 156 | # |
| 157 | ssh $SSHOPTS -t -i $PVTKEY2 $SSHUSER@$PUBIP 'sudo bash -xc "echo y; mkdir -p /root/.virtualenv; echo '"'"'[virtualenv]'"'"' >/root/.virtualenv/virtualenv.ini; echo no-download=true >>/root/.virtualenv/virtualenv.ini"' |
| 158 | |
| 159 | # Gather installation artifacts |
| 160 | # from documentation, URL for manager blueprints archive |
| 161 | BSURL=https://github.com/cloudify-cosmo/cloudify-manager-blueprints/archive/3.4.tar.gz |
| 162 | BSFILE=$(basename $BSURL) |
| 163 | |
| 164 | umask 022 |
| 165 | wget -qO- $BSURL >$BSDIR/$BSFILE |
| 166 | cd $BSDIR |
| 167 | tar xzvf $BSFILE |
| 168 | MRPURL=$(python $TOOL $BSDIR/cloudify-manager-blueprints-3.4) |
| 169 | MRPFILE=$(basename $MRPURL) |
| 170 | wget -qO- $MRPURL >$TMPDIR/cloudify/sources/$MRPFILE |
| 171 | |
| 172 | tar cf $SRCS -C $TMPDIR cloudify |
| 173 | rm -rf $TMPBASE |
| 174 | # |
| 175 | # Load required package files onto VM |
| 176 | # |
| 177 | scp $SSHOPTS -i $PVTKEY2 $SRCS $SSHUSER@$PUBIP:/tmp/. |
| 178 | ssh -t $SSHOPTS -i $PVTKEY2 $SSHUSER@$PUBIP 'sudo bash -xc "cd /opt; tar xf /tmp/srcs.tar; chown -R root:root /opt/cloudify /opt/manager; rm -rf /tmp/srcs.tar"' |
| 179 | # |
| 180 | # Install config file -- was done by DCAE controller. What now? |
| 181 | # |
| 182 | ssh $SSHOPTS -t -i $PVTKEY2 $SSHUSER@$PUBIP 'sudo bash -xc '"'"'mkdir -p /opt/dcae; if [ -f /tmp/cfy-config.txt ]; then cp /tmp/cfy-config.txt /opt/dcae/config.txt && chmod 644 /opt/dcae/config.txt; fi'"'" |
| 183 | cd $WORKDIR |
| 184 | |
| 185 | # |
| 186 | # Check for and set up https certificate information |
| 187 | # |
| 188 | rm -f $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.key $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.crt |
| 189 | ssh -t $SSHOPTS -i $PVTKEY2 $SSHUSER@$PUBIP 'sudo bash -xc "openssl pkcs12 -in /opt/app/dcae-certificate/certificate.pkcs12 -passin file:/opt/app/dcae-certificate/.password -nodes -chain"' | awk 'BEGIN{x="/dev/null";}/-----BEGIN CERTIFICATE-----/{x="'$BSDIR'/cloudify-manager-blueprints-3.4/resources/ssl/server.crt";}/-----BEGIN PRIVATE KEY-----/{x="'$BSDIR'/cloudify-manager-blueprints-3.4/resources/ssl/server.key";}{print >x;}/-----END /{x="/dev/null";}' |
| 190 | USESSL=false |
| 191 | if [ -f $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.key -a -f $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.crt ] |
| 192 | then |
| 193 | USESSL=true |
| 194 | fi |
| 195 | # |
| 196 | # Set up configuration for the bootstrap |
| 197 | # |
| 198 | export CLOUDIFY_USERNAME=admin CLOUDIFY_PASSWORD=encc0fba9f6d618a1a51935b42342b17658 |
| 199 | cd $BSDIR/cloudify-manager-blueprints-3.4 |
| 200 | cp simple-manager-blueprint.yaml bootstrap-blueprint.yaml |
| 201 | ed bootstrap-blueprint.yaml <<'!EOF' |
| 202 | /^node_types:/-1a |
| 203 | plugin_resources: |
| 204 | description: > |
| 205 | Holds any archives that should be uploaded to the manager. |
| 206 | default: [] |
| 207 | dsl_resources: |
| 208 | description: > |
| 209 | Holds a set of dsl required resources |
| 210 | default: [] |
| 211 | . |
| 212 | /^ upload_resources:/a |
| 213 | plugin_resources: { get_input: plugin_resources } |
| 214 | . |
| 215 | w |
| 216 | q |
| 217 | !EOF |
| 218 | |
| 219 | sed <simple-manager-blueprint-inputs.yaml >bootstrap-inputs.yaml \ |
| 220 | -e "s;.*public_ip: .*;public_ip: '$PUBIP';" \ |
| 221 | -e "s;.*private_ip: .*;private_ip: '$PVTIP';" \ |
| 222 | -e "s;.*ssh_user: .*;ssh_user: '$SSHUSER';" \ |
| 223 | -e "s;.*ssh_key_filename: .*;ssh_key_filename: '$PVTKEY2';" \ |
| 224 | -e "s;.*elasticsearch_java_opts: .*;elasticsearch_java_opts: '-Des.cluster.name=$ESMAGIC';" \ |
| 225 | -e "/ssl_enabled: /s/.*/ssl_enabled: $USESSL/" \ |
| 226 | -e "/security_enabled: /s/.*/security_enabled: $USESSL/" \ |
| 227 | -e "/admin_password: /s/.*/admin_password: '$CLOUDIFY_PASSWORD'/" \ |
| 228 | -e "/admin_username: /s/.*/admin_username: '$CLOUDIFY_USERNAME'/" \ |
| 229 | -e "s;.*manager_resources_package: .*;manager_resources_package: 'http://169.254.169.254/nosuchthing/$MRPFILE';" \ |
| 230 | -e "s;.*ignore_bootstrap_validations: .*;ignore_bootstrap_validations: true;" \ |
| 231 | |
| 232 | # Add plugin resources |
Jack Lucas | 1e353cb | 2017-10-11 21:10:08 +0000 | [diff] [blame^] | 233 | # TODO Maintain plugin list as updates/additions occur |
Lusheng Ji | c38ca2f | 2017-09-11 20:11:29 +0000 | [diff] [blame] | 234 | cat >>bootstrap-inputs.yaml <<'!EOF' |
| 235 | plugin_resources: |
| 236 | - 'http://repository.cloudifysource.org/org/cloudify3/wagons/cloudify-openstack-plugin/1.4/cloudify_openstack_plugin-1.4-py27-none-linux_x86_64-centos-Core.wgn' |
| 237 | - 'http://repository.cloudifysource.org/org/cloudify3/wagons/cloudify-fabric-plugin/1.4.1/cloudify_fabric_plugin-1.4.1-py27-none-linux_x86_64-centos-Core.wgn' |
| 238 | - '{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/plugins/dnsdesig-1.0.0-py27-none-any.wgn' |
| 239 | - '{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/plugins/sshkeyshare-1.0.0-py27-none-any.wgn' |
Jack Lucas | 1e353cb | 2017-10-11 21:10:08 +0000 | [diff] [blame^] | 240 | - '{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/plugins/cdapcloudify/cdapcloudify-14.2.5-py27-none-any.wgn' |
| 241 | - '{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/plugins/dcaepolicyplugin/dcaepolicyplugin-1.0.0-py27-none-any.wgn' |
| 242 | - '{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/plugins/dockerplugin/dockerplugin-2.4.0-py27-none-any.wgn' |
| 243 | - '{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/plugins/relationshipplugin/relationshipplugin-1.0.0-py27-none-any.wgn' |
Lusheng Ji | c38ca2f | 2017-09-11 20:11:29 +0000 | [diff] [blame] | 244 | !EOF |
| 245 | # |
| 246 | # And away we go |
| 247 | # |
| 248 | cfy init -r |
| 249 | cfy bootstrap --install-plugins -p bootstrap-blueprint.yaml -i bootstrap-inputs.yaml |
| 250 | rm -f resources/ssl/server.key |
| 251 | |
| 252 | # Install Consul VM via a blueprint |
| 253 | cd $STARTDIR |
| 254 | mkdir consul |
| 255 | cd consul |
| 256 | cfy init -r |
| 257 | cfy use -t ${PUBIP} |
| 258 | echo "Deploying Consul VM" |
| 259 | |
| 260 | set +e |
| 261 | if wget -P ../blueprints/ {{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases }}/blueprints/consul_cluster.yaml; then |
| 262 | echo "Succeeded in getting the newest consul_cluster.yaml" |
| 263 | else |
| 264 | echo "Failed to update consul_cluster.yaml, using default version" |
| 265 | fi |
| 266 | set -e |
| 267 | cfy install -p ../blueprints/consul_cluster.yaml -d consul -i ../${INPUTS} -i "datacenter=$LOCATION" |
| 268 | |
| 269 | # Get the floating IP for one member of the cluster |
| 270 | # Needed for instructing the Consul agent on CM host to join the cluster |
| 271 | CONSULIP=$(cfy deployments outputs -d consul | grep -Po 'Value: \K.*') |
| 272 | echo Consul deployed at $CONSULIP |
| 273 | |
| 274 | # Wait for Consul API to come up |
| 275 | until curl http://$CONSULIP:8500/v1/agent/services |
| 276 | do |
| 277 | echo Waiting for Consul API |
| 278 | sleep 60 |
| 279 | done |
| 280 | |
| 281 | # Wait for a leader to be elected |
| 282 | until [[ "$(curl -Ss http://$CONSULIP:8500/v1/status/leader)" != '""' ]] |
| 283 | do |
| 284 | echo Waiting for leader |
| 285 | sleep 30 |
| 286 | done |
| 287 | |
| 288 | # Instruct the client-mode Consul agent running on the CM to join the cluster |
| 289 | curl http://$PUBIP:8500/v1/agent/join/$CONSULIP |
| 290 | |
| 291 | # Register Cloudify Manager in Consul via the local agent on CM host |
| 292 | |
| 293 | REGREQ=" |
| 294 | { |
| 295 | \"Name\" : \"cloudify_manager\", |
| 296 | \"ID\" : \"cloudify_manager\", |
| 297 | \"Tags\" : [\"http://${PUBIP}/api/v2.1\"], |
| 298 | \"Address\": \"${PUBIP}\", |
| 299 | \"Port\": 80, |
| 300 | \"Check\" : { |
| 301 | \"Name\" : \"cloudify_manager_health\", |
| 302 | \"Interval\" : \"300s\", |
| 303 | \"HTTP\" : \"http://${PUBIP}/api/v2.1/status\", |
| 304 | \"Status\" : \"passing\", |
| 305 | \"DeregisterCriticalServiceAfter\" : \"30m\" |
| 306 | } |
| 307 | } |
| 308 | " |
| 309 | |
| 310 | curl -X PUT -H 'Content-Type: application/json' --data-binary "$REGREQ" http://$PUBIP:8500/v1/agent/service/register |
| 311 | # Make Consul address available to plugins on Cloudify Manager |
| 312 | # TODO probably not necessary anymore |
| 313 | ENVINI=$(mktemp) |
| 314 | cat <<!EOF > $ENVINI |
| 315 | [$LOCATION] |
| 316 | CONSUL_HOST=$CONSULIP |
| 317 | CONFIG_BINDING_SERVICE=config_binding_service |
| 318 | !EOF |
| 319 | scp $SSHOPTS -i ../$PVTKEY $ENVINI $SSHUSER@$PUBIP:/tmp/env.ini |
| 320 | ssh -t $SSHOPTS -i ../$PVTKEY $SSHUSER@$PUBIP sudo mv /tmp/env.ini /opt/env.ini |
| 321 | rm $ENVINI |
| 322 | |
| 323 | while true |
| 324 | do |
| 325 | sleep 300 |
| 326 | done |