blob: 0a14e9d2736b7f29b8585675c6cd67caed2feaa7 [file] [log] [blame]
garciadeblasd8bc5c32018-05-09 17:37:56 +02001#!/bin/bash
2# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16function usage(){
17 echo -e "usage: $0 [OPTIONS]"
18 echo -e "Install OSM from binaries or source code (by default, from binaries)"
19 echo -e " OPTIONS"
garciadeblasd8bc5c32018-05-09 17:37:56 +020020 echo -e " -r <repo>: use specified repository name for osm packages"
21 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
22 echo -e " -u <repo base>: use specified repository url for osm packages"
23 echo -e " -k <repo key>: use specified repository public key url"
24 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
25 echo -e " -b master (main dev branch)"
26 echo -e " -b v2.0 (v2.0 branch)"
27 echo -e " -b tags/v1.1.0 (a specific tag)"
28 echo -e " ..."
Mike Marchetti67411aa2018-09-13 11:38:38 -040029 echo -e " -s <stack name> user defined stack name, default is osm"
30 echo -e " -H <VCA host> use specific juju host controller IP"
31 echo -e " -S <VCA secret> use VCA/juju secret key"
garciadeblas6c66abf2018-05-16 14:46:19 +020032 echo -e " --vimemu: additionally deploy the VIM emulator as a docker container"
33 echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging"
34 echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
garciadeblas0e596bc2018-05-28 16:04:42 +020035 echo -e " -m <MODULE>: install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)"
garciadeblas282ff4e2018-07-10 09:16:30 +020036 echo -e " -o <ADDON>: ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)"
garciadeblase990f662018-05-18 11:43:39 +020037 echo -e " -D <devops path> use local devops installation path"
garciadeblasd41f5482018-05-25 10:25:06 +020038 echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
garciadeblasa3e26612018-05-30 17:58:55 +020039 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
Mike Marchetti67411aa2018-09-13 11:38:38 -040040 echo -e " --nojuju: do not juju, assumes already installed"
41 echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)"
42 echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)"
garciadeblase990f662018-05-18 11:43:39 +020043 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
44 echo -e " --source: install OSM from source code using the latest stable tag"
garciadeblasd8bc5c32018-05-09 17:37:56 +020045 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
garciadeblasd41f5482018-05-25 10:25:06 +020046 echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
47 echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch"
48 echo -e " -l <lxd_repo>: (only for Rel THREE with --soui) use specified repository url for lxd images"
49 echo -e " -p <path>: (only for Rel THREE with --soui) use specified repository path for lxd images"
garciadeblasd8bc5c32018-05-09 17:37:56 +020050# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
garciadeblasd41f5482018-05-25 10:25:06 +020051 echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules"
52 echo -e " --noconfigure: (only for Rel THREE with --soui) DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
garciadeblasd8bc5c32018-05-09 17:37:56 +020053# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
54 echo -e " --showopts: print chosen options and exit (only for debugging)"
55 echo -e " -y: do not prompt for confirmation, assumes yes"
garciadeblasd8bc5c32018-05-09 17:37:56 +020056 echo -e " -h / --help: print this help"
57}
58
59#Uninstall OSM: remove containers
60function uninstall(){
61 echo -e "\nUninstalling OSM"
62 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
63 $OSM_DEVOPS/jenkins/host/clean_container RO
64 $OSM_DEVOPS/jenkins/host/clean_container VCA
65 $OSM_DEVOPS/jenkins/host/clean_container MON
66 $OSM_DEVOPS/jenkins/host/clean_container SO
67 #$OSM_DEVOPS/jenkins/host/clean_container UI
68 else
69 lxc stop RO && lxc delete RO
70 lxc stop VCA && lxc delete VCA
71 lxc stop MON && lxc delete MON
72 lxc stop SO-ub && lxc delete SO-ub
73 fi
74 echo -e "\nDeleting imported lxd images if they exist"
75 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
76 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
77 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
78 return 0
79}
80
Mike Marchetti67411aa2018-09-13 11:38:38 -040081# takes a juju/accounts.yaml file and returns the password specific
82# for a controller. I wrote this using only bash tools to minimize
83# additions of other packages
84function parse_juju_password {
85 password_file="${HOME}/.local/share/juju/accounts.yaml"
86 local controller_name=$1
Mike Marchetti2fafbba2018-09-13 15:35:42 -040087 local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
Mike Marchetti67411aa2018-09-13 11:38:38 -040088 sed -ne "s|^\($s\):|\1|" \
89 -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
90 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
91 awk -F$fs -v controller=$controller_name '{
92 indent = length($1)/2;
93 vname[indent] = $2;
94 for (i in vname) {if (i > indent) {delete vname[i]}}
95 if (length($3) > 0) {
96 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
97 if (match(vn,controller) && match($2,"password")) {
98 printf("%s",$3);
99 }
100 }
101 }'
102}
103
garciadeblas5b857d32018-05-24 18:37:58 +0200104function remove_stack() {
105 stack=$1
garciadeblas5ef98212018-05-28 09:25:36 +0200106 if sg docker -c "docker stack ps ${stack}" ; then
garciadeblas5b857d32018-05-24 18:37:58 +0200107 echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
108 COUNTER=0
109 result=1
110 while [ ${COUNTER} -lt 30 ]; do
111 result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
112 #echo "Dockers running: $result"
113 if [ "${result}" == "0" ]; then
114 break
115 fi
116 let COUNTER=COUNTER+1
117 sleep 1
118 done
garciadeblasd8bc5c32018-05-09 17:37:56 +0200119 if [ "${result}" == "0" ]; then
garciadeblas5b857d32018-05-24 18:37:58 +0200120 echo "All dockers of the stack ${stack} were removed"
121 else
122 FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
garciadeblasd8bc5c32018-05-09 17:37:56 +0200123 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200124 sleep 5
garciadeblasd8bc5c32018-05-09 17:37:56 +0200125 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200126}
127
128#Uninstall lightweight OSM: remove dockers
129function uninstall_lightweight() {
garciadeblas282ff4e2018-07-10 09:16:30 +0200130 if [ -n "$INSTALL_ONLY" ]; then
131 if [ -n "$INSTALL_ELK" ]; then
132 echo -e "\nUninstalling OSM ELK stack"
133 remove_stack osm_elk
Mike Marchetti67411aa2018-09-13 11:38:38 -0400134 rm -rf $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas282ff4e2018-07-10 09:16:30 +0200135 fi
136 if [ -n "$INSTALL_PERFMON" ]; then
137 echo -e "\nUninstalling OSM Performance Monitoring stack"
138 remove_stack osm_metrics
139 sg docker -c "docker image rm osm/kafka-exporter"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400140 rm -rf $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas282ff4e2018-07-10 09:16:30 +0200141 fi
142 else
143 echo -e "\nUninstalling OSM"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400144 remove_stack $OSM_STACK_NAME
garciadeblas282ff4e2018-07-10 09:16:30 +0200145 remove_stack osm_elk
146 remove_stack osm_metrics
147 echo "Now osm docker images and volumes will be deleted"
148 newgrp docker << EONG
149 docker image rm osm/ro
150 docker image rm osm/lcm
151 docker image rm osm/light-ui
152 docker image rm osm/nbi
153 docker image rm osm/mon
154 docker image rm osm/pm
155 docker image rm osm/kafka-exporter
156 docker volume rm osm_mon_db
157 docker volume rm osm_mongo_db
158 docker volume rm osm_osm_packages
159 docker volume rm osm_ro_db
garciadeblas83ca1322018-05-22 18:31:14 +0200160EONG
Mike Marchetti67411aa2018-09-13 11:38:38 -0400161 echo "Removing $OSM_DOCKER_WORK_DIR"
162 rm -rf $OSM_DOCKER_WORK_DIR
garciadeblas282ff4e2018-07-10 09:16:30 +0200163 fi
164 echo "Some docker images will be kept in case they are used by other docker stacks"
165 echo "To remove them, just run 'docker image prune' in a terminal"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200166 return 0
167}
168
169#Configure NAT rules, based on the current IP addresses of containers
170function nat(){
171 echo -e "\nChecking required packages: iptables-persistent"
172 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
173 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
174 echo -e "\nConfiguring NAT rules"
175 echo -e " Required root privileges"
176 sudo $OSM_DEVOPS/installers/nat_osm
177}
178
179function FATAL(){
180 echo "FATAL error: Cannot install OSM due to \"$1\""
181 exit 1
182}
183
184#Update RO, SO and UI:
185function update(){
186 echo -e "\nUpdating components"
187
188 echo -e " Updating RO"
189 CONTAINER="RO"
190 MDG="RO"
191 INSTALL_FOLDER="/opt/openmano"
192 echo -e " Fetching the repo"
193 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
194 BRANCH=""
195 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
196 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
197 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
198 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
199 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
200 # COMMIT_ID either was previously set with -b option, or is an empty string
201 CHECKOUT_ID=$COMMIT_ID
202 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
203 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
204 if [[ $CHECKOUT_ID == "tags/"* ]]; then
205 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
206 else
207 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
208 fi
209 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
210 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
211 echo " Nothing to be done."
212 else
213 echo " Update required."
214 lxc exec $CONTAINER -- service osm-ro stop
215 lxc exec $CONTAINER -- git -C /opt/openmano stash
216 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
217 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
218 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
219 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
220 lxc exec $CONTAINER -- service osm-ro start
221 fi
222 echo
223
224 echo -e " Updating SO and UI"
225 CONTAINER="SO-ub"
226 MDG="SO"
227 INSTALL_FOLDER="" # To be filled in
228 echo -e " Fetching the repo"
229 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
230 BRANCH=""
231 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
232 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
233 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
234 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
235 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
236 # COMMIT_ID either was previously set with -b option, or is an empty string
237 CHECKOUT_ID=$COMMIT_ID
238 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
239 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
240 if [[ $CHECKOUT_ID == "tags/"* ]]; then
241 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
242 else
243 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
244 fi
245 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
246 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
247 echo " Nothing to be done."
248 else
249 echo " Update required."
250 # Instructions to be added
251 # lxc exec SO-ub -- ...
252 fi
253 echo
254 echo -e "Updating MON Container"
255 CONTAINER="MON"
256 MDG="MON"
257 INSTALL_FOLDER="/root/MON"
258 echo -e " Fetching the repo"
259 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
260 BRANCH=""
261 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
262 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
263 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
264 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
265 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
266 # COMMIT_ID either was previously set with -b option, or is an empty string
267 CHECKOUT_ID=$COMMIT_ID
268 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
269 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
270 if [[ $CHECKOUT_ID == "tags/"* ]]; then
271 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
272 else
273 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
274 fi
275 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
276 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
277 echo " Nothing to be done."
278 else
279 echo " Update required."
280 fi
281 echo
282}
283
284function so_is_up() {
285 if [ -n "$1" ]; then
286 SO_IP=$1
287 else
288 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
289 fi
290 time=0
291 step=5
292 timelength=300
293 while [ $time -le $timelength ]
294 do
295 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
296 -H 'accept: application/vnd.yang.data+json' \
297 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
298 -H 'cache-control: no-cache' 2> /dev/null | jq '.[].components.component_info[] | select(.component_name=="RW.Restconf")' 2>/dev/null | grep "RUNNING" | wc -l` -eq 1 ]]
299 then
300 echo "RW.Restconf running....SO is up"
301 return 0
302 fi
303
304 sleep $step
305 echo -n "."
306 time=$((time+step))
307 done
308
309 FATAL "OSM Failed to startup. SO failed to startup"
310}
311
312function vca_is_up() {
313 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
314 echo "VCA is up and running"
315 return 0
316 fi
317
318 FATAL "OSM Failed to startup. VCA failed to startup"
319}
320
321function mon_is_up() {
322 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
323 echo "MON is up and running"
324 return 0
325 fi
326
327 FATAL "OSM Failed to startup. MON failed to startup"
328}
329
330function ro_is_up() {
331 if [ -n "$1" ]; then
332 RO_IP=$1
333 else
334 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
335 fi
336 time=0
337 step=2
338 timelength=20
339 while [ $time -le $timelength ]; do
340 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
341 echo "RO is up and running"
342 return 0
343 fi
344 sleep $step
345 echo -n "."
346 time=$((time+step))
347 done
348
349 FATAL "OSM Failed to startup. RO failed to startup"
350}
351
352
353function configure_RO(){
354 . $OSM_DEVOPS/installers/export_ips
355 echo -e " Configuring RO"
356 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
357 lxc exec RO -- service osm-ro restart
358
359 ro_is_up
360
361 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
362 lxc exec RO -- openmano tenant-create osm > /dev/null
363 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
364 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
365 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
366}
367
368function configure_VCA(){
369 echo -e " Configuring VCA"
370 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
371 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
372}
373
374function configure_SOUI(){
375 . $OSM_DEVOPS/installers/export_ips
376 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
377 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
378
379 echo -e " Configuring MON"
380 #Information to be added about SO socket for logging
381
382 echo -e " Configuring SO"
383 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200384 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200385 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200386 sudo sed -i "$ i ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP" /etc/rc.local
garciadeblasd8bc5c32018-05-09 17:37:56 +0200387 # make journaling persistent
388 lxc exec SO-ub -- mkdir -p /var/log/journal
389 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
390 lxc exec SO-ub -- systemctl restart systemd-journald
391
392 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
393
394 lxc exec SO-ub -- systemctl restart launchpad
395
396 so_is_up $SO_CONTAINER_IP
397
398 #delete existing config agent (could be there on reconfigure)
399 curl -k --request DELETE \
400 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
401 --header 'accept: application/vnd.yang.data+json' \
402 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
403 --header 'cache-control: no-cache' \
404 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
405
406 result=$(curl -k --request POST \
407 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
408 --header 'accept: application/vnd.yang.data+json' \
409 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
410 --header 'cache-control: no-cache' \
411 --header 'content-type: application/vnd.yang.data+json' \
412 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
413 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
414
415 #R1/R2 config line
416 #result=$(curl -k --request PUT \
417 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
418 # --header 'accept: application/vnd.yang.data+json' \
419 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
420 # --header 'cache-control: no-cache' \
421 # --header 'content-type: application/vnd.yang.data+json' \
422 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
423
424 result=$(curl -k --request PUT \
425 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
426 --header 'accept: application/vnd.yang.data+json' \
427 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
428 --header 'cache-control: no-cache' \
429 --header 'content-type: application/vnd.yang.data+json' \
430 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
431 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
432
433 result=$(curl -k --request PATCH \
434 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
435 --header 'accept: application/vnd.yang.data+json' \
436 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
437 --header 'cache-control: no-cache' \
438 --header 'content-type: application/vnd.yang.data+json' \
439 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
440 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
441
442 result=$(curl -k --request PATCH \
443 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
444 --header 'accept: application/vnd.yang.data+json' \
445 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
446 --header 'cache-control: no-cache' \
447 --header 'content-type: application/vnd.yang.data+json' \
448 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
449 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
450
451 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
452auto lo:1
453iface lo:1 inet static
454 address $DEFAULT_IP
455 netmask 255.255.255.255
456EOF
457 lxc exec SO-ub ifup lo:1
458}
459
460#Configure RO, VCA, and SO with the initial configuration:
461# RO -> tenant:osm, logs to be sent to SO
462# VCA -> juju-password
463# SO -> route to Juju Controller, add RO account, add VCA account
464function configure(){
465 #Configure components
466 echo -e "\nConfiguring components"
467 configure_RO
468 configure_VCA
469 configure_SOUI
470}
471
472function install_lxd() {
473 sudo apt-get update
474 sudo apt-get install -y lxd
475 newgrp lxd
476 lxd init --auto
477 lxd waitready
478 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
479 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
480 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
481 lxc profile device set default eth0 mtu $DEFAULT_MTU
482 #sudo systemctl stop lxd-bridge
483 #sudo systemctl --system daemon-reload
484 #sudo systemctl enable lxd-bridge
485 #sudo systemctl start lxd-bridge
486}
487
488function ask_user(){
489 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
490 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
491 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
492 read -e -p "$1" USER_CONFIRMATION
493 while true ; do
494 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
495 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
496 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
497 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
498 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
499 done
500}
501
502function launch_container_from_lxd(){
503 export OSM_MDG=$1
504 OSM_load_config
505 export OSM_BASE_IMAGE=$2
506 if ! container_exists $OSM_BUILD_CONTAINER; then
507 CONTAINER_OPTS=""
508 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
509 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
510 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
511 wait_container_up $OSM_BUILD_CONTAINER
512 fi
513}
514
515function install_osmclient(){
516 CLIENT_RELEASE=${RELEASE#"-R "}
517 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
518 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
519 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
520 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
521 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
522 curl $key_location | sudo apt-key add -
523 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
524 sudo apt-get update
525 sudo apt-get install -y python-pip
526 sudo -H pip install pip==9.0.3
527 sudo -H pip install python-magic
528 sudo apt-get install -y python-osmclient
529 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
530 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
531 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
532 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
533 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200534 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200535 echo -e "\nOSM client installed"
536 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
537 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
538 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
539 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
540 return 0
541}
542
543function install_from_lxdimages(){
544 LXD_RELEASE=${RELEASE#"-R "}
545 if [ -n "$LXD_REPOSITORY_PATH" ]; then
546 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
547 else
548 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
549 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
550 fi
551 echo -e "\nDeleting previous lxd images if they exist"
552 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
553 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
554 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
555 echo -e "\nImporting osm-ro"
556 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
557 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
558 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
559 echo -e "\nImporting osm-vca"
560 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
561 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
562 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
563 echo -e "\nImporting osm-soui"
564 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
565 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
566 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
567 launch_container_from_lxd RO osm-ro
568 ro_is_up && track RO
569 launch_container_from_lxd VCA osm-vca
570 vca_is_up && track VCA
571 launch_container_from_lxd MON osm-mon
572 mon_is_up && track MON
573 launch_container_from_lxd SO osm-soui
574 #so_is_up && track SOUI
575 track SOUI
576}
577
578function install_docker_ce() {
579 # installs and configures Docker CE
580 echo "Installing Docker CE ..."
581 sudo apt-get -qq update
582 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
583 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
584 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
585 sudo apt-get -qq update
586 sudo apt-get install -y docker-ce
587 echo "Adding user to group 'docker'"
588 sudo groupadd -f docker
589 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200590 sleep 2
591 sudo service docker restart
592 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200593 sg docker -c "docker version" || FATAL "Docker installation failed"
594 echo "... Docker CE installation done"
595 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200596}
597
598function install_docker_compose() {
599 # installs and configures docker-compose
600 echo "Installing Docker Compose ..."
601 sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
602 sudo chmod +x /usr/local/bin/docker-compose
603 echo "... Docker Compose installation done"
604}
605
606function install_juju() {
607 echo "Installing juju"
608 sudo snap install juju --classic
garciadeblasd41f5482018-05-25 10:25:06 +0200609 [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
garciadeblasd8bc5c32018-05-09 17:37:56 +0200610 echo "Finished installation of juju"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400611 return 0
612}
613
614function juju_createcontroller() {
615 if ! sg lxd -c "juju show-controller $OSM_STACK_NAME &> /dev/null"; then
616 # Not found created, create the controller
617 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost $OSM_STACK_NAME"
618 fi
619 [ $(sg lxd -c "juju controllers" |grep "$OSM_STACK_NAME" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200620}
621
622function generate_docker_images() {
623 echo "Pulling and generating docker images"
Michael Marchettiee374142018-08-02 22:47:16 +0200624 _build_from=$COMMIT_ID
625 [ -z "$_build_from" ] && _build_from="master"
626
627 echo "OSM Docker images generated from $_build_from"
628
garciadeblas0e596bc2018-05-28 16:04:42 +0200629 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
630 sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
631 sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
632 fi
633 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then
634 sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image"
635 fi
636 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then
637 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
638 git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
639 sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
640 sg docker -c "docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm --no-cache" || FATAL "cannot build PM docker image"
641 fi
642 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then
643 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
644 git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
645 sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
646 fi
647 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then
648 sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image"
649 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
650 git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
651 sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
652 fi
653 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then
654 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
655 git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
656 sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
657 fi
658 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then
659 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
660 git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
661 sg docker -c "docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile --no-cache" || FATAL "cannot build LW-UI docker image"
662 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200663 echo "Finished generation of docker images"
664}
665
garciadeblas5b857d32018-05-24 18:37:58 +0200666function cmp_overwrite() {
667 file1="$1"
668 file2="$2"
669 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
670 if [ -f "${file2}" ]; then
Mike Marchetti67411aa2018-09-13 11:38:38 -0400671 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200672 else
Mike Marchetti67411aa2018-09-13 11:38:38 -0400673 cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200674 fi
675 fi
676}
677
garciadeblascf0e34a2018-05-24 10:45:53 +0200678function generate_config_log_folders() {
679 echo "Generating config and log folders"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400680 cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml
garciadeblascf0e34a2018-05-24 10:45:53 +0200681 echo "Finished generation of config and log folders"
682}
683
garciadeblasd8bc5c32018-05-09 17:37:56 +0200684function generate_docker_env_files() {
685 echo "Generating docker env files"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400686 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" | tee $OSM_DOCKER_WORK_DIR/lcm.env
687 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" | tee -a $OSM_DOCKER_WORK_DIR/lcm.env
688
garciadeblasd8bc5c32018-05-09 17:37:56 +0200689 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
Mike Marchetti67411aa2018-09-13 11:38:38 -0400690 if [ ! -f $OSM_DOCKER_WORK_DIR/ro-db.env ]; then
691 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro-db.env
garciadeblas5b857d32018-05-24 18:37:58 +0200692 fi
Mike Marchetti67411aa2018-09-13 11:38:38 -0400693 if [ ! -f $OSM_DOCKER_WORK_DIR/ro.env ]; then
694 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro.env
garciadeblas5b857d32018-05-24 18:37:58 +0200695 fi
Mike Marchetti67411aa2018-09-13 11:38:38 -0400696 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |tee $OSM_DOCKER_WORK_DIR/mon.env
garciadeblasd8bc5c32018-05-09 17:37:56 +0200697 echo "Finished generation of docker env files"
698}
699
garciadeblasa3e26612018-05-30 17:58:55 +0200700function init_docker_swarm() {
garciadeblasd8bc5c32018-05-09 17:37:56 +0200701 if [ "${DEFAULT_MTU}" != "1500" ]; then
702 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
703 DOCKER_GW_NET=`sg docker -c "docker network inspect ${DOCKER_NETS}" | grep Subnet | awk -F\" '{print $4}' | egrep "^172" | sort -u | tail -1 | awk -F\. '{if ($2 != 255) print $1"."$2+1"."$3"."$4; else print "-1";}'`
704 sg docker -c "docker network create --subnet ${DOCKER_GW_NET} --opt com.docker.network.bridge.name=docker_gwbridge --opt com.docker.network.bridge.enable_icc=false --opt com.docker.network.bridge.enable_ip_masquerade=true --opt com.docker.network.driver.mtu=${DEFAULT_MTU} docker_gwbridge"
705 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200706 sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
707 sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM"
garciadeblasa3e26612018-05-30 17:58:55 +0200708 return 0
709}
710
711function deploy_lightweight() {
712 echo "Deploying lightweight build"
713 [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
Mike Marchetti67411aa2018-09-13 11:38:38 -0400714 remove_stack $OSM_STACK_NAME
715
716 OSM_NBI_PORT=9999
717 OSM_RO_PORT=9090
718 OSM_UI_PORT=80
719
720 if [ -n "$NO_HOST_PORTS" ]; then
721 OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT)
722 OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT)
723 OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT)
724 else
725 OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT:$OSM_NBI_PORT)
726 OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT:$OSM_RO_PORT)
727 OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT:$OSM_UI_PORT)
728 fi
729 echo "export ${OSM_PORTS[@]}" > $OSM_DOCKER_WORK_DIR/osm_ports.sh
730
731 pushd $OSM_DOCKER_WORK_DIR > /dev/null
732 sg docker -c "source ./osm_ports.sh; docker stack deploy -c $OSM_DOCKER_WORK_DIR/docker-compose.yaml $OSM_STACK_NAME"
733 popd > /dev/null
734
garciadeblasd8bc5c32018-05-09 17:37:56 +0200735 echo "Finished deployment of lightweight build"
736}
737
garciadeblas6c66abf2018-05-16 14:46:19 +0200738function deploy_elk() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200739 echo "Pulling docker images for ELK"
740 sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
741 sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
742 sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
743 echo "Finished pulling elk docker images"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400744 mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk"
745 cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas5b857d32018-05-24 18:37:58 +0200746 remove_stack osm_elk
garciadeblas6c66abf2018-05-16 14:46:19 +0200747 echo "Deploying ELK stack"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400748 sg docker -c "docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_elk/docker-compose.yml osm_elk"
garciadeblas6c66abf2018-05-16 14:46:19 +0200749 echo "Waiting for ELK stack to be up and running"
750 time=0
garciadeblase2aebfe2018-07-06 14:11:20 +0200751 step=5
752 timelength=40
garciadeblas6c66abf2018-05-16 14:46:19 +0200753 elk_is_up=1
754 while [ $time -le $timelength ]; do
garciadeblase2aebfe2018-07-06 14:11:20 +0200755 if [[ $(curl -f -XGET http://127.0.0.1:5601/status -I 2>/dev/null | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
garciadeblas6c66abf2018-05-16 14:46:19 +0200756 elk_is_up=0
757 break
758 fi
759 sleep $step
760 time=$((time+step))
761 done
762 if [ $elk_is_up -eq 0 ]; then
763 echo "ELK is up and running. Trying to create index pattern..."
764 #Create index pattern
765 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200766 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200767 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200768 #Make it the default index
garciadeblase2aebfe2018-07-06 14:11:20 +0200769 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200770 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200771 -d"{\"value\":\"logstash-*\"}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200772 else
773 echo "Cannot connect to Kibana to create index pattern."
774 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
775 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200776 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200777 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
778 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200779 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200780 -d"{\"value\":\"logstash-*\"}"'
781 fi
782 echo "Finished deployment of ELK stack"
783 return 0
784}
785
786function deploy_perfmon() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200787 echo "Pulling docker images for PM (Grafana and Prometheus)"
788 sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
789 sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
790 echo "Finished pulling PM docker images"
garciadeblas6c66abf2018-05-16 14:46:19 +0200791 echo "Generating osm/kafka-exporter docker image"
garciadeblasc119fb32018-05-25 09:13:30 +0200792 sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter --no-cache" || FATAL "cannot build kafka-exporter docker image"
garciadeblas6c66abf2018-05-16 14:46:19 +0200793 echo "Finished generation of osm/kafka-exporter docker image"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400794 mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics
795 cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics
796 cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas5b857d32018-05-24 18:37:58 +0200797 remove_stack osm_metrics
garciadeblas6c66abf2018-05-16 14:46:19 +0200798 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400799 sg docker -c "docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_metrics/docker-compose.yml osm_metrics"
garciadeblas6c66abf2018-05-16 14:46:19 +0200800 echo "Finished deployment of PM stack"
801 return 0
802}
803
garciadeblasd8bc5c32018-05-09 17:37:56 +0200804function install_lightweight() {
Mike Marchetti67411aa2018-09-13 11:38:38 -0400805 [ -z "$OSM_DOCKER_WORK_DIR" ] && OSM_DOCKER_WORK_DIR="$HOME/.osm/stack/$OSM_STACK_NAME"
806 [ ! -d "$OSM_DOCKER_WORK_DIR" ] && mkdir -p $OSM_DOCKER_WORK_DIR
807
garciadeblasd13a8aa2018-05-18 15:24:51 +0200808 [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
garciadeblas0ebde162018-05-30 18:36:29 +0200809 [ -z "$ASSUME_YES" ] && ! ask_user "The installation will configure LXD, install juju, install docker CE and init a docker swarm, as pre-requirements. Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
garciadeblasfae5e972018-06-12 18:27:11 +0200810 track proceed
garciadeblasd8bc5c32018-05-09 17:37:56 +0200811 echo "Installing lightweight build of OSM"
812 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
813 trap 'rm -rf "${LWTEMPDIR}"' EXIT
814 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200815 [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200816 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200817 [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200818 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
Mike Marchetti67411aa2018-09-13 11:38:38 -0400819
820 # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to
821 if [ -z "$OSMLCM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ]; then
garciadeblasd41f5482018-05-25 10:25:06 +0200822 need_packages_lw="lxd"
823 echo -e "Checking required packages: $need_packages_lw"
824 dpkg -l $need_packages_lw &>/dev/null \
825 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
826 || sudo apt-get update \
827 || FATAL "failed to run apt-get update"
828 dpkg -l $need_packages_lw &>/dev/null \
829 || ! echo -e "Installing $need_packages_lw requires root privileges." \
830 || sudo apt-get install -y $need_packages_lw \
831 || FATAL "failed to install $need_packages_lw"
832 fi
garciadeblasfae5e972018-06-12 18:27:11 +0200833 track prereqok
Mike Marchetti67411aa2018-09-13 11:38:38 -0400834 [ -z "$INSTALL_NOJUJU" ] && install_juju
835
836 if [ -z "$OSMLCM_VCA_HOST" ]; then
837 juju_createcontroller
838 OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_STACK_NAME"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
839 [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
840 fi
841 if [ -z "$OSMLCM_VCA_SECRET" ]; then
842 OSMLCM_VCA_SECRET=$(parse_juju_password $OSM_STACK_NAME)
843 [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
844 fi
845
garciadeblas6c66abf2018-05-16 14:46:19 +0200846 track juju
garciadeblasa3e26612018-05-30 17:58:55 +0200847 [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200848 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200849 #install_docker_compose
Mike Marchetti67411aa2018-09-13 11:38:38 -0400850 [ -z "$DOCKER_NOBUILD" ] && generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200851 track docker_build
garciadeblasd8bc5c32018-05-09 17:37:56 +0200852 generate_docker_env_files
Mike Marchetti67411aa2018-09-13 11:38:38 -0400853 generate_config_log_folders
garciadeblasd8bc5c32018-05-09 17:37:56 +0200854 deploy_lightweight
garciadeblas6c66abf2018-05-16 14:46:19 +0200855 track docker_deploy
856 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
857 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
858 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
garciadeblasd8bc5c32018-05-09 17:37:56 +0200859 install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200860 track osmclient
861 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
862 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200863 return 0
864}
865
866function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200867 echo "\nInstalling vim-emu"
868 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
869 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200870 # clone vim-emu repository (attention: branch is currently master only)
871 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200872 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200873 # build vim-emu docker
874 echo "Building vim-emu Docker container..."
Mike Marchetti67411aa2018-09-13 11:38:38 -0400875
876 sg docker -c "docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile --no-cache $EMUTEMPDIR/" || FATAL "cannot build vim-emu-img docker image"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200877 # start vim-emu container as daemon
878 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200879 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
880 # in lightweight mode, the emulator needs to be attached to netOSM
Mike Marchetti67411aa2018-09-13 11:38:38 -0400881 sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py"
peusterm76353e42018-05-08 13:56:05 +0200882 else
883 # classic build mode
Mike Marchetti67411aa2018-09-13 11:38:38 -0400884 sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py"
peusterm76353e42018-05-08 13:56:05 +0200885 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200886 echo "Waiting for 'vim-emu' container to start ..."
887 sleep 5
Mike Marchetti67411aa2018-09-13 11:38:38 -0400888 export VIMEMU_HOSTNAME=$(sg docker -c "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200889 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200890 # print vim-emu connection info
891 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200892 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200893 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200894 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
895}
896
897function dump_vars(){
898 echo "DEVELOP=$DEVELOP"
899 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
900 echo "UNINSTALL=$UNINSTALL"
901 echo "NAT=$NAT"
902 echo "UPDATE=$UPDATE"
903 echo "RECONFIGURE=$RECONFIGURE"
904 echo "TEST_INSTALLER=$TEST_INSTALLER"
905 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
906 echo "INSTALL_LXD=$INSTALL_LXD"
907 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
908 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
909 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
910 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200911 echo "INSTALL_ONLY=$INSTALL_ONLY"
912 echo "INSTALL_ELK=$INSTALL_ELK"
913 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblas0e596bc2018-05-28 16:04:42 +0200914 echo "TO_REBUILD=$TO_REBUILD"
garciadeblasd41f5482018-05-25 10:25:06 +0200915 echo "INSTALL_NOLXD=$INSTALL_NOLXD"
garciadeblasa3e26612018-05-30 17:58:55 +0200916 echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200917 echo "RELEASE=$RELEASE"
918 echo "REPOSITORY=$REPOSITORY"
919 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
920 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
921 echo "NOCONFIGURE=$NOCONFIGURE"
922 echo "SHOWOPTS=$SHOWOPTS"
923 echo "Install from specific refspec (-b): $COMMIT_ID"
924}
925
926function track(){
927 ctime=`date +%s`
928 duration=$((ctime - SESSION_ID))
929 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
930 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
931 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200932 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
933 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
934 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200935 event_name="${event_name}_$1"
936 url="${url}&event=${event_name}&ce_duration=${duration}"
937 wget -q -O /dev/null $url
938}
939
940UNINSTALL=""
941DEVELOP=""
942NAT=""
943UPDATE=""
944RECONFIGURE=""
945TEST_INSTALLER=""
946INSTALL_LXD=""
947SHOWOPTS=""
948COMMIT_ID=""
949ASSUME_YES=""
950INSTALL_FROM_SOURCE=""
garciadeblasfb566272018-05-25 10:33:36 +0200951RELEASE="-R ReleaseFOUR"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200952REPOSITORY="-r stable"
953INSTALL_VIMEMU=""
954INSTALL_FROM_LXDIMAGES=""
955LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
956LXD_REPOSITORY_PATH=""
957INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200958INSTALL_ONLY=""
959INSTALL_ELK=""
960INSTALL_PERFMON=""
garciadeblas0e596bc2018-05-28 16:04:42 +0200961TO_REBUILD=""
garciadeblasd41f5482018-05-25 10:25:06 +0200962INSTALL_NOLXD=""
garciadeblasa3e26612018-05-30 17:58:55 +0200963INSTALL_NODOCKER=""
Mike Marchetti67411aa2018-09-13 11:38:38 -0400964INSTALL_NOJUJU=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200965NOCONFIGURE=""
966RELEASE_DAILY=""
967SESSION_ID=`date +%s`
968OSM_DEVOPS=
Mike Marchetti67411aa2018-09-13 11:38:38 -0400969OSMLCM_VCA_HOST=
970OSMLCM_VCA_SECRET=
971OSM_STACK_NAME=osm
972NO_HOST_PORTS=""
973DOCKER_NOBUILD=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200974
Mike Marchetti67411aa2018-09-13 11:38:38 -0400975while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +0200976 case "${o}" in
977 h)
978 usage && exit 0
979 ;;
980 b)
981 COMMIT_ID=${OPTARG}
982 ;;
983 r)
984 REPOSITORY="-r ${OPTARG}"
985 ;;
986 R)
987 RELEASE="-R ${OPTARG}"
988 ;;
989 k)
990 REPOSITORY_KEY="-k ${OPTARG}"
991 ;;
992 u)
993 REPOSITORY_BASE="-u ${OPTARG}"
994 ;;
995 l)
996 LXD_REPOSITORY_BASE="${OPTARG}"
997 ;;
998 p)
999 LXD_REPOSITORY_PATH="${OPTARG}"
1000 ;;
1001 D)
1002 OSM_DEVOPS="${OPTARG}"
1003 ;;
Mike Marchetti67411aa2018-09-13 11:38:38 -04001004 s)
1005 OSM_STACK_NAME="${OPTARG}"
1006 ;;
1007 H)
1008 OSMLCM_VCA_HOST="${OPTARG}"
1009 ;;
1010 S)
1011 OSMLCM_VCA_SECRET="${OPTARG}"
1012 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +02001013 o)
1014 INSTALL_ONLY="y"
1015 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
1016 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1017 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
1018 ;;
garciadeblas0e596bc2018-05-28 16:04:42 +02001019 m)
1020 [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
1021 [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
1022 [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
1023 [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue
1024 [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
1025 [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
1026 [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
1027 [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
1028 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +02001029 -)
1030 [ "${OPTARG}" == "help" ] && usage && exit 0
1031 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
1032 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
1033 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
1034 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
1035 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
1036 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
1037 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
1038 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblasd41f5482018-05-25 10:25:06 +02001039 [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
garciadeblasa3e26612018-05-30 17:58:55 +02001040 [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001041 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
1042 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblase990f662018-05-18 11:43:39 +02001043 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001044 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +02001045 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1046 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001047 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
1048 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
1049 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
Mike Marchetti67411aa2018-09-13 11:38:38 -04001050 [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue
1051 [ "${OPTARG}" == "nojuju" ] && INSTALL_NOJUJU="y" && continue
1052 [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001053 echo -e "Invalid option: '--$OPTARG'\n" >&2
1054 usage && exit 1
1055 ;;
1056 \?)
1057 echo -e "Invalid option: '-$OPTARG'\n" >&2
1058 usage && exit 1
1059 ;;
1060 y)
1061 ASSUME_YES="y"
1062 ;;
1063 *)
1064 usage && exit 1
1065 ;;
1066 esac
1067done
1068
garciadeblas6c66abf2018-05-16 14:46:19 +02001069[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
garciadeblase990f662018-05-18 11:43:39 +02001070[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
1071[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
garciadeblasfb566272018-05-25 10:33:36 +02001072[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
garciadeblasd41f5482018-05-25 10:25:06 +02001073[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
garciadeblasa3e26612018-05-30 17:58:55 +02001074[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
garciadeblas0e596bc2018-05-28 16:04:42 +02001075[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
1076[ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options"
garciadeblas6c66abf2018-05-16 14:46:19 +02001077
garciadeblasd8bc5c32018-05-09 17:37:56 +02001078if [ -n "$SHOWOPTS" ]; then
1079 dump_vars
1080 exit 0
1081fi
1082
1083[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
1084
1085# if develop, we force master
1086[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
1087
garciadeblasd8bc5c32018-05-09 17:37:56 +02001088need_packages="git jq wget curl tar"
1089echo -e "Checking required packages: $need_packages"
1090dpkg -l $need_packages &>/dev/null \
1091 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
1092 || sudo apt-get update \
1093 || FATAL "failed to run apt-get update"
1094dpkg -l $need_packages &>/dev/null \
1095 || ! echo -e "Installing $need_packages requires root privileges." \
1096 || sudo apt-get install -y $need_packages \
1097 || FATAL "failed to install $need_packages"
1098
1099if [ -z "$OSM_DEVOPS" ]; then
Michael Marchettiee374142018-08-02 22:47:16 +02001100 if [ -n "$TEST_INSTALLER" ]; then
1101 echo -e "\nUsing local devops repo for OSM installation"
1102 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
1103 else
1104 echo -e "\nCreating temporary dir for OSM installation"
1105 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
1106 trap 'rm -rf "$OSM_DEVOPS"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +02001107
Michael Marchettiee374142018-08-02 22:47:16 +02001108 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
garciadeblasd8bc5c32018-05-09 17:37:56 +02001109
Michael Marchettiee374142018-08-02 22:47:16 +02001110 if [ -z "$COMMIT_ID" ]; then
1111 echo -e "\nGuessing the current stable release"
1112 LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1`
1113 [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
1114
1115 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
1116 COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
1117 else
1118 echo -e "\nDEVOPS Using commit $COMMIT_ID"
1119 fi
1120 git -C $OSM_DEVOPS checkout $COMMIT_ID
garciadeblasd8bc5c32018-05-09 17:37:56 +02001121 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +02001122fi
1123
1124OSM_JENKINS="$OSM_DEVOPS/jenkins"
1125. $OSM_JENKINS/common/all_funcs
1126
1127[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
1128[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
1129[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
1130[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
1131[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +02001132[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
1133[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
1134[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
1135[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +02001136
1137#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +02001138wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
1139track start
1140
garciadeblasd8bc5c32018-05-09 17:37:56 +02001141[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
1142echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
1143if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
1144 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
1145fi
1146
1147echo -e "Checking required packages: lxd"
1148lxd --version &>/dev/null || FATAL "lxd not present, exiting."
1149[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
1150
garciadeblasd8bc5c32018-05-09 17:37:56 +02001151# use local devops for containers
1152export OSM_USE_LOCAL_DEVOPS=true
1153if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
1154 echo -e "\nCreating the containers and building from source ..."
1155 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
1156 ro_is_up && track RO
1157 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
1158 vca_is_up && track VCA
1159 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
1160 mon_is_up && track MON
1161 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
1162 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
1163 #so_is_up && track SOUI
1164 track SOUI
1165elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
1166 echo -e "\nInstalling from lxd images ..."
1167 install_from_lxdimages
1168else #install from binaries
1169 echo -e "\nCreating the containers and installing from binaries ..."
1170 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
1171 ro_is_up && track RO
1172 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
1173 vca_is_up && track VCA
1174 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
1175 mon_is_up && track MON
1176 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
1177 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
1178 #so_is_up && track SOUI
1179 track SOUI
1180fi
1181
1182#Install iptables-persistent and configure NAT rules
1183[ -z "$NOCONFIGURE" ] && nat
1184
1185#Configure components
1186[ -z "$NOCONFIGURE" ] && configure
1187
1188#Install osmclient
1189[ -z "$NOCONFIGURE" ] && install_osmclient
1190
1191#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +02001192[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +02001193
1194wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
1195track end
1196echo -e "\nDONE"
1197