blob: f96bfae092f7916243f0d232b789218025655b05 [file] [log] [blame]
garciadeblasd8bc5c32018-05-09 17:37:56 +02001#!/bin/bash
2# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16function usage(){
17 echo -e "usage: $0 [OPTIONS]"
18 echo -e "Install OSM from binaries or source code (by default, from binaries)"
19 echo -e " OPTIONS"
garciadeblasd8bc5c32018-05-09 17:37:56 +020020 echo -e " -r <repo>: use specified repository name for osm packages"
21 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
22 echo -e " -u <repo base>: use specified repository url for osm packages"
23 echo -e " -k <repo key>: use specified repository public key url"
24 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
25 echo -e " -b master (main dev branch)"
26 echo -e " -b v2.0 (v2.0 branch)"
27 echo -e " -b tags/v1.1.0 (a specific tag)"
28 echo -e " ..."
Mike Marchettib8420852018-09-13 13:45:06 -040029 echo -e " -s <stack name> user defined stack name, default is osm"
30 echo -e " -H <VCA host> use specific juju host controller IP"
31 echo -e " -S <VCA secret> use VCA/juju secret key"
garciadeblas6c66abf2018-05-16 14:46:19 +020032 echo -e " --vimemu: additionally deploy the VIM emulator as a docker container"
33 echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging"
34 echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
garciadeblas0e596bc2018-05-28 16:04:42 +020035 echo -e " -m <MODULE>: install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)"
garciadeblas282ff4e2018-07-10 09:16:30 +020036 echo -e " -o <ADDON>: ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)"
garciadeblase990f662018-05-18 11:43:39 +020037 echo -e " -D <devops path> use local devops installation path"
Mike Marchettib8420852018-09-13 13:45:06 -040038 echo -e " -w <work dir> Location to store runtime installation"
Mike Marchetti13d76c82018-09-19 15:00:36 -040039 echo -e " -t <docker tag> specify osm docker tag (default is latest)"
garciadeblasd41f5482018-05-25 10:25:06 +020040 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 +020041 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
Mike Marchettib8420852018-09-13 13:45:06 -040042 echo -e " --nojuju: do not juju, assumes already installed"
43 echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)"
44 echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)"
45 echo -e " --nohostclient: do not install the osmclient"
garciadeblase990f662018-05-18 11:43:39 +020046 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
47 echo -e " --source: install OSM from source code using the latest stable tag"
garciadeblasd8bc5c32018-05-09 17:37:56 +020048 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
garciadeblasd41f5482018-05-25 10:25:06 +020049 echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
50 echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch"
51 echo -e " -l <lxd_repo>: (only for Rel THREE with --soui) use specified repository url for lxd images"
52 echo -e " -p <path>: (only for Rel THREE with --soui) use specified repository path for lxd images"
garciadeblasd8bc5c32018-05-09 17:37:56 +020053# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
garciadeblasd41f5482018-05-25 10:25:06 +020054 echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules"
55 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 +020056# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
57 echo -e " --showopts: print chosen options and exit (only for debugging)"
58 echo -e " -y: do not prompt for confirmation, assumes yes"
garciadeblasd8bc5c32018-05-09 17:37:56 +020059 echo -e " -h / --help: print this help"
60}
61
62#Uninstall OSM: remove containers
63function uninstall(){
64 echo -e "\nUninstalling OSM"
65 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
66 $OSM_DEVOPS/jenkins/host/clean_container RO
67 $OSM_DEVOPS/jenkins/host/clean_container VCA
68 $OSM_DEVOPS/jenkins/host/clean_container MON
69 $OSM_DEVOPS/jenkins/host/clean_container SO
70 #$OSM_DEVOPS/jenkins/host/clean_container UI
71 else
72 lxc stop RO && lxc delete RO
73 lxc stop VCA && lxc delete VCA
74 lxc stop MON && lxc delete MON
75 lxc stop SO-ub && lxc delete SO-ub
76 fi
77 echo -e "\nDeleting imported lxd images if they exist"
78 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
79 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
80 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
81 return 0
82}
83
Mike Marchettib8420852018-09-13 13:45:06 -040084# takes a juju/accounts.yaml file and returns the password specific
85# for a controller. I wrote this using only bash tools to minimize
86# additions of other packages
87function parse_juju_password {
88 password_file="${HOME}/.local/share/juju/accounts.yaml"
89 local controller_name=$1
90 local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
91 sed -ne "s|^\($s\):|\1|" \
92 -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
93 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
94 awk -F$fs -v controller=$controller_name '{
95 indent = length($1)/2;
96 vname[indent] = $2;
97 for (i in vname) {if (i > indent) {delete vname[i]}}
98 if (length($3) > 0) {
99 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
100 if (match(vn,controller) && match($2,"password")) {
101 printf("%s",$3);
102 }
103 }
104 }'
105}
106
107function remove_volumes() {
108 stack=$1
109 volumes="mongo_db mon_db osm_packages ro_db"
110 for volume in $volumes; do
111 sg docker -c "docker volume rm ${stack}_${volume}"
112 done
113}
114
115function remove_network() {
116 stack=$1
117 sg docker -c "docker network rm net${stack}"
118}
119
garciadeblas5b857d32018-05-24 18:37:58 +0200120function remove_stack() {
121 stack=$1
garciadeblas5ef98212018-05-28 09:25:36 +0200122 if sg docker -c "docker stack ps ${stack}" ; then
garciadeblas5b857d32018-05-24 18:37:58 +0200123 echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
124 COUNTER=0
125 result=1
126 while [ ${COUNTER} -lt 30 ]; do
127 result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
128 #echo "Dockers running: $result"
129 if [ "${result}" == "0" ]; then
130 break
131 fi
132 let COUNTER=COUNTER+1
133 sleep 1
134 done
garciadeblasd8bc5c32018-05-09 17:37:56 +0200135 if [ "${result}" == "0" ]; then
garciadeblas5b857d32018-05-24 18:37:58 +0200136 echo "All dockers of the stack ${stack} were removed"
137 else
138 FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
garciadeblasd8bc5c32018-05-09 17:37:56 +0200139 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200140 sleep 5
garciadeblasd8bc5c32018-05-09 17:37:56 +0200141 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200142}
143
144#Uninstall lightweight OSM: remove dockers
145function uninstall_lightweight() {
garciadeblas282ff4e2018-07-10 09:16:30 +0200146 if [ -n "$INSTALL_ONLY" ]; then
147 if [ -n "$INSTALL_ELK" ]; then
148 echo -e "\nUninstalling OSM ELK stack"
149 remove_stack osm_elk
Mike Marchettib8420852018-09-13 13:45:06 -0400150 $WORKDIR_SUDO rm -rf $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas282ff4e2018-07-10 09:16:30 +0200151 fi
152 if [ -n "$INSTALL_PERFMON" ]; then
153 echo -e "\nUninstalling OSM Performance Monitoring stack"
154 remove_stack osm_metrics
155 sg docker -c "docker image rm osm/kafka-exporter"
Mike Marchettib8420852018-09-13 13:45:06 -0400156 $WORKDIR_SUDO rm -rf $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas282ff4e2018-07-10 09:16:30 +0200157 fi
158 else
159 echo -e "\nUninstalling OSM"
Mike Marchettib8420852018-09-13 13:45:06 -0400160 remove_stack $OSM_STACK_NAME
garciadeblas282ff4e2018-07-10 09:16:30 +0200161 remove_stack osm_elk
162 remove_stack osm_metrics
163 echo "Now osm docker images and volumes will be deleted"
164 newgrp docker << EONG
165 docker image rm osm/ro
166 docker image rm osm/lcm
167 docker image rm osm/light-ui
168 docker image rm osm/nbi
169 docker image rm osm/mon
170 docker image rm osm/pm
171 docker image rm osm/kafka-exporter
garciadeblas83ca1322018-05-22 18:31:14 +0200172EONG
Mike Marchettib8420852018-09-13 13:45:06 -0400173 remove_volumes $OSM_STACK_NAME
174 remove_network $OSM_STACK_NAME
175 echo "Removing $OSM_DOCKER_WORK_DIR"
176 $WORKDIR_SUDO rm -rf $OSM_DOCKER_WORK_DIR
177 sg lxd -c "juju destroy-controller --yes $OSM_STACK_NAME"
garciadeblas282ff4e2018-07-10 09:16:30 +0200178 fi
179 echo "Some docker images will be kept in case they are used by other docker stacks"
180 echo "To remove them, just run 'docker image prune' in a terminal"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200181 return 0
182}
183
184#Configure NAT rules, based on the current IP addresses of containers
185function nat(){
186 echo -e "\nChecking required packages: iptables-persistent"
187 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
188 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
189 echo -e "\nConfiguring NAT rules"
190 echo -e " Required root privileges"
191 sudo $OSM_DEVOPS/installers/nat_osm
192}
193
194function FATAL(){
195 echo "FATAL error: Cannot install OSM due to \"$1\""
196 exit 1
197}
198
199#Update RO, SO and UI:
200function update(){
201 echo -e "\nUpdating components"
202
203 echo -e " Updating RO"
204 CONTAINER="RO"
205 MDG="RO"
206 INSTALL_FOLDER="/opt/openmano"
207 echo -e " Fetching the repo"
208 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
209 BRANCH=""
210 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
211 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
212 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
213 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
214 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
215 # COMMIT_ID either was previously set with -b option, or is an empty string
216 CHECKOUT_ID=$COMMIT_ID
217 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
218 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
219 if [[ $CHECKOUT_ID == "tags/"* ]]; then
220 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
221 else
222 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
223 fi
224 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
225 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
226 echo " Nothing to be done."
227 else
228 echo " Update required."
229 lxc exec $CONTAINER -- service osm-ro stop
230 lxc exec $CONTAINER -- git -C /opt/openmano stash
231 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
232 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
233 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
234 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
235 lxc exec $CONTAINER -- service osm-ro start
236 fi
237 echo
238
239 echo -e " Updating SO and UI"
240 CONTAINER="SO-ub"
241 MDG="SO"
242 INSTALL_FOLDER="" # To be filled in
243 echo -e " Fetching the repo"
244 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
245 BRANCH=""
246 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
247 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
248 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
249 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
250 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
251 # COMMIT_ID either was previously set with -b option, or is an empty string
252 CHECKOUT_ID=$COMMIT_ID
253 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
254 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
255 if [[ $CHECKOUT_ID == "tags/"* ]]; then
256 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
257 else
258 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
259 fi
260 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
261 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
262 echo " Nothing to be done."
263 else
264 echo " Update required."
265 # Instructions to be added
266 # lxc exec SO-ub -- ...
267 fi
268 echo
269 echo -e "Updating MON Container"
270 CONTAINER="MON"
271 MDG="MON"
272 INSTALL_FOLDER="/root/MON"
273 echo -e " Fetching the repo"
274 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
275 BRANCH=""
276 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
277 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
278 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
279 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
280 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
281 # COMMIT_ID either was previously set with -b option, or is an empty string
282 CHECKOUT_ID=$COMMIT_ID
283 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
284 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
285 if [[ $CHECKOUT_ID == "tags/"* ]]; then
286 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
287 else
288 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
289 fi
290 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
291 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
292 echo " Nothing to be done."
293 else
294 echo " Update required."
295 fi
296 echo
297}
298
299function so_is_up() {
300 if [ -n "$1" ]; then
301 SO_IP=$1
302 else
303 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
304 fi
305 time=0
306 step=5
307 timelength=300
308 while [ $time -le $timelength ]
309 do
310 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
311 -H 'accept: application/vnd.yang.data+json' \
312 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
313 -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 ]]
314 then
315 echo "RW.Restconf running....SO is up"
316 return 0
317 fi
318
319 sleep $step
320 echo -n "."
321 time=$((time+step))
322 done
323
324 FATAL "OSM Failed to startup. SO failed to startup"
325}
326
327function vca_is_up() {
328 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
329 echo "VCA is up and running"
330 return 0
331 fi
332
333 FATAL "OSM Failed to startup. VCA failed to startup"
334}
335
336function mon_is_up() {
337 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
338 echo "MON is up and running"
339 return 0
340 fi
341
342 FATAL "OSM Failed to startup. MON failed to startup"
343}
344
345function ro_is_up() {
346 if [ -n "$1" ]; then
347 RO_IP=$1
348 else
349 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
350 fi
351 time=0
352 step=2
353 timelength=20
354 while [ $time -le $timelength ]; do
355 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
356 echo "RO is up and running"
357 return 0
358 fi
359 sleep $step
360 echo -n "."
361 time=$((time+step))
362 done
363
364 FATAL "OSM Failed to startup. RO failed to startup"
365}
366
367
368function configure_RO(){
369 . $OSM_DEVOPS/installers/export_ips
370 echo -e " Configuring RO"
371 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
372 lxc exec RO -- service osm-ro restart
373
374 ro_is_up
375
376 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
377 lxc exec RO -- openmano tenant-create osm > /dev/null
378 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
379 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
380 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
381}
382
383function configure_VCA(){
384 echo -e " Configuring VCA"
385 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
386 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
387}
388
389function configure_SOUI(){
390 . $OSM_DEVOPS/installers/export_ips
391 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
392 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
393
394 echo -e " Configuring MON"
395 #Information to be added about SO socket for logging
396
397 echo -e " Configuring SO"
398 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200399 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200400 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200401 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 +0200402 # make journaling persistent
403 lxc exec SO-ub -- mkdir -p /var/log/journal
404 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
405 lxc exec SO-ub -- systemctl restart systemd-journald
406
407 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
408
409 lxc exec SO-ub -- systemctl restart launchpad
410
411 so_is_up $SO_CONTAINER_IP
412
413 #delete existing config agent (could be there on reconfigure)
414 curl -k --request DELETE \
415 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
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' &> /dev/null
420
421 result=$(curl -k --request POST \
422 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
423 --header 'accept: application/vnd.yang.data+json' \
424 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
425 --header 'cache-control: no-cache' \
426 --header 'content-type: application/vnd.yang.data+json' \
427 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
428 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
429
430 #R1/R2 config line
431 #result=$(curl -k --request PUT \
432 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
433 # --header 'accept: application/vnd.yang.data+json' \
434 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
435 # --header 'cache-control: no-cache' \
436 # --header 'content-type: application/vnd.yang.data+json' \
437 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
438
439 result=$(curl -k --request PUT \
440 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
441 --header 'accept: application/vnd.yang.data+json' \
442 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
443 --header 'cache-control: no-cache' \
444 --header 'content-type: application/vnd.yang.data+json' \
445 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
446 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
447
448 result=$(curl -k --request PATCH \
449 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
450 --header 'accept: application/vnd.yang.data+json' \
451 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
452 --header 'cache-control: no-cache' \
453 --header 'content-type: application/vnd.yang.data+json' \
454 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
455 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
456
457 result=$(curl -k --request PATCH \
458 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
459 --header 'accept: application/vnd.yang.data+json' \
460 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
461 --header 'cache-control: no-cache' \
462 --header 'content-type: application/vnd.yang.data+json' \
463 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
464 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
465
466 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
467auto lo:1
468iface lo:1 inet static
469 address $DEFAULT_IP
470 netmask 255.255.255.255
471EOF
472 lxc exec SO-ub ifup lo:1
473}
474
475#Configure RO, VCA, and SO with the initial configuration:
476# RO -> tenant:osm, logs to be sent to SO
477# VCA -> juju-password
478# SO -> route to Juju Controller, add RO account, add VCA account
479function configure(){
480 #Configure components
481 echo -e "\nConfiguring components"
482 configure_RO
483 configure_VCA
484 configure_SOUI
485}
486
487function install_lxd() {
488 sudo apt-get update
489 sudo apt-get install -y lxd
490 newgrp lxd
491 lxd init --auto
492 lxd waitready
493 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
494 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
495 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
496 lxc profile device set default eth0 mtu $DEFAULT_MTU
497 #sudo systemctl stop lxd-bridge
498 #sudo systemctl --system daemon-reload
499 #sudo systemctl enable lxd-bridge
500 #sudo systemctl start lxd-bridge
501}
502
503function ask_user(){
504 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
505 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
506 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
507 read -e -p "$1" USER_CONFIRMATION
508 while true ; do
509 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
510 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
511 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
512 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
513 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
514 done
515}
516
517function launch_container_from_lxd(){
518 export OSM_MDG=$1
519 OSM_load_config
520 export OSM_BASE_IMAGE=$2
521 if ! container_exists $OSM_BUILD_CONTAINER; then
522 CONTAINER_OPTS=""
523 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
524 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
525 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
526 wait_container_up $OSM_BUILD_CONTAINER
527 fi
528}
529
530function install_osmclient(){
531 CLIENT_RELEASE=${RELEASE#"-R "}
532 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
533 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
garciadeblasd8bc5c32018-05-09 17:37:56 +0200534 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
535 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
536 curl $key_location | sudo apt-key add -
537 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
538 sudo apt-get update
539 sudo apt-get install -y python-pip
540 sudo -H pip install pip==9.0.3
541 sudo -H pip install python-magic
542 sudo apt-get install -y python-osmclient
543 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
544 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
545 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
546 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
547 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200548 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200549 echo -e "\nOSM client installed"
550 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
551 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
552 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
553 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
554 return 0
555}
556
557function install_from_lxdimages(){
558 LXD_RELEASE=${RELEASE#"-R "}
559 if [ -n "$LXD_REPOSITORY_PATH" ]; then
560 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
561 else
562 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
563 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
564 fi
565 echo -e "\nDeleting previous lxd images if they exist"
566 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
567 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
568 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
569 echo -e "\nImporting osm-ro"
570 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
571 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
572 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
573 echo -e "\nImporting osm-vca"
574 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
575 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
576 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
577 echo -e "\nImporting osm-soui"
578 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
579 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
580 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
581 launch_container_from_lxd RO osm-ro
582 ro_is_up && track RO
583 launch_container_from_lxd VCA osm-vca
584 vca_is_up && track VCA
585 launch_container_from_lxd MON osm-mon
586 mon_is_up && track MON
587 launch_container_from_lxd SO osm-soui
588 #so_is_up && track SOUI
589 track SOUI
590}
591
592function install_docker_ce() {
593 # installs and configures Docker CE
594 echo "Installing Docker CE ..."
595 sudo apt-get -qq update
596 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
597 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
598 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
599 sudo apt-get -qq update
600 sudo apt-get install -y docker-ce
601 echo "Adding user to group 'docker'"
602 sudo groupadd -f docker
603 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200604 sleep 2
605 sudo service docker restart
606 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200607 sg docker -c "docker version" || FATAL "Docker installation failed"
608 echo "... Docker CE installation done"
609 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200610}
611
612function install_docker_compose() {
613 # installs and configures docker-compose
614 echo "Installing Docker Compose ..."
615 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
616 sudo chmod +x /usr/local/bin/docker-compose
617 echo "... Docker Compose installation done"
618}
619
620function install_juju() {
621 echo "Installing juju"
622 sudo snap install juju --classic
garciadeblasd41f5482018-05-25 10:25:06 +0200623 [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
garciadeblasd8bc5c32018-05-09 17:37:56 +0200624 echo "Finished installation of juju"
Mike Marchettib8420852018-09-13 13:45:06 -0400625 return 0
626}
627
628function juju_createcontroller() {
629 if ! sg lxd -c "juju show-controller $OSM_STACK_NAME &> /dev/null"; then
630 # Not found created, create the controller
631 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost $OSM_STACK_NAME"
632 fi
Mike Marchetti13d76c82018-09-19 15:00:36 -0400633 [ $(sg lxd -c "juju controllers" | awk "/^${OSM_STACK_NAME}[\*| ]/{print $1}"|wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200634}
635
636function generate_docker_images() {
637 echo "Pulling and generating docker images"
Michael Marchettiee374142018-08-02 22:47:16 +0200638 _build_from=$COMMIT_ID
639 [ -z "$_build_from" ] && _build_from="master"
640
641 echo "OSM Docker images generated from $_build_from"
642
Mike Marchettib8420852018-09-13 13:45:06 -0400643 BUILD_ARGS+=(--build-arg REPOSITORY="$REPOSITORY")
644 BUILD_ARGS+=(--build-arg RELEASE="$RELEASE")
645 BUILD_ARGS+=(--build-arg REPOSITORY_KEY="$REPOSITORY_KEY")
646 BUILD_ARGS+=(--build-arg REPOSITORY_BASE="$REPOSITORY_BASE")
647
garciadeblas0e596bc2018-05-28 16:04:42 +0200648 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
649 sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
650 sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
651 fi
652 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then
653 sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image"
654 fi
655 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then
656 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
657 git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
658 sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
659 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"
660 fi
661 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then
662 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
663 git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
664 sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
665 fi
666 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then
667 sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image"
668 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
669 git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
670 sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
671 fi
672 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then
673 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
674 git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
675 sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
676 fi
677 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then
678 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
679 git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
680 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"
681 fi
Mike Marchettib8420852018-09-13 13:45:06 -0400682 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-osmclient; then
683 sg docker -c "docker build -t osm/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ."
684 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200685 echo "Finished generation of docker images"
686}
687
garciadeblas5b857d32018-05-24 18:37:58 +0200688function cmp_overwrite() {
689 file1="$1"
690 file2="$2"
691 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
692 if [ -f "${file2}" ]; then
Mike Marchettib8420852018-09-13 13:45:06 -0400693 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200694 else
Mike Marchettib8420852018-09-13 13:45:06 -0400695 cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200696 fi
697 fi
698}
699
garciadeblascf0e34a2018-05-24 10:45:53 +0200700function generate_config_log_folders() {
701 echo "Generating config and log folders"
Mike Marchettib8420852018-09-13 13:45:06 -0400702 $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml
garciadeblascf0e34a2018-05-24 10:45:53 +0200703 echo "Finished generation of config and log folders"
704}
705
garciadeblasd8bc5c32018-05-09 17:37:56 +0200706function generate_docker_env_files() {
707 echo "Generating docker env files"
Mike Marchettib8420852018-09-13 13:45:06 -0400708 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/lcm.env
709 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" | $WORKDIR_SUDO tee -a $OSM_DOCKER_WORK_DIR/lcm.env
710
garciadeblasd8bc5c32018-05-09 17:37:56 +0200711 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
Mike Marchettib8420852018-09-13 13:45:06 -0400712 if [ ! -f $OSM_DOCKER_WORK_DIR/ro-db.env ]; then
713 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |$WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/ro-db.env
garciadeblas5b857d32018-05-24 18:37:58 +0200714 fi
Mike Marchettib8420852018-09-13 13:45:06 -0400715 if [ ! -f $OSM_DOCKER_WORK_DIR/ro.env ]; then
716 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |$WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/ro.env
garciadeblas5b857d32018-05-24 18:37:58 +0200717 fi
Mike Marchettib8420852018-09-13 13:45:06 -0400718 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |$WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/mon.env
719
garciadeblasd8bc5c32018-05-09 17:37:56 +0200720 echo "Finished generation of docker env files"
721}
722
Mike Marchettib8420852018-09-13 13:45:06 -0400723function generate_osmclient_script () {
Mike Marchetti13d76c82018-09-19 15:00:36 -0400724 echo "docker run -ti --network net${OSM_STACK_NAME} osm/osmclient:${OSM_DOCKER_TAG}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/osm
Mike Marchettib8420852018-09-13 13:45:06 -0400725 $WORKDIR_SUDO chmod +x "$OSM_DOCKER_WORK_DIR/osm"
726 echo "osmclient sidecar container can be found at: $OSM_DOCKER_WORK_DIR/osm"
727}
728
garciadeblasa3e26612018-05-30 17:58:55 +0200729function init_docker_swarm() {
garciadeblasd8bc5c32018-05-09 17:37:56 +0200730 if [ "${DEFAULT_MTU}" != "1500" ]; then
731 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
732 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";}'`
733 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"
734 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200735 sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
garciadeblasa3e26612018-05-30 17:58:55 +0200736 return 0
737}
738
Mike Marchettib8420852018-09-13 13:45:06 -0400739function create_docker_network() {
740 echo "creating network"
741 sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} net${OSM_STACK_NAME}"
742 echo "creating network DONE"
743}
744
garciadeblasa3e26612018-05-30 17:58:55 +0200745function deploy_lightweight() {
Mike Marchettib8420852018-09-13 13:45:06 -0400746
garciadeblasa3e26612018-05-30 17:58:55 +0200747 echo "Deploying lightweight build"
Mike Marchettib8420852018-09-13 13:45:06 -0400748 OSM_NBI_PORT=9999
749 OSM_RO_PORT=9090
750 OSM_UI_PORT=80
751
752 if [ -n "$NO_HOST_PORTS" ]; then
753 OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT)
754 OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT)
755 OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT)
756 else
757 OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT:$OSM_NBI_PORT)
758 OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT:$OSM_RO_PORT)
759 OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT:$OSM_UI_PORT)
760 fi
761 echo "export ${OSM_PORTS[@]}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/osm_ports.sh
762 echo "export OSM_NETWORK=net${OSM_STACK_NAME}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh
Mike Marchetti13d76c82018-09-19 15:00:36 -0400763 echo "export TAG=${OSM_DOCKER_TAG}" | $WORKDIR_SUDO tee --append $OSM_DOCKER_WORK_DIR/osm_ports.sh
Mike Marchettib8420852018-09-13 13:45:06 -0400764
765 pushd $OSM_DOCKER_WORK_DIR
766 sg docker -c "source ./osm_ports.sh; docker stack deploy -c $OSM_DOCKER_WORK_DIR/docker-compose.yaml $OSM_STACK_NAME"
767 popd
768
garciadeblasd8bc5c32018-05-09 17:37:56 +0200769 echo "Finished deployment of lightweight build"
770}
771
garciadeblas6c66abf2018-05-16 14:46:19 +0200772function deploy_elk() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200773 echo "Pulling docker images for ELK"
774 sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
775 sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
776 sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
777 echo "Finished pulling elk docker images"
Mike Marchettib8420852018-09-13 13:45:06 -0400778 $WORKDIR_SUDO mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk"
779 $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas5b857d32018-05-24 18:37:58 +0200780 remove_stack osm_elk
garciadeblas6c66abf2018-05-16 14:46:19 +0200781 echo "Deploying ELK stack"
Mike Marchettib8420852018-09-13 13:45:06 -0400782 sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_elk/docker-compose.yml osm_elk"
garciadeblas6c66abf2018-05-16 14:46:19 +0200783 echo "Waiting for ELK stack to be up and running"
784 time=0
garciadeblase2aebfe2018-07-06 14:11:20 +0200785 step=5
786 timelength=40
garciadeblas6c66abf2018-05-16 14:46:19 +0200787 elk_is_up=1
788 while [ $time -le $timelength ]; do
garciadeblase2aebfe2018-07-06 14:11:20 +0200789 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 +0200790 elk_is_up=0
791 break
792 fi
793 sleep $step
794 time=$((time+step))
795 done
796 if [ $elk_is_up -eq 0 ]; then
797 echo "ELK is up and running. Trying to create index pattern..."
798 #Create index pattern
799 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200800 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200801 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200802 #Make it the default index
garciadeblase2aebfe2018-07-06 14:11:20 +0200803 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200804 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200805 -d"{\"value\":\"logstash-*\"}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200806 else
807 echo "Cannot connect to Kibana to create index pattern."
808 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
809 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200810 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200811 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
812 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200813 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200814 -d"{\"value\":\"logstash-*\"}"'
815 fi
816 echo "Finished deployment of ELK stack"
817 return 0
818}
819
820function deploy_perfmon() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200821 echo "Pulling docker images for PM (Grafana and Prometheus)"
822 sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
823 sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
824 echo "Finished pulling PM docker images"
garciadeblas6c66abf2018-05-16 14:46:19 +0200825 echo "Generating osm/kafka-exporter docker image"
garciadeblasc119fb32018-05-25 09:13:30 +0200826 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 +0200827 echo "Finished generation of osm/kafka-exporter docker image"
Mike Marchettib8420852018-09-13 13:45:06 -0400828 $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics
829 $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics
830 $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas5b857d32018-05-24 18:37:58 +0200831 remove_stack osm_metrics
garciadeblas6c66abf2018-05-16 14:46:19 +0200832 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
Mike Marchettib8420852018-09-13 13:45:06 -0400833 sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_metrics/docker-compose.yml osm_metrics"
garciadeblas6c66abf2018-05-16 14:46:19 +0200834 echo "Finished deployment of PM stack"
835 return 0
836}
837
garciadeblasd8bc5c32018-05-09 17:37:56 +0200838function install_lightweight() {
Mike Marchettib8420852018-09-13 13:45:06 -0400839 OSM_DOCKER_WORK_DIR="$OSM_WORK_DIR/stack/$OSM_STACK_NAME"
840 [ ! -d "$OSM_DOCKER_WORK_DIR" ] && $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR
841
garciadeblasd13a8aa2018-05-18 15:24:51 +0200842 [ "$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 +0200843 [ -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 +0200844 track proceed
garciadeblasd8bc5c32018-05-09 17:37:56 +0200845 echo "Installing lightweight build of OSM"
846 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
847 trap 'rm -rf "${LWTEMPDIR}"' EXIT
848 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200849 [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200850 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200851 [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200852 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
Mike Marchettib8420852018-09-13 13:45:06 -0400853
854 # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to
855 if [ -z "$OSMLCM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ]; then
garciadeblasd41f5482018-05-25 10:25:06 +0200856 need_packages_lw="lxd"
857 echo -e "Checking required packages: $need_packages_lw"
858 dpkg -l $need_packages_lw &>/dev/null \
859 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
860 || sudo apt-get update \
861 || FATAL "failed to run apt-get update"
862 dpkg -l $need_packages_lw &>/dev/null \
863 || ! echo -e "Installing $need_packages_lw requires root privileges." \
864 || sudo apt-get install -y $need_packages_lw \
865 || FATAL "failed to install $need_packages_lw"
866 fi
garciadeblasfae5e972018-06-12 18:27:11 +0200867 track prereqok
Mike Marchettib8420852018-09-13 13:45:06 -0400868 [ -z "$INSTALL_NOJUJU" ] && install_juju
869
870 if [ -z "$OSMLCM_VCA_HOST" ]; then
871 juju_createcontroller
872 OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_STACK_NAME"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
873 [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
874 fi
875 if [ -z "$OSMLCM_VCA_SECRET" ]; then
876 OSMLCM_VCA_SECRET=$(parse_juju_password $OSM_STACK_NAME)
877 [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
878 fi
879
garciadeblas6c66abf2018-05-16 14:46:19 +0200880 track juju
garciadeblasa3e26612018-05-30 17:58:55 +0200881 [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200882 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200883 #install_docker_compose
Mike Marchettib8420852018-09-13 13:45:06 -0400884 [ -z "$DOCKER_NOBUILD" ] && generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200885 track docker_build
garciadeblasd8bc5c32018-05-09 17:37:56 +0200886 generate_docker_env_files
Mike Marchettib8420852018-09-13 13:45:06 -0400887 generate_config_log_folders
888
889 [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
890 # remove old stack
891 remove_stack $OSM_STACK_NAME
892 create_docker_network
garciadeblasd8bc5c32018-05-09 17:37:56 +0200893 deploy_lightweight
Mike Marchettib8420852018-09-13 13:45:06 -0400894 generate_osmclient_script
garciadeblas6c66abf2018-05-16 14:46:19 +0200895 track docker_deploy
896 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
897 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
898 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
Mike Marchettib8420852018-09-13 13:45:06 -0400899 [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200900 track osmclient
901 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
902 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200903 return 0
904}
905
906function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200907 echo "\nInstalling vim-emu"
908 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
909 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200910 # clone vim-emu repository (attention: branch is currently master only)
911 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200912 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200913 # build vim-emu docker
914 echo "Building vim-emu Docker container..."
Mike Marchettib8420852018-09-13 13:45:06 -0400915
916 sg docker -c "docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile --no-cache $EMUTEMPDIR/" || FATAL "cannot build vim-emu-img docker image"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200917 # start vim-emu container as daemon
918 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200919 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
920 # in lightweight mode, the emulator needs to be attached to netOSM
Mike Marchettib8420852018-09-13 13:45:06 -0400921 sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' --network=net${OSM_STACK_NAME} -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 +0200922 else
923 # classic build mode
Mike Marchettib8420852018-09-13 13:45:06 -0400924 sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py"
peusterm76353e42018-05-08 13:56:05 +0200925 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200926 echo "Waiting for 'vim-emu' container to start ..."
927 sleep 5
Mike Marchettib8420852018-09-13 13:45:06 -0400928 export VIMEMU_HOSTNAME=$(sg docker -c "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200929 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200930 # print vim-emu connection info
931 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200932 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200933 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200934 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
935}
936
937function dump_vars(){
938 echo "DEVELOP=$DEVELOP"
939 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
940 echo "UNINSTALL=$UNINSTALL"
941 echo "NAT=$NAT"
942 echo "UPDATE=$UPDATE"
943 echo "RECONFIGURE=$RECONFIGURE"
944 echo "TEST_INSTALLER=$TEST_INSTALLER"
945 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
946 echo "INSTALL_LXD=$INSTALL_LXD"
947 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
948 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
949 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
950 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200951 echo "INSTALL_ONLY=$INSTALL_ONLY"
952 echo "INSTALL_ELK=$INSTALL_ELK"
953 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblas0e596bc2018-05-28 16:04:42 +0200954 echo "TO_REBUILD=$TO_REBUILD"
garciadeblasd41f5482018-05-25 10:25:06 +0200955 echo "INSTALL_NOLXD=$INSTALL_NOLXD"
garciadeblasa3e26612018-05-30 17:58:55 +0200956 echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200957 echo "RELEASE=$RELEASE"
958 echo "REPOSITORY=$REPOSITORY"
959 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
960 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
961 echo "NOCONFIGURE=$NOCONFIGURE"
962 echo "SHOWOPTS=$SHOWOPTS"
963 echo "Install from specific refspec (-b): $COMMIT_ID"
964}
965
966function track(){
967 ctime=`date +%s`
968 duration=$((ctime - SESSION_ID))
969 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
970 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
971 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200972 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
973 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
974 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200975 event_name="${event_name}_$1"
976 url="${url}&event=${event_name}&ce_duration=${duration}"
977 wget -q -O /dev/null $url
978}
979
980UNINSTALL=""
981DEVELOP=""
982NAT=""
983UPDATE=""
984RECONFIGURE=""
985TEST_INSTALLER=""
986INSTALL_LXD=""
987SHOWOPTS=""
988COMMIT_ID=""
989ASSUME_YES=""
990INSTALL_FROM_SOURCE=""
Mike Marchettib8420852018-09-13 13:45:06 -0400991RELEASE="ReleaseFOUR"
992REPOSITORY="stable"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200993INSTALL_VIMEMU=""
994INSTALL_FROM_LXDIMAGES=""
995LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
996LXD_REPOSITORY_PATH=""
997INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200998INSTALL_ONLY=""
999INSTALL_ELK=""
1000INSTALL_PERFMON=""
garciadeblas0e596bc2018-05-28 16:04:42 +02001001TO_REBUILD=""
garciadeblasd41f5482018-05-25 10:25:06 +02001002INSTALL_NOLXD=""
garciadeblasa3e26612018-05-30 17:58:55 +02001003INSTALL_NODOCKER=""
Mike Marchettib8420852018-09-13 13:45:06 -04001004INSTALL_NOJUJU=""
garciadeblasd8bc5c32018-05-09 17:37:56 +02001005NOCONFIGURE=""
1006RELEASE_DAILY=""
1007SESSION_ID=`date +%s`
1008OSM_DEVOPS=
Mike Marchettib8420852018-09-13 13:45:06 -04001009OSMLCM_VCA_HOST=
1010OSMLCM_VCA_SECRET=
1011OSM_STACK_NAME=osm
1012NO_HOST_PORTS=""
1013DOCKER_NOBUILD=""
1014REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
1015REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian"
1016WORKDIR_SUDO=sudo
1017OSM_WORK_DIR="/etc/osm"
Mike Marchetti13d76c82018-09-19 15:00:36 -04001018OSM_DOCKER_TAG=latest
garciadeblasd8bc5c32018-05-09 17:37:56 +02001019
Mike Marchetti13d76c82018-09-19 15:00:36 -04001020while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:w:t:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +02001021 case "${o}" in
1022 h)
1023 usage && exit 0
1024 ;;
1025 b)
1026 COMMIT_ID=${OPTARG}
1027 ;;
1028 r)
Mike Marchettib8420852018-09-13 13:45:06 -04001029 REPOSITORY="${OPTARG}"
1030 REPO_ARGS+=(-r "$REPOSITORY")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001031 ;;
1032 R)
Mike Marchettib8420852018-09-13 13:45:06 -04001033 RELEASE="${OPTARG}"
1034 REPO_ARGS+=(-R "$RELEASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001035 ;;
1036 k)
Mike Marchettib8420852018-09-13 13:45:06 -04001037 REPOSITORY_KEY="${OPTARG}"
1038 REPO_ARGS+=(-k "$REPOSITORY_KEY")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001039 ;;
1040 u)
Mike Marchettib8420852018-09-13 13:45:06 -04001041 REPOSITORY_BASE="${OPTARG}"
1042 REPO_ARGS+=(-u "$REPOSITORY_BASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001043 ;;
1044 l)
1045 LXD_REPOSITORY_BASE="${OPTARG}"
1046 ;;
1047 p)
1048 LXD_REPOSITORY_PATH="${OPTARG}"
1049 ;;
1050 D)
1051 OSM_DEVOPS="${OPTARG}"
1052 ;;
Mike Marchettib8420852018-09-13 13:45:06 -04001053 s)
1054 OSM_STACK_NAME="${OPTARG}"
1055 ;;
1056 H)
1057 OSMLCM_VCA_HOST="${OPTARG}"
1058 ;;
1059 S)
1060 OSMLCM_VCA_SECRET="${OPTARG}"
1061 ;;
1062 w)
1063 # when specifying workdir, do not use sudo for access
1064 WORKDIR_SUDO=
1065 OSM_WORK_DIR="${OPTARG}"
1066 ;;
Mike Marchetti13d76c82018-09-19 15:00:36 -04001067 t)
1068 OSM_DOCKER_TAG="${OPTARG}"
1069 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +02001070 o)
1071 INSTALL_ONLY="y"
1072 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
1073 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1074 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
1075 ;;
garciadeblas0e596bc2018-05-28 16:04:42 +02001076 m)
1077 [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
1078 [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
1079 [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
1080 [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue
1081 [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
1082 [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
1083 [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
1084 [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
1085 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +02001086 -)
1087 [ "${OPTARG}" == "help" ] && usage && exit 0
1088 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
1089 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
1090 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
1091 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
1092 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
1093 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
1094 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
1095 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblasd41f5482018-05-25 10:25:06 +02001096 [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
garciadeblasa3e26612018-05-30 17:58:55 +02001097 [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001098 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
1099 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblase990f662018-05-18 11:43:39 +02001100 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001101 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +02001102 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1103 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001104 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
1105 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
1106 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
Mike Marchettib8420852018-09-13 13:45:06 -04001107 [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue
1108 [ "${OPTARG}" == "nojuju" ] && INSTALL_NOJUJU="y" && continue
1109 [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue
1110 [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001111 echo -e "Invalid option: '--$OPTARG'\n" >&2
1112 usage && exit 1
1113 ;;
1114 \?)
1115 echo -e "Invalid option: '-$OPTARG'\n" >&2
1116 usage && exit 1
1117 ;;
1118 y)
1119 ASSUME_YES="y"
1120 ;;
1121 *)
1122 usage && exit 1
1123 ;;
1124 esac
1125done
1126
garciadeblas6c66abf2018-05-16 14:46:19 +02001127[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
garciadeblase990f662018-05-18 11:43:39 +02001128[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
1129[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
garciadeblasfb566272018-05-25 10:33:36 +02001130[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
garciadeblasd41f5482018-05-25 10:25:06 +02001131[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
garciadeblasa3e26612018-05-30 17:58:55 +02001132[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
garciadeblas0e596bc2018-05-28 16:04:42 +02001133[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
1134[ -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 +02001135
garciadeblasd8bc5c32018-05-09 17:37:56 +02001136if [ -n "$SHOWOPTS" ]; then
1137 dump_vars
1138 exit 0
1139fi
1140
1141[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
1142
1143# if develop, we force master
1144[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
1145
garciadeblasd8bc5c32018-05-09 17:37:56 +02001146need_packages="git jq wget curl tar"
1147echo -e "Checking required packages: $need_packages"
1148dpkg -l $need_packages &>/dev/null \
1149 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
1150 || sudo apt-get update \
1151 || FATAL "failed to run apt-get update"
1152dpkg -l $need_packages &>/dev/null \
1153 || ! echo -e "Installing $need_packages requires root privileges." \
1154 || sudo apt-get install -y $need_packages \
1155 || FATAL "failed to install $need_packages"
1156
1157if [ -z "$OSM_DEVOPS" ]; then
Michael Marchettiee374142018-08-02 22:47:16 +02001158 if [ -n "$TEST_INSTALLER" ]; then
1159 echo -e "\nUsing local devops repo for OSM installation"
1160 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
1161 else
1162 echo -e "\nCreating temporary dir for OSM installation"
1163 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
1164 trap 'rm -rf "$OSM_DEVOPS"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +02001165
Michael Marchettiee374142018-08-02 22:47:16 +02001166 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
garciadeblasd8bc5c32018-05-09 17:37:56 +02001167
Michael Marchettiee374142018-08-02 22:47:16 +02001168 if [ -z "$COMMIT_ID" ]; then
1169 echo -e "\nGuessing the current stable release"
1170 LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1`
1171 [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
1172
1173 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
1174 COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
1175 else
1176 echo -e "\nDEVOPS Using commit $COMMIT_ID"
1177 fi
1178 git -C $OSM_DEVOPS checkout $COMMIT_ID
garciadeblasd8bc5c32018-05-09 17:37:56 +02001179 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +02001180fi
1181
1182OSM_JENKINS="$OSM_DEVOPS/jenkins"
1183. $OSM_JENKINS/common/all_funcs
1184
1185[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
1186[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
1187[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
1188[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
1189[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +02001190[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
1191[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
1192[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
1193[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +02001194
1195#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +02001196wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
1197track start
1198
garciadeblasd8bc5c32018-05-09 17:37:56 +02001199[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
1200echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
1201if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
1202 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
1203fi
1204
1205echo -e "Checking required packages: lxd"
1206lxd --version &>/dev/null || FATAL "lxd not present, exiting."
1207[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
1208
garciadeblasd8bc5c32018-05-09 17:37:56 +02001209# use local devops for containers
1210export OSM_USE_LOCAL_DEVOPS=true
1211if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
1212 echo -e "\nCreating the containers and building from source ..."
1213 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
1214 ro_is_up && track RO
1215 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
1216 vca_is_up && track VCA
1217 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
1218 mon_is_up && track MON
1219 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
1220 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
1221 #so_is_up && track SOUI
1222 track SOUI
1223elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
1224 echo -e "\nInstalling from lxd images ..."
1225 install_from_lxdimages
1226else #install from binaries
1227 echo -e "\nCreating the containers and installing from binaries ..."
Mike Marchettib8420852018-09-13 13:45:06 -04001228 $OSM_DEVOPS/jenkins/host/install RO ${REPO_ARGS[@]} || FATAL "RO install failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001229 ro_is_up && track RO
1230 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
1231 vca_is_up && track VCA
1232 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
1233 mon_is_up && track MON
Mike Marchettib8420852018-09-13 13:45:06 -04001234 $OSM_DEVOPS/jenkins/host/install SO ${REPO_ARGS[@]} || FATAL "SO install failed"
1235 $OSM_DEVOPS/jenkins/host/install UI ${REPO_ARGS[@]} || FATAL "UI install failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001236 #so_is_up && track SOUI
1237 track SOUI
1238fi
1239
1240#Install iptables-persistent and configure NAT rules
1241[ -z "$NOCONFIGURE" ] && nat
1242
1243#Configure components
1244[ -z "$NOCONFIGURE" ] && configure
1245
1246#Install osmclient
1247[ -z "$NOCONFIGURE" ] && install_osmclient
1248
1249#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +02001250[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +02001251
1252wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
1253track end
1254echo -e "\nDONE"
1255