blob: a92e1ba74449ee154c1939807510701ac6347c3e [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 " ..."
garciadeblas6c66abf2018-05-16 14:46:19 +020029 echo -e " --vimemu: additionally deploy the VIM emulator as a docker container"
30 echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging"
31 echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
garciadeblas0e596bc2018-05-28 16:04:42 +020032 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 +020033 echo -e " -o <ADDON>: ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)"
garciadeblase990f662018-05-18 11:43:39 +020034 echo -e " -D <devops path> use local devops installation path"
garciadeblasd41f5482018-05-25 10:25:06 +020035 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 +020036 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
garciadeblase990f662018-05-18 11:43:39 +020037 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
38 echo -e " --source: install OSM from source code using the latest stable tag"
garciadeblasd8bc5c32018-05-09 17:37:56 +020039 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
garciadeblasd41f5482018-05-25 10:25:06 +020040 echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
41 echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch"
42 echo -e " -l <lxd_repo>: (only for Rel THREE with --soui) use specified repository url for lxd images"
43 echo -e " -p <path>: (only for Rel THREE with --soui) use specified repository path for lxd images"
garciadeblasd8bc5c32018-05-09 17:37:56 +020044# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
garciadeblasd41f5482018-05-25 10:25:06 +020045 echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules"
46 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 +020047# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
48 echo -e " --showopts: print chosen options and exit (only for debugging)"
49 echo -e " -y: do not prompt for confirmation, assumes yes"
garciadeblasd8bc5c32018-05-09 17:37:56 +020050 echo -e " -h / --help: print this help"
51}
52
53#Uninstall OSM: remove containers
54function uninstall(){
55 echo -e "\nUninstalling OSM"
56 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
57 $OSM_DEVOPS/jenkins/host/clean_container RO
58 $OSM_DEVOPS/jenkins/host/clean_container VCA
59 $OSM_DEVOPS/jenkins/host/clean_container MON
60 $OSM_DEVOPS/jenkins/host/clean_container SO
61 #$OSM_DEVOPS/jenkins/host/clean_container UI
62 else
63 lxc stop RO && lxc delete RO
64 lxc stop VCA && lxc delete VCA
65 lxc stop MON && lxc delete MON
66 lxc stop SO-ub && lxc delete SO-ub
67 fi
68 echo -e "\nDeleting imported lxd images if they exist"
69 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
70 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
71 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
72 return 0
73}
74
garciadeblas5b857d32018-05-24 18:37:58 +020075function remove_stack() {
76 stack=$1
garciadeblas5ef98212018-05-28 09:25:36 +020077 if sg docker -c "docker stack ps ${stack}" ; then
garciadeblas5b857d32018-05-24 18:37:58 +020078 echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
79 COUNTER=0
80 result=1
81 while [ ${COUNTER} -lt 30 ]; do
82 result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
83 #echo "Dockers running: $result"
84 if [ "${result}" == "0" ]; then
85 break
86 fi
87 let COUNTER=COUNTER+1
88 sleep 1
89 done
garciadeblasd8bc5c32018-05-09 17:37:56 +020090 if [ "${result}" == "0" ]; then
garciadeblas5b857d32018-05-24 18:37:58 +020091 echo "All dockers of the stack ${stack} were removed"
92 else
93 FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
garciadeblasd8bc5c32018-05-09 17:37:56 +020094 fi
garciadeblas5b857d32018-05-24 18:37:58 +020095 sleep 5
garciadeblasd8bc5c32018-05-09 17:37:56 +020096 fi
garciadeblas5b857d32018-05-24 18:37:58 +020097}
98
99#Uninstall lightweight OSM: remove dockers
100function uninstall_lightweight() {
garciadeblas282ff4e2018-07-10 09:16:30 +0200101 if [ -n "$INSTALL_ONLY" ]; then
102 if [ -n "$INSTALL_ELK" ]; then
103 echo -e "\nUninstalling OSM ELK stack"
104 remove_stack osm_elk
105 sudo rm -rf /etc/osm/docker/osm_elk
106 fi
107 if [ -n "$INSTALL_PERFMON" ]; then
108 echo -e "\nUninstalling OSM Performance Monitoring stack"
109 remove_stack osm_metrics
110 sg docker -c "docker image rm osm/kafka-exporter"
111 sudo rm -rf /etc/osm/docker/osm_metrics
112 fi
113 else
114 echo -e "\nUninstalling OSM"
115 remove_stack osm
116 remove_stack osm_elk
117 remove_stack osm_metrics
118 echo "Now osm docker images and volumes will be deleted"
119 newgrp docker << EONG
120 docker image rm osm/ro
121 docker image rm osm/lcm
122 docker image rm osm/light-ui
123 docker image rm osm/nbi
124 docker image rm osm/mon
125 docker image rm osm/pm
126 docker image rm osm/kafka-exporter
127 docker volume rm osm_mon_db
128 docker volume rm osm_mongo_db
129 docker volume rm osm_osm_packages
130 docker volume rm osm_ro_db
garciadeblas83ca1322018-05-22 18:31:14 +0200131EONG
garciadeblas282ff4e2018-07-10 09:16:30 +0200132 echo "Removing /etc/osm and /var/log/osm files"
133 sudo rm -rf /etc/osm
134 sudo rm -rf /var/log/osm
135 fi
136 echo "Some docker images will be kept in case they are used by other docker stacks"
137 echo "To remove them, just run 'docker image prune' in a terminal"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200138 return 0
139}
140
141#Configure NAT rules, based on the current IP addresses of containers
142function nat(){
143 echo -e "\nChecking required packages: iptables-persistent"
144 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
145 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
146 echo -e "\nConfiguring NAT rules"
147 echo -e " Required root privileges"
148 sudo $OSM_DEVOPS/installers/nat_osm
149}
150
151function FATAL(){
152 echo "FATAL error: Cannot install OSM due to \"$1\""
153 exit 1
154}
155
156#Update RO, SO and UI:
157function update(){
158 echo -e "\nUpdating components"
159
160 echo -e " Updating RO"
161 CONTAINER="RO"
162 MDG="RO"
163 INSTALL_FOLDER="/opt/openmano"
164 echo -e " Fetching the repo"
165 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
166 BRANCH=""
167 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
168 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
169 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
170 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
171 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
172 # COMMIT_ID either was previously set with -b option, or is an empty string
173 CHECKOUT_ID=$COMMIT_ID
174 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
175 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
176 if [[ $CHECKOUT_ID == "tags/"* ]]; then
177 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
178 else
179 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
180 fi
181 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
182 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
183 echo " Nothing to be done."
184 else
185 echo " Update required."
186 lxc exec $CONTAINER -- service osm-ro stop
187 lxc exec $CONTAINER -- git -C /opt/openmano stash
188 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
189 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
190 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
191 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
192 lxc exec $CONTAINER -- service osm-ro start
193 fi
194 echo
195
196 echo -e " Updating SO and UI"
197 CONTAINER="SO-ub"
198 MDG="SO"
199 INSTALL_FOLDER="" # To be filled in
200 echo -e " Fetching the repo"
201 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
202 BRANCH=""
203 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
204 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
205 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
206 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
207 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
208 # COMMIT_ID either was previously set with -b option, or is an empty string
209 CHECKOUT_ID=$COMMIT_ID
210 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
211 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
212 if [[ $CHECKOUT_ID == "tags/"* ]]; then
213 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
214 else
215 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
216 fi
217 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
218 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
219 echo " Nothing to be done."
220 else
221 echo " Update required."
222 # Instructions to be added
223 # lxc exec SO-ub -- ...
224 fi
225 echo
226 echo -e "Updating MON Container"
227 CONTAINER="MON"
228 MDG="MON"
229 INSTALL_FOLDER="/root/MON"
230 echo -e " Fetching the repo"
231 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
232 BRANCH=""
233 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
234 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
235 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
236 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
237 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
238 # COMMIT_ID either was previously set with -b option, or is an empty string
239 CHECKOUT_ID=$COMMIT_ID
240 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
241 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
242 if [[ $CHECKOUT_ID == "tags/"* ]]; then
243 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
244 else
245 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
246 fi
247 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
248 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
249 echo " Nothing to be done."
250 else
251 echo " Update required."
252 fi
253 echo
254}
255
256function so_is_up() {
257 if [ -n "$1" ]; then
258 SO_IP=$1
259 else
260 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
261 fi
262 time=0
263 step=5
264 timelength=300
265 while [ $time -le $timelength ]
266 do
267 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
268 -H 'accept: application/vnd.yang.data+json' \
269 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
270 -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 ]]
271 then
272 echo "RW.Restconf running....SO is up"
273 return 0
274 fi
275
276 sleep $step
277 echo -n "."
278 time=$((time+step))
279 done
280
281 FATAL "OSM Failed to startup. SO failed to startup"
282}
283
284function vca_is_up() {
285 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
286 echo "VCA is up and running"
287 return 0
288 fi
289
290 FATAL "OSM Failed to startup. VCA failed to startup"
291}
292
293function mon_is_up() {
294 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
295 echo "MON is up and running"
296 return 0
297 fi
298
299 FATAL "OSM Failed to startup. MON failed to startup"
300}
301
302function ro_is_up() {
303 if [ -n "$1" ]; then
304 RO_IP=$1
305 else
306 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
307 fi
308 time=0
309 step=2
310 timelength=20
311 while [ $time -le $timelength ]; do
312 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
313 echo "RO is up and running"
314 return 0
315 fi
316 sleep $step
317 echo -n "."
318 time=$((time+step))
319 done
320
321 FATAL "OSM Failed to startup. RO failed to startup"
322}
323
324
325function configure_RO(){
326 . $OSM_DEVOPS/installers/export_ips
327 echo -e " Configuring RO"
328 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
329 lxc exec RO -- service osm-ro restart
330
331 ro_is_up
332
333 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
334 lxc exec RO -- openmano tenant-create osm > /dev/null
335 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
336 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
337 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
338}
339
340function configure_VCA(){
341 echo -e " Configuring VCA"
342 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
343 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
344}
345
346function configure_SOUI(){
347 . $OSM_DEVOPS/installers/export_ips
348 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
349 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
350
351 echo -e " Configuring MON"
352 #Information to be added about SO socket for logging
353
354 echo -e " Configuring SO"
355 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200356 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200357 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200358 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 +0200359 # make journaling persistent
360 lxc exec SO-ub -- mkdir -p /var/log/journal
361 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
362 lxc exec SO-ub -- systemctl restart systemd-journald
363
364 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
365
366 lxc exec SO-ub -- systemctl restart launchpad
367
368 so_is_up $SO_CONTAINER_IP
369
370 #delete existing config agent (could be there on reconfigure)
371 curl -k --request DELETE \
372 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
373 --header 'accept: application/vnd.yang.data+json' \
374 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
375 --header 'cache-control: no-cache' \
376 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
377
378 result=$(curl -k --request POST \
379 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
380 --header 'accept: application/vnd.yang.data+json' \
381 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
382 --header 'cache-control: no-cache' \
383 --header 'content-type: application/vnd.yang.data+json' \
384 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
385 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
386
387 #R1/R2 config line
388 #result=$(curl -k --request PUT \
389 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
390 # --header 'accept: application/vnd.yang.data+json' \
391 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
392 # --header 'cache-control: no-cache' \
393 # --header 'content-type: application/vnd.yang.data+json' \
394 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
395
396 result=$(curl -k --request PUT \
397 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
398 --header 'accept: application/vnd.yang.data+json' \
399 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
400 --header 'cache-control: no-cache' \
401 --header 'content-type: application/vnd.yang.data+json' \
402 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
403 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
404
405 result=$(curl -k --request PATCH \
406 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
407 --header 'accept: application/vnd.yang.data+json' \
408 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
409 --header 'cache-control: no-cache' \
410 --header 'content-type: application/vnd.yang.data+json' \
411 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
412 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
413
414 result=$(curl -k --request PATCH \
415 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
416 --header 'accept: application/vnd.yang.data+json' \
417 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
418 --header 'cache-control: no-cache' \
419 --header 'content-type: application/vnd.yang.data+json' \
420 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
421 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
422
423 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
424auto lo:1
425iface lo:1 inet static
426 address $DEFAULT_IP
427 netmask 255.255.255.255
428EOF
429 lxc exec SO-ub ifup lo:1
430}
431
432#Configure RO, VCA, and SO with the initial configuration:
433# RO -> tenant:osm, logs to be sent to SO
434# VCA -> juju-password
435# SO -> route to Juju Controller, add RO account, add VCA account
436function configure(){
437 #Configure components
438 echo -e "\nConfiguring components"
439 configure_RO
440 configure_VCA
441 configure_SOUI
442}
443
444function install_lxd() {
445 sudo apt-get update
446 sudo apt-get install -y lxd
447 newgrp lxd
448 lxd init --auto
449 lxd waitready
450 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
451 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
452 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
453 lxc profile device set default eth0 mtu $DEFAULT_MTU
454 #sudo systemctl stop lxd-bridge
455 #sudo systemctl --system daemon-reload
456 #sudo systemctl enable lxd-bridge
457 #sudo systemctl start lxd-bridge
458}
459
460function ask_user(){
461 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
462 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
463 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
464 read -e -p "$1" USER_CONFIRMATION
465 while true ; do
466 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
467 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
468 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
469 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
470 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
471 done
472}
473
474function launch_container_from_lxd(){
475 export OSM_MDG=$1
476 OSM_load_config
477 export OSM_BASE_IMAGE=$2
478 if ! container_exists $OSM_BUILD_CONTAINER; then
479 CONTAINER_OPTS=""
480 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
481 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
482 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
483 wait_container_up $OSM_BUILD_CONTAINER
484 fi
485}
486
487function install_osmclient(){
488 CLIENT_RELEASE=${RELEASE#"-R "}
489 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
490 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
491 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
492 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
493 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
494 curl $key_location | sudo apt-key add -
495 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
496 sudo apt-get update
497 sudo apt-get install -y python-pip
498 sudo -H pip install pip==9.0.3
499 sudo -H pip install python-magic
500 sudo apt-get install -y python-osmclient
501 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
502 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
503 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
504 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
505 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200506 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200507 echo -e "\nOSM client installed"
508 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
509 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
510 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
511 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
512 return 0
513}
514
515function install_from_lxdimages(){
516 LXD_RELEASE=${RELEASE#"-R "}
517 if [ -n "$LXD_REPOSITORY_PATH" ]; then
518 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
519 else
520 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
521 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
522 fi
523 echo -e "\nDeleting previous lxd images if they exist"
524 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
525 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
526 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
527 echo -e "\nImporting osm-ro"
528 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
529 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
530 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
531 echo -e "\nImporting osm-vca"
532 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
533 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
534 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
535 echo -e "\nImporting osm-soui"
536 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
537 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
538 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
539 launch_container_from_lxd RO osm-ro
540 ro_is_up && track RO
541 launch_container_from_lxd VCA osm-vca
542 vca_is_up && track VCA
543 launch_container_from_lxd MON osm-mon
544 mon_is_up && track MON
545 launch_container_from_lxd SO osm-soui
546 #so_is_up && track SOUI
547 track SOUI
548}
549
550function install_docker_ce() {
551 # installs and configures Docker CE
552 echo "Installing Docker CE ..."
553 sudo apt-get -qq update
554 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
555 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
556 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
557 sudo apt-get -qq update
558 sudo apt-get install -y docker-ce
559 echo "Adding user to group 'docker'"
560 sudo groupadd -f docker
561 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200562 sleep 2
563 sudo service docker restart
564 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200565 sg docker -c "docker version" || FATAL "Docker installation failed"
566 echo "... Docker CE installation done"
567 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200568}
569
570function install_docker_compose() {
571 # installs and configures docker-compose
572 echo "Installing Docker Compose ..."
573 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
574 sudo chmod +x /usr/local/bin/docker-compose
575 echo "... Docker Compose installation done"
576}
577
578function install_juju() {
579 echo "Installing juju"
580 sudo snap install juju --classic
garciadeblasd41f5482018-05-25 10:25:06 +0200581 [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
garciadeblasa235be82018-05-18 15:37:28 +0200582 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost osm"
garciadeblasf79d1632018-05-24 10:48:59 +0200583 [ $(sg lxd -c "juju status" |grep "osm" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200584 echo "Finished installation of juju"
585}
586
587function generate_docker_images() {
588 echo "Pulling and generating docker images"
Michael Marchettiee374142018-08-02 22:47:16 +0200589 _build_from=$COMMIT_ID
590 [ -z "$_build_from" ] && _build_from="master"
591
592 echo "OSM Docker images generated from $_build_from"
593
garciadeblas0e596bc2018-05-28 16:04:42 +0200594 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
595 sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
596 sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
597 fi
598 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then
599 sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image"
600 fi
601 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then
602 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
603 git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
604 sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
605 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"
606 fi
607 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then
608 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
609 git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
610 sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
611 fi
612 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then
613 sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image"
614 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
615 git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
616 sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
617 fi
618 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then
619 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
620 git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
621 sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
622 fi
623 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then
624 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
625 git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
626 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"
627 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200628 echo "Finished generation of docker images"
629}
630
garciadeblas5b857d32018-05-24 18:37:58 +0200631function cmp_overwrite() {
632 file1="$1"
633 file2="$2"
634 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
635 if [ -f "${file2}" ]; then
garciadeblas70502ad2018-05-25 12:15:12 +0200636 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && sudo cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200637 else
garciadeblas70502ad2018-05-25 12:15:12 +0200638 sudo cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200639 fi
640 fi
641}
642
garciadeblascf0e34a2018-05-24 10:45:53 +0200643function generate_config_log_folders() {
644 echo "Generating config and log folders"
garciadeblas5b857d32018-05-24 18:37:58 +0200645 sudo mkdir -p /etc/osm/docker
garciadeblas5ef98212018-05-28 09:25:36 +0200646 sudo cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml /etc/osm/docker/docker-compose.yaml
garciadeblascf0e34a2018-05-24 10:45:53 +0200647 sudo mkdir -p /var/log/osm
648 echo "Finished generation of config and log folders"
649}
650
garciadeblasd8bc5c32018-05-09 17:37:56 +0200651function generate_docker_env_files() {
652 echo "Generating docker env files"
garciadeblas5b857d32018-05-24 18:37:58 +0200653 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee /etc/osm/docker/lcm.env
654 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a /etc/osm/docker/lcm.env
garciadeblasd8bc5c32018-05-09 17:37:56 +0200655 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
garciadeblas5b857d32018-05-24 18:37:58 +0200656 if [ ! -f /etc/osm/docker/ro-db.env ]; then
657 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro-db.env
658 fi
659 if [ ! -f /etc/osm/docker/ro.env ]; then
660 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro.env
661 fi
Mike Marchettiaa245142018-08-17 13:54:21 -0400662 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |tee /tmp/mon.env
663 cmp_overwrite /tmp/mon.env /etc/osm/docker/mon.env
garciadeblasd8bc5c32018-05-09 17:37:56 +0200664 echo "Finished generation of docker env files"
665}
666
garciadeblasa3e26612018-05-30 17:58:55 +0200667function init_docker_swarm() {
garciadeblasd8bc5c32018-05-09 17:37:56 +0200668 if [ "${DEFAULT_MTU}" != "1500" ]; then
669 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
670 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";}'`
671 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"
672 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200673 sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
674 sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM"
garciadeblasa3e26612018-05-30 17:58:55 +0200675 return 0
676}
677
678function deploy_lightweight() {
679 echo "Deploying lightweight build"
680 [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
garciadeblas5b857d32018-05-24 18:37:58 +0200681 remove_stack osm
682 sg docker -c "docker stack deploy -c /etc/osm/docker/docker-compose.yaml osm"
683 #docker-compose -f /etc/osm/docker/docker-compose.yaml up -d
garciadeblasd8bc5c32018-05-09 17:37:56 +0200684 echo "Finished deployment of lightweight build"
685}
686
garciadeblas6c66abf2018-05-16 14:46:19 +0200687function deploy_elk() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200688 echo "Pulling docker images for ELK"
689 sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
690 sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
691 sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
692 echo "Finished pulling elk docker images"
garciadeblas5b857d32018-05-24 18:37:58 +0200693 sudo mkdir -p /etc/osm/docker/osm_elk
garciadeblas5ef98212018-05-28 09:25:36 +0200694 sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* /etc/osm/docker/osm_elk
garciadeblas5b857d32018-05-24 18:37:58 +0200695 remove_stack osm_elk
garciadeblas6c66abf2018-05-16 14:46:19 +0200696 echo "Deploying ELK stack"
garciadeblas5b857d32018-05-24 18:37:58 +0200697 sg docker -c "docker stack deploy -c /etc/osm/docker/osm_elk/docker-compose.yml osm_elk"
garciadeblas6c66abf2018-05-16 14:46:19 +0200698 echo "Waiting for ELK stack to be up and running"
699 time=0
garciadeblase2aebfe2018-07-06 14:11:20 +0200700 step=5
701 timelength=40
garciadeblas6c66abf2018-05-16 14:46:19 +0200702 elk_is_up=1
703 while [ $time -le $timelength ]; do
garciadeblase2aebfe2018-07-06 14:11:20 +0200704 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 +0200705 elk_is_up=0
706 break
707 fi
708 sleep $step
709 time=$((time+step))
710 done
711 if [ $elk_is_up -eq 0 ]; then
712 echo "ELK is up and running. Trying to create index pattern..."
713 #Create index pattern
714 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200715 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200716 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200717 #Make it the default index
garciadeblase2aebfe2018-07-06 14:11:20 +0200718 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200719 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200720 -d"{\"value\":\"logstash-*\"}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200721 else
722 echo "Cannot connect to Kibana to create index pattern."
723 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
724 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200725 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200726 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
727 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200728 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200729 -d"{\"value\":\"logstash-*\"}"'
730 fi
731 echo "Finished deployment of ELK stack"
732 return 0
733}
734
735function deploy_perfmon() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200736 echo "Pulling docker images for PM (Grafana and Prometheus)"
737 sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
738 sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
739 echo "Finished pulling PM docker images"
garciadeblas6c66abf2018-05-16 14:46:19 +0200740 echo "Generating osm/kafka-exporter docker image"
garciadeblasc119fb32018-05-25 09:13:30 +0200741 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 +0200742 echo "Finished generation of osm/kafka-exporter docker image"
garciadeblas5b857d32018-05-24 18:37:58 +0200743 sudo mkdir -p /etc/osm/docker/osm_metrics
garciadeblas5ef98212018-05-28 09:25:36 +0200744 sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml /etc/osm/docker/osm_metrics
745 sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json /etc/osm/docker/osm_metrics
garciadeblas5b857d32018-05-24 18:37:58 +0200746 remove_stack osm_metrics
garciadeblas6c66abf2018-05-16 14:46:19 +0200747 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
garciadeblas5b857d32018-05-24 18:37:58 +0200748 sg docker -c "docker stack deploy -c /etc/osm/docker/osm_metrics/docker-compose.yml osm_metrics"
garciadeblas6c66abf2018-05-16 14:46:19 +0200749 echo "Finished deployment of PM stack"
750 return 0
751}
752
garciadeblasd8bc5c32018-05-09 17:37:56 +0200753function install_lightweight() {
garciadeblasd13a8aa2018-05-18 15:24:51 +0200754 [ "$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 +0200755 [ -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 +0200756 track proceed
garciadeblasd8bc5c32018-05-09 17:37:56 +0200757 echo "Installing lightweight build of OSM"
758 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
759 trap 'rm -rf "${LWTEMPDIR}"' EXIT
760 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200761 [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200762 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200763 [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200764 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
garciadeblasd41f5482018-05-25 10:25:06 +0200765 if [ -z "$INSTALL_NOLXD" ]; then
766 need_packages_lw="lxd"
767 echo -e "Checking required packages: $need_packages_lw"
768 dpkg -l $need_packages_lw &>/dev/null \
769 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
770 || sudo apt-get update \
771 || FATAL "failed to run apt-get update"
772 dpkg -l $need_packages_lw &>/dev/null \
773 || ! echo -e "Installing $need_packages_lw requires root privileges." \
774 || sudo apt-get install -y $need_packages_lw \
775 || FATAL "failed to install $need_packages_lw"
776 fi
garciadeblasfae5e972018-06-12 18:27:11 +0200777 track prereqok
garciadeblasd8bc5c32018-05-09 17:37:56 +0200778 install_juju
garciadeblas70502ad2018-05-25 12:15:12 +0200779 OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
780 OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
781 [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
782 [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
garciadeblas6c66abf2018-05-16 14:46:19 +0200783 track juju
garciadeblasa3e26612018-05-30 17:58:55 +0200784 [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200785 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200786 #install_docker_compose
787 generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200788 track docker_build
garciadeblas5ef98212018-05-28 09:25:36 +0200789 generate_config_log_folders
garciadeblasd8bc5c32018-05-09 17:37:56 +0200790 generate_docker_env_files
791 deploy_lightweight
garciadeblas6c66abf2018-05-16 14:46:19 +0200792 track docker_deploy
793 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
794 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
795 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
garciadeblasd8bc5c32018-05-09 17:37:56 +0200796 install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200797 track osmclient
798 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
799 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200800 return 0
801}
802
803function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200804 echo "\nInstalling vim-emu"
805 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
806 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200807 # clone vim-emu repository (attention: branch is currently master only)
808 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200809 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200810 # build vim-emu docker
811 echo "Building vim-emu Docker container..."
garciadeblasc119fb32018-05-25 09:13:30 +0200812 sudo 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 +0200813 # start vim-emu container as daemon
814 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200815 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
816 # in lightweight mode, the emulator needs to be attached to netOSM
Mike Marchetti00a22332018-06-14 15:06:21 -0400817 sudo 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 +0200818 else
819 # classic build mode
Mike Marchetti00a22332018-06-14 15:06:21 -0400820 sudo 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 +0200821 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200822 echo "Waiting for 'vim-emu' container to start ..."
823 sleep 5
824 export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
825 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200826 # print vim-emu connection info
827 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200828 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200829 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200830 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
831}
832
833function dump_vars(){
834 echo "DEVELOP=$DEVELOP"
835 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
836 echo "UNINSTALL=$UNINSTALL"
837 echo "NAT=$NAT"
838 echo "UPDATE=$UPDATE"
839 echo "RECONFIGURE=$RECONFIGURE"
840 echo "TEST_INSTALLER=$TEST_INSTALLER"
841 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
842 echo "INSTALL_LXD=$INSTALL_LXD"
843 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
844 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
845 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
846 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200847 echo "INSTALL_ONLY=$INSTALL_ONLY"
848 echo "INSTALL_ELK=$INSTALL_ELK"
849 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblas0e596bc2018-05-28 16:04:42 +0200850 echo "TO_REBUILD=$TO_REBUILD"
garciadeblasd41f5482018-05-25 10:25:06 +0200851 echo "INSTALL_NOLXD=$INSTALL_NOLXD"
garciadeblasa3e26612018-05-30 17:58:55 +0200852 echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200853 echo "RELEASE=$RELEASE"
854 echo "REPOSITORY=$REPOSITORY"
855 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
856 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
857 echo "NOCONFIGURE=$NOCONFIGURE"
858 echo "SHOWOPTS=$SHOWOPTS"
859 echo "Install from specific refspec (-b): $COMMIT_ID"
860}
861
862function track(){
863 ctime=`date +%s`
864 duration=$((ctime - SESSION_ID))
865 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
866 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
867 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200868 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
869 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
870 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200871 event_name="${event_name}_$1"
872 url="${url}&event=${event_name}&ce_duration=${duration}"
873 wget -q -O /dev/null $url
874}
875
876UNINSTALL=""
877DEVELOP=""
878NAT=""
879UPDATE=""
880RECONFIGURE=""
881TEST_INSTALLER=""
882INSTALL_LXD=""
883SHOWOPTS=""
884COMMIT_ID=""
885ASSUME_YES=""
886INSTALL_FROM_SOURCE=""
garciadeblasfb566272018-05-25 10:33:36 +0200887RELEASE="-R ReleaseFOUR"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200888REPOSITORY="-r stable"
889INSTALL_VIMEMU=""
890INSTALL_FROM_LXDIMAGES=""
891LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
892LXD_REPOSITORY_PATH=""
893INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200894INSTALL_ONLY=""
895INSTALL_ELK=""
896INSTALL_PERFMON=""
garciadeblas0e596bc2018-05-28 16:04:42 +0200897TO_REBUILD=""
garciadeblasd41f5482018-05-25 10:25:06 +0200898INSTALL_NOLXD=""
garciadeblasa3e26612018-05-30 17:58:55 +0200899INSTALL_NODOCKER=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200900NOCONFIGURE=""
901RELEASE_DAILY=""
902SESSION_ID=`date +%s`
903OSM_DEVOPS=
904
garciadeblas0e596bc2018-05-28 16:04:42 +0200905while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +0200906 case "${o}" in
907 h)
908 usage && exit 0
909 ;;
910 b)
911 COMMIT_ID=${OPTARG}
912 ;;
913 r)
914 REPOSITORY="-r ${OPTARG}"
915 ;;
916 R)
917 RELEASE="-R ${OPTARG}"
918 ;;
919 k)
920 REPOSITORY_KEY="-k ${OPTARG}"
921 ;;
922 u)
923 REPOSITORY_BASE="-u ${OPTARG}"
924 ;;
925 l)
926 LXD_REPOSITORY_BASE="${OPTARG}"
927 ;;
928 p)
929 LXD_REPOSITORY_PATH="${OPTARG}"
930 ;;
931 D)
932 OSM_DEVOPS="${OPTARG}"
933 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +0200934 o)
935 INSTALL_ONLY="y"
936 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
937 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
938 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
939 ;;
garciadeblas0e596bc2018-05-28 16:04:42 +0200940 m)
941 [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
942 [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
943 [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
944 [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue
945 [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
946 [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
947 [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
948 [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
949 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200950 -)
951 [ "${OPTARG}" == "help" ] && usage && exit 0
952 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
953 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
954 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
955 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
956 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
957 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
958 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
959 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblasd41f5482018-05-25 10:25:06 +0200960 [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
garciadeblasa3e26612018-05-30 17:58:55 +0200961 [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200962 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
963 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblase990f662018-05-18 11:43:39 +0200964 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200965 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +0200966 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
967 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200968 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
969 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
970 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
971 echo -e "Invalid option: '--$OPTARG'\n" >&2
972 usage && exit 1
973 ;;
974 \?)
975 echo -e "Invalid option: '-$OPTARG'\n" >&2
976 usage && exit 1
977 ;;
978 y)
979 ASSUME_YES="y"
980 ;;
981 *)
982 usage && exit 1
983 ;;
984 esac
985done
986
garciadeblas6c66abf2018-05-16 14:46:19 +0200987[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
garciadeblase990f662018-05-18 11:43:39 +0200988[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
989[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
garciadeblasfb566272018-05-25 10:33:36 +0200990[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
garciadeblasd41f5482018-05-25 10:25:06 +0200991[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
garciadeblasa3e26612018-05-30 17:58:55 +0200992[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
garciadeblas0e596bc2018-05-28 16:04:42 +0200993[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
994[ -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 +0200995
garciadeblasd8bc5c32018-05-09 17:37:56 +0200996if [ -n "$SHOWOPTS" ]; then
997 dump_vars
998 exit 0
999fi
1000
1001[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
1002
1003# if develop, we force master
1004[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
1005
garciadeblasd8bc5c32018-05-09 17:37:56 +02001006need_packages="git jq wget curl tar"
1007echo -e "Checking required packages: $need_packages"
1008dpkg -l $need_packages &>/dev/null \
1009 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
1010 || sudo apt-get update \
1011 || FATAL "failed to run apt-get update"
1012dpkg -l $need_packages &>/dev/null \
1013 || ! echo -e "Installing $need_packages requires root privileges." \
1014 || sudo apt-get install -y $need_packages \
1015 || FATAL "failed to install $need_packages"
1016
1017if [ -z "$OSM_DEVOPS" ]; then
Michael Marchettiee374142018-08-02 22:47:16 +02001018 if [ -n "$TEST_INSTALLER" ]; then
1019 echo -e "\nUsing local devops repo for OSM installation"
1020 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
1021 else
1022 echo -e "\nCreating temporary dir for OSM installation"
1023 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
1024 trap 'rm -rf "$OSM_DEVOPS"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +02001025
Michael Marchettiee374142018-08-02 22:47:16 +02001026 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
garciadeblasd8bc5c32018-05-09 17:37:56 +02001027
Michael Marchettiee374142018-08-02 22:47:16 +02001028 if [ -z "$COMMIT_ID" ]; then
1029 echo -e "\nGuessing the current stable release"
1030 LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1`
1031 [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
1032
1033 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
1034 COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
1035 else
1036 echo -e "\nDEVOPS Using commit $COMMIT_ID"
1037 fi
1038 git -C $OSM_DEVOPS checkout $COMMIT_ID
garciadeblasd8bc5c32018-05-09 17:37:56 +02001039 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +02001040fi
1041
1042OSM_JENKINS="$OSM_DEVOPS/jenkins"
1043. $OSM_JENKINS/common/all_funcs
1044
1045[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
1046[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
1047[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
1048[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
1049[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +02001050[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
1051[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
1052[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
1053[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +02001054
1055#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +02001056wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
1057track start
1058
garciadeblasd8bc5c32018-05-09 17:37:56 +02001059[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
1060echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
1061if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
1062 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
1063fi
1064
1065echo -e "Checking required packages: lxd"
1066lxd --version &>/dev/null || FATAL "lxd not present, exiting."
1067[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
1068
garciadeblasd8bc5c32018-05-09 17:37:56 +02001069# use local devops for containers
1070export OSM_USE_LOCAL_DEVOPS=true
1071if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
1072 echo -e "\nCreating the containers and building from source ..."
1073 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
1074 ro_is_up && track RO
1075 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
1076 vca_is_up && track VCA
1077 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
1078 mon_is_up && track MON
1079 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
1080 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
1081 #so_is_up && track SOUI
1082 track SOUI
1083elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
1084 echo -e "\nInstalling from lxd images ..."
1085 install_from_lxdimages
1086else #install from binaries
1087 echo -e "\nCreating the containers and installing from binaries ..."
1088 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
1089 ro_is_up && track RO
1090 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
1091 vca_is_up && track VCA
1092 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
1093 mon_is_up && track MON
1094 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
1095 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
1096 #so_is_up && track SOUI
1097 track SOUI
1098fi
1099
1100#Install iptables-persistent and configure NAT rules
1101[ -z "$NOCONFIGURE" ] && nat
1102
1103#Configure components
1104[ -z "$NOCONFIGURE" ] && configure
1105
1106#Install osmclient
1107[ -z "$NOCONFIGURE" ] && install_osmclient
1108
1109#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +02001110[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +02001111
1112wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
1113track end
1114echo -e "\nDONE"
1115