blob: e0bfafa6086ab78691cee3ab55904b832bdb5017 [file] [log] [blame]
garciadeblasd8bc5c32018-05-09 17:37:56 +02001#!/bin/bash
2# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16function usage(){
17 echo -e "usage: $0 [OPTIONS]"
18 echo -e "Install OSM from binaries or source code (by default, from binaries)"
19 echo -e " OPTIONS"
garciadeblasd8bc5c32018-05-09 17:37:56 +020020 echo -e " -r <repo>: use specified repository name for osm packages"
21 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
22 echo -e " -u <repo base>: use specified repository url for osm packages"
23 echo -e " -k <repo key>: use specified repository public key url"
24 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
25 echo -e " -b master (main dev branch)"
26 echo -e " -b v2.0 (v2.0 branch)"
27 echo -e " -b tags/v1.1.0 (a specific tag)"
28 echo -e " ..."
Mike Marchetti67411aa2018-09-13 11:38:38 -040029 echo -e " -s <stack name> user defined stack name, default is osm"
30 echo -e " -H <VCA host> use specific juju host controller IP"
31 echo -e " -S <VCA secret> use VCA/juju secret key"
garciadeblas6c66abf2018-05-16 14:46:19 +020032 echo -e " --vimemu: additionally deploy the VIM emulator as a docker container"
33 echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging"
34 echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
garciadeblas0e596bc2018-05-28 16:04:42 +020035 echo -e " -m <MODULE>: install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)"
garciadeblas282ff4e2018-07-10 09:16:30 +020036 echo -e " -o <ADDON>: ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)"
garciadeblase990f662018-05-18 11:43:39 +020037 echo -e " -D <devops path> use local devops installation path"
garciadeblasd41f5482018-05-25 10:25:06 +020038 echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
garciadeblasa3e26612018-05-30 17:58:55 +020039 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
Mike Marchetti67411aa2018-09-13 11:38:38 -040040 echo -e " --nojuju: do not juju, assumes already installed"
41 echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)"
42 echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)"
Mike Marchetti972947c2018-09-15 12:28:29 -040043 echo -e " --nohostclient: do not install the osmclient"
garciadeblase990f662018-05-18 11:43:39 +020044 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
45 echo -e " --source: install OSM from source code using the latest stable tag"
garciadeblasd8bc5c32018-05-09 17:37:56 +020046 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
garciadeblasd41f5482018-05-25 10:25:06 +020047 echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
48 echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch"
49 echo -e " -l <lxd_repo>: (only for Rel THREE with --soui) use specified repository url for lxd images"
50 echo -e " -p <path>: (only for Rel THREE with --soui) use specified repository path for lxd images"
garciadeblasd8bc5c32018-05-09 17:37:56 +020051# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
garciadeblasd41f5482018-05-25 10:25:06 +020052 echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules"
53 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 +020054# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
55 echo -e " --showopts: print chosen options and exit (only for debugging)"
56 echo -e " -y: do not prompt for confirmation, assumes yes"
garciadeblasd8bc5c32018-05-09 17:37:56 +020057 echo -e " -h / --help: print this help"
58}
59
60#Uninstall OSM: remove containers
61function uninstall(){
62 echo -e "\nUninstalling OSM"
63 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
64 $OSM_DEVOPS/jenkins/host/clean_container RO
65 $OSM_DEVOPS/jenkins/host/clean_container VCA
66 $OSM_DEVOPS/jenkins/host/clean_container MON
67 $OSM_DEVOPS/jenkins/host/clean_container SO
68 #$OSM_DEVOPS/jenkins/host/clean_container UI
69 else
70 lxc stop RO && lxc delete RO
71 lxc stop VCA && lxc delete VCA
72 lxc stop MON && lxc delete MON
73 lxc stop SO-ub && lxc delete SO-ub
74 fi
75 echo -e "\nDeleting imported lxd images if they exist"
76 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
77 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
78 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
79 return 0
80}
81
Mike Marchetti67411aa2018-09-13 11:38:38 -040082# takes a juju/accounts.yaml file and returns the password specific
83# for a controller. I wrote this using only bash tools to minimize
84# additions of other packages
85function parse_juju_password {
86 password_file="${HOME}/.local/share/juju/accounts.yaml"
87 local controller_name=$1
Mike Marchetti2fafbba2018-09-13 15:35:42 -040088 local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
Mike Marchetti67411aa2018-09-13 11:38:38 -040089 sed -ne "s|^\($s\):|\1|" \
90 -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
91 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
92 awk -F$fs -v controller=$controller_name '{
93 indent = length($1)/2;
94 vname[indent] = $2;
95 for (i in vname) {if (i > indent) {delete vname[i]}}
96 if (length($3) > 0) {
97 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
98 if (match(vn,controller) && match($2,"password")) {
99 printf("%s",$3);
100 }
101 }
102 }'
103}
104
Mike Marchetti972947c2018-09-15 12:28:29 -0400105function remove_volumes() {
106 stack=$1
107 volumes="mongo_db mon_db osm_packages ro_db"
108 for volume in $volumes; do
109 sg docker -c "docker volume rm ${stack}_${volume}"
110 done
111}
112
113function remove_network() {
114 stack=$1
115 sg docker -c "docker network rm net${stack}"
116}
117
garciadeblas5b857d32018-05-24 18:37:58 +0200118function remove_stack() {
119 stack=$1
garciadeblas5ef98212018-05-28 09:25:36 +0200120 if sg docker -c "docker stack ps ${stack}" ; then
garciadeblas5b857d32018-05-24 18:37:58 +0200121 echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
122 COUNTER=0
123 result=1
124 while [ ${COUNTER} -lt 30 ]; do
125 result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
126 #echo "Dockers running: $result"
127 if [ "${result}" == "0" ]; then
128 break
129 fi
130 let COUNTER=COUNTER+1
131 sleep 1
132 done
garciadeblasd8bc5c32018-05-09 17:37:56 +0200133 if [ "${result}" == "0" ]; then
garciadeblas5b857d32018-05-24 18:37:58 +0200134 echo "All dockers of the stack ${stack} were removed"
135 else
136 FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
garciadeblasd8bc5c32018-05-09 17:37:56 +0200137 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200138 sleep 5
garciadeblasd8bc5c32018-05-09 17:37:56 +0200139 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200140}
141
142#Uninstall lightweight OSM: remove dockers
143function uninstall_lightweight() {
garciadeblas282ff4e2018-07-10 09:16:30 +0200144 if [ -n "$INSTALL_ONLY" ]; then
145 if [ -n "$INSTALL_ELK" ]; then
146 echo -e "\nUninstalling OSM ELK stack"
147 remove_stack osm_elk
Mike Marchetti67411aa2018-09-13 11:38:38 -0400148 rm -rf $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas282ff4e2018-07-10 09:16:30 +0200149 fi
150 if [ -n "$INSTALL_PERFMON" ]; then
151 echo -e "\nUninstalling OSM Performance Monitoring stack"
152 remove_stack osm_metrics
153 sg docker -c "docker image rm osm/kafka-exporter"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400154 rm -rf $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas282ff4e2018-07-10 09:16:30 +0200155 fi
156 else
157 echo -e "\nUninstalling OSM"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400158 remove_stack $OSM_STACK_NAME
garciadeblas282ff4e2018-07-10 09:16:30 +0200159 remove_stack osm_elk
160 remove_stack osm_metrics
161 echo "Now osm docker images and volumes will be deleted"
162 newgrp docker << EONG
163 docker image rm osm/ro
164 docker image rm osm/lcm
165 docker image rm osm/light-ui
166 docker image rm osm/nbi
167 docker image rm osm/mon
168 docker image rm osm/pm
169 docker image rm osm/kafka-exporter
garciadeblas83ca1322018-05-22 18:31:14 +0200170EONG
Mike Marchetti972947c2018-09-15 12:28:29 -0400171 remove_volumes $OSM_STACK_NAME
172 remove_network $OSM_STACK_NAME
Mike Marchetti67411aa2018-09-13 11:38:38 -0400173 echo "Removing $OSM_DOCKER_WORK_DIR"
174 rm -rf $OSM_DOCKER_WORK_DIR
garciadeblas282ff4e2018-07-10 09:16:30 +0200175 fi
176 echo "Some docker images will be kept in case they are used by other docker stacks"
177 echo "To remove them, just run 'docker image prune' in a terminal"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200178 return 0
179}
180
181#Configure NAT rules, based on the current IP addresses of containers
182function nat(){
183 echo -e "\nChecking required packages: iptables-persistent"
184 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
185 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
186 echo -e "\nConfiguring NAT rules"
187 echo -e " Required root privileges"
188 sudo $OSM_DEVOPS/installers/nat_osm
189}
190
191function FATAL(){
192 echo "FATAL error: Cannot install OSM due to \"$1\""
193 exit 1
194}
195
196#Update RO, SO and UI:
197function update(){
198 echo -e "\nUpdating components"
199
200 echo -e " Updating RO"
201 CONTAINER="RO"
202 MDG="RO"
203 INSTALL_FOLDER="/opt/openmano"
204 echo -e " Fetching the repo"
205 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
206 BRANCH=""
207 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
208 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
209 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
210 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
211 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
212 # COMMIT_ID either was previously set with -b option, or is an empty string
213 CHECKOUT_ID=$COMMIT_ID
214 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
215 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
216 if [[ $CHECKOUT_ID == "tags/"* ]]; then
217 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
218 else
219 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
220 fi
221 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
222 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
223 echo " Nothing to be done."
224 else
225 echo " Update required."
226 lxc exec $CONTAINER -- service osm-ro stop
227 lxc exec $CONTAINER -- git -C /opt/openmano stash
228 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
229 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
230 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
231 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
232 lxc exec $CONTAINER -- service osm-ro start
233 fi
234 echo
235
236 echo -e " Updating SO and UI"
237 CONTAINER="SO-ub"
238 MDG="SO"
239 INSTALL_FOLDER="" # To be filled in
240 echo -e " Fetching the repo"
241 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
242 BRANCH=""
243 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
244 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
245 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
246 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
247 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
248 # COMMIT_ID either was previously set with -b option, or is an empty string
249 CHECKOUT_ID=$COMMIT_ID
250 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
251 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
252 if [[ $CHECKOUT_ID == "tags/"* ]]; then
253 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
254 else
255 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
256 fi
257 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
258 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
259 echo " Nothing to be done."
260 else
261 echo " Update required."
262 # Instructions to be added
263 # lxc exec SO-ub -- ...
264 fi
265 echo
266 echo -e "Updating MON Container"
267 CONTAINER="MON"
268 MDG="MON"
269 INSTALL_FOLDER="/root/MON"
270 echo -e " Fetching the repo"
271 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
272 BRANCH=""
273 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
274 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
275 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
276 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
277 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
278 # COMMIT_ID either was previously set with -b option, or is an empty string
279 CHECKOUT_ID=$COMMIT_ID
280 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
281 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
282 if [[ $CHECKOUT_ID == "tags/"* ]]; then
283 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
284 else
285 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
286 fi
287 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
288 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
289 echo " Nothing to be done."
290 else
291 echo " Update required."
292 fi
293 echo
294}
295
296function so_is_up() {
297 if [ -n "$1" ]; then
298 SO_IP=$1
299 else
300 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
301 fi
302 time=0
303 step=5
304 timelength=300
305 while [ $time -le $timelength ]
306 do
307 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
308 -H 'accept: application/vnd.yang.data+json' \
309 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
310 -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 ]]
311 then
312 echo "RW.Restconf running....SO is up"
313 return 0
314 fi
315
316 sleep $step
317 echo -n "."
318 time=$((time+step))
319 done
320
321 FATAL "OSM Failed to startup. SO failed to startup"
322}
323
324function vca_is_up() {
325 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
326 echo "VCA is up and running"
327 return 0
328 fi
329
330 FATAL "OSM Failed to startup. VCA failed to startup"
331}
332
333function mon_is_up() {
334 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
335 echo "MON is up and running"
336 return 0
337 fi
338
339 FATAL "OSM Failed to startup. MON failed to startup"
340}
341
342function ro_is_up() {
343 if [ -n "$1" ]; then
344 RO_IP=$1
345 else
346 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
347 fi
348 time=0
349 step=2
350 timelength=20
351 while [ $time -le $timelength ]; do
352 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
353 echo "RO is up and running"
354 return 0
355 fi
356 sleep $step
357 echo -n "."
358 time=$((time+step))
359 done
360
361 FATAL "OSM Failed to startup. RO failed to startup"
362}
363
364
365function configure_RO(){
366 . $OSM_DEVOPS/installers/export_ips
367 echo -e " Configuring RO"
368 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
369 lxc exec RO -- service osm-ro restart
370
371 ro_is_up
372
373 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
374 lxc exec RO -- openmano tenant-create osm > /dev/null
375 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
376 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
377 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
378}
379
380function configure_VCA(){
381 echo -e " Configuring VCA"
382 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
383 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
384}
385
386function configure_SOUI(){
387 . $OSM_DEVOPS/installers/export_ips
388 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
389 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
390
391 echo -e " Configuring MON"
392 #Information to be added about SO socket for logging
393
394 echo -e " Configuring SO"
395 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200396 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200397 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200398 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 +0200399 # make journaling persistent
400 lxc exec SO-ub -- mkdir -p /var/log/journal
401 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
402 lxc exec SO-ub -- systemctl restart systemd-journald
403
404 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
405
406 lxc exec SO-ub -- systemctl restart launchpad
407
408 so_is_up $SO_CONTAINER_IP
409
410 #delete existing config agent (could be there on reconfigure)
411 curl -k --request DELETE \
412 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
413 --header 'accept: application/vnd.yang.data+json' \
414 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
415 --header 'cache-control: no-cache' \
416 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
417
418 result=$(curl -k --request POST \
419 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
420 --header 'accept: application/vnd.yang.data+json' \
421 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
422 --header 'cache-control: no-cache' \
423 --header 'content-type: application/vnd.yang.data+json' \
424 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
425 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
426
427 #R1/R2 config line
428 #result=$(curl -k --request PUT \
429 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
430 # --header 'accept: application/vnd.yang.data+json' \
431 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
432 # --header 'cache-control: no-cache' \
433 # --header 'content-type: application/vnd.yang.data+json' \
434 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
435
436 result=$(curl -k --request PUT \
437 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
438 --header 'accept: application/vnd.yang.data+json' \
439 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
440 --header 'cache-control: no-cache' \
441 --header 'content-type: application/vnd.yang.data+json' \
442 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
443 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
444
445 result=$(curl -k --request PATCH \
446 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
447 --header 'accept: application/vnd.yang.data+json' \
448 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
449 --header 'cache-control: no-cache' \
450 --header 'content-type: application/vnd.yang.data+json' \
451 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
452 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
453
454 result=$(curl -k --request PATCH \
455 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
456 --header 'accept: application/vnd.yang.data+json' \
457 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
458 --header 'cache-control: no-cache' \
459 --header 'content-type: application/vnd.yang.data+json' \
460 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
461 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
462
463 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
464auto lo:1
465iface lo:1 inet static
466 address $DEFAULT_IP
467 netmask 255.255.255.255
468EOF
469 lxc exec SO-ub ifup lo:1
470}
471
472#Configure RO, VCA, and SO with the initial configuration:
473# RO -> tenant:osm, logs to be sent to SO
474# VCA -> juju-password
475# SO -> route to Juju Controller, add RO account, add VCA account
476function configure(){
477 #Configure components
478 echo -e "\nConfiguring components"
479 configure_RO
480 configure_VCA
481 configure_SOUI
482}
483
484function install_lxd() {
485 sudo apt-get update
486 sudo apt-get install -y lxd
487 newgrp lxd
488 lxd init --auto
489 lxd waitready
490 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
491 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
492 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
493 lxc profile device set default eth0 mtu $DEFAULT_MTU
494 #sudo systemctl stop lxd-bridge
495 #sudo systemctl --system daemon-reload
496 #sudo systemctl enable lxd-bridge
497 #sudo systemctl start lxd-bridge
498}
499
500function ask_user(){
501 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
502 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
503 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
504 read -e -p "$1" USER_CONFIRMATION
505 while true ; do
506 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
507 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
508 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
509 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
510 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
511 done
512}
513
514function launch_container_from_lxd(){
515 export OSM_MDG=$1
516 OSM_load_config
517 export OSM_BASE_IMAGE=$2
518 if ! container_exists $OSM_BUILD_CONTAINER; then
519 CONTAINER_OPTS=""
520 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
521 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
522 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
523 wait_container_up $OSM_BUILD_CONTAINER
524 fi
525}
526
527function install_osmclient(){
528 CLIENT_RELEASE=${RELEASE#"-R "}
529 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
530 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
garciadeblasd8bc5c32018-05-09 17:37:56 +0200531 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
532 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
533 curl $key_location | sudo apt-key add -
534 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
535 sudo apt-get update
536 sudo apt-get install -y python-pip
537 sudo -H pip install pip==9.0.3
538 sudo -H pip install python-magic
539 sudo apt-get install -y python-osmclient
540 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
541 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
542 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
543 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
544 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200545 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200546 echo -e "\nOSM client installed"
547 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
548 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
549 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
550 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
551 return 0
552}
553
554function install_from_lxdimages(){
555 LXD_RELEASE=${RELEASE#"-R "}
556 if [ -n "$LXD_REPOSITORY_PATH" ]; then
557 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
558 else
559 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
560 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
561 fi
562 echo -e "\nDeleting previous lxd images if they exist"
563 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
564 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
565 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
566 echo -e "\nImporting osm-ro"
567 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
568 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
569 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
570 echo -e "\nImporting osm-vca"
571 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
572 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
573 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
574 echo -e "\nImporting osm-soui"
575 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
576 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
577 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
578 launch_container_from_lxd RO osm-ro
579 ro_is_up && track RO
580 launch_container_from_lxd VCA osm-vca
581 vca_is_up && track VCA
582 launch_container_from_lxd MON osm-mon
583 mon_is_up && track MON
584 launch_container_from_lxd SO osm-soui
585 #so_is_up && track SOUI
586 track SOUI
587}
588
589function install_docker_ce() {
590 # installs and configures Docker CE
591 echo "Installing Docker CE ..."
592 sudo apt-get -qq update
593 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
594 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
595 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
596 sudo apt-get -qq update
597 sudo apt-get install -y docker-ce
598 echo "Adding user to group 'docker'"
599 sudo groupadd -f docker
600 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200601 sleep 2
602 sudo service docker restart
603 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200604 sg docker -c "docker version" || FATAL "Docker installation failed"
605 echo "... Docker CE installation done"
606 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200607}
608
609function install_docker_compose() {
610 # installs and configures docker-compose
611 echo "Installing Docker Compose ..."
612 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
613 sudo chmod +x /usr/local/bin/docker-compose
614 echo "... Docker Compose installation done"
615}
616
617function install_juju() {
618 echo "Installing juju"
619 sudo snap install juju --classic
garciadeblasd41f5482018-05-25 10:25:06 +0200620 [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
garciadeblasd8bc5c32018-05-09 17:37:56 +0200621 echo "Finished installation of juju"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400622 return 0
623}
624
625function juju_createcontroller() {
626 if ! sg lxd -c "juju show-controller $OSM_STACK_NAME &> /dev/null"; then
627 # Not found created, create the controller
628 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost $OSM_STACK_NAME"
629 fi
630 [ $(sg lxd -c "juju controllers" |grep "$OSM_STACK_NAME" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200631}
632
633function generate_docker_images() {
634 echo "Pulling and generating docker images"
Michael Marchettiee374142018-08-02 22:47:16 +0200635 _build_from=$COMMIT_ID
636 [ -z "$_build_from" ] && _build_from="master"
637
638 echo "OSM Docker images generated from $_build_from"
639
Mike Marchetti972947c2018-09-15 12:28:29 -0400640 BUILD_ARGS+=(--build-arg REPOSITORY="$REPOSITORY")
641 BUILD_ARGS+=(--build-arg RELEASE="$RELEASE")
642 BUILD_ARGS+=(--build-arg REPOSITORY_KEY="$REPOSITORY_KEY")
643 BUILD_ARGS+=(--build-arg REPOSITORY_BASE="$REPOSITORY_BASE")
644
garciadeblas0e596bc2018-05-28 16:04:42 +0200645 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
646 sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
647 sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
648 fi
649 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then
650 sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image"
651 fi
652 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then
653 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
654 git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
655 sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
656 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"
657 fi
658 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then
659 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
660 git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
661 sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
662 fi
663 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then
664 sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image"
665 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
666 git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
667 sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
668 fi
669 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then
670 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
671 git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
672 sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
673 fi
674 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then
675 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
676 git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
677 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"
678 fi
Mike Marchetti972947c2018-09-15 12:28:29 -0400679 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-osmclient; then
680 sg docker -c "docker build -t osm/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ."
681 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200682 echo "Finished generation of docker images"
683}
684
garciadeblas5b857d32018-05-24 18:37:58 +0200685function cmp_overwrite() {
686 file1="$1"
687 file2="$2"
688 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
689 if [ -f "${file2}" ]; then
Mike Marchetti67411aa2018-09-13 11:38:38 -0400690 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200691 else
Mike Marchetti67411aa2018-09-13 11:38:38 -0400692 cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200693 fi
694 fi
695}
696
garciadeblascf0e34a2018-05-24 10:45:53 +0200697function generate_config_log_folders() {
698 echo "Generating config and log folders"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400699 cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml
garciadeblascf0e34a2018-05-24 10:45:53 +0200700 echo "Finished generation of config and log folders"
701}
702
garciadeblasd8bc5c32018-05-09 17:37:56 +0200703function generate_docker_env_files() {
704 echo "Generating docker env files"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400705 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" | tee $OSM_DOCKER_WORK_DIR/lcm.env
706 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" | tee -a $OSM_DOCKER_WORK_DIR/lcm.env
707
garciadeblasd8bc5c32018-05-09 17:37:56 +0200708 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
Mike Marchetti67411aa2018-09-13 11:38:38 -0400709 if [ ! -f $OSM_DOCKER_WORK_DIR/ro-db.env ]; then
710 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro-db.env
garciadeblas5b857d32018-05-24 18:37:58 +0200711 fi
Mike Marchetti67411aa2018-09-13 11:38:38 -0400712 if [ ! -f $OSM_DOCKER_WORK_DIR/ro.env ]; then
713 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro.env
garciadeblas5b857d32018-05-24 18:37:58 +0200714 fi
Mike Marchetti67411aa2018-09-13 11:38:38 -0400715 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |tee $OSM_DOCKER_WORK_DIR/mon.env
Mike Marchetti972947c2018-09-15 12:28:29 -0400716
garciadeblasd8bc5c32018-05-09 17:37:56 +0200717 echo "Finished generation of docker env files"
718}
719
Mike Marchetti972947c2018-09-15 12:28:29 -0400720function generate_osmclient_script () {
721 cat >"$OSM_DOCKER_WORK_DIR/osm" <<-EOF
722 docker run -ti --network net${OSM_STACK_NAME} osm/osmclient
723 EOF
724 chmod +x "$OSM_DOCKER_WORK_DIR/osm"
725 echo "osmclient sidecar container can be found at: $OSM_DOCKER_WORK_DIR/osm"
726}
727
garciadeblasa3e26612018-05-30 17:58:55 +0200728function init_docker_swarm() {
garciadeblasd8bc5c32018-05-09 17:37:56 +0200729 if [ "${DEFAULT_MTU}" != "1500" ]; then
730 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
731 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";}'`
732 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"
733 fi
garciadeblas5b857d32018-05-24 18:37:58 +0200734 sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
garciadeblasa3e26612018-05-30 17:58:55 +0200735 return 0
736}
737
Mike Marchetti972947c2018-09-15 12:28:29 -0400738function create_docker_network() {
739 echo "creating network"
740 sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} net${OSM_STACK_NAME}"
741 echo "creating network DONE"
742}
Mike Marchetti67411aa2018-09-13 11:38:38 -0400743
Mike Marchetti972947c2018-09-15 12:28:29 -0400744function deploy_lightweight() {
745
746 echo "Deploying lightweight build"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400747 OSM_NBI_PORT=9999
748 OSM_RO_PORT=9090
749 OSM_UI_PORT=80
750
751 if [ -n "$NO_HOST_PORTS" ]; then
752 OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT)
753 OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT)
754 OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT)
755 else
756 OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT:$OSM_NBI_PORT)
757 OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT:$OSM_RO_PORT)
758 OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT:$OSM_UI_PORT)
759 fi
760 echo "export ${OSM_PORTS[@]}" > $OSM_DOCKER_WORK_DIR/osm_ports.sh
Mike Marchetti972947c2018-09-15 12:28:29 -0400761 echo "export OSM_NETWORK=net${OSM_STACK_NAME}" >> $OSM_DOCKER_WORK_DIR/osm_ports.sh
Mike Marchetti67411aa2018-09-13 11:38:38 -0400762
Mike Marchetti972947c2018-09-15 12:28:29 -0400763 pushd $OSM_DOCKER_WORK_DIR
Mike Marchetti67411aa2018-09-13 11:38:38 -0400764 sg docker -c "source ./osm_ports.sh; docker stack deploy -c $OSM_DOCKER_WORK_DIR/docker-compose.yaml $OSM_STACK_NAME"
Mike Marchetti972947c2018-09-15 12:28:29 -0400765 popd
Mike Marchetti67411aa2018-09-13 11:38:38 -0400766
garciadeblasd8bc5c32018-05-09 17:37:56 +0200767 echo "Finished deployment of lightweight build"
768}
769
garciadeblas6c66abf2018-05-16 14:46:19 +0200770function deploy_elk() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200771 echo "Pulling docker images for ELK"
772 sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
773 sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
774 sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
775 echo "Finished pulling elk docker images"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400776 mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk"
777 cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas5b857d32018-05-24 18:37:58 +0200778 remove_stack osm_elk
garciadeblas6c66abf2018-05-16 14:46:19 +0200779 echo "Deploying ELK stack"
Mike Marchetti972947c2018-09-15 12:28:29 -0400780 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 +0200781 echo "Waiting for ELK stack to be up and running"
782 time=0
garciadeblase2aebfe2018-07-06 14:11:20 +0200783 step=5
784 timelength=40
garciadeblas6c66abf2018-05-16 14:46:19 +0200785 elk_is_up=1
786 while [ $time -le $timelength ]; do
garciadeblase2aebfe2018-07-06 14:11:20 +0200787 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 +0200788 elk_is_up=0
789 break
790 fi
791 sleep $step
792 time=$((time+step))
793 done
794 if [ $elk_is_up -eq 0 ]; then
795 echo "ELK is up and running. Trying to create index pattern..."
796 #Create index pattern
797 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200798 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200799 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200800 #Make it the default index
garciadeblase2aebfe2018-07-06 14:11:20 +0200801 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200802 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200803 -d"{\"value\":\"logstash-*\"}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200804 else
805 echo "Cannot connect to Kibana to create index pattern."
806 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
807 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200808 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200809 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
810 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200811 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200812 -d"{\"value\":\"logstash-*\"}"'
813 fi
814 echo "Finished deployment of ELK stack"
815 return 0
816}
817
818function deploy_perfmon() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200819 echo "Pulling docker images for PM (Grafana and Prometheus)"
820 sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
821 sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
822 echo "Finished pulling PM docker images"
garciadeblas6c66abf2018-05-16 14:46:19 +0200823 echo "Generating osm/kafka-exporter docker image"
garciadeblasc119fb32018-05-25 09:13:30 +0200824 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 +0200825 echo "Finished generation of osm/kafka-exporter docker image"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400826 mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics
827 cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics
828 cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas5b857d32018-05-24 18:37:58 +0200829 remove_stack osm_metrics
garciadeblas6c66abf2018-05-16 14:46:19 +0200830 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
Mike Marchetti972947c2018-09-15 12:28:29 -0400831 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 +0200832 echo "Finished deployment of PM stack"
833 return 0
834}
835
garciadeblasd8bc5c32018-05-09 17:37:56 +0200836function install_lightweight() {
Mike Marchetti67411aa2018-09-13 11:38:38 -0400837 [ -z "$OSM_DOCKER_WORK_DIR" ] && OSM_DOCKER_WORK_DIR="$HOME/.osm/stack/$OSM_STACK_NAME"
838 [ ! -d "$OSM_DOCKER_WORK_DIR" ] && mkdir -p $OSM_DOCKER_WORK_DIR
839
garciadeblasd13a8aa2018-05-18 15:24:51 +0200840 [ "$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 +0200841 [ -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 +0200842 track proceed
garciadeblasd8bc5c32018-05-09 17:37:56 +0200843 echo "Installing lightweight build of OSM"
844 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
845 trap 'rm -rf "${LWTEMPDIR}"' EXIT
846 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200847 [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200848 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200849 [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200850 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
Mike Marchetti67411aa2018-09-13 11:38:38 -0400851
852 # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to
853 if [ -z "$OSMLCM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ]; then
garciadeblasd41f5482018-05-25 10:25:06 +0200854 need_packages_lw="lxd"
855 echo -e "Checking required packages: $need_packages_lw"
856 dpkg -l $need_packages_lw &>/dev/null \
857 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
858 || sudo apt-get update \
859 || FATAL "failed to run apt-get update"
860 dpkg -l $need_packages_lw &>/dev/null \
861 || ! echo -e "Installing $need_packages_lw requires root privileges." \
862 || sudo apt-get install -y $need_packages_lw \
863 || FATAL "failed to install $need_packages_lw"
864 fi
garciadeblasfae5e972018-06-12 18:27:11 +0200865 track prereqok
Mike Marchetti67411aa2018-09-13 11:38:38 -0400866 [ -z "$INSTALL_NOJUJU" ] && install_juju
867
868 if [ -z "$OSMLCM_VCA_HOST" ]; then
869 juju_createcontroller
870 OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_STACK_NAME"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
871 [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
872 fi
873 if [ -z "$OSMLCM_VCA_SECRET" ]; then
874 OSMLCM_VCA_SECRET=$(parse_juju_password $OSM_STACK_NAME)
875 [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
876 fi
877
garciadeblas6c66abf2018-05-16 14:46:19 +0200878 track juju
garciadeblasa3e26612018-05-30 17:58:55 +0200879 [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200880 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200881 #install_docker_compose
Mike Marchetti67411aa2018-09-13 11:38:38 -0400882 [ -z "$DOCKER_NOBUILD" ] && generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200883 track docker_build
garciadeblasd8bc5c32018-05-09 17:37:56 +0200884 generate_docker_env_files
Mike Marchetti67411aa2018-09-13 11:38:38 -0400885 generate_config_log_folders
Mike Marchetti972947c2018-09-15 12:28:29 -0400886
887 [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
888 # remove old stack
889 remove_stack $OSM_STACK_NAME
890 create_docker_network
garciadeblasd8bc5c32018-05-09 17:37:56 +0200891 deploy_lightweight
Mike Marchetti972947c2018-09-15 12:28:29 -0400892 generate_osmclient_script
garciadeblas6c66abf2018-05-16 14:46:19 +0200893 track docker_deploy
894 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
895 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
896 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
Mike Marchetti972947c2018-09-15 12:28:29 -0400897 [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200898 track osmclient
899 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
900 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200901 return 0
902}
903
904function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200905 echo "\nInstalling vim-emu"
906 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
907 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200908 # clone vim-emu repository (attention: branch is currently master only)
909 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200910 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200911 # build vim-emu docker
912 echo "Building vim-emu Docker container..."
Mike Marchetti67411aa2018-09-13 11:38:38 -0400913
914 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 +0200915 # start vim-emu container as daemon
916 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200917 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
918 # in lightweight mode, the emulator needs to be attached to netOSM
Mike Marchetti972947c2018-09-15 12:28:29 -0400919 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 +0200920 else
921 # classic build mode
Mike Marchetti67411aa2018-09-13 11:38:38 -0400922 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 +0200923 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200924 echo "Waiting for 'vim-emu' container to start ..."
925 sleep 5
Mike Marchetti67411aa2018-09-13 11:38:38 -0400926 export VIMEMU_HOSTNAME=$(sg docker -c "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200927 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200928 # print vim-emu connection info
929 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200930 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200931 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200932 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
933}
934
935function dump_vars(){
936 echo "DEVELOP=$DEVELOP"
937 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
938 echo "UNINSTALL=$UNINSTALL"
939 echo "NAT=$NAT"
940 echo "UPDATE=$UPDATE"
941 echo "RECONFIGURE=$RECONFIGURE"
942 echo "TEST_INSTALLER=$TEST_INSTALLER"
943 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
944 echo "INSTALL_LXD=$INSTALL_LXD"
945 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
946 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
947 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
948 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200949 echo "INSTALL_ONLY=$INSTALL_ONLY"
950 echo "INSTALL_ELK=$INSTALL_ELK"
951 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblas0e596bc2018-05-28 16:04:42 +0200952 echo "TO_REBUILD=$TO_REBUILD"
garciadeblasd41f5482018-05-25 10:25:06 +0200953 echo "INSTALL_NOLXD=$INSTALL_NOLXD"
garciadeblasa3e26612018-05-30 17:58:55 +0200954 echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200955 echo "RELEASE=$RELEASE"
956 echo "REPOSITORY=$REPOSITORY"
957 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
958 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
959 echo "NOCONFIGURE=$NOCONFIGURE"
960 echo "SHOWOPTS=$SHOWOPTS"
961 echo "Install from specific refspec (-b): $COMMIT_ID"
962}
963
964function track(){
965 ctime=`date +%s`
966 duration=$((ctime - SESSION_ID))
967 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
968 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
969 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200970 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
971 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
972 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200973 event_name="${event_name}_$1"
974 url="${url}&event=${event_name}&ce_duration=${duration}"
975 wget -q -O /dev/null $url
976}
977
978UNINSTALL=""
979DEVELOP=""
980NAT=""
981UPDATE=""
982RECONFIGURE=""
983TEST_INSTALLER=""
984INSTALL_LXD=""
985SHOWOPTS=""
986COMMIT_ID=""
987ASSUME_YES=""
988INSTALL_FROM_SOURCE=""
Mike Marchetti972947c2018-09-15 12:28:29 -0400989RELEASE="ReleaseFOUR"
990REPOSITORY="stable"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200991INSTALL_VIMEMU=""
992INSTALL_FROM_LXDIMAGES=""
993LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
994LXD_REPOSITORY_PATH=""
995INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200996INSTALL_ONLY=""
997INSTALL_ELK=""
998INSTALL_PERFMON=""
garciadeblas0e596bc2018-05-28 16:04:42 +0200999TO_REBUILD=""
garciadeblasd41f5482018-05-25 10:25:06 +02001000INSTALL_NOLXD=""
garciadeblasa3e26612018-05-30 17:58:55 +02001001INSTALL_NODOCKER=""
Mike Marchetti67411aa2018-09-13 11:38:38 -04001002INSTALL_NOJUJU=""
garciadeblasd8bc5c32018-05-09 17:37:56 +02001003NOCONFIGURE=""
1004RELEASE_DAILY=""
1005SESSION_ID=`date +%s`
1006OSM_DEVOPS=
Mike Marchetti67411aa2018-09-13 11:38:38 -04001007OSMLCM_VCA_HOST=
1008OSMLCM_VCA_SECRET=
1009OSM_STACK_NAME=osm
1010NO_HOST_PORTS=""
1011DOCKER_NOBUILD=""
Mike Marchetti972947c2018-09-15 12:28:29 -04001012REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
1013REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001014
Mike Marchetti67411aa2018-09-13 11:38:38 -04001015while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +02001016 case "${o}" in
1017 h)
1018 usage && exit 0
1019 ;;
1020 b)
1021 COMMIT_ID=${OPTARG}
1022 ;;
1023 r)
Mike Marchetti972947c2018-09-15 12:28:29 -04001024 REPOSITORY="${OPTARG}"
1025 REPO_ARGS+=(-r "$REPOSITORY")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001026 ;;
1027 R)
Mike Marchetti972947c2018-09-15 12:28:29 -04001028 RELEASE="${OPTARG}"
1029 REPO_ARGS+=(-R "$RELEASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001030 ;;
1031 k)
Mike Marchetti972947c2018-09-15 12:28:29 -04001032 REPOSITORY_KEY="${OPTARG}"
1033 REPO_ARGS+=(-k "$REPOSITORY_KEY")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001034 ;;
1035 u)
Mike Marchetti972947c2018-09-15 12:28:29 -04001036 REPOSITORY_BASE="${OPTARG}"
1037 REPO_ARGS+=(-u "$REPOSITORY_BASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001038 ;;
1039 l)
1040 LXD_REPOSITORY_BASE="${OPTARG}"
1041 ;;
1042 p)
1043 LXD_REPOSITORY_PATH="${OPTARG}"
1044 ;;
1045 D)
1046 OSM_DEVOPS="${OPTARG}"
1047 ;;
Mike Marchetti67411aa2018-09-13 11:38:38 -04001048 s)
1049 OSM_STACK_NAME="${OPTARG}"
1050 ;;
1051 H)
1052 OSMLCM_VCA_HOST="${OPTARG}"
1053 ;;
1054 S)
1055 OSMLCM_VCA_SECRET="${OPTARG}"
1056 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +02001057 o)
1058 INSTALL_ONLY="y"
1059 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
1060 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1061 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
1062 ;;
garciadeblas0e596bc2018-05-28 16:04:42 +02001063 m)
1064 [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
1065 [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
1066 [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
1067 [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue
1068 [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
1069 [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
1070 [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
1071 [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
1072 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +02001073 -)
1074 [ "${OPTARG}" == "help" ] && usage && exit 0
1075 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
1076 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
1077 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
1078 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
1079 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
1080 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
1081 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
1082 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblasd41f5482018-05-25 10:25:06 +02001083 [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
garciadeblasa3e26612018-05-30 17:58:55 +02001084 [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001085 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
1086 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblase990f662018-05-18 11:43:39 +02001087 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001088 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +02001089 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1090 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001091 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
1092 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
1093 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
Mike Marchetti67411aa2018-09-13 11:38:38 -04001094 [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue
1095 [ "${OPTARG}" == "nojuju" ] && INSTALL_NOJUJU="y" && continue
1096 [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue
Mike Marchetti972947c2018-09-15 12:28:29 -04001097 [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001098 echo -e "Invalid option: '--$OPTARG'\n" >&2
1099 usage && exit 1
1100 ;;
1101 \?)
1102 echo -e "Invalid option: '-$OPTARG'\n" >&2
1103 usage && exit 1
1104 ;;
1105 y)
1106 ASSUME_YES="y"
1107 ;;
1108 *)
1109 usage && exit 1
1110 ;;
1111 esac
1112done
1113
garciadeblas6c66abf2018-05-16 14:46:19 +02001114[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
garciadeblase990f662018-05-18 11:43:39 +02001115[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
1116[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
garciadeblasfb566272018-05-25 10:33:36 +02001117[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
garciadeblasd41f5482018-05-25 10:25:06 +02001118[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
garciadeblasa3e26612018-05-30 17:58:55 +02001119[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
garciadeblas0e596bc2018-05-28 16:04:42 +02001120[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
1121[ -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 +02001122
garciadeblasd8bc5c32018-05-09 17:37:56 +02001123if [ -n "$SHOWOPTS" ]; then
1124 dump_vars
1125 exit 0
1126fi
1127
1128[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
1129
1130# if develop, we force master
1131[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
1132
garciadeblasd8bc5c32018-05-09 17:37:56 +02001133need_packages="git jq wget curl tar"
1134echo -e "Checking required packages: $need_packages"
1135dpkg -l $need_packages &>/dev/null \
1136 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
1137 || sudo apt-get update \
1138 || FATAL "failed to run apt-get update"
1139dpkg -l $need_packages &>/dev/null \
1140 || ! echo -e "Installing $need_packages requires root privileges." \
1141 || sudo apt-get install -y $need_packages \
1142 || FATAL "failed to install $need_packages"
1143
1144if [ -z "$OSM_DEVOPS" ]; then
Michael Marchettiee374142018-08-02 22:47:16 +02001145 if [ -n "$TEST_INSTALLER" ]; then
1146 echo -e "\nUsing local devops repo for OSM installation"
1147 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
1148 else
1149 echo -e "\nCreating temporary dir for OSM installation"
1150 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
1151 trap 'rm -rf "$OSM_DEVOPS"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +02001152
Michael Marchettiee374142018-08-02 22:47:16 +02001153 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
garciadeblasd8bc5c32018-05-09 17:37:56 +02001154
Michael Marchettiee374142018-08-02 22:47:16 +02001155 if [ -z "$COMMIT_ID" ]; then
1156 echo -e "\nGuessing the current stable release"
1157 LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1`
1158 [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
1159
1160 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
1161 COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
1162 else
1163 echo -e "\nDEVOPS Using commit $COMMIT_ID"
1164 fi
1165 git -C $OSM_DEVOPS checkout $COMMIT_ID
garciadeblasd8bc5c32018-05-09 17:37:56 +02001166 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +02001167fi
1168
1169OSM_JENKINS="$OSM_DEVOPS/jenkins"
1170. $OSM_JENKINS/common/all_funcs
1171
1172[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
1173[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
1174[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
1175[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
1176[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +02001177[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
1178[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
1179[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
1180[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +02001181
1182#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +02001183wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
1184track start
1185
garciadeblasd8bc5c32018-05-09 17:37:56 +02001186[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
1187echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
1188if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
1189 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
1190fi
1191
1192echo -e "Checking required packages: lxd"
1193lxd --version &>/dev/null || FATAL "lxd not present, exiting."
1194[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
1195
garciadeblasd8bc5c32018-05-09 17:37:56 +02001196# use local devops for containers
1197export OSM_USE_LOCAL_DEVOPS=true
1198if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
1199 echo -e "\nCreating the containers and building from source ..."
1200 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
1201 ro_is_up && track RO
1202 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
1203 vca_is_up && track VCA
1204 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
1205 mon_is_up && track MON
1206 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
1207 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
1208 #so_is_up && track SOUI
1209 track SOUI
1210elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
1211 echo -e "\nInstalling from lxd images ..."
1212 install_from_lxdimages
1213else #install from binaries
1214 echo -e "\nCreating the containers and installing from binaries ..."
Mike Marchetti972947c2018-09-15 12:28:29 -04001215 $OSM_DEVOPS/jenkins/host/install RO ${REPO_ARGS[@]} || FATAL "RO install failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001216 ro_is_up && track RO
1217 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
1218 vca_is_up && track VCA
1219 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
1220 mon_is_up && track MON
Mike Marchetti972947c2018-09-15 12:28:29 -04001221 $OSM_DEVOPS/jenkins/host/install SO ${REPO_ARGS[@]} || FATAL "SO install failed"
1222 $OSM_DEVOPS/jenkins/host/install UI ${REPO_ARGS[@]} || FATAL "UI install failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001223 #so_is_up && track SOUI
1224 track SOUI
1225fi
1226
1227#Install iptables-persistent and configure NAT rules
1228[ -z "$NOCONFIGURE" ] && nat
1229
1230#Configure components
1231[ -z "$NOCONFIGURE" ] && configure
1232
1233#Install osmclient
1234[ -z "$NOCONFIGURE" ] && install_osmclient
1235
1236#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +02001237[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +02001238
1239wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
1240track end
1241echo -e "\nDONE"
1242