blob: 0573759cf4e6ce438c17caf6c067300d583005ff [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)"
32 echo -e " -o <ADDON>: do not install OSM, but ONLY one of the addons (vimemu, elk_stack, pm_stack) (assumes OSM is already installed)"
garciadeblase990f662018-05-18 11:43:39 +020033 echo -e " -D <devops path> use local devops installation path"
garciadeblasd41f5482018-05-25 10:25:06 +020034 echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
garciadeblase990f662018-05-18 11:43:39 +020035 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
36 echo -e " --source: install OSM from source code using the latest stable tag"
garciadeblasd8bc5c32018-05-09 17:37:56 +020037 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
garciadeblasd41f5482018-05-25 10:25:06 +020038 echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
39 echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch"
40 echo -e " -l <lxd_repo>: (only for Rel THREE with --soui) use specified repository url for lxd images"
41 echo -e " -p <path>: (only for Rel THREE with --soui) use specified repository path for lxd images"
garciadeblasd8bc5c32018-05-09 17:37:56 +020042# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
garciadeblasd41f5482018-05-25 10:25:06 +020043 echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules"
44 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 +020045# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
46 echo -e " --showopts: print chosen options and exit (only for debugging)"
47 echo -e " -y: do not prompt for confirmation, assumes yes"
garciadeblasd8bc5c32018-05-09 17:37:56 +020048 echo -e " -h / --help: print this help"
49}
50
51#Uninstall OSM: remove containers
52function uninstall(){
53 echo -e "\nUninstalling OSM"
54 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
55 $OSM_DEVOPS/jenkins/host/clean_container RO
56 $OSM_DEVOPS/jenkins/host/clean_container VCA
57 $OSM_DEVOPS/jenkins/host/clean_container MON
58 $OSM_DEVOPS/jenkins/host/clean_container SO
59 #$OSM_DEVOPS/jenkins/host/clean_container UI
60 else
61 lxc stop RO && lxc delete RO
62 lxc stop VCA && lxc delete VCA
63 lxc stop MON && lxc delete MON
64 lxc stop SO-ub && lxc delete SO-ub
65 fi
66 echo -e "\nDeleting imported lxd images if they exist"
67 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
68 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
69 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
70 return 0
71}
72
garciadeblas5b857d32018-05-24 18:37:58 +020073function remove_stack() {
74 stack=$1
75 if $(sg docker -c "docker stack ps ${stack}"); then
76 echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
77 COUNTER=0
78 result=1
79 while [ ${COUNTER} -lt 30 ]; do
80 result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
81 #echo "Dockers running: $result"
82 if [ "${result}" == "0" ]; then
83 break
84 fi
85 let COUNTER=COUNTER+1
86 sleep 1
87 done
garciadeblasd8bc5c32018-05-09 17:37:56 +020088 if [ "${result}" == "0" ]; then
garciadeblas5b857d32018-05-24 18:37:58 +020089 echo "All dockers of the stack ${stack} were removed"
90 else
91 FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
garciadeblasd8bc5c32018-05-09 17:37:56 +020092 fi
garciadeblas5b857d32018-05-24 18:37:58 +020093 sleep 5
garciadeblasd8bc5c32018-05-09 17:37:56 +020094 fi
garciadeblas5b857d32018-05-24 18:37:58 +020095}
96
97#Uninstall lightweight OSM: remove dockers
98function uninstall_lightweight() {
99 echo -e "\nUninstalling lightweight OSM"
100 remove_stack osm
garciadeblas83ca1322018-05-22 18:31:14 +0200101 echo "Now osm docker images and volumes will be deleted"
102 newgrp docker << EONG
garciadeblasd8bc5c32018-05-09 17:37:56 +0200103 docker image rm osm/ro
104 docker image rm osm/lcm
105 docker image rm osm/light-ui
106 docker image rm osm/nbi
107 docker image rm osm/mon
108 docker image rm osm/pm
garciadeblas83ca1322018-05-22 18:31:14 +0200109 docker volume rm osm_mon_db
110 docker volume rm osm_mongo_db
111 docker volume rm osm_osm_packages
112 docker volume rm osm_ro_db
113EONG
garciadeblas70502ad2018-05-25 12:15:12 +0200114 echo "Removing /etc/osm and /var/log/osm files"
115 rm -rf /etc/osm
116 rm -rf /var/log/osm
garciadeblasd8bc5c32018-05-09 17:37:56 +0200117 return 0
118}
119
120#Configure NAT rules, based on the current IP addresses of containers
121function nat(){
122 echo -e "\nChecking required packages: iptables-persistent"
123 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
124 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
125 echo -e "\nConfiguring NAT rules"
126 echo -e " Required root privileges"
127 sudo $OSM_DEVOPS/installers/nat_osm
128}
129
130function FATAL(){
131 echo "FATAL error: Cannot install OSM due to \"$1\""
132 exit 1
133}
134
135#Update RO, SO and UI:
136function update(){
137 echo -e "\nUpdating components"
138
139 echo -e " Updating RO"
140 CONTAINER="RO"
141 MDG="RO"
142 INSTALL_FOLDER="/opt/openmano"
143 echo -e " Fetching the repo"
144 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
145 BRANCH=""
146 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
147 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
148 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
149 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
150 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
151 # COMMIT_ID either was previously set with -b option, or is an empty string
152 CHECKOUT_ID=$COMMIT_ID
153 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
154 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
155 if [[ $CHECKOUT_ID == "tags/"* ]]; then
156 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
157 else
158 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
159 fi
160 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
161 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
162 echo " Nothing to be done."
163 else
164 echo " Update required."
165 lxc exec $CONTAINER -- service osm-ro stop
166 lxc exec $CONTAINER -- git -C /opt/openmano stash
167 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
168 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
169 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
170 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
171 lxc exec $CONTAINER -- service osm-ro start
172 fi
173 echo
174
175 echo -e " Updating SO and UI"
176 CONTAINER="SO-ub"
177 MDG="SO"
178 INSTALL_FOLDER="" # To be filled in
179 echo -e " Fetching the repo"
180 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
181 BRANCH=""
182 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
183 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
184 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
185 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
186 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
187 # COMMIT_ID either was previously set with -b option, or is an empty string
188 CHECKOUT_ID=$COMMIT_ID
189 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
190 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
191 if [[ $CHECKOUT_ID == "tags/"* ]]; then
192 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
193 else
194 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
195 fi
196 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
197 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
198 echo " Nothing to be done."
199 else
200 echo " Update required."
201 # Instructions to be added
202 # lxc exec SO-ub -- ...
203 fi
204 echo
205 echo -e "Updating MON Container"
206 CONTAINER="MON"
207 MDG="MON"
208 INSTALL_FOLDER="/root/MON"
209 echo -e " Fetching the repo"
210 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
211 BRANCH=""
212 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
213 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
214 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
215 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
216 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
217 # COMMIT_ID either was previously set with -b option, or is an empty string
218 CHECKOUT_ID=$COMMIT_ID
219 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
220 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
221 if [[ $CHECKOUT_ID == "tags/"* ]]; then
222 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
223 else
224 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
225 fi
226 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
227 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
228 echo " Nothing to be done."
229 else
230 echo " Update required."
231 fi
232 echo
233}
234
235function so_is_up() {
236 if [ -n "$1" ]; then
237 SO_IP=$1
238 else
239 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
240 fi
241 time=0
242 step=5
243 timelength=300
244 while [ $time -le $timelength ]
245 do
246 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
247 -H 'accept: application/vnd.yang.data+json' \
248 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
249 -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 ]]
250 then
251 echo "RW.Restconf running....SO is up"
252 return 0
253 fi
254
255 sleep $step
256 echo -n "."
257 time=$((time+step))
258 done
259
260 FATAL "OSM Failed to startup. SO failed to startup"
261}
262
263function vca_is_up() {
264 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
265 echo "VCA is up and running"
266 return 0
267 fi
268
269 FATAL "OSM Failed to startup. VCA failed to startup"
270}
271
272function mon_is_up() {
273 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
274 echo "MON is up and running"
275 return 0
276 fi
277
278 FATAL "OSM Failed to startup. MON failed to startup"
279}
280
281function ro_is_up() {
282 if [ -n "$1" ]; then
283 RO_IP=$1
284 else
285 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
286 fi
287 time=0
288 step=2
289 timelength=20
290 while [ $time -le $timelength ]; do
291 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
292 echo "RO is up and running"
293 return 0
294 fi
295 sleep $step
296 echo -n "."
297 time=$((time+step))
298 done
299
300 FATAL "OSM Failed to startup. RO failed to startup"
301}
302
303
304function configure_RO(){
305 . $OSM_DEVOPS/installers/export_ips
306 echo -e " Configuring RO"
307 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
308 lxc exec RO -- service osm-ro restart
309
310 ro_is_up
311
312 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
313 lxc exec RO -- openmano tenant-create osm > /dev/null
314 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
315 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
316 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
317}
318
319function configure_VCA(){
320 echo -e " Configuring VCA"
321 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
322 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
323}
324
325function configure_SOUI(){
326 . $OSM_DEVOPS/installers/export_ips
327 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
328 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
329
330 echo -e " Configuring MON"
331 #Information to be added about SO socket for logging
332
333 echo -e " Configuring SO"
334 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200335 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200336 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200337 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 +0200338 # make journaling persistent
339 lxc exec SO-ub -- mkdir -p /var/log/journal
340 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
341 lxc exec SO-ub -- systemctl restart systemd-journald
342
343 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
344
345 lxc exec SO-ub -- systemctl restart launchpad
346
347 so_is_up $SO_CONTAINER_IP
348
349 #delete existing config agent (could be there on reconfigure)
350 curl -k --request DELETE \
351 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
352 --header 'accept: application/vnd.yang.data+json' \
353 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
354 --header 'cache-control: no-cache' \
355 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
356
357 result=$(curl -k --request POST \
358 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
359 --header 'accept: application/vnd.yang.data+json' \
360 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
361 --header 'cache-control: no-cache' \
362 --header 'content-type: application/vnd.yang.data+json' \
363 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
364 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
365
366 #R1/R2 config line
367 #result=$(curl -k --request PUT \
368 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
369 # --header 'accept: application/vnd.yang.data+json' \
370 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
371 # --header 'cache-control: no-cache' \
372 # --header 'content-type: application/vnd.yang.data+json' \
373 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
374
375 result=$(curl -k --request PUT \
376 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
377 --header 'accept: application/vnd.yang.data+json' \
378 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
379 --header 'cache-control: no-cache' \
380 --header 'content-type: application/vnd.yang.data+json' \
381 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
382 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
383
384 result=$(curl -k --request PATCH \
385 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
386 --header 'accept: application/vnd.yang.data+json' \
387 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
388 --header 'cache-control: no-cache' \
389 --header 'content-type: application/vnd.yang.data+json' \
390 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
391 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
392
393 result=$(curl -k --request PATCH \
394 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
395 --header 'accept: application/vnd.yang.data+json' \
396 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
397 --header 'cache-control: no-cache' \
398 --header 'content-type: application/vnd.yang.data+json' \
399 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
400 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
401
402 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
403auto lo:1
404iface lo:1 inet static
405 address $DEFAULT_IP
406 netmask 255.255.255.255
407EOF
408 lxc exec SO-ub ifup lo:1
409}
410
411#Configure RO, VCA, and SO with the initial configuration:
412# RO -> tenant:osm, logs to be sent to SO
413# VCA -> juju-password
414# SO -> route to Juju Controller, add RO account, add VCA account
415function configure(){
416 #Configure components
417 echo -e "\nConfiguring components"
418 configure_RO
419 configure_VCA
420 configure_SOUI
421}
422
423function install_lxd() {
424 sudo apt-get update
425 sudo apt-get install -y lxd
426 newgrp lxd
427 lxd init --auto
428 lxd waitready
429 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
430 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
431 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
432 lxc profile device set default eth0 mtu $DEFAULT_MTU
433 #sudo systemctl stop lxd-bridge
434 #sudo systemctl --system daemon-reload
435 #sudo systemctl enable lxd-bridge
436 #sudo systemctl start lxd-bridge
437}
438
439function ask_user(){
440 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
441 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
442 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
443 read -e -p "$1" USER_CONFIRMATION
444 while true ; do
445 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
446 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
447 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
448 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
449 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
450 done
451}
452
453function launch_container_from_lxd(){
454 export OSM_MDG=$1
455 OSM_load_config
456 export OSM_BASE_IMAGE=$2
457 if ! container_exists $OSM_BUILD_CONTAINER; then
458 CONTAINER_OPTS=""
459 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
460 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
461 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
462 wait_container_up $OSM_BUILD_CONTAINER
463 fi
464}
465
466function install_osmclient(){
467 CLIENT_RELEASE=${RELEASE#"-R "}
468 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
469 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
470 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
471 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
472 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
473 curl $key_location | sudo apt-key add -
474 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
475 sudo apt-get update
476 sudo apt-get install -y python-pip
477 sudo -H pip install pip==9.0.3
478 sudo -H pip install python-magic
479 sudo apt-get install -y python-osmclient
480 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
481 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
482 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
483 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
484 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200485 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200486 echo -e "\nOSM client installed"
487 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
488 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
489 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
490 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
491 return 0
492}
493
494function install_from_lxdimages(){
495 LXD_RELEASE=${RELEASE#"-R "}
496 if [ -n "$LXD_REPOSITORY_PATH" ]; then
497 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
498 else
499 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
500 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
501 fi
502 echo -e "\nDeleting previous lxd images if they exist"
503 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
504 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
505 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
506 echo -e "\nImporting osm-ro"
507 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
508 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
509 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
510 echo -e "\nImporting osm-vca"
511 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
512 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
513 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
514 echo -e "\nImporting osm-soui"
515 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
516 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
517 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
518 launch_container_from_lxd RO osm-ro
519 ro_is_up && track RO
520 launch_container_from_lxd VCA osm-vca
521 vca_is_up && track VCA
522 launch_container_from_lxd MON osm-mon
523 mon_is_up && track MON
524 launch_container_from_lxd SO osm-soui
525 #so_is_up && track SOUI
526 track SOUI
527}
528
529function install_docker_ce() {
530 # installs and configures Docker CE
531 echo "Installing Docker CE ..."
532 sudo apt-get -qq update
533 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
534 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
535 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
536 sudo apt-get -qq update
537 sudo apt-get install -y docker-ce
538 echo "Adding user to group 'docker'"
539 sudo groupadd -f docker
540 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200541 sleep 2
542 sudo service docker restart
543 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200544 sg docker -c "docker version" || FATAL "Docker installation failed"
545 echo "... Docker CE installation done"
546 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200547}
548
549function install_docker_compose() {
550 # installs and configures docker-compose
551 echo "Installing Docker Compose ..."
552 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
553 sudo chmod +x /usr/local/bin/docker-compose
554 echo "... Docker Compose installation done"
555}
556
557function install_juju() {
558 echo "Installing juju"
559 sudo snap install juju --classic
garciadeblasd41f5482018-05-25 10:25:06 +0200560 [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
garciadeblasa235be82018-05-18 15:37:28 +0200561 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost osm"
garciadeblasf79d1632018-05-24 10:48:59 +0200562 [ $(sg lxd -c "juju status" |grep "osm" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200563 echo "Finished installation of juju"
564}
565
566function generate_docker_images() {
567 echo "Pulling and generating docker images"
568 newgrp docker << EONG
569 docker pull wurstmeister/kafka
570 docker pull wurstmeister/zookeeper
571 docker pull mongo
572 docker pull mysql:5
garciadeblase990f662018-05-18 11:43:39 +0200573EONG
garciadeblasd8bc5c32018-05-09 17:37:56 +0200574 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
garciadeblase990f662018-05-18 11:43:39 +0200575 git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
576 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
577 git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
578 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
579 git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
580 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
581 git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
582 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
583 git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
garciadeblasc119fb32018-05-25 09:13:30 +0200584 sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
585 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"
586 sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
587 sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
588 sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
589 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"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200590 echo "Finished generation of docker images"
591}
592
garciadeblas5b857d32018-05-24 18:37:58 +0200593function cmp_overwrite() {
594 file1="$1"
595 file2="$2"
596 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
597 if [ -f "${file2}" ]; then
garciadeblas70502ad2018-05-25 12:15:12 +0200598 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && sudo cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200599 else
garciadeblas70502ad2018-05-25 12:15:12 +0200600 sudo cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200601 fi
602 fi
603}
604
garciadeblascf0e34a2018-05-24 10:45:53 +0200605function generate_config_log_folders() {
606 echo "Generating config and log folders"
garciadeblas5b857d32018-05-24 18:37:58 +0200607 sudo mkdir -p /etc/osm/docker
garciadeblas70502ad2018-05-25 12:15:12 +0200608 sudo cp -b ${DEVOPS}/installers/docker/docker-compose.yaml /etc/osm/docker/docker-compose.yaml
garciadeblascf0e34a2018-05-24 10:45:53 +0200609 sudo mkdir -p /var/log/osm
610 echo "Finished generation of config and log folders"
611}
612
garciadeblasd8bc5c32018-05-09 17:37:56 +0200613function generate_docker_env_files() {
614 echo "Generating docker env files"
garciadeblas5b857d32018-05-24 18:37:58 +0200615 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee /etc/osm/docker/lcm.env
616 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a /etc/osm/docker/lcm.env
garciadeblasd8bc5c32018-05-09 17:37:56 +0200617 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
garciadeblas5b857d32018-05-24 18:37:58 +0200618 if [ ! -f /etc/osm/docker/ro-db.env ]; then
619 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro-db.env
620 fi
621 if [ ! -f /etc/osm/docker/ro.env ]; then
622 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee /etc/osm/docker/ro.env
623 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200624 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env
garciadeblas5b857d32018-05-24 18:37:58 +0200625 cmp_overwrite ${DEVOPS}/installers/docker/mon.env /etc/osm/docker/mon.env
garciadeblasd8bc5c32018-05-09 17:37:56 +0200626 echo "Finished generation of docker env files"
627}
628
629function deploy_lightweight() {
630 echo "Deploying lightweight build"
631 if [ "${DEFAULT_MTU}" != "1500" ]; then
632 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
633 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";}'`
634 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"
635 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200636 sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
637 sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM"
638 remove_stack osm
639 sg docker -c "docker stack deploy -c /etc/osm/docker/docker-compose.yaml osm"
640 #docker-compose -f /etc/osm/docker/docker-compose.yaml up -d
garciadeblasd8bc5c32018-05-09 17:37:56 +0200641 echo "Finished deployment of lightweight build"
642}
643
garciadeblas6c66abf2018-05-16 14:46:19 +0200644function deploy_elk() {
garciadeblas5b857d32018-05-24 18:37:58 +0200645 sudo mkdir -p /etc/osm/docker/osm_elk
garciadeblas70502ad2018-05-25 12:15:12 +0200646 sudo cp -b ${DEVOPS}/installers/docker/osm_elk/* /etc/osm/docker/osm_elk
garciadeblas5b857d32018-05-24 18:37:58 +0200647 remove_stack osm_elk
garciadeblas6c66abf2018-05-16 14:46:19 +0200648 echo "Deploying ELK stack"
garciadeblas5b857d32018-05-24 18:37:58 +0200649 sg docker -c "docker stack deploy -c /etc/osm/docker/osm_elk/docker-compose.yml osm_elk"
garciadeblas6c66abf2018-05-16 14:46:19 +0200650 echo "Waiting for ELK stack to be up and running"
651 time=0
652 step=2
653 timelength=20
654 elk_is_up=1
655 while [ $time -le $timelength ]; do
garciadeblas5b857d32018-05-24 18:37:58 +0200656 if [[ $(curl -XGET http://127.0.0.1:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
garciadeblas6c66abf2018-05-16 14:46:19 +0200657 elk_is_up=0
658 break
659 fi
660 sleep $step
661 time=$((time+step))
662 done
663 if [ $elk_is_up -eq 0 ]; then
664 echo "ELK is up and running. Trying to create index pattern..."
665 #Create index pattern
666 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200667 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200668 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"
669 #Make it the default index
670 curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200671 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200672 -d"{\"value\":\"logstash-*\"}"
673 else
674 echo "Cannot connect to Kibana to create index pattern."
675 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
676 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200677 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200678 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
679 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200680 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200681 -d"{\"value\":\"logstash-*\"}"'
682 fi
683 echo "Finished deployment of ELK stack"
684 return 0
685}
686
687function deploy_perfmon() {
688 echo "Generating osm/kafka-exporter docker image"
garciadeblasc119fb32018-05-25 09:13:30 +0200689 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 +0200690 echo "Finished generation of osm/kafka-exporter docker image"
garciadeblas5b857d32018-05-24 18:37:58 +0200691 sudo mkdir -p /etc/osm/docker/osm_metrics
garciadeblas70502ad2018-05-25 12:15:12 +0200692 sudo cp -b ${DEVOPS}/installers/docker/osm_metrics/*.yml /etc/osm/docker/osm_metrics
693 sudo cp -b ${DEVOPS}/installers/docker/osm_metrics/*.json /etc/osm/docker/osm_metrics
garciadeblas5b857d32018-05-24 18:37:58 +0200694 remove_stack osm_metrics
garciadeblas6c66abf2018-05-16 14:46:19 +0200695 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
garciadeblas5b857d32018-05-24 18:37:58 +0200696 sg docker -c "docker stack deploy -c /etc/osm/docker/osm_metrics/docker-compose.yml osm_metrics"
garciadeblas6c66abf2018-05-16 14:46:19 +0200697 echo "Finished deployment of PM stack"
698 return 0
699}
700
garciadeblasd8bc5c32018-05-09 17:37:56 +0200701function install_lightweight() {
garciadeblasd13a8aa2018-05-18 15:24:51 +0200702 [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
garciadeblasd8bc5c32018-05-09 17:37:56 +0200703 echo "Installing lightweight build of OSM"
704 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
705 trap 'rm -rf "${LWTEMPDIR}"' EXIT
706 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
707 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
708 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
garciadeblasd41f5482018-05-25 10:25:06 +0200709 if [ -z "$INSTALL_NOLXD" ]; then
710 need_packages_lw="lxd"
711 echo -e "Checking required packages: $need_packages_lw"
712 dpkg -l $need_packages_lw &>/dev/null \
713 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
714 || sudo apt-get update \
715 || FATAL "failed to run apt-get update"
716 dpkg -l $need_packages_lw &>/dev/null \
717 || ! echo -e "Installing $need_packages_lw requires root privileges." \
718 || sudo apt-get install -y $need_packages_lw \
719 || FATAL "failed to install $need_packages_lw"
720 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200721 install_juju
garciadeblas70502ad2018-05-25 12:15:12 +0200722 OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
723 OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
724 [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
725 [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
garciadeblas6c66abf2018-05-16 14:46:19 +0200726 track juju
garciadeblasd8bc5c32018-05-09 17:37:56 +0200727 install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200728 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200729 #install_docker_compose
730 generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200731 track docker_build
garciadeblasd8bc5c32018-05-09 17:37:56 +0200732 generate_docker_env_files
733 deploy_lightweight
garciadeblas6c66abf2018-05-16 14:46:19 +0200734 track docker_deploy
735 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
736 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
737 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
garciadeblasd8bc5c32018-05-09 17:37:56 +0200738 install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200739 track osmclient
740 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
741 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200742 return 0
743}
744
745function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200746 echo "\nInstalling vim-emu"
747 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
748 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200749 # clone vim-emu repository (attention: branch is currently master only)
750 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200751 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200752 # build vim-emu docker
753 echo "Building vim-emu Docker container..."
garciadeblasc119fb32018-05-25 09:13:30 +0200754 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 +0200755 # start vim-emu container as daemon
756 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200757 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
758 # in lightweight mode, the emulator needs to be attached to netOSM
759 sudo docker run --name vim-emu -t -d --rm --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
760 else
761 # classic build mode
762 sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
763 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200764 echo "Waiting for 'vim-emu' container to start ..."
765 sleep 5
766 export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
767 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200768 # print vim-emu connection info
769 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200770 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200771 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200772 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
773}
774
775function dump_vars(){
776 echo "DEVELOP=$DEVELOP"
777 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
778 echo "UNINSTALL=$UNINSTALL"
779 echo "NAT=$NAT"
780 echo "UPDATE=$UPDATE"
781 echo "RECONFIGURE=$RECONFIGURE"
782 echo "TEST_INSTALLER=$TEST_INSTALLER"
783 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
784 echo "INSTALL_LXD=$INSTALL_LXD"
785 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
786 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
787 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
788 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200789 echo "INSTALL_ONLY=$INSTALL_ONLY"
790 echo "INSTALL_ELK=$INSTALL_ELK"
791 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblasd41f5482018-05-25 10:25:06 +0200792 echo "INSTALL_NOLXD=$INSTALL_NOLXD"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200793 echo "RELEASE=$RELEASE"
794 echo "REPOSITORY=$REPOSITORY"
795 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
796 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
797 echo "NOCONFIGURE=$NOCONFIGURE"
798 echo "SHOWOPTS=$SHOWOPTS"
799 echo "Install from specific refspec (-b): $COMMIT_ID"
800}
801
802function track(){
803 ctime=`date +%s`
804 duration=$((ctime - SESSION_ID))
805 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
806 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
807 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200808 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
809 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
810 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200811 event_name="${event_name}_$1"
812 url="${url}&event=${event_name}&ce_duration=${duration}"
813 wget -q -O /dev/null $url
814}
815
816UNINSTALL=""
817DEVELOP=""
818NAT=""
819UPDATE=""
820RECONFIGURE=""
821TEST_INSTALLER=""
822INSTALL_LXD=""
823SHOWOPTS=""
824COMMIT_ID=""
825ASSUME_YES=""
826INSTALL_FROM_SOURCE=""
garciadeblasfb566272018-05-25 10:33:36 +0200827RELEASE="-R ReleaseFOUR"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200828REPOSITORY="-r stable"
829INSTALL_VIMEMU=""
830INSTALL_FROM_LXDIMAGES=""
831LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
832LXD_REPOSITORY_PATH=""
833INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200834INSTALL_ONLY=""
835INSTALL_ELK=""
836INSTALL_PERFMON=""
garciadeblasd41f5482018-05-25 10:25:06 +0200837INSTALL_NOLXD=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200838NOCONFIGURE=""
839RELEASE_DAILY=""
840SESSION_ID=`date +%s`
841OSM_DEVOPS=
842
garciadeblas6c66abf2018-05-16 14:46:19 +0200843while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +0200844 case "${o}" in
845 h)
846 usage && exit 0
847 ;;
848 b)
849 COMMIT_ID=${OPTARG}
850 ;;
851 r)
852 REPOSITORY="-r ${OPTARG}"
853 ;;
854 R)
855 RELEASE="-R ${OPTARG}"
856 ;;
857 k)
858 REPOSITORY_KEY="-k ${OPTARG}"
859 ;;
860 u)
861 REPOSITORY_BASE="-u ${OPTARG}"
862 ;;
863 l)
864 LXD_REPOSITORY_BASE="${OPTARG}"
865 ;;
866 p)
867 LXD_REPOSITORY_PATH="${OPTARG}"
868 ;;
869 D)
870 OSM_DEVOPS="${OPTARG}"
871 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +0200872 o)
873 INSTALL_ONLY="y"
874 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
875 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
876 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
877 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200878 -)
879 [ "${OPTARG}" == "help" ] && usage && exit 0
880 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
881 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
882 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
883 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
884 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
885 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
886 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
887 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblasd41f5482018-05-25 10:25:06 +0200888 [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200889 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
890 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblase990f662018-05-18 11:43:39 +0200891 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200892 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +0200893 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
894 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200895 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
896 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
897 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
898 echo -e "Invalid option: '--$OPTARG'\n" >&2
899 usage && exit 1
900 ;;
901 \?)
902 echo -e "Invalid option: '-$OPTARG'\n" >&2
903 usage && exit 1
904 ;;
905 y)
906 ASSUME_YES="y"
907 ;;
908 *)
909 usage && exit 1
910 ;;
911 esac
912done
913
garciadeblas6c66abf2018-05-16 14:46:19 +0200914[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
garciadeblase990f662018-05-18 11:43:39 +0200915[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
916[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
garciadeblasfb566272018-05-25 10:33:36 +0200917[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
garciadeblasd41f5482018-05-25 10:25:06 +0200918[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
garciadeblas6c66abf2018-05-16 14:46:19 +0200919
garciadeblasd8bc5c32018-05-09 17:37:56 +0200920if [ -n "$SHOWOPTS" ]; then
921 dump_vars
922 exit 0
923fi
924
925[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
926
927# if develop, we force master
928[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
929
930# forcing source from master removed. Now only install from source when explicit
931# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
932
933if [ -z "$OSM_DEVOPS" ]; then
934 if [ -n "$TEST_INSTALLER" ]; then
935 echo -e "\nUsing local devops repo for OSM installation"
936 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
937 else
938 echo -e "\nCreating temporary dir for OSM installation"
939 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
940 trap 'rm -rf "$TEMPDIR"' EXIT
941 fi
942fi
943
944need_packages="git jq wget curl tar"
945echo -e "Checking required packages: $need_packages"
946dpkg -l $need_packages &>/dev/null \
947 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
948 || sudo apt-get update \
949 || FATAL "failed to run apt-get update"
950dpkg -l $need_packages &>/dev/null \
951 || ! echo -e "Installing $need_packages requires root privileges." \
952 || sudo apt-get install -y $need_packages \
953 || FATAL "failed to install $need_packages"
954
955if [ -z "$OSM_DEVOPS" ]; then
956 if [ -z "$TEST_INSTALLER" ]; then
957 echo -e "\nCloning devops repo temporarily"
958 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
959 RC_CLONE=$?
960 fi
961
962 echo -e "\nGuessing the current stable release"
963 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
964 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
965 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
966 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
967
968 if [ -n "$RELEASE_DAILY" ]; then
969 echo "Using master/HEAD devops"
970 git -C $TEMPDIR checkout master
971 elif [ -z "$TEST_INSTALLER" ]; then
972 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
973 fi
974 OSM_DEVOPS=$TEMPDIR
975fi
976
977OSM_JENKINS="$OSM_DEVOPS/jenkins"
978. $OSM_JENKINS/common/all_funcs
979
980[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
981[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
982[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
983[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
984[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +0200985[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
986[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
987[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
988[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200989
990#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +0200991wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
992track start
993
garciadeblasd8bc5c32018-05-09 17:37:56 +0200994[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
995echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
996if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
997 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
998fi
999
1000echo -e "Checking required packages: lxd"
1001lxd --version &>/dev/null || FATAL "lxd not present, exiting."
1002[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
1003
garciadeblasd8bc5c32018-05-09 17:37:56 +02001004# use local devops for containers
1005export OSM_USE_LOCAL_DEVOPS=true
1006if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
1007 echo -e "\nCreating the containers and building from source ..."
1008 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
1009 ro_is_up && track RO
1010 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
1011 vca_is_up && track VCA
1012 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
1013 mon_is_up && track MON
1014 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
1015 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
1016 #so_is_up && track SOUI
1017 track SOUI
1018elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
1019 echo -e "\nInstalling from lxd images ..."
1020 install_from_lxdimages
1021else #install from binaries
1022 echo -e "\nCreating the containers and installing from binaries ..."
1023 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
1024 ro_is_up && track RO
1025 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
1026 vca_is_up && track VCA
1027 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
1028 mon_is_up && track MON
1029 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
1030 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
1031 #so_is_up && track SOUI
1032 track SOUI
1033fi
1034
1035#Install iptables-persistent and configure NAT rules
1036[ -z "$NOCONFIGURE" ] && nat
1037
1038#Configure components
1039[ -z "$NOCONFIGURE" ] && configure
1040
1041#Install osmclient
1042[ -z "$NOCONFIGURE" ] && install_osmclient
1043
1044#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +02001045[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +02001046
1047wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
1048track end
1049echo -e "\nDONE"
1050