blob: a853f9987d2a5e5c9337a34bc3470d576e6553bc [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
Mike Marchettib7c442c2018-09-15 13:10:06 -0400175 sg lxd -c "juju destroy-controller --yes $OSM_STACK_NAME"
garciadeblas282ff4e2018-07-10 09:16:30 +0200176 fi
177 echo "Some docker images will be kept in case they are used by other docker stacks"
178 echo "To remove them, just run 'docker image prune' in a terminal"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200179 return 0
180}
181
182#Configure NAT rules, based on the current IP addresses of containers
183function nat(){
184 echo -e "\nChecking required packages: iptables-persistent"
185 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
186 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
187 echo -e "\nConfiguring NAT rules"
188 echo -e " Required root privileges"
189 sudo $OSM_DEVOPS/installers/nat_osm
190}
191
192function FATAL(){
193 echo "FATAL error: Cannot install OSM due to \"$1\""
194 exit 1
195}
196
197#Update RO, SO and UI:
198function update(){
199 echo -e "\nUpdating components"
200
201 echo -e " Updating RO"
202 CONTAINER="RO"
203 MDG="RO"
204 INSTALL_FOLDER="/opt/openmano"
205 echo -e " Fetching the repo"
206 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
207 BRANCH=""
208 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
209 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
210 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
211 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
212 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
213 # COMMIT_ID either was previously set with -b option, or is an empty string
214 CHECKOUT_ID=$COMMIT_ID
215 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
216 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
217 if [[ $CHECKOUT_ID == "tags/"* ]]; then
218 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
219 else
220 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
221 fi
222 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
223 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
224 echo " Nothing to be done."
225 else
226 echo " Update required."
227 lxc exec $CONTAINER -- service osm-ro stop
228 lxc exec $CONTAINER -- git -C /opt/openmano stash
229 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
230 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
231 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
232 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
233 lxc exec $CONTAINER -- service osm-ro start
234 fi
235 echo
236
237 echo -e " Updating SO and UI"
238 CONTAINER="SO-ub"
239 MDG="SO"
240 INSTALL_FOLDER="" # To be filled in
241 echo -e " Fetching the repo"
242 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
243 BRANCH=""
244 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
245 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
246 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
247 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
248 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
249 # COMMIT_ID either was previously set with -b option, or is an empty string
250 CHECKOUT_ID=$COMMIT_ID
251 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
252 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
253 if [[ $CHECKOUT_ID == "tags/"* ]]; then
254 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
255 else
256 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
257 fi
258 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
259 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
260 echo " Nothing to be done."
261 else
262 echo " Update required."
263 # Instructions to be added
264 # lxc exec SO-ub -- ...
265 fi
266 echo
267 echo -e "Updating MON Container"
268 CONTAINER="MON"
269 MDG="MON"
270 INSTALL_FOLDER="/root/MON"
271 echo -e " Fetching the repo"
272 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
273 BRANCH=""
274 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
275 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
276 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
277 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
278 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
279 # COMMIT_ID either was previously set with -b option, or is an empty string
280 CHECKOUT_ID=$COMMIT_ID
281 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
282 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
283 if [[ $CHECKOUT_ID == "tags/"* ]]; then
284 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
285 else
286 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
287 fi
288 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
289 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
290 echo " Nothing to be done."
291 else
292 echo " Update required."
293 fi
294 echo
295}
296
297function so_is_up() {
298 if [ -n "$1" ]; then
299 SO_IP=$1
300 else
301 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
302 fi
303 time=0
304 step=5
305 timelength=300
306 while [ $time -le $timelength ]
307 do
308 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
309 -H 'accept: application/vnd.yang.data+json' \
310 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
311 -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 ]]
312 then
313 echo "RW.Restconf running....SO is up"
314 return 0
315 fi
316
317 sleep $step
318 echo -n "."
319 time=$((time+step))
320 done
321
322 FATAL "OSM Failed to startup. SO failed to startup"
323}
324
325function vca_is_up() {
326 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
327 echo "VCA is up and running"
328 return 0
329 fi
330
331 FATAL "OSM Failed to startup. VCA failed to startup"
332}
333
334function mon_is_up() {
335 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
336 echo "MON is up and running"
337 return 0
338 fi
339
340 FATAL "OSM Failed to startup. MON failed to startup"
341}
342
343function ro_is_up() {
344 if [ -n "$1" ]; then
345 RO_IP=$1
346 else
347 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
348 fi
349 time=0
350 step=2
351 timelength=20
352 while [ $time -le $timelength ]; do
353 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
354 echo "RO is up and running"
355 return 0
356 fi
357 sleep $step
358 echo -n "."
359 time=$((time+step))
360 done
361
362 FATAL "OSM Failed to startup. RO failed to startup"
363}
364
365
366function configure_RO(){
367 . $OSM_DEVOPS/installers/export_ips
368 echo -e " Configuring RO"
369 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
370 lxc exec RO -- service osm-ro restart
371
372 ro_is_up
373
374 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
375 lxc exec RO -- openmano tenant-create osm > /dev/null
376 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
377 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
378 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
379}
380
381function configure_VCA(){
382 echo -e " Configuring VCA"
383 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
384 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
385}
386
387function configure_SOUI(){
388 . $OSM_DEVOPS/installers/export_ips
389 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
390 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
391
392 echo -e " Configuring MON"
393 #Information to be added about SO socket for logging
394
395 echo -e " Configuring SO"
396 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200397 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200398 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200399 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 +0200400 # make journaling persistent
401 lxc exec SO-ub -- mkdir -p /var/log/journal
402 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
403 lxc exec SO-ub -- systemctl restart systemd-journald
404
405 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
406
407 lxc exec SO-ub -- systemctl restart launchpad
408
409 so_is_up $SO_CONTAINER_IP
410
411 #delete existing config agent (could be there on reconfigure)
412 curl -k --request DELETE \
413 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
414 --header 'accept: application/vnd.yang.data+json' \
415 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
416 --header 'cache-control: no-cache' \
417 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
418
419 result=$(curl -k --request POST \
420 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
421 --header 'accept: application/vnd.yang.data+json' \
422 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
423 --header 'cache-control: no-cache' \
424 --header 'content-type: application/vnd.yang.data+json' \
425 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
426 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
427
428 #R1/R2 config line
429 #result=$(curl -k --request PUT \
430 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
431 # --header 'accept: application/vnd.yang.data+json' \
432 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
433 # --header 'cache-control: no-cache' \
434 # --header 'content-type: application/vnd.yang.data+json' \
435 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
436
437 result=$(curl -k --request PUT \
438 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
439 --header 'accept: application/vnd.yang.data+json' \
440 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
441 --header 'cache-control: no-cache' \
442 --header 'content-type: application/vnd.yang.data+json' \
443 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
444 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
445
446 result=$(curl -k --request PATCH \
447 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
448 --header 'accept: application/vnd.yang.data+json' \
449 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
450 --header 'cache-control: no-cache' \
451 --header 'content-type: application/vnd.yang.data+json' \
452 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
453 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
454
455 result=$(curl -k --request PATCH \
456 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
457 --header 'accept: application/vnd.yang.data+json' \
458 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
459 --header 'cache-control: no-cache' \
460 --header 'content-type: application/vnd.yang.data+json' \
461 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
462 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
463
464 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
465auto lo:1
466iface lo:1 inet static
467 address $DEFAULT_IP
468 netmask 255.255.255.255
469EOF
470 lxc exec SO-ub ifup lo:1
471}
472
473#Configure RO, VCA, and SO with the initial configuration:
474# RO -> tenant:osm, logs to be sent to SO
475# VCA -> juju-password
476# SO -> route to Juju Controller, add RO account, add VCA account
477function configure(){
478 #Configure components
479 echo -e "\nConfiguring components"
480 configure_RO
481 configure_VCA
482 configure_SOUI
483}
484
485function install_lxd() {
486 sudo apt-get update
487 sudo apt-get install -y lxd
488 newgrp lxd
489 lxd init --auto
490 lxd waitready
491 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
492 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
493 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
494 lxc profile device set default eth0 mtu $DEFAULT_MTU
495 #sudo systemctl stop lxd-bridge
496 #sudo systemctl --system daemon-reload
497 #sudo systemctl enable lxd-bridge
498 #sudo systemctl start lxd-bridge
499}
500
501function ask_user(){
502 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
503 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
504 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
505 read -e -p "$1" USER_CONFIRMATION
506 while true ; do
507 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
508 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
509 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
510 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
511 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
512 done
513}
514
515function launch_container_from_lxd(){
516 export OSM_MDG=$1
517 OSM_load_config
518 export OSM_BASE_IMAGE=$2
519 if ! container_exists $OSM_BUILD_CONTAINER; then
520 CONTAINER_OPTS=""
521 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
522 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
523 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
524 wait_container_up $OSM_BUILD_CONTAINER
525 fi
526}
527
528function install_osmclient(){
529 CLIENT_RELEASE=${RELEASE#"-R "}
530 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
531 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
garciadeblasd8bc5c32018-05-09 17:37:56 +0200532 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
533 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
534 curl $key_location | sudo apt-key add -
535 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
536 sudo apt-get update
537 sudo apt-get install -y python-pip
538 sudo -H pip install pip==9.0.3
539 sudo -H pip install python-magic
540 sudo apt-get install -y python-osmclient
541 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
542 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
543 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
544 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
545 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200546 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200547 echo -e "\nOSM client installed"
548 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
549 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
550 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
551 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
552 return 0
553}
554
555function install_from_lxdimages(){
556 LXD_RELEASE=${RELEASE#"-R "}
557 if [ -n "$LXD_REPOSITORY_PATH" ]; then
558 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
559 else
560 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
561 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
562 fi
563 echo -e "\nDeleting previous lxd images if they exist"
564 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
565 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
566 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
567 echo -e "\nImporting osm-ro"
568 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
569 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
570 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
571 echo -e "\nImporting osm-vca"
572 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
573 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
574 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
575 echo -e "\nImporting osm-soui"
576 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
577 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
578 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
579 launch_container_from_lxd RO osm-ro
580 ro_is_up && track RO
581 launch_container_from_lxd VCA osm-vca
582 vca_is_up && track VCA
583 launch_container_from_lxd MON osm-mon
584 mon_is_up && track MON
585 launch_container_from_lxd SO osm-soui
586 #so_is_up && track SOUI
587 track SOUI
588}
589
590function install_docker_ce() {
591 # installs and configures Docker CE
592 echo "Installing Docker CE ..."
593 sudo apt-get -qq update
594 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
595 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
596 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
597 sudo apt-get -qq update
598 sudo apt-get install -y docker-ce
599 echo "Adding user to group 'docker'"
600 sudo groupadd -f docker
601 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200602 sleep 2
603 sudo service docker restart
604 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200605 sg docker -c "docker version" || FATAL "Docker installation failed"
606 echo "... Docker CE installation done"
607 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200608}
609
610function install_docker_compose() {
611 # installs and configures docker-compose
612 echo "Installing Docker Compose ..."
613 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
614 sudo chmod +x /usr/local/bin/docker-compose
615 echo "... Docker Compose installation done"
616}
617
618function install_juju() {
619 echo "Installing juju"
620 sudo snap install juju --classic
garciadeblasd41f5482018-05-25 10:25:06 +0200621 [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd
garciadeblasd8bc5c32018-05-09 17:37:56 +0200622 echo "Finished installation of juju"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400623 return 0
624}
625
626function juju_createcontroller() {
627 if ! sg lxd -c "juju show-controller $OSM_STACK_NAME &> /dev/null"; then
628 # Not found created, create the controller
629 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost $OSM_STACK_NAME"
630 fi
631 [ $(sg lxd -c "juju controllers" |grep "$OSM_STACK_NAME" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200632}
633
634function generate_docker_images() {
635 echo "Pulling and generating docker images"
Michael Marchettiee374142018-08-02 22:47:16 +0200636 _build_from=$COMMIT_ID
637 [ -z "$_build_from" ] && _build_from="master"
638
639 echo "OSM Docker images generated from $_build_from"
640
Mike Marchetti972947c2018-09-15 12:28:29 -0400641 BUILD_ARGS+=(--build-arg REPOSITORY="$REPOSITORY")
642 BUILD_ARGS+=(--build-arg RELEASE="$RELEASE")
643 BUILD_ARGS+=(--build-arg REPOSITORY_KEY="$REPOSITORY_KEY")
644 BUILD_ARGS+=(--build-arg REPOSITORY_BASE="$REPOSITORY_BASE")
645
garciadeblas0e596bc2018-05-28 16:04:42 +0200646 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
647 sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
648 sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
649 fi
650 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then
651 sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image"
652 fi
653 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then
654 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
655 git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID}
656 sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image"
657 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"
658 fi
659 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then
660 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
661 git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID}
662 sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image"
663 fi
664 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then
665 sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image"
666 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
667 git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID}
668 sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image"
669 fi
670 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then
671 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
672 git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID}
673 sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image"
674 fi
675 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then
676 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
677 git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID}
678 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"
679 fi
Mike Marchetti972947c2018-09-15 12:28:29 -0400680 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-osmclient; then
681 sg docker -c "docker build -t osm/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ."
682 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200683 echo "Finished generation of docker images"
684}
685
garciadeblas5b857d32018-05-24 18:37:58 +0200686function cmp_overwrite() {
687 file1="$1"
688 file2="$2"
689 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
690 if [ -f "${file2}" ]; then
Mike Marchetti67411aa2018-09-13 11:38:38 -0400691 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200692 else
Mike Marchetti67411aa2018-09-13 11:38:38 -0400693 cp -b ${file1} ${file2}
garciadeblas5b857d32018-05-24 18:37:58 +0200694 fi
695 fi
696}
697
garciadeblascf0e34a2018-05-24 10:45:53 +0200698function generate_config_log_folders() {
699 echo "Generating config and log folders"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400700 cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml
garciadeblascf0e34a2018-05-24 10:45:53 +0200701 echo "Finished generation of config and log folders"
702}
703
garciadeblasd8bc5c32018-05-09 17:37:56 +0200704function generate_docker_env_files() {
705 echo "Generating docker env files"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400706 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" | tee $OSM_DOCKER_WORK_DIR/lcm.env
707 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" | tee -a $OSM_DOCKER_WORK_DIR/lcm.env
708
garciadeblasd8bc5c32018-05-09 17:37:56 +0200709 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
Mike Marchetti67411aa2018-09-13 11:38:38 -0400710 if [ ! -f $OSM_DOCKER_WORK_DIR/ro-db.env ]; then
711 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro-db.env
garciadeblas5b857d32018-05-24 18:37:58 +0200712 fi
Mike Marchetti67411aa2018-09-13 11:38:38 -0400713 if [ ! -f $OSM_DOCKER_WORK_DIR/ro.env ]; then
714 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro.env
garciadeblas5b857d32018-05-24 18:37:58 +0200715 fi
Mike Marchetti67411aa2018-09-13 11:38:38 -0400716 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |tee $OSM_DOCKER_WORK_DIR/mon.env
Mike Marchetti972947c2018-09-15 12:28:29 -0400717
garciadeblasd8bc5c32018-05-09 17:37:56 +0200718 echo "Finished generation of docker env files"
719}
720
Mike Marchetti972947c2018-09-15 12:28:29 -0400721function generate_osmclient_script () {
722 cat >"$OSM_DOCKER_WORK_DIR/osm" <<-EOF
723 docker run -ti --network net${OSM_STACK_NAME} osm/osmclient
724 EOF
725 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 Marchetti972947c2018-09-15 12:28:29 -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}
Mike Marchetti67411aa2018-09-13 11:38:38 -0400744
Mike Marchetti972947c2018-09-15 12:28:29 -0400745function deploy_lightweight() {
746
747 echo "Deploying lightweight build"
Mike Marchetti67411aa2018-09-13 11:38:38 -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[@]}" > $OSM_DOCKER_WORK_DIR/osm_ports.sh
Mike Marchetti972947c2018-09-15 12:28:29 -0400762 echo "export OSM_NETWORK=net${OSM_STACK_NAME}" >> $OSM_DOCKER_WORK_DIR/osm_ports.sh
Mike Marchetti67411aa2018-09-13 11:38:38 -0400763
Mike Marchetti972947c2018-09-15 12:28:29 -0400764 pushd $OSM_DOCKER_WORK_DIR
Mike Marchetti67411aa2018-09-13 11:38:38 -0400765 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 -0400766 popd
Mike Marchetti67411aa2018-09-13 11:38:38 -0400767
garciadeblasd8bc5c32018-05-09 17:37:56 +0200768 echo "Finished deployment of lightweight build"
769}
770
garciadeblas6c66abf2018-05-16 14:46:19 +0200771function deploy_elk() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200772 echo "Pulling docker images for ELK"
773 sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
774 sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
775 sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
776 echo "Finished pulling elk docker images"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400777 mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk"
778 cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk
garciadeblas5b857d32018-05-24 18:37:58 +0200779 remove_stack osm_elk
garciadeblas6c66abf2018-05-16 14:46:19 +0200780 echo "Deploying ELK stack"
Mike Marchetti972947c2018-09-15 12:28:29 -0400781 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 +0200782 echo "Waiting for ELK stack to be up and running"
783 time=0
garciadeblase2aebfe2018-07-06 14:11:20 +0200784 step=5
785 timelength=40
garciadeblas6c66abf2018-05-16 14:46:19 +0200786 elk_is_up=1
787 while [ $time -le $timelength ]; do
garciadeblase2aebfe2018-07-06 14:11:20 +0200788 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 +0200789 elk_is_up=0
790 break
791 fi
792 sleep $step
793 time=$((time+step))
794 done
795 if [ $elk_is_up -eq 0 ]; then
796 echo "ELK is up and running. Trying to create index pattern..."
797 #Create index pattern
798 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200799 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200800 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200801 #Make it the default index
garciadeblase2aebfe2018-07-06 14:11:20 +0200802 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200803 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblase2aebfe2018-07-06 14:11:20 +0200804 -d"{\"value\":\"logstash-*\"}" 2>/dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200805 else
806 echo "Cannot connect to Kibana to create index pattern."
807 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
808 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200809 "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200810 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
811 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
garciadeblas5b857d32018-05-24 18:37:58 +0200812 "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
garciadeblas6c66abf2018-05-16 14:46:19 +0200813 -d"{\"value\":\"logstash-*\"}"'
814 fi
815 echo "Finished deployment of ELK stack"
816 return 0
817}
818
819function deploy_perfmon() {
garciadeblase2aebfe2018-07-06 14:11:20 +0200820 echo "Pulling docker images for PM (Grafana and Prometheus)"
821 sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
822 sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
823 echo "Finished pulling PM docker images"
garciadeblas6c66abf2018-05-16 14:46:19 +0200824 echo "Generating osm/kafka-exporter docker image"
garciadeblasc119fb32018-05-25 09:13:30 +0200825 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 +0200826 echo "Finished generation of osm/kafka-exporter docker image"
Mike Marchetti67411aa2018-09-13 11:38:38 -0400827 mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics
828 cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics
829 cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics
garciadeblas5b857d32018-05-24 18:37:58 +0200830 remove_stack osm_metrics
garciadeblas6c66abf2018-05-16 14:46:19 +0200831 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
Mike Marchetti972947c2018-09-15 12:28:29 -0400832 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 +0200833 echo "Finished deployment of PM stack"
834 return 0
835}
836
garciadeblasd8bc5c32018-05-09 17:37:56 +0200837function install_lightweight() {
Mike Marchetti67411aa2018-09-13 11:38:38 -0400838 [ -z "$OSM_DOCKER_WORK_DIR" ] && OSM_DOCKER_WORK_DIR="$HOME/.osm/stack/$OSM_STACK_NAME"
839 [ ! -d "$OSM_DOCKER_WORK_DIR" ] && mkdir -p $OSM_DOCKER_WORK_DIR
840
garciadeblasd13a8aa2018-05-18 15:24:51 +0200841 [ "$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 +0200842 [ -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 +0200843 track proceed
garciadeblasd8bc5c32018-05-09 17:37:56 +0200844 echo "Installing lightweight build of OSM"
845 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
846 trap 'rm -rf "${LWTEMPDIR}"' EXIT
847 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200848 [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200849 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas8cd60772018-06-02 08:38:17 +0200850 [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200851 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
Mike Marchetti67411aa2018-09-13 11:38:38 -0400852
853 # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to
854 if [ -z "$OSMLCM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ]; then
garciadeblasd41f5482018-05-25 10:25:06 +0200855 need_packages_lw="lxd"
856 echo -e "Checking required packages: $need_packages_lw"
857 dpkg -l $need_packages_lw &>/dev/null \
858 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
859 || sudo apt-get update \
860 || FATAL "failed to run apt-get update"
861 dpkg -l $need_packages_lw &>/dev/null \
862 || ! echo -e "Installing $need_packages_lw requires root privileges." \
863 || sudo apt-get install -y $need_packages_lw \
864 || FATAL "failed to install $need_packages_lw"
865 fi
garciadeblasfae5e972018-06-12 18:27:11 +0200866 track prereqok
Mike Marchetti67411aa2018-09-13 11:38:38 -0400867 [ -z "$INSTALL_NOJUJU" ] && install_juju
868
869 if [ -z "$OSMLCM_VCA_HOST" ]; then
870 juju_createcontroller
871 OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_STACK_NAME"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
872 [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
873 fi
874 if [ -z "$OSMLCM_VCA_SECRET" ]; then
875 OSMLCM_VCA_SECRET=$(parse_juju_password $OSM_STACK_NAME)
876 [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
877 fi
878
garciadeblas6c66abf2018-05-16 14:46:19 +0200879 track juju
garciadeblasa3e26612018-05-30 17:58:55 +0200880 [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200881 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200882 #install_docker_compose
Mike Marchetti67411aa2018-09-13 11:38:38 -0400883 [ -z "$DOCKER_NOBUILD" ] && generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200884 track docker_build
garciadeblasd8bc5c32018-05-09 17:37:56 +0200885 generate_docker_env_files
Mike Marchetti67411aa2018-09-13 11:38:38 -0400886 generate_config_log_folders
Mike Marchetti972947c2018-09-15 12:28:29 -0400887
888 [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
889 # remove old stack
890 remove_stack $OSM_STACK_NAME
891 create_docker_network
garciadeblasd8bc5c32018-05-09 17:37:56 +0200892 deploy_lightweight
Mike Marchetti972947c2018-09-15 12:28:29 -0400893 generate_osmclient_script
garciadeblas6c66abf2018-05-16 14:46:19 +0200894 track docker_deploy
895 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
896 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
897 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
Mike Marchetti972947c2018-09-15 12:28:29 -0400898 [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200899 track osmclient
900 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
901 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200902 return 0
903}
904
905function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200906 echo "\nInstalling vim-emu"
907 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
908 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200909 # clone vim-emu repository (attention: branch is currently master only)
910 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200911 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200912 # build vim-emu docker
913 echo "Building vim-emu Docker container..."
Mike Marchetti67411aa2018-09-13 11:38:38 -0400914
915 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 +0200916 # start vim-emu container as daemon
917 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200918 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
919 # in lightweight mode, the emulator needs to be attached to netOSM
Mike Marchetti972947c2018-09-15 12:28:29 -0400920 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 +0200921 else
922 # classic build mode
Mike Marchetti67411aa2018-09-13 11:38:38 -0400923 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 +0200924 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200925 echo "Waiting for 'vim-emu' container to start ..."
926 sleep 5
Mike Marchetti67411aa2018-09-13 11:38:38 -0400927 export VIMEMU_HOSTNAME=$(sg docker -c "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200928 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200929 # print vim-emu connection info
930 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200931 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200932 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200933 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
934}
935
936function dump_vars(){
937 echo "DEVELOP=$DEVELOP"
938 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
939 echo "UNINSTALL=$UNINSTALL"
940 echo "NAT=$NAT"
941 echo "UPDATE=$UPDATE"
942 echo "RECONFIGURE=$RECONFIGURE"
943 echo "TEST_INSTALLER=$TEST_INSTALLER"
944 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
945 echo "INSTALL_LXD=$INSTALL_LXD"
946 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
947 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
948 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
949 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200950 echo "INSTALL_ONLY=$INSTALL_ONLY"
951 echo "INSTALL_ELK=$INSTALL_ELK"
952 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblas0e596bc2018-05-28 16:04:42 +0200953 echo "TO_REBUILD=$TO_REBUILD"
garciadeblasd41f5482018-05-25 10:25:06 +0200954 echo "INSTALL_NOLXD=$INSTALL_NOLXD"
garciadeblasa3e26612018-05-30 17:58:55 +0200955 echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200956 echo "RELEASE=$RELEASE"
957 echo "REPOSITORY=$REPOSITORY"
958 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
959 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
960 echo "NOCONFIGURE=$NOCONFIGURE"
961 echo "SHOWOPTS=$SHOWOPTS"
962 echo "Install from specific refspec (-b): $COMMIT_ID"
963}
964
965function track(){
966 ctime=`date +%s`
967 duration=$((ctime - SESSION_ID))
968 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
969 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
970 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200971 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
972 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
973 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200974 event_name="${event_name}_$1"
975 url="${url}&event=${event_name}&ce_duration=${duration}"
976 wget -q -O /dev/null $url
977}
978
979UNINSTALL=""
980DEVELOP=""
981NAT=""
982UPDATE=""
983RECONFIGURE=""
984TEST_INSTALLER=""
985INSTALL_LXD=""
986SHOWOPTS=""
987COMMIT_ID=""
988ASSUME_YES=""
989INSTALL_FROM_SOURCE=""
Mike Marchetti972947c2018-09-15 12:28:29 -0400990RELEASE="ReleaseFOUR"
991REPOSITORY="stable"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200992INSTALL_VIMEMU=""
993INSTALL_FROM_LXDIMAGES=""
994LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
995LXD_REPOSITORY_PATH=""
996INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200997INSTALL_ONLY=""
998INSTALL_ELK=""
999INSTALL_PERFMON=""
garciadeblas0e596bc2018-05-28 16:04:42 +02001000TO_REBUILD=""
garciadeblasd41f5482018-05-25 10:25:06 +02001001INSTALL_NOLXD=""
garciadeblasa3e26612018-05-30 17:58:55 +02001002INSTALL_NODOCKER=""
Mike Marchetti67411aa2018-09-13 11:38:38 -04001003INSTALL_NOJUJU=""
garciadeblasd8bc5c32018-05-09 17:37:56 +02001004NOCONFIGURE=""
1005RELEASE_DAILY=""
1006SESSION_ID=`date +%s`
1007OSM_DEVOPS=
Mike Marchetti67411aa2018-09-13 11:38:38 -04001008OSMLCM_VCA_HOST=
1009OSMLCM_VCA_SECRET=
1010OSM_STACK_NAME=osm
1011NO_HOST_PORTS=""
1012DOCKER_NOBUILD=""
Mike Marchetti972947c2018-09-15 12:28:29 -04001013REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
1014REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001015
Mike Marchetti67411aa2018-09-13 11:38:38 -04001016while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +02001017 case "${o}" in
1018 h)
1019 usage && exit 0
1020 ;;
1021 b)
1022 COMMIT_ID=${OPTARG}
1023 ;;
1024 r)
Mike Marchetti972947c2018-09-15 12:28:29 -04001025 REPOSITORY="${OPTARG}"
1026 REPO_ARGS+=(-r "$REPOSITORY")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001027 ;;
1028 R)
Mike Marchetti972947c2018-09-15 12:28:29 -04001029 RELEASE="${OPTARG}"
1030 REPO_ARGS+=(-R "$RELEASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001031 ;;
1032 k)
Mike Marchetti972947c2018-09-15 12:28:29 -04001033 REPOSITORY_KEY="${OPTARG}"
1034 REPO_ARGS+=(-k "$REPOSITORY_KEY")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001035 ;;
1036 u)
Mike Marchetti972947c2018-09-15 12:28:29 -04001037 REPOSITORY_BASE="${OPTARG}"
1038 REPO_ARGS+=(-u "$REPOSITORY_BASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +02001039 ;;
1040 l)
1041 LXD_REPOSITORY_BASE="${OPTARG}"
1042 ;;
1043 p)
1044 LXD_REPOSITORY_PATH="${OPTARG}"
1045 ;;
1046 D)
1047 OSM_DEVOPS="${OPTARG}"
1048 ;;
Mike Marchetti67411aa2018-09-13 11:38:38 -04001049 s)
1050 OSM_STACK_NAME="${OPTARG}"
1051 ;;
1052 H)
1053 OSMLCM_VCA_HOST="${OPTARG}"
1054 ;;
1055 S)
1056 OSMLCM_VCA_SECRET="${OPTARG}"
1057 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +02001058 o)
1059 INSTALL_ONLY="y"
1060 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
1061 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1062 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
1063 ;;
garciadeblas0e596bc2018-05-28 16:04:42 +02001064 m)
1065 [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
1066 [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
1067 [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
1068 [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue
1069 [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
1070 [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
1071 [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
1072 [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
1073 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +02001074 -)
1075 [ "${OPTARG}" == "help" ] && usage && exit 0
1076 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
1077 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
1078 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
1079 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
1080 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
1081 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
1082 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
1083 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblasd41f5482018-05-25 10:25:06 +02001084 [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
garciadeblasa3e26612018-05-30 17:58:55 +02001085 [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001086 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
1087 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblase990f662018-05-18 11:43:39 +02001088 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001089 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +02001090 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
1091 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001092 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
1093 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
1094 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
Mike Marchetti67411aa2018-09-13 11:38:38 -04001095 [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue
1096 [ "${OPTARG}" == "nojuju" ] && INSTALL_NOJUJU="y" && continue
1097 [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue
Mike Marchetti972947c2018-09-15 12:28:29 -04001098 [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +02001099 echo -e "Invalid option: '--$OPTARG'\n" >&2
1100 usage && exit 1
1101 ;;
1102 \?)
1103 echo -e "Invalid option: '-$OPTARG'\n" >&2
1104 usage && exit 1
1105 ;;
1106 y)
1107 ASSUME_YES="y"
1108 ;;
1109 *)
1110 usage && exit 1
1111 ;;
1112 esac
1113done
1114
garciadeblas6c66abf2018-05-16 14:46:19 +02001115[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
garciadeblase990f662018-05-18 11:43:39 +02001116[ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui"
1117[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
garciadeblasfb566272018-05-25 10:33:36 +02001118[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
garciadeblasd41f5482018-05-25 10:25:06 +02001119[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
garciadeblasa3e26612018-05-30 17:58:55 +02001120[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
garciadeblas0e596bc2018-05-28 16:04:42 +02001121[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
1122[ -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 +02001123
garciadeblasd8bc5c32018-05-09 17:37:56 +02001124if [ -n "$SHOWOPTS" ]; then
1125 dump_vars
1126 exit 0
1127fi
1128
1129[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
1130
1131# if develop, we force master
1132[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
1133
garciadeblasd8bc5c32018-05-09 17:37:56 +02001134need_packages="git jq wget curl tar"
1135echo -e "Checking required packages: $need_packages"
1136dpkg -l $need_packages &>/dev/null \
1137 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
1138 || sudo apt-get update \
1139 || FATAL "failed to run apt-get update"
1140dpkg -l $need_packages &>/dev/null \
1141 || ! echo -e "Installing $need_packages requires root privileges." \
1142 || sudo apt-get install -y $need_packages \
1143 || FATAL "failed to install $need_packages"
1144
1145if [ -z "$OSM_DEVOPS" ]; then
Michael Marchettiee374142018-08-02 22:47:16 +02001146 if [ -n "$TEST_INSTALLER" ]; then
1147 echo -e "\nUsing local devops repo for OSM installation"
1148 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
1149 else
1150 echo -e "\nCreating temporary dir for OSM installation"
1151 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
1152 trap 'rm -rf "$OSM_DEVOPS"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +02001153
Michael Marchettiee374142018-08-02 22:47:16 +02001154 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
garciadeblasd8bc5c32018-05-09 17:37:56 +02001155
Michael Marchettiee374142018-08-02 22:47:16 +02001156 if [ -z "$COMMIT_ID" ]; then
1157 echo -e "\nGuessing the current stable release"
1158 LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1`
1159 [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
1160
1161 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
1162 COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
1163 else
1164 echo -e "\nDEVOPS Using commit $COMMIT_ID"
1165 fi
1166 git -C $OSM_DEVOPS checkout $COMMIT_ID
garciadeblasd8bc5c32018-05-09 17:37:56 +02001167 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +02001168fi
1169
1170OSM_JENKINS="$OSM_DEVOPS/jenkins"
1171. $OSM_JENKINS/common/all_funcs
1172
1173[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
1174[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
1175[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
1176[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
1177[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +02001178[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
1179[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
1180[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
1181[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +02001182
1183#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +02001184wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
1185track start
1186
garciadeblasd8bc5c32018-05-09 17:37:56 +02001187[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
1188echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
1189if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
1190 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
1191fi
1192
1193echo -e "Checking required packages: lxd"
1194lxd --version &>/dev/null || FATAL "lxd not present, exiting."
1195[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
1196
garciadeblasd8bc5c32018-05-09 17:37:56 +02001197# use local devops for containers
1198export OSM_USE_LOCAL_DEVOPS=true
1199if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
1200 echo -e "\nCreating the containers and building from source ..."
1201 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
1202 ro_is_up && track RO
1203 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
1204 vca_is_up && track VCA
1205 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
1206 mon_is_up && track MON
1207 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
1208 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
1209 #so_is_up && track SOUI
1210 track SOUI
1211elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
1212 echo -e "\nInstalling from lxd images ..."
1213 install_from_lxdimages
1214else #install from binaries
1215 echo -e "\nCreating the containers and installing from binaries ..."
Mike Marchetti972947c2018-09-15 12:28:29 -04001216 $OSM_DEVOPS/jenkins/host/install RO ${REPO_ARGS[@]} || FATAL "RO install failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001217 ro_is_up && track RO
1218 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
1219 vca_is_up && track VCA
1220 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
1221 mon_is_up && track MON
Mike Marchetti972947c2018-09-15 12:28:29 -04001222 $OSM_DEVOPS/jenkins/host/install SO ${REPO_ARGS[@]} || FATAL "SO install failed"
1223 $OSM_DEVOPS/jenkins/host/install UI ${REPO_ARGS[@]} || FATAL "UI install failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +02001224 #so_is_up && track SOUI
1225 track SOUI
1226fi
1227
1228#Install iptables-persistent and configure NAT rules
1229[ -z "$NOCONFIGURE" ] && nat
1230
1231#Configure components
1232[ -z "$NOCONFIGURE" ] && configure
1233
1234#Install osmclient
1235[ -z "$NOCONFIGURE" ] && install_osmclient
1236
1237#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +02001238[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +02001239
1240wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
1241track end
1242echo -e "\nDONE"
1243