blob: 7cdf8bc41102c5eedf12b93b10e885b475c06b34 [file] [log] [blame]
garciadeblas93c61312016-09-28 15:12:48 +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]"
garciadeblasa1fc4572017-04-24 19:08:21 +020018 echo -e "Install OSM from binaries or source code (by default, from binaries)"
garciadeblas93c61312016-09-28 15:12:48 +020019 echo -e " OPTIONS"
garciadeblas0d934c12017-11-17 15:39:17 +010020 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
21 echo -e " --source: install OSM from source code using the latest stable tag"
Mike Marchetti425f8ce2017-06-15 13:02:16 -040022 echo -e " -r <repo>: use specified repository name for osm packages"
garciadeblas0d934c12017-11-17 15:39:17 +010023 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
Mike Marchetti425f8ce2017-06-15 13:02:16 -040024 echo -e " -u <repo base>: use specified repository url for osm packages"
25 echo -e " -k <repo key>: use specified repository public key url"
garciadeblas0d934c12017-11-17 15:39:17 +010026 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
27 echo -e " -b master (main dev branch)"
28 echo -e " -b v2.0 (v2.0 branch)"
29 echo -e " -b tags/v1.1.0 (a specific tag)"
30 echo -e " ..."
31 echo -e " --lxdimages: download lxd images from OSM repository instead of creating them from scratch"
32 echo -e " -l <lxd_repo>: use specified repository url for lxd images"
garciadeblasfc8f0292018-04-02 16:55:29 +020033 echo -e " -p <path>: use specified repository path for lxd images"
garciadeblas661681a2018-05-09 15:42:19 +020034 echo -e " --lightweight: install lightweight build of OSM (default installation)"
35 echo -e " --soui: install classic build of OSM (based on LXD containers, with SO and UI)"
peustermd74dc842018-01-24 15:32:17 +010036 echo -e " --vimemu: additionally fetch, build, and deploy the VIM emulator as a docker container"
garciadeblas0d934c12017-11-17 15:39:17 +010037 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
38# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
39 echo -e " --nat: install only NAT rules"
40 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
41# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
42 echo -e " --showopts: print chosen options and exit (only for debugging)"
43 echo -e " -y: do not prompt for confirmation, assumes yes"
Mike Marchetti4de48492018-04-05 12:44:01 -040044 echo -e " -D <devops path> use local devops installation path"
garciadeblas0d934c12017-11-17 15:39:17 +010045 echo -e " -h / --help: print this help"
garciadeblas93c61312016-09-28 15:12:48 +020046}
47
garciadeblas55490d42016-10-29 14:22:03 +020048#Uninstall OSM: remove containers
49function uninstall(){
garciadeblasa1fc4572017-04-24 19:08:21 +020050 echo -e "\nUninstalling OSM"
garciadeblas55490d42016-10-29 14:22:03 +020051 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
52 $OSM_DEVOPS/jenkins/host/clean_container RO
53 $OSM_DEVOPS/jenkins/host/clean_container VCA
prithiv4a98a042017-12-05 23:19:39 +000054 $OSM_DEVOPS/jenkins/host/clean_container MON
garciadeblas55490d42016-10-29 14:22:03 +020055 $OSM_DEVOPS/jenkins/host/clean_container SO
56 #$OSM_DEVOPS/jenkins/host/clean_container UI
57 else
58 lxc stop RO && lxc delete RO
59 lxc stop VCA && lxc delete VCA
prithiv4a98a042017-12-05 23:19:39 +000060 lxc stop MON && lxc delete MON
garciadeblas55490d42016-10-29 14:22:03 +020061 lxc stop SO-ub && lxc delete SO-ub
62 fi
garciadeblas54e7eed2018-03-19 17:38:04 +010063 echo -e "\nDeleting imported lxd images if they exist"
64 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
65 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
66 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
garciadeblas429b9f82018-03-20 02:09:44 +010067 return 0
garciadeblas55490d42016-10-29 14:22:03 +020068}
69
garciadeblas831ee562018-04-30 10:02:21 +020070#Uninstall lightweight OSM: remove dockers
71function uninstall_lightweight(){
72 echo -e "\nUninstalling lightweight OSM"
73 docker stack rm osm
74 COUNTER=0
75 result=11
76 while [ ${COUNTER} -lt 30 ]; do
77 sleep 1
78 result=$(docker stack ps osm | wc -l)
79 #echo "Dockers running: $result"
80 if [ "${result}" == "0" ]; then
81 break
82 fi
83 let COUNTER=COUNTER+1
84 done
85 if [ "${result}" == "0" ]; then
86 echo "All dockers of the stack osm were removed"
87 else
88 FATAL "Some dockers of the stack osm could not be removed. Could not uninstall OSM in single shot. Try to uninstall again"
89 fi
90 sleep 5
91 docker image rm osm/ro
92 docker image rm osm/lcm
93 docker image rm osm/light-ui
94 docker image rm osm/nbi
95 docker image rm osm/mon
96 docker image rm osm/pm
97 return 0
98}
99
garciadeblas55490d42016-10-29 14:22:03 +0200100#Configure NAT rules, based on the current IP addresses of containers
101function nat(){
102 echo -e "\nChecking required packages: iptables-persistent"
103 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
104 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
105 echo -e "\nConfiguring NAT rules"
106 echo -e " Required root privileges"
107 sudo $OSM_DEVOPS/installers/nat_osm
108}
109
Mike Marchettid8577f52017-10-19 15:27:48 -0400110function FATAL(){
111 echo "FATAL error: Cannot install OSM due to \"$1\""
112 exit 1
113}
114
garciadeblas2a382732017-01-12 12:11:14 +0100115#Update RO, SO and UI:
116function update(){
117 echo -e "\nUpdating components"
118
119 echo -e " Updating RO"
120 CONTAINER="RO"
121 MDG="RO"
122 INSTALL_FOLDER="/opt/openmano"
123 echo -e " Fetching the repo"
124 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
125 BRANCH=""
126 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
Jokin Garayc17db012017-03-08 17:45:39 +0100127 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
garciadeblas2a382732017-01-12 12:11:14 +0100128 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
129 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
130 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
131 # COMMIT_ID either was previously set with -b option, or is an empty string
132 CHECKOUT_ID=$COMMIT_ID
133 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
134 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
135 if [[ $CHECKOUT_ID == "tags/"* ]]; then
136 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
137 else
138 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
139 fi
140 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
141 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
142 echo " Nothing to be done."
143 else
144 echo " Update required."
garciadeblasa1fc4572017-04-24 19:08:21 +0200145 lxc exec $CONTAINER -- service osm-ro stop
garciadeblas2a382732017-01-12 12:11:14 +0100146 lxc exec $CONTAINER -- git -C /opt/openmano stash
147 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
148 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
149 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
150 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
garciadeblasa1fc4572017-04-24 19:08:21 +0200151 lxc exec $CONTAINER -- service osm-ro start
garciadeblas2a382732017-01-12 12:11:14 +0100152 fi
153 echo
154
155 echo -e " Updating SO and UI"
156 CONTAINER="SO-ub"
157 MDG="SO"
158 INSTALL_FOLDER="" # To be filled in
159 echo -e " Fetching the repo"
160 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
161 BRANCH=""
162 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
Jokin Garayc17db012017-03-08 17:45:39 +0100163 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
garciadeblas2a382732017-01-12 12:11:14 +0100164 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
165 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
166 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
167 # COMMIT_ID either was previously set with -b option, or is an empty string
168 CHECKOUT_ID=$COMMIT_ID
169 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
170 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
171 if [[ $CHECKOUT_ID == "tags/"* ]]; then
172 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
173 else
174 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
175 fi
176 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
177 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
178 echo " Nothing to be done."
179 else
180 echo " Update required."
181 # Instructions to be added
182 # lxc exec SO-ub -- ...
183 fi
184 echo
prithiv4a98a042017-12-05 23:19:39 +0000185 echo -e "Updating MON Container"
186 CONTAINER="MON"
187 MDG="MON"
188 INSTALL_FOLDER="/root/MON"
189 echo -e " Fetching the repo"
190 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
191 BRANCH=""
192 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
193 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
194 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
195 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
196 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
197 # COMMIT_ID either was previously set with -b option, or is an empty string
198 CHECKOUT_ID=$COMMIT_ID
199 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
200 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
201 if [[ $CHECKOUT_ID == "tags/"* ]]; then
202 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
203 else
204 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
205 fi
206 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
207 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
208 echo " Nothing to be done."
209 else
210 echo " Update required."
211 fi
212 echo
garciadeblas2a382732017-01-12 12:11:14 +0100213}
214
Mike Marchetti2b951282017-10-10 15:43:15 -0400215function so_is_up() {
garciadeblas0d934c12017-11-17 15:39:17 +0100216 if [ -n "$1" ]; then
217 SO_IP=$1
218 else
219 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
220 fi
Mike Marchetti6930bc02017-05-31 16:33:02 -0400221 time=0
222 step=5
223 timelength=300
224 while [ $time -le $timelength ]
225 do
Mike Marchetti2b951282017-10-10 15:43:15 -0400226 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
227 -H 'accept: application/vnd.yang.data+json' \
228 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
229 -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 ]]
230 then
231 echo "RW.Restconf running....SO is up"
232 return 0
Mike Marchetti6930bc02017-05-31 16:33:02 -0400233 fi
Mike Marchetti2b951282017-10-10 15:43:15 -0400234
Mike Marchetti6930bc02017-05-31 16:33:02 -0400235 sleep $step
236 echo -n "."
237 time=$((time+step))
238 done
Mike Marchetti2b951282017-10-10 15:43:15 -0400239
garciadeblas0d934c12017-11-17 15:39:17 +0100240 FATAL "OSM Failed to startup. SO failed to startup"
Mike Marchetti6930bc02017-05-31 16:33:02 -0400241}
242
garciadeblas0d934c12017-11-17 15:39:17 +0100243function vca_is_up() {
244 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
245 echo "VCA is up and running"
246 return 0
247 fi
garciadeblas55490d42016-10-29 14:22:03 +0200248
garciadeblas0d934c12017-11-17 15:39:17 +0100249 FATAL "OSM Failed to startup. VCA failed to startup"
250}
251
prithiv4a98a042017-12-05 23:19:39 +0000252function mon_is_up() {
253 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
254 echo "MON is up and running"
255 return 0
256 fi
257
258 FATAL "OSM Failed to startup. MON failed to startup"
259}
260
garciadeblas0d934c12017-11-17 15:39:17 +0100261function ro_is_up() {
262 if [ -n "$1" ]; then
263 RO_IP=$1
264 else
265 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
266 fi
267 time=0
268 step=2
269 timelength=20
270 while [ $time -le $timelength ]; do
271 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
272 echo "RO is up and running"
273 return 0
274 fi
275 sleep $step
276 echo -n "."
277 time=$((time+step))
278 done
279
280 FATAL "OSM Failed to startup. RO failed to startup"
281}
282
283
284function configure_RO(){
285 . $OSM_DEVOPS/installers/export_ips
garciadeblas55490d42016-10-29 14:22:03 +0200286 echo -e " Configuring RO"
garciadeblasa1fc4572017-04-24 19:08:21 +0200287 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
288 lxc exec RO -- service osm-ro restart
Mike Marchetti6930bc02017-05-31 16:33:02 -0400289
garciadeblas0d934c12017-11-17 15:39:17 +0100290 ro_is_up
Mike Marchetti6930bc02017-05-31 16:33:02 -0400291
garciadeblasd8718f12016-10-30 19:39:01 +0100292 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
garciadeblas1b7107e2017-12-21 15:32:02 +0100293 lxc exec RO -- openmano tenant-create osm > /dev/null
prithiv4a98a042017-12-05 23:19:39 +0000294 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
tierno15f4f222017-06-14 13:23:01 +0200295 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
garciadeblas1b7107e2017-12-21 15:32:02 +0100296 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
garciadeblas0d934c12017-11-17 15:39:17 +0100297}
garciadeblas55490d42016-10-29 14:22:03 +0200298
garciadeblas0d934c12017-11-17 15:39:17 +0100299function configure_VCA(){
garciadeblas55490d42016-10-29 14:22:03 +0200300 echo -e " Configuring VCA"
301 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
302 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
garciadeblas0d934c12017-11-17 15:39:17 +0100303}
304
305function configure_SOUI(){
306 . $OSM_DEVOPS/installers/export_ips
garciadeblas55490d42016-10-29 14:22:03 +0200307 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
garciadeblas1b7107e2017-12-21 15:32:02 +0100308 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
garciadeblas55490d42016-10-29 14:22:03 +0200309
prithiv4a98a042017-12-05 23:19:39 +0000310 echo -e " Configuring MON"
311 #Information to be added about SO socket for logging
312
garciadeblas55490d42016-10-29 14:22:03 +0200313 echo -e " Configuring SO"
314 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas2f4c93b2017-04-10 18:12:12 +0200315 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
Jeremy Mordkoff5cc6ccc2017-10-05 15:21:07 -0400316 # make journaling persistent
317 lxc exec SO-ub -- mkdir -p /var/log/journal
318 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
319 lxc exec SO-ub -- systemctl restart systemd-journald
320
Jeremy Mordkoff3b3edea2017-10-03 16:21:56 -0400321 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
322
Mike Marchetti6930bc02017-05-31 16:33:02 -0400323 lxc exec SO-ub -- systemctl restart launchpad
garciadeblas55490d42016-10-29 14:22:03 +0200324
Mike Marchetti6930bc02017-05-31 16:33:02 -0400325 so_is_up $SO_CONTAINER_IP
326
327 #delete existing config agent (could be there on reconfigure)
328 curl -k --request DELETE \
329 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
330 --header 'accept: application/vnd.yang.data+json' \
331 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
332 --header 'cache-control: no-cache' \
333 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
334
335 result=$(curl -k --request POST \
garciadeblas55490d42016-10-29 14:22:03 +0200336 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
337 --header 'accept: application/vnd.yang.data+json' \
338 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
339 --header 'cache-control: no-cache' \
340 --header 'content-type: application/vnd.yang.data+json' \
Mike Marchetti6930bc02017-05-31 16:33:02 -0400341 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
342 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
garciadeblas55490d42016-10-29 14:22:03 +0200343
Mike Marchetti397a65d2017-10-02 22:36:16 -0400344 #R1/R2 config line
345 #result=$(curl -k --request PUT \
346 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
347 # --header 'accept: application/vnd.yang.data+json' \
348 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
349 # --header 'cache-control: no-cache' \
350 # --header 'content-type: application/vnd.yang.data+json' \
351 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
352
Mike Marchetti6930bc02017-05-31 16:33:02 -0400353 result=$(curl -k --request PUT \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400354 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
garciadeblas55490d42016-10-29 14:22:03 +0200355 --header 'accept: application/vnd.yang.data+json' \
356 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400357 --header 'cache-control: no-cache' \
garciadeblas55490d42016-10-29 14:22:03 +0200358 --header 'content-type: application/vnd.yang.data+json' \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400359 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
Mike Marchetti6930bc02017-05-31 16:33:02 -0400360 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
Jeremy Mordkoff2059b392017-10-03 17:34:10 -0400361
Jeremy Mordkoff34151f22017-10-04 19:45:37 -0400362 result=$(curl -k --request PATCH \
363 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
364 --header 'accept: application/vnd.yang.data+json' \
365 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
366 --header 'cache-control: no-cache' \
367 --header 'content-type: application/vnd.yang.data+json' \
368 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
369 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
370
371 result=$(curl -k --request PATCH \
372 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
373 --header 'accept: application/vnd.yang.data+json' \
374 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
375 --header 'cache-control: no-cache' \
376 --header 'content-type: application/vnd.yang.data+json' \
377 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
378 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
379
Jeremy Mordkofff4b6e622017-10-04 12:05:41 -0400380 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
381auto lo:1
prithiv4a98a042017-12-05 23:19:39 +0000382iface lo:1 inet static
Jeremy Mordkofff4b6e622017-10-04 12:05:41 -0400383 address $DEFAULT_IP
384 netmask 255.255.255.255
385EOF
386 lxc exec SO-ub ifup lo:1
garciadeblas0d934c12017-11-17 15:39:17 +0100387}
Jeremy Mordkoff2059b392017-10-03 17:34:10 -0400388
garciadeblas0d934c12017-11-17 15:39:17 +0100389#Configure RO, VCA, and SO with the initial configuration:
390# RO -> tenant:osm, logs to be sent to SO
391# VCA -> juju-password
392# SO -> route to Juju Controller, add RO account, add VCA account
393function configure(){
394 #Configure components
395 echo -e "\nConfiguring components"
396 configure_RO
397 configure_VCA
398 configure_SOUI
garciadeblas55490d42016-10-29 14:22:03 +0200399}
400
garciadeblas2a5a6512016-12-19 10:19:52 +0100401function install_lxd() {
garciadeblas0d934c12017-11-17 15:39:17 +0100402 sudo apt-get update
403 sudo apt-get install -y lxd
404 newgrp lxd
garciadeblas2a5a6512016-12-19 10:19:52 +0100405 lxd init --auto
406 lxd waitready
garciadeblas0d934c12017-11-17 15:39:17 +0100407 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
408 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
garciadeblas749af852018-04-19 18:43:50 +0200409 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
garciadeblas0d934c12017-11-17 15:39:17 +0100410 lxc profile device set default eth0 mtu $DEFAULT_MTU
411 #sudo systemctl stop lxd-bridge
412 #sudo systemctl --system daemon-reload
413 #sudo systemctl enable lxd-bridge
414 #sudo systemctl start lxd-bridge
garciadeblas2a5a6512016-12-19 10:19:52 +0100415}
416
tierno53881d72017-04-25 11:58:57 +0200417function ask_user(){
418 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
419 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
420 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
421 read -e -p "$1" USER_CONFIRMATION
422 while true ; do
423 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
424 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
425 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
426 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
427 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
428 done
429}
garciadeblas2a5a6512016-12-19 10:19:52 +0100430
garciadeblas0d934c12017-11-17 15:39:17 +0100431function launch_container_from_lxd(){
432 export OSM_MDG=$1
433 OSM_load_config
434 export OSM_BASE_IMAGE=$2
435 if ! container_exists $OSM_BUILD_CONTAINER; then
436 CONTAINER_OPTS=""
437 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
438 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
439 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
440 wait_container_up $OSM_BUILD_CONTAINER
441 fi
442}
443
444function install_osmclient(){
445 CLIENT_RELEASE=${RELEASE#"-R "}
446 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
garciadeblasa9ef0992018-04-19 11:18:06 +0200447 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
garciadeblas0d934c12017-11-17 15:39:17 +0100448 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
449 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
450 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
451 curl $key_location | sudo apt-key add -
452 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
453 sudo apt-get update
garciadeblas8db0ffd2018-04-20 11:56:34 +0200454 sudo apt-get install -y python-pip
455 sudo -H pip install pip==9.0.3
456 sudo -H pip install python-magic
garciadeblas0d934c12017-11-17 15:39:17 +0100457 sudo apt-get install -y python-osmclient
garciadeblasb7d8d802018-04-18 16:39:17 +0200458 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
459 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
460 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
garciadeblasfeef8872018-04-19 13:35:25 +0200461 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
462 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
463 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=localhost
garciadeblas0d934c12017-11-17 15:39:17 +0100464 echo -e "\nOSM client installed"
465 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
466 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
garciadeblasb7d8d802018-04-18 16:39:17 +0200467 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
468 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
469 return 0
garciadeblas0d934c12017-11-17 15:39:17 +0100470}
471
472function install_from_lxdimages(){
473 LXD_RELEASE=${RELEASE#"-R "}
garciadeblasfc8f0292018-04-02 16:55:29 +0200474 if [ -n "$LXD_REPOSITORY_PATH" ]; then
475 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
476 else
477 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
478 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
479 fi
garciadeblas54e7eed2018-03-19 17:38:04 +0100480 echo -e "\nDeleting previous lxd images if they exist"
481 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
482 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
483 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
484 echo -e "\nImporting osm-ro"
garciadeblasfc8f0292018-04-02 16:55:29 +0200485 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
garciadeblas0d934c12017-11-17 15:39:17 +0100486 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
487 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
garciadeblas54e7eed2018-03-19 17:38:04 +0100488 echo -e "\nImporting osm-vca"
garciadeblasfc8f0292018-04-02 16:55:29 +0200489 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
garciadeblas0d934c12017-11-17 15:39:17 +0100490 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
491 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
garciadeblas54e7eed2018-03-19 17:38:04 +0100492 echo -e "\nImporting osm-soui"
garciadeblasfc8f0292018-04-02 16:55:29 +0200493 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
garciadeblas0d934c12017-11-17 15:39:17 +0100494 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
495 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
496 launch_container_from_lxd RO osm-ro
497 ro_is_up && track RO
498 launch_container_from_lxd VCA osm-vca
499 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000500 launch_container_from_lxd MON osm-mon
501 mon_is_up && track MON
garciadeblas0d934c12017-11-17 15:39:17 +0100502 launch_container_from_lxd SO osm-soui
503 #so_is_up && track SOUI
504 track SOUI
505}
506
peusterm3a3e7a52017-12-22 13:10:54 +0100507function install_docker_ce() {
508 # installs and configures Docker CE
509 echo "Installing Docker CE ..."
peusterme2c017e2018-02-07 11:51:11 +0100510 sudo apt-get -qq update
511 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
peusterm3a3e7a52017-12-22 13:10:54 +0100512 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
513 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
514 sudo apt-get -qq update
peusterme2c017e2018-02-07 11:51:11 +0100515 sudo apt-get install -y docker-ce
peusterm3a3e7a52017-12-22 13:10:54 +0100516 echo "Adding user to group 'docker'"
peusterme2c017e2018-02-07 11:51:11 +0100517 sudo groupadd -f docker
peusterm3a3e7a52017-12-22 13:10:54 +0100518 sudo usermod -aG docker $USER
519 echo "... Docker CE installation done"
peusterme2c017e2018-02-07 11:51:11 +0100520 sleep 2
521 sudo service docker restart
522 echo "... restarted Docker service"
peusterm3a3e7a52017-12-22 13:10:54 +0100523}
524
garciadeblas41012602018-04-23 17:23:35 +0200525function install_docker_compose() {
526 # installs and configures docker-compose
527 echo "Installing Docker Compose ..."
528 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
529 sudo chmod +x /usr/local/bin/docker-compose
530 echo "... Docker Compose installation done"
531}
532
garciadeblas14097dc2018-04-04 18:36:32 +0200533function install_juju() {
534 echo "Installing juju"
535 sudo snap install juju --classic
536 sudo dpkg-reconfigure -p medium lxd
garciadeblasdb797322018-05-04 11:03:31 +0200537 sg lxd -c "juju bootstrap localhost osm"
garciadeblas14097dc2018-04-04 18:36:32 +0200538 echo "Finished installation of juju"
539}
540
541function generate_docker_images() {
542 echo "Pulling and generating docker images"
543 newgrp docker << EONG
544 docker pull wurstmeister/kafka
545 docker pull wurstmeister/zookeeper
546 docker pull mongo
garciadeblas41012602018-04-23 17:23:35 +0200547 docker pull mysql:5
garciadeblas14097dc2018-04-04 18:36:32 +0200548 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
549 docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon || ! echo "cannot build MON docker image" >&2
550 docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm || ! echo "cannot build PM docker image" >&2
551 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
Mike Marchetti00b76aa2018-04-18 14:09:50 -0400552 docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2
garciadeblas14097dc2018-04-04 18:36:32 +0200553 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
554 docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2
555 docker build ${LWTEMPDIR}/RO/lcm -t osm/lcm || ! echo "cannot build LCM docker image" >&2
556 git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git
557 docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile
garciadeblas131fa742018-05-08 18:29:43 +0200558# git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
559# docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile
garciadeblas14097dc2018-04-04 18:36:32 +0200560EONG
561 echo "Finished generation of docker images"
562}
563
garciadeblas46e99592018-04-16 13:32:02 +0200564function generate_docker_env_files() {
565 echo "Generating docker env files"
566 OSMLCM_VCA_HOST=`juju show-controller|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
garciadeblas7077be62018-05-03 15:06:24 +0200567 OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
garciadeblas46e99592018-04-16 13:32:02 +0200568 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
garciadeblas5de942e2018-04-19 15:25:23 +0200569 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee ${OSM_DEVOPS}/installers/docker/lcm.env
570 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a ${OSM_DEVOPS}/installers/docker/lcm.env
571 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro-db.env
572 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro.env
573 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env
garciadeblas46e99592018-04-16 13:32:02 +0200574 echo "Finished generation of docker env files"
575}
576
garciadeblas14097dc2018-04-04 18:36:32 +0200577function deploy_lightweight() {
578 echo "Deploying lightweight build"
gcalvinoa40dfaf2018-05-07 10:31:04 +0200579 if [ "${DEFAULT_MTU}" != "1500" ]; then
580 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
581 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";}'`
582 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"
583 fi
garciadeblas14097dc2018-04-04 18:36:32 +0200584 newgrp docker << EONG
garciadeblas46e99592018-04-16 13:32:02 +0200585 docker swarm init --advertise-addr ${DEFAULT_IP}
garciadeblas749af852018-04-19 18:43:50 +0200586 docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM
garciadeblas46e99592018-04-16 13:32:02 +0200587 docker stack deploy -c ${OSM_DEVOPS}/installers/docker/docker-compose.yaml osm
garciadeblas41012602018-04-23 17:23:35 +0200588 #docker-compose -f /usr/share/osm-devops/installers/docker/docker-compose.yaml up -d
garciadeblas14097dc2018-04-04 18:36:32 +0200589EONG
590 echo "Finished deployment of lightweight build"
591}
592
garciadeblas14097dc2018-04-04 18:36:32 +0200593function install_lightweight() {
594 echo "Installing lightweight build of OSM"
595 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
garciadeblas46e99592018-04-16 13:32:02 +0200596 trap 'rm -rf "${LWTEMPDIR}"' EXIT
597 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
598 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas749af852018-04-19 18:43:50 +0200599 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
garciadeblas63ac9022018-05-03 11:49:00 +0200600 need_packages_lw="lxd"
601 echo -e "Checking required packages: $need_packages_lw"
602 dpkg -l $need_packages_lw &>/dev/null \
603 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
604 || sudo apt-get update \
605 || FATAL "failed to run apt-get update"
606 dpkg -l $need_packages_lw &>/dev/null \
607 || ! echo -e "Installing $need_packages_lw requires root privileges." \
608 || sudo apt-get install -y $need_packages_lw \
609 || FATAL "failed to install $need_packages_lw"
garciadeblas14097dc2018-04-04 18:36:32 +0200610 install_juju
611 install_docker_ce
garciadeblas41012602018-04-23 17:23:35 +0200612 #install_docker_compose
garciadeblas14097dc2018-04-04 18:36:32 +0200613 generate_docker_images
garciadeblas46e99592018-04-16 13:32:02 +0200614 generate_docker_env_files
garciadeblas14097dc2018-04-04 18:36:32 +0200615 deploy_lightweight
garciadeblasb7d8d802018-04-18 16:39:17 +0200616 install_osmclient
617 return 0
garciadeblas14097dc2018-04-04 18:36:32 +0200618}
619
peusterm3a3e7a52017-12-22 13:10:54 +0100620function install_vimemu() {
621 # install Docker
622 install_docker_ce
623 # clone vim-emu repository (attention: branch is currently master only)
624 echo "Cloning vim-emu repository ..."
625 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git
626 # build vim-emu docker
627 echo "Building vim-emu Docker container..."
peusterme2c017e2018-02-07 11:51:11 +0100628 sudo docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
peusterm3a3e7a52017-12-22 13:10:54 +0100629 # start vim-emu container as daemon
630 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterme2c017e2018-02-07 11:51:11 +0100631 sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
peusterm3a3e7a52017-12-22 13:10:54 +0100632 echo "Waiting for 'vim-emu' container to start ..."
633 sleep 5
peusterme2c017e2018-02-07 11:51:11 +0100634 export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
garciadeblas46e99592018-04-16 13:32:02 +0200635 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peustermd74dc842018-01-24 15:32:17 +0100636 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
637 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
638 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
639 echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:"
peusterm3a3e7a52017-12-22 13:10:54 +0100640 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
641 echo -e "\nTo add the emulated VIM to OSM you should do:"
garciadeblas46e99592018-04-16 13:32:02 +0200642 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
peusterm3a3e7a52017-12-22 13:10:54 +0100643}
644
garciadeblas0d934c12017-11-17 15:39:17 +0100645function dump_vars(){
646 echo "DEVELOP=$DEVELOP"
647 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
648 echo "UNINSTALL=$UNINSTALL"
649 echo "NAT=$NAT"
650 echo "UPDATE=$UPDATE"
651 echo "RECONFIGURE=$RECONFIGURE"
652 echo "TEST_INSTALLER=$TEST_INSTALLER"
peusterm3a3e7a52017-12-22 13:10:54 +0100653 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
garciadeblas0d934c12017-11-17 15:39:17 +0100654 echo "INSTALL_LXD=$INSTALL_LXD"
655 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
656 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
garciadeblasfc8f0292018-04-02 16:55:29 +0200657 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
garciadeblas14097dc2018-04-04 18:36:32 +0200658 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas0d934c12017-11-17 15:39:17 +0100659 echo "RELEASE=$RELEASE"
660 echo "REPOSITORY=$REPOSITORY"
661 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
662 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
663 echo "NOCONFIGURE=$NOCONFIGURE"
664 echo "SHOWOPTS=$SHOWOPTS"
665 echo "Install from specific refspec (-b): $COMMIT_ID"
666}
667
668function track(){
669 ctime=`date +%s`
670 duration=$((ctime - SESSION_ID))
671 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
672 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
673 event_name="bin"
674 [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src"
675 [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
676 event_name="${event_name}_$1"
677 url="${url}&event=${event_name}&ce_duration=${duration}"
678 wget -q -O /dev/null $url
679}
680
garciadeblas93c61312016-09-28 15:12:48 +0200681UNINSTALL=""
682DEVELOP=""
683NAT=""
garciadeblas2a382732017-01-12 12:11:14 +0100684UPDATE=""
garciadeblas55490d42016-10-29 14:22:03 +0200685RECONFIGURE=""
686TEST_INSTALLER=""
garciadeblas0d934c12017-11-17 15:39:17 +0100687INSTALL_LXD=""
garciadeblas2a5a6512016-12-19 10:19:52 +0100688SHOWOPTS=""
689COMMIT_ID=""
tierno2cc8e252017-03-08 17:12:05 +0100690ASSUME_YES=""
garciadeblasa1fc4572017-04-24 19:08:21 +0200691INSTALL_FROM_SOURCE=""
garciadeblas82442292017-11-16 14:48:12 +0100692RELEASE="-R ReleaseTHREE"
garciadeblasa9ef0992018-04-19 11:18:06 +0200693REPOSITORY="-r stable"
peusterm3a3e7a52017-12-22 13:10:54 +0100694INSTALL_VIMEMU=""
garciadeblas0d934c12017-11-17 15:39:17 +0100695INSTALL_FROM_LXDIMAGES=""
696LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
garciadeblasfc8f0292018-04-02 16:55:29 +0200697LXD_REPOSITORY_PATH=""
garciadeblas661681a2018-05-09 15:42:19 +0200698INSTALL_LIGHTWEIGHT="y"
garciadeblas0d934c12017-11-17 15:39:17 +0100699NOCONFIGURE=""
Mike Marchettica56c642017-12-16 16:04:52 -0500700RELEASE_DAILY=""
garciadeblas0d934c12017-11-17 15:39:17 +0100701SESSION_ID=`date +%s`
Mike Marchetti4de48492018-04-05 12:44:01 -0400702OSM_DEVOPS=
garciadeblas0d934c12017-11-17 15:39:17 +0100703
Mike Marchetti4de48492018-04-05 12:44:01 -0400704while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
garciadeblas93c61312016-09-28 15:12:48 +0200705 case "${o}" in
706 h)
707 usage && exit 0
708 ;;
garciadeblas2a5a6512016-12-19 10:19:52 +0100709 b)
710 COMMIT_ID=${OPTARG}
711 ;;
Mike Marchetti425f8ce2017-06-15 13:02:16 -0400712 r)
713 REPOSITORY="-r ${OPTARG}"
714 ;;
715 R)
716 RELEASE="-R ${OPTARG}"
717 ;;
718 k)
719 REPOSITORY_KEY="-k ${OPTARG}"
720 ;;
721 u)
722 REPOSITORY_BASE="-u ${OPTARG}"
723 ;;
garciadeblas0d934c12017-11-17 15:39:17 +0100724 l)
725 LXD_REPOSITORY_BASE="${OPTARG}"
726 ;;
garciadeblasfc8f0292018-04-02 16:55:29 +0200727 p)
728 LXD_REPOSITORY_PATH="${OPTARG}"
729 ;;
Mike Marchetti4de48492018-04-05 12:44:01 -0400730 D)
731 OSM_DEVOPS="${OPTARG}"
732 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200733 -)
734 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblasa1fc4572017-04-24 19:08:21 +0200735 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200736 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
737 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
738 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
garciadeblas2a382732017-01-12 12:11:14 +0100739 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
garciadeblas55490d42016-10-29 14:22:03 +0200740 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
741 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
garciadeblas0d934c12017-11-17 15:39:17 +0100742 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
743 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
garciadeblas14097dc2018-04-04 18:36:32 +0200744 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblas661681a2018-05-09 15:42:19 +0200745 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && && continue
peusterm3a3e7a52017-12-22 13:10:54 +0100746 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas0d934c12017-11-17 15:39:17 +0100747 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
garciadeblas2a5a6512016-12-19 10:19:52 +0100748 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
Mike Marchettica56c642017-12-16 16:04:52 -0500749 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200750 echo -e "Invalid option: '--$OPTARG'\n" >&2
751 usage && exit 1
752 ;;
753 \?)
754 echo -e "Invalid option: '-$OPTARG'\n" >&2
755 usage && exit 1
756 ;;
tierno2cc8e252017-03-08 17:12:05 +0100757 y)
758 ASSUME_YES="y"
759 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200760 *)
761 usage && exit 1
762 ;;
763 esac
764done
765
garciadeblasa6ff9862017-04-07 02:00:29 +0200766if [ -n "$SHOWOPTS" ]; then
garciadeblas0d934c12017-11-17 15:39:17 +0100767 dump_vars
garciadeblasa6ff9862017-04-07 02:00:29 +0200768 exit 0
769fi
770
Mike Marchettica56c642017-12-16 16:04:52 -0500771[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
772
Mike Marchetti6930bc02017-05-31 16:33:02 -0400773# if develop, we force master
garciadeblas2a5a6512016-12-19 10:19:52 +0100774[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
Mike Marchetti6930bc02017-05-31 16:33:02 -0400775
Mike Marchetti0d567602017-09-29 14:30:28 -0400776# forcing source from master removed. Now only install from source when explicit
777# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
garciadeblas2a5a6512016-12-19 10:19:52 +0100778
Mike Marchetti4de48492018-04-05 12:44:01 -0400779if [ -z "$OSM_DEVOPS" ]; then
780 if [ -n "$TEST_INSTALLER" ]; then
781 echo -e "\nUsing local devops repo for OSM installation"
782 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
783 else
784 echo -e "\nCreating temporary dir for OSM installation"
785 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
786 trap 'rm -rf "$TEMPDIR"' EXIT
787 fi
garciadeblas55490d42016-10-29 14:22:03 +0200788fi
garciadeblas93c61312016-09-28 15:12:48 +0200789
garciadeblas14097dc2018-04-04 18:36:32 +0200790need_packages="git jq wget curl tar"
791echo -e "Checking required packages: $need_packages"
792dpkg -l $need_packages &>/dev/null \
793 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
794 || sudo apt-get update \
795 || FATAL "failed to run apt-get update"
796dpkg -l $need_packages &>/dev/null \
797 || ! echo -e "Installing $need_packages requires root privileges." \
798 || sudo apt-get install -y $need_packages \
799 || FATAL "failed to install $need_packages"
Mike Marchetti2b951282017-10-10 15:43:15 -0400800
Mike Marchetti4de48492018-04-05 12:44:01 -0400801if [ -z "$OSM_DEVOPS" ]; then
802 if [ -z "$TEST_INSTALLER" ]; then
803 echo -e "\nCloning devops repo temporarily"
804 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
805 RC_CLONE=$?
806 fi
807
808 echo -e "\nGuessing the current stable release"
809 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
810 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
811 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
812 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
813
814 if [ -n "$RELEASE_DAILY" ]; then
815 echo "Using master/HEAD devops"
816 git -C $TEMPDIR checkout master
817 elif [ -z "$TEST_INSTALLER" ]; then
818 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
819 fi
820 OSM_DEVOPS=$TEMPDIR
garciadeblas55490d42016-10-29 14:22:03 +0200821fi
garciadeblas2a382732017-01-12 12:11:14 +0100822
Mike Marchetti4de48492018-04-05 12:44:01 -0400823OSM_JENKINS="$OSM_DEVOPS/jenkins"
garciadeblas0fe45dd2016-10-04 07:54:17 +0200824. $OSM_JENKINS/common/all_funcs
garciadeblas93c61312016-09-28 15:12:48 +0200825
garciadeblas831ee562018-04-30 10:02:21 +0200826[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
garciadeblasd8718f12016-10-30 19:39:01 +0100827[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
828[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
garciadeblas2a382732017-01-12 12:11:14 +0100829[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
garciadeblasd8718f12016-10-30 19:39:01 +0100830[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas93c61312016-09-28 15:12:48 +0200831
832#Installation starts here
garciadeblas14097dc2018-04-04 18:36:32 +0200833[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
garciadeblasa1fc4572017-04-24 19:08:21 +0200834echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
prithiv4a98a042017-12-05 23:19:39 +0000835if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
tierno53881d72017-04-25 11:58:57 +0200836 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
tierno2cc8e252017-03-08 17:12:05 +0100837fi
838
Jokin Garayc0a65962017-03-09 14:51:48 +0100839echo -e "Checking required packages: lxd"
garciadeblasd880f722017-04-07 20:14:57 +0200840lxd --version &>/dev/null || FATAL "lxd not present, exiting."
garciadeblas0d934c12017-11-17 15:39:17 +0100841[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
garciadeblas2a5a6512016-12-19 10:19:52 +0100842
Mike Marchetti02a533a2018-04-05 21:23:33 -0400843wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
garciadeblas0d934c12017-11-17 15:39:17 +0100844track start
garciadeblas93c61312016-09-28 15:12:48 +0200845
Mike Marchettid1e08b92017-09-29 16:14:11 -0400846# use local devops for containers
847export OSM_USE_LOCAL_DEVOPS=true
garciadeblas0d934c12017-11-17 15:39:17 +0100848if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
garciadeblasa1fc4572017-04-24 19:08:21 +0200849 echo -e "\nCreating the containers and building from source ..."
850 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
garciadeblas0d934c12017-11-17 15:39:17 +0100851 ro_is_up && track RO
garciadeblasa1fc4572017-04-24 19:08:21 +0200852 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
garciadeblas0d934c12017-11-17 15:39:17 +0100853 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000854 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
855 mon_is_up && track MON
garciadeblasa1fc4572017-04-24 19:08:21 +0200856 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
857 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
garciadeblas0d934c12017-11-17 15:39:17 +0100858 #so_is_up && track SOUI
859 track SOUI
860elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
861 echo -e "\nInstalling from lxd images ..."
862 install_from_lxdimages
863else #install from binaries
864 echo -e "\nCreating the containers and installing from binaries ..."
865 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
866 ro_is_up && track RO
867 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
868 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000869 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
870 mon_is_up && track MON
garciadeblas0d934c12017-11-17 15:39:17 +0100871 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
872 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
873 #so_is_up && track SOUI
874 track SOUI
garciadeblasa1fc4572017-04-24 19:08:21 +0200875fi
garciadeblas93c61312016-09-28 15:12:48 +0200876
garciadeblas55490d42016-10-29 14:22:03 +0200877#Install iptables-persistent and configure NAT rules
garciadeblas0d934c12017-11-17 15:39:17 +0100878[ -z "$NOCONFIGURE" ] && nat
garciadeblas93c61312016-09-28 15:12:48 +0200879
880#Configure components
garciadeblas0d934c12017-11-17 15:39:17 +0100881[ -z "$NOCONFIGURE" ] && configure
882
883#Install osmclient
884[ -z "$NOCONFIGURE" ] && install_osmclient
garciadeblas93c61312016-09-28 15:12:48 +0200885
peusterm3a3e7a52017-12-22 13:10:54 +0100886#Install vim-emu (optional)
887if [ -n "$INSTALL_VIMEMU" ]; then
888 echo -e "\nInstalling vim-emu ..."
889 install_vimemu
890fi
891
Mike Marchetti02a533a2018-04-05 21:23:33 -0400892wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
garciadeblas0d934c12017-11-17 15:39:17 +0100893track end
Jokin Garay3eb9ce72017-03-09 14:48:11 +0100894echo -e "\nDONE"
garciadeblas0d934c12017-11-17 15:39:17 +0100895