blob: bf0f3fcfe3fcf51c3293702c2e5d9f8844374f62 [file] [log] [blame]
Lusheng Jic38ca2f2017-09-11 20:11:29 +00001#!/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
25DESIGTYPES={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml
26DESIGPLUG={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/plugins/dnsdesig-1.0.0-py27-none-any.wgn
27SSHKEYTYPES={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/sshkeyshare/sshkey_types.yaml
28SSHKEYPLUG={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/plugins/sshkeyshare-1.0.0-py27-none-any.wgn
29OSPLUGINZIP=https://github.com/cloudify-cosmo/cloudify-openstack-plugin/archive/1.4.zip
Lusheng Jid92d4482017-09-21 05:42:28 +000030OSPLUGINWGN=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 Jic38ca2f2017-09-11 20:11:29 +000032
33# Make sure ssh doesn't prompt for new host or choke on a new host with an IP it's seen before
34SSHOPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
35STARTDIR=$(pwd)
36
37SSHUSER=centos
38PVTKEY=./config/key
39INPUTS=./config/inputs.yaml
40
Lusheng Jid92d4482017-09-21 05:42:28 +000041if [ "$LOCATION" = "" ]
Lusheng Jic38ca2f2017-09-11 20:11:29 +000042then
43 echo 'Environment variable LOCATION not set. Should be set to location ID for this installation.'
44 exit 1
45fi
46
47set -e
48set -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.
56PVTKEY=./key600
57cp ./config/key ${PVTKEY}
58chmod 600 ${PVTKEY}
59
60# Create a virtual environment
61virtualenv dcaeinstall
62source dcaeinstall/bin/activate
63
64# Install Cloudify
65pip install cloudify==3.4.0
66
67# Install the Cloudify OpenStack plugin
68wget -qO- ${OSPLUGINZIP} > openstack.zip
69pip install openstack.zip
70
71# Spin up a VM
72
73# Get the Designate and SSH key type files and plugins
74mkdir types
75wget -qO- ${DESIGTYPES} > types/dns_types.yaml
76wget -qO- ${SSHKEYTYPES} > types/sshkey_types.yaml
77
78wget -O dnsdesig.wgn ${DESIGPLUG}
79wget -O sshkeyshare.wgn ${SSHKEYPLUG}
80
81wagon install -s dnsdesig.wgn
82wagon install -s sshkeyshare.wgn
83
84## Fix up the inputs file to get the private key locally
85sed -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
89set +e
90if 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"
92else
93 echo "Failed to update centos_vm.yaml, using default version"
94fi
95set -e
96cfy local init --install-plugins -p ./blueprints/centos_vm.yaml -i /tmp/local_inputs -i "datacenter=$LOCATION"
97cfy local execute -w install --task-retries=10
98PUBIP=$(cfy local outputs | grep -Po '"public_ip": "\K.*?(?=")')
99
100
101## It's probably not completely ready when the installation finish, so wait
102sleep 180
103
104echo "Installing Cloudify Manager on ${PUBIP}."
105
106PVTIP=$(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=//')
107if [ "$PVTIP" = "" ]
108then
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
115fi
116
117
118# Copy private key onto Cloudify Manager VM
119PVTKEYPATH=$(cat ${INPUTS} | grep "key_filename" | cut -d "'" -f2)
120PVTKEYNAME=$(basename $PVTKEYPATH)
121PVTKEYDIR=$(dirname $PVTKEYPATH)
122scp $SSHOPTS -i $PVTKEY $PVTKEY $SSHUSER@$PUBIP:/tmp/$PVTKEYNAME
123ssh -t $SSHOPTS -i $PVTKEY $SSHUSER@$PUBIP sudo mkdir -p $PVTKEYDIR
124ssh -t $SSHOPTS -i $PVTKEY $SSHUSER@$PUBIP sudo mv /tmp/$PVTKEYNAME $PVTKEYPATH
125
126ESMAGIC=$(uuidgen -r)
127WORKDIR=$HOME/cmtmp
128BSDIR=$WORKDIR/cmbootstrap
129PVTKEY2=$BSDIR/id_rsa.cfybootstrap
130TMPBASE=$WORKDIR/tmp
131TMPDIR=$TMPBASE/lib
132SRCS=$WORKDIR/srcs.tar
133TOOL=$WORKDIR/tool.py
134rm -rf $WORKDIR
135mkdir -p $BSDIR $TMPDIR/cloudify/wheels $TMPDIR/cloudify/sources $TMPDIR/manager
136chmod 700 $WORKDIR
137cp "$PVTKEY" $PVTKEY2
138cat >$TOOL <<!EOF
139#!/usr/local/bin/python
140#
141import yaml
142import sys
143bsdir = sys.argv[1]
144with open(bsdir + '/simple-manager-blueprint-inputs.yaml', 'r') as f:
145 inpyaml = yaml.load(f)
146with open(bsdir + '/simple-manager-blueprint.yaml', 'r') as f:
147 bpyaml = yaml.load(f)
148for param, value in bpyaml['inputs'].items():
149 if value.has_key('default') and not inpyaml.has_key(param):
150 inpyaml[param] = value['default']
151print inpyaml['manager_resources_package']
152!EOF
153
154#
155# Try to disable attempt to download virtualenv when not needed
156#
157ssh $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
161BSURL=https://github.com/cloudify-cosmo/cloudify-manager-blueprints/archive/3.4.tar.gz
162BSFILE=$(basename $BSURL)
163
164umask 022
165wget -qO- $BSURL >$BSDIR/$BSFILE
166cd $BSDIR
167tar xzvf $BSFILE
168MRPURL=$(python $TOOL $BSDIR/cloudify-manager-blueprints-3.4)
169MRPFILE=$(basename $MRPURL)
170wget -qO- $MRPURL >$TMPDIR/cloudify/sources/$MRPFILE
171
172tar cf $SRCS -C $TMPDIR cloudify
173rm -rf $TMPBASE
174#
175# Load required package files onto VM
176#
177scp $SSHOPTS -i $PVTKEY2 $SRCS $SSHUSER@$PUBIP:/tmp/.
178ssh -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#
182ssh $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'"'"
183cd $WORKDIR
184
185#
186# Check for and set up https certificate information
187#
188rm -f $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.key $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.crt
189ssh -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";}'
190USESSL=false
191if [ -f $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.key -a -f $BSDIR/cloudify-manager-blueprints-3.4/resources/ssl/server.crt ]
192then
193 USESSL=true
194fi
195#
196# Set up configuration for the bootstrap
197#
198export CLOUDIFY_USERNAME=admin CLOUDIFY_PASSWORD=encc0fba9f6d618a1a51935b42342b17658
199cd $BSDIR/cloudify-manager-blueprints-3.4
200cp simple-manager-blueprint.yaml bootstrap-blueprint.yaml
201ed 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.
215w
216q
217!EOF
218
219sed <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 Lucas1e353cb2017-10-11 21:10:08 +0000233# TODO Maintain plugin list as updates/additions occur
Lusheng Jic38ca2f2017-09-11 20:11:29 +0000234cat >>bootstrap-inputs.yaml <<'!EOF'
235plugin_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 Lucas1e353cb2017-10-11 21:10:08 +0000240 - '{{ 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 Jic38ca2f2017-09-11 20:11:29 +0000244!EOF
245#
246# And away we go
247#
248cfy init -r
249cfy bootstrap --install-plugins -p bootstrap-blueprint.yaml -i bootstrap-inputs.yaml
250rm -f resources/ssl/server.key
251
252# Install Consul VM via a blueprint
253cd $STARTDIR
254mkdir consul
255cd consul
256cfy init -r
257cfy use -t ${PUBIP}
258echo "Deploying Consul VM"
259
260set +e
261if 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"
263else
264 echo "Failed to update consul_cluster.yaml, using default version"
265fi
266set -e
267cfy 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
271CONSULIP=$(cfy deployments outputs -d consul | grep -Po 'Value: \K.*')
272echo Consul deployed at $CONSULIP
273
274# Wait for Consul API to come up
275until curl http://$CONSULIP:8500/v1/agent/services
276do
277 echo Waiting for Consul API
278 sleep 60
279done
280
281# Wait for a leader to be elected
282until [[ "$(curl -Ss http://$CONSULIP:8500/v1/status/leader)" != '""' ]]
283do
284 echo Waiting for leader
285 sleep 30
286done
287
288# Instruct the client-mode Consul agent running on the CM to join the cluster
289curl http://$PUBIP:8500/v1/agent/join/$CONSULIP
290
291# Register Cloudify Manager in Consul via the local agent on CM host
292
293REGREQ="
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
310curl -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
313ENVINI=$(mktemp)
314cat <<!EOF > $ENVINI
315[$LOCATION]
316CONSUL_HOST=$CONSULIP
317CONFIG_BINDING_SERVICE=config_binding_service
318!EOF
319scp $SSHOPTS -i ../$PVTKEY $ENVINI $SSHUSER@$PUBIP:/tmp/env.ini
320ssh -t $SSHOPTS -i ../$PVTKEY $SSHUSER@$PUBIP sudo mv /tmp/env.ini /opt/env.ini
321rm $ENVINI
322
323while true
324do
325 sleep 300
326done