2 # Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 echo -e "usage: $0 [OPTIONS]"
18 echo -e "Install OSM from binaries or source code (by default, from binaries)"
20 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"
22 echo -e " -r <repo>: use specified repository name for osm packages"
23 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
24 echo -e " -u <repo base>: use specified repository url for osm packages"
25 echo -e " -k <repo key>: use specified repository public key url"
26 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)"
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"
33 echo -e " -p <path>: use specified repository path for lxd images"
34 echo -e " --lightweight: install lightweight build of OSM"
35 echo -e " --vimemu: additionally fetch, build, and deploy the VIM emulator as a docker container"
36 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
37 # echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
38 echo -e " --nat: install only NAT rules"
39 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
40 # echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
41 echo -e " --showopts: print chosen options and exit (only for debugging)"
42 echo -e " -y: do not prompt for confirmation, assumes yes"
43 echo -e " -D <devops path> use local devops installation path"
44 echo -e " -h / --help: print this help"
47 #Uninstall OSM: remove containers
49 echo -e "\nUninstalling OSM"
50 if [ $RC_CLONE ] ||
[ -n "$TEST_INSTALLER" ]; then
51 $OSM_DEVOPS/jenkins
/host
/clean_container RO
52 $OSM_DEVOPS/jenkins
/host
/clean_container VCA
53 $OSM_DEVOPS/jenkins
/host
/clean_container MON
54 $OSM_DEVOPS/jenkins
/host
/clean_container SO
55 #$OSM_DEVOPS/jenkins/host/clean_container UI
57 lxc stop RO
&& lxc delete RO
58 lxc stop VCA
&& lxc delete VCA
59 lxc stop MON
&& lxc delete MON
60 lxc stop SO-ub
&& lxc delete SO-ub
62 echo -e "\nDeleting imported lxd images if they exist"
63 lxc image show osm-ro
&>/dev
/null
&& lxc image delete osm-ro
64 lxc image show osm-vca
&>/dev
/null
&& lxc image delete osm-vca
65 lxc image show osm-soui
&>/dev
/null
&& lxc image delete osm-soui
69 #Configure NAT rules, based on the current IP addresses of containers
71 echo -e "\nChecking required packages: iptables-persistent"
72 dpkg
-l iptables-persistent
&>/dev
/null ||
! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
73 sudo DEBIAN_FRONTEND
=noninteractive apt-get
-yq install iptables-persistent
74 echo -e "\nConfiguring NAT rules"
75 echo -e " Required root privileges"
76 sudo
$OSM_DEVOPS/installers
/nat_osm
80 echo "FATAL error: Cannot install OSM due to \"$1\""
84 #Update RO, SO and UI:
86 echo -e "\nUpdating components"
88 echo -e " Updating RO"
91 INSTALL_FOLDER
="/opt/openmano"
92 echo -e " Fetching the repo"
93 lxc
exec $CONTAINER -- git
-C $INSTALL_FOLDER fetch
--all
95 BRANCH
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
96 [ -z "$BRANCH" ] && FATAL
"Could not find the current branch in use in the '$MDG'"
97 CURRENT
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
98 CURRENT_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
99 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
100 # COMMIT_ID either was previously set with -b option, or is an empty string
101 CHECKOUT_ID
=$COMMIT_ID
102 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID
="tags/$LATEST_STABLE_DEVOPS"
103 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID
="$BRANCH"
104 if [[ $CHECKOUT_ID == "tags/"* ]]; then
105 REMOTE_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
107 REMOTE_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
109 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
110 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
111 echo " Nothing to be done."
113 echo " Update required."
114 lxc
exec $CONTAINER -- service osm-ro stop
115 lxc
exec $CONTAINER -- git
-C /opt
/openmano stash
116 lxc
exec $CONTAINER -- git
-C /opt
/openmano pull
--rebase
117 lxc
exec $CONTAINER -- git
-C /opt
/openmano checkout
$CHECKOUT_ID
118 lxc
exec $CONTAINER -- git
-C /opt
/openmano stash pop
119 lxc
exec $CONTAINER -- /opt
/openmano
/database_utils
/migrate_mano_db.sh
120 lxc
exec $CONTAINER -- service osm-ro start
124 echo -e " Updating SO and UI"
127 INSTALL_FOLDER
="" # To be filled in
128 echo -e " Fetching the repo"
129 lxc
exec $CONTAINER -- git
-C $INSTALL_FOLDER fetch
--all
131 BRANCH
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
132 [ -z "$BRANCH" ] && FATAL
"Could not find the current branch in use in the '$MDG'"
133 CURRENT
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
134 CURRENT_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
135 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
136 # COMMIT_ID either was previously set with -b option, or is an empty string
137 CHECKOUT_ID
=$COMMIT_ID
138 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID
="tags/$LATEST_STABLE_DEVOPS"
139 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID
="$BRANCH"
140 if [[ $CHECKOUT_ID == "tags/"* ]]; then
141 REMOTE_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
143 REMOTE_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
145 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
146 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
147 echo " Nothing to be done."
149 echo " Update required."
150 # Instructions to be added
151 # lxc exec SO-ub -- ...
154 echo -e "Updating MON Container"
157 INSTALL_FOLDER
="/root/MON"
158 echo -e " Fetching the repo"
159 lxc
exec $CONTAINER -- git
-C $INSTALL_FOLDER fetch
--all
161 BRANCH
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
162 [ -z "$BRANCH" ] && FATAL
"Could not find the current branch in use in the '$MDG'"
163 CURRENT
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
164 CURRENT_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
165 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
166 # COMMIT_ID either was previously set with -b option, or is an empty string
167 CHECKOUT_ID
=$COMMIT_ID
168 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID
="tags/$LATEST_STABLE_DEVOPS"
169 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID
="$BRANCH"
170 if [[ $CHECKOUT_ID == "tags/"* ]]; then
171 REMOTE_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
173 REMOTE_COMMIT_ID
=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
175 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
176 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
177 echo " Nothing to be done."
179 echo " Update required."
184 function so_is_up
() {
188 SO_IP
=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
193 while [ $time -le $timelength ]
195 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
196 -H 'accept: application/vnd.yang.data+json' \
197 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
198 -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 ]]
200 echo "RW.Restconf running....SO is up"
209 FATAL
"OSM Failed to startup. SO failed to startup"
212 function vca_is_up
() {
213 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
214 echo "VCA is up and running"
218 FATAL
"OSM Failed to startup. VCA failed to startup"
221 function mon_is_up
() {
222 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
223 echo "MON is up and running"
227 FATAL
"OSM Failed to startup. MON failed to startup"
230 function ro_is_up
() {
234 RO_IP
=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
239 while [ $time -le $timelength ]; do
240 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
241 echo "RO is up and running"
249 FATAL
"OSM Failed to startup. RO failed to startup"
253 function configure_RO
(){
254 .
$OSM_DEVOPS/installers
/export_ips
255 echo -e " Configuring RO"
256 lxc
exec RO
-- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc
/osm
/openmanod.cfg
257 lxc
exec RO
-- service osm-ro restart
261 lxc
exec RO
-- openmano tenant-delete
-f osm
>/dev
/null
262 lxc
exec RO
-- openmano tenant-create osm
> /dev
/null
263 lxc
exec RO
-- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
264 lxc
exec RO
-- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
265 lxc
exec RO
-- sh
-c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
268 function configure_VCA
(){
269 echo -e " Configuring VCA"
270 JUJU_PASSWD
=`date +%s | sha256sum | base64 | head -c 32`
271 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc
exec VCA
-- juju change-user-password
274 function configure_SOUI
(){
275 .
$OSM_DEVOPS/installers
/export_ips
276 JUJU_CONTROLLER_IP
=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
277 RO_TENANT_ID
=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
279 echo -e " Configuring MON"
280 #Information to be added about SO socket for logging
282 echo -e " Configuring SO"
283 sudo route add
-host $JUJU_CONTROLLER_IP gw
$VCA_CONTAINER_IP
284 sudo
sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc
/rc.
local
285 # make journaling persistent
286 lxc
exec SO-ub
-- mkdir
-p /var
/log
/journal
287 lxc
exec SO-ub
-- systemd-tmpfiles
--create --prefix /var
/log
/journal
288 lxc
exec SO-ub
-- systemctl restart systemd-journald
290 echo RIFT_EXTERNAL_ADDRESS
=$DEFAULT_IP | lxc
exec SO-ub
-- tee -a /usr
/rift
/etc
/default
/launchpad
292 lxc
exec SO-ub
-- systemctl restart launchpad
294 so_is_up
$SO_CONTAINER_IP
296 #delete existing config agent (could be there on reconfigure)
297 curl
-k --request DELETE \
298 --url https
://$SO_CONTAINER_IP:8008/api
/config
/config-agent
/account
/osmjuju \
299 --header 'accept: application/vnd.yang.data+json' \
300 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
301 --header 'cache-control: no-cache' \
302 --header 'content-type: application/vnd.yang.data+json' &> /dev
/null
304 result
=$
(curl
-k --request POST \
305 --url https
://$SO_CONTAINER_IP:8008/api
/config
/config-agent \
306 --header 'accept: application/vnd.yang.data+json' \
307 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
308 --header 'cache-control: no-cache' \
309 --header 'content-type: application/vnd.yang.data+json' \
310 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
311 [[ $result =~ .
*success.
* ]] || FATAL
"Failed config-agent configuration: $result"
314 #result=$(curl -k --request PUT \
315 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
316 # --header 'accept: application/vnd.yang.data+json' \
317 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
318 # --header 'cache-control: no-cache' \
319 # --header 'content-type: application/vnd.yang.data+json' \
320 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
322 result
=$
(curl
-k --request PUT \
323 --url https
://$SO_CONTAINER_IP:8008/api
/config
/project
/default
/ro-account
/account \
324 --header 'accept: application/vnd.yang.data+json' \
325 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
326 --header 'cache-control: no-cache' \
327 --header 'content-type: application/vnd.yang.data+json' \
328 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
329 [[ $result =~ .
*success.
* ]] || FATAL
"Failed resource-orchestrator configuration: $result"
331 result
=$
(curl
-k --request PATCH \
332 --url https
://$SO_CONTAINER_IP:8008/v
2/api
/config
/openidc-provider-config
/rw-ui-client
/redirect-uri \
333 --header 'accept: application/vnd.yang.data+json' \
334 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
335 --header 'cache-control: no-cache' \
336 --header 'content-type: application/vnd.yang.data+json' \
337 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
338 [[ $result =~ .
*success.
* ]] || FATAL
"Failed redirect-uri configuration: $result"
340 result
=$
(curl
-k --request PATCH \
341 --url https
://$SO_CONTAINER_IP:8008/v
2/api
/config
/openidc-provider-config
/rw-ui-client
/post-logout-redirect-uri \
342 --header 'accept: application/vnd.yang.data+json' \
343 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
344 --header 'cache-control: no-cache' \
345 --header 'content-type: application/vnd.yang.data+json' \
346 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
347 [[ $result =~ .
*success.
* ]] || FATAL
"Failed post-logout-redirect-uri configuration: $result"
349 lxc
exec SO-ub
-- tee /etc
/network
/interfaces.d
/60-rift.cfg
<<EOF
351 iface lo:1 inet static
353 netmask 255.255.255.255
355 lxc
exec SO-ub ifup lo
:1
358 #Configure RO, VCA, and SO with the initial configuration:
359 # RO -> tenant:osm, logs to be sent to SO
360 # VCA -> juju-password
361 # SO -> route to Juju Controller, add RO account, add VCA account
362 function configure
(){
363 #Configure components
364 echo -e "\nConfiguring components"
370 function install_lxd
() {
372 sudo apt-get
install -y lxd
376 lxc network create lxdbr0 ipv4.address
=auto ipv4.nat
=true ipv6.address
=none ipv6.nat
=false
377 DEFAULT_INTERFACE
=$
(route
-n |
awk '$1~/^0.0.0.0/ {print $8}')
378 DEFAULT_MTU
=$
( ip addr show
$DEFAULT_INTERFACE | perl
-ne 'if (/mtu\s(\d+)/) {print $1;}')
379 lxc profile device
set default eth0 mtu
$DEFAULT_MTU
380 #sudo systemctl stop lxd-bridge
381 #sudo systemctl --system daemon-reload
382 #sudo systemctl enable lxd-bridge
383 #sudo systemctl start lxd-bridge
387 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
388 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
389 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
390 read -e -p "$1" USER_CONFIRMATION
392 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
393 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
394 [ "${USER_CONFIRMATION,,}" == "yes" ] ||
[ "${USER_CONFIRMATION,,}" == "y" ] && return 0
395 [ "${USER_CONFIRMATION,,}" == "no" ] ||
[ "${USER_CONFIRMATION,,}" == "n" ] && return 1
396 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
400 function launch_container_from_lxd
(){
403 export OSM_BASE_IMAGE
=$2
404 if ! container_exists
$OSM_BUILD_CONTAINER; then
406 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS
="$CONTAINER_OPTS -c security.privileged=true"
407 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS
="$CONTAINER_OPTS -c security.nesting=true"
408 create_container
$OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
409 wait_container_up
$OSM_BUILD_CONTAINER
413 function install_osmclient
(){
414 CLIENT_RELEASE
=${RELEASE#"-R "}
415 CLIENT_REPOSITORY_KEY
="OSM%20ETSI%20Release%20Key.gpg"
416 CLIENT_REPOSITORY
=${REPOSITORY#"-r "}
417 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE
="-u https://osm-download.etsi.org/repository/osm/debian"
418 CLIENT_REPOSITORY_BASE
=${REPOSITORY_BASE#"-u "}
419 key_location
=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
420 curl
$key_location | sudo apt-key add
-
421 sudo add-apt-repository
-y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
423 sudo apt-get
install -y python-osmclient
424 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
425 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
426 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
427 echo -e "\nOSM client installed"
428 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
429 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
430 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
431 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
435 function install_from_lxdimages
(){
436 LXD_RELEASE
=${RELEASE#"-R "}
437 if [ -n "$LXD_REPOSITORY_PATH" ]; then
438 LXD_IMAGE_DIR
="$LXD_REPOSITORY_PATH"
440 LXD_IMAGE_DIR
="$(mktemp -d -q --tmpdir "osmimages.XXXXXX
")"
441 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
443 echo -e "\nDeleting previous lxd images if they exist"
444 lxc image show osm-ro
&>/dev
/null
&& lxc image delete osm-ro
445 lxc image show osm-vca
&>/dev
/null
&& lxc image delete osm-vca
446 lxc image show osm-soui
&>/dev
/null
&& lxc image delete osm-soui
447 echo -e "\nImporting osm-ro"
448 [ -z "$LXD_REPOSITORY_PATH" ] && wget
-O $LXD_IMAGE_DIR/osm-ro.
tar.gz
$LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.
tar.gz
449 lxc image import
$LXD_IMAGE_DIR/osm-ro.
tar.gz
--alias osm-ro
450 rm -f $LXD_IMAGE_DIR/osm-ro.
tar.gz
451 echo -e "\nImporting osm-vca"
452 [ -z "$LXD_REPOSITORY_PATH" ] && wget
-O $LXD_IMAGE_DIR/osm-vca.
tar.gz
$LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.
tar.gz
453 lxc image import
$LXD_IMAGE_DIR/osm-vca.
tar.gz
--alias osm-vca
454 rm -f $LXD_IMAGE_DIR/osm-vca.
tar.gz
455 echo -e "\nImporting osm-soui"
456 [ -z "$LXD_REPOSITORY_PATH" ] && wget
-O $LXD_IMAGE_DIR/osm-soui.
tar.gz
$LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.
tar.gz
457 lxc image import
$LXD_IMAGE_DIR/osm-soui.
tar.gz
--alias osm-soui
458 rm -f $LXD_IMAGE_DIR/osm-soui.
tar.gz
459 launch_container_from_lxd RO osm-ro
461 launch_container_from_lxd VCA osm-vca
462 vca_is_up
&& track VCA
463 launch_container_from_lxd MON osm-mon
464 mon_is_up
&& track MON
465 launch_container_from_lxd SO osm-soui
466 #so_is_up && track SOUI
470 function install_docker_ce
() {
471 # installs and configures Docker CE
472 echo "Installing Docker CE ..."
473 sudo apt-get
-qq update
474 sudo apt-get
install -y apt-transport-https ca-certificates software-properties-common
475 curl
-fsSL https
://download.docker.com
/linux
/ubuntu
/gpg | sudo apt-key add
-
476 sudo add-apt-repository
"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
477 sudo apt-get
-qq update
478 sudo apt-get
install -y docker-ce
479 echo "Adding user to group 'docker'"
480 sudo groupadd
-f docker
481 sudo usermod
-aG docker
$USER
482 echo "... Docker CE installation done"
484 sudo service docker restart
485 echo "... restarted Docker service"
488 function install_juju
() {
489 echo "Installing juju"
490 sudo snap
install juju
--classic
491 sudo dpkg-reconfigure
-p medium lxd
492 juju bootstrap localhost osm
493 echo "Finished installation of juju"
496 function generate_docker_images
() {
497 echo "Pulling and generating docker images"
498 newgrp docker
<< EONG
499 docker pull wurstmeister/kafka
500 docker pull wurstmeister/zookeeper
503 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
504 docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon || ! echo "cannot build MON docker image" >&2
505 docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm || ! echo "cannot build PM docker image" >&2
506 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
507 docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2
508 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
509 docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2
510 docker build ${LWTEMPDIR}/RO/lcm -t osm/lcm || ! echo "cannot build LCM docker image" >&2
511 git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git
512 docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile
514 echo "Finished generation of docker images"
517 function generate_docker_env_files
() {
518 echo "Generating docker env files"
519 OSMLCM_VCA_HOST
=`juju show-controller|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
520 OSMLCM_VCA_SECRET
=`grep password /home/ubuntu/.local/share/juju/accounts.yaml |awk '{print $2}'`
521 MYSQL_ROOT_PASSWORD
=`date +%s | sha256sum | base64 | head -c 32`
522 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" > ${OSM_DEVOPS}/installers
/docker
/lcm.env
523 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" >> ${OSM_DEVOPS}/installers
/docker
/lcm.env
524 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" > ${OSM_DEVOPS}/installers
/docker
/ro-db.env
525 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" > ${OSM_DEVOPS}/installers
/docker
/ro.env
526 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" > ${OSM_DEVOPS}/installers
/docker
/mon.env
527 echo "Finished generation of docker env files"
530 function deploy_lightweight
() {
531 echo "Deploying lightweight build"
532 newgrp docker
<< EONG
533 docker swarm init --advertise-addr ${DEFAULT_IP}
534 docker network create --driver=overlay --attachable netOSM
535 docker stack deploy -c ${OSM_DEVOPS}/installers/docker/docker-compose.yaml osm
537 echo "Finished deployment of lightweight build"
540 function install_osmclient_sol005
() {
542 sudo apt-get
install -y python-pip libcurl4-gnutls-dev libgnutls-dev
543 git
-C ${LWTEMPDIR} clone https
://osm.etsi.org
/gerrit
/osm
/osmclient
544 sudo
-H pip
install -U pip
545 sudo
-H pip
install -U setuptools
546 pushd ${LWTEMPDIR}/osmclient
547 sudo
-H python setup.py
install
549 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ~/.bashrc
550 echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
551 echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
554 function install_lightweight
() {
555 echo "Installing lightweight build of OSM"
556 LWTEMPDIR
="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX
")"
557 trap 'rm -rf "${LWTEMPDIR}"' EXIT
558 DEFAULT_IF
=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
559 DEFAULT_IP
=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
562 generate_docker_images
563 generate_docker_env_files
569 function install_vimemu
() {
572 # clone vim-emu repository (attention: branch is currently master only)
573 echo "Cloning vim-emu repository ..."
574 git clone https
://osm.etsi.org
/gerrit
/osm
/vim-emu.git
575 # build vim-emu docker
576 echo "Building vim-emu Docker container..."
577 sudo docker build
-t vim-emu-img
-f vim-emu
/Dockerfile vim-emu
/
578 # start vim-emu container as daemon
579 echo "Starting vim-emu Docker container 'vim-emu' ..."
580 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
581 echo "Waiting for 'vim-emu' container to start ..."
583 export VIMEMU_HOSTNAME
=$
(sudo docker inspect
-f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu
)
584 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
585 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
586 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
587 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
588 echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:"
589 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
590 echo -e "\nTo add the emulated VIM to OSM you should do:"
591 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
594 function dump_vars
(){
595 echo "DEVELOP=$DEVELOP"
596 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
597 echo "UNINSTALL=$UNINSTALL"
599 echo "UPDATE=$UPDATE"
600 echo "RECONFIGURE=$RECONFIGURE"
601 echo "TEST_INSTALLER=$TEST_INSTALLER"
602 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
603 echo "INSTALL_LXD=$INSTALL_LXD"
604 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
605 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
606 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
607 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
608 echo "RELEASE=$RELEASE"
609 echo "REPOSITORY=$REPOSITORY"
610 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
611 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
612 echo "NOCONFIGURE=$NOCONFIGURE"
613 echo "SHOWOPTS=$SHOWOPTS"
614 echo "Install from specific refspec (-b): $COMMIT_ID"
619 duration
=$
((ctime
- SESSION_ID
))
620 url
="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
621 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
623 [ -n "$INSTALL_FROM_SOURCE" ] && event_name
="src"
624 [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name
="lxd"
625 event_name
="${event_name}_$1"
626 url
="${url}&event=${event_name}&ce_duration=${duration}"
627 wget
-q -O /dev
/null
$url
640 INSTALL_FROM_SOURCE
=""
641 RELEASE
="-R ReleaseTHREE"
642 REPOSITORY
="-r stable"
644 INSTALL_FROM_LXDIMAGES
=""
645 LXD_REPOSITORY_BASE
="https://osm-download.etsi.org/repository/osm/lxd"
646 LXD_REPOSITORY_PATH
=""
647 INSTALL_LIGHTWEIGHT
=""
650 SESSION_ID
=`date +%s`
653 while getopts ":hy-:b:r:k:u:R:l:p:D:" o
; do
662 REPOSITORY
="-r ${OPTARG}"
665 RELEASE
="-R ${OPTARG}"
668 REPOSITORY_KEY
="-k ${OPTARG}"
671 REPOSITORY_BASE
="-u ${OPTARG}"
674 LXD_REPOSITORY_BASE
="${OPTARG}"
677 LXD_REPOSITORY_PATH
="${OPTARG}"
680 OSM_DEVOPS
="${OPTARG}"
683 [ "${OPTARG}" == "help" ] && usage
&& exit 0
684 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE
="y" && continue
685 [ "${OPTARG}" == "develop" ] && DEVELOP
="y" && continue
686 [ "${OPTARG}" == "uninstall" ] && UNINSTALL
="y" && continue
687 [ "${OPTARG}" == "nat" ] && NAT
="y" && continue
688 [ "${OPTARG}" == "update" ] && UPDATE
="y" && continue
689 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE
="y" && continue
690 [ "${OPTARG}" == "test" ] && TEST_INSTALLER
="y" && continue
691 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD
="y" && continue
692 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES
="y" && continue
693 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT
="y" && continue
694 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU
="y" && continue
695 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE
="y" && continue
696 [ "${OPTARG}" == "showopts" ] && SHOWOPTS
="y" && continue
697 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY
="y" && continue
698 echo -e "Invalid option: '--$OPTARG'\n" >&2
702 echo -e "Invalid option: '-$OPTARG'\n" >&2
714 if [ -n "$SHOWOPTS" ]; then
719 [ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE
="-R ReleaseTHREE-daily" && REPOSITORY
="-r testing" && COMMIT_ID
="master"
721 # if develop, we force master
722 [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID
="master"
724 # forcing source from master removed. Now only install from source when explicit
725 # [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
727 if [ -z "$OSM_DEVOPS" ]; then
728 if [ -n "$TEST_INSTALLER" ]; then
729 echo -e "\nUsing local devops repo for OSM installation"
730 TEMPDIR
="$(dirname $(realpath $(dirname $0)))"
732 echo -e "\nCreating temporary dir for OSM installation"
733 TEMPDIR
="$(mktemp -d -q --tmpdir "installosm.XXXXXX
")"
734 trap 'rm -rf "$TEMPDIR"' EXIT
738 need_packages
="git jq wget curl tar"
739 echo -e "Checking required packages: $need_packages"
740 dpkg
-l $need_packages &>/dev
/null \
741 ||
! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
742 || sudo apt-get update \
743 || FATAL
"failed to run apt-get update"
744 dpkg
-l $need_packages &>/dev
/null \
745 ||
! echo -e "Installing $need_packages requires root privileges." \
746 || sudo apt-get
install -y $need_packages \
747 || FATAL
"failed to install $need_packages"
749 if [ -z "$OSM_DEVOPS" ]; then
750 if [ -z "$TEST_INSTALLER" ]; then
751 echo -e "\nCloning devops repo temporarily"
752 git clone https
://osm.etsi.org
/gerrit
/osm
/devops.git
$TEMPDIR
756 echo -e "\nGuessing the current stable release"
757 LATEST_STABLE_DEVOPS
=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
758 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
759 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
760 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID
="tags/$LATEST_STABLE_DEVOPS"
762 if [ -n "$RELEASE_DAILY" ]; then
763 echo "Using master/HEAD devops"
764 git
-C $TEMPDIR checkout master
765 elif [ -z "$TEST_INSTALLER" ]; then
766 git
-C $TEMPDIR checkout tags
/$LATEST_STABLE_DEVOPS
771 OSM_JENKINS
="$OSM_DEVOPS/jenkins"
772 .
$OSM_JENKINS/common
/all_funcs
774 [ -n "$UNINSTALL" ] && uninstall
&& echo -e "\nDONE" && exit 0
775 [ -n "$NAT" ] && nat
&& echo -e "\nDONE" && exit 0
776 [ -n "$UPDATE" ] && update
&& echo -e "\nDONE" && exit 0
777 [ -n "$RECONFIGURE" ] && configure
&& echo -e "\nDONE" && exit 0
779 #Installation starts here
780 [ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight
&& echo -e "\nDONE" && exit 0
781 echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
782 if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
783 ! ask_user
"The installation will take about 75-90 minutes. Continue (Y/n)? " y
&& echo "Cancelled!" && exit 1
786 echo -e "Checking required packages: lxd"
787 lxd
--version &>/dev
/null || FATAL
"lxd not present, exiting."
788 [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
790 wget
-q -O- https
://osm-download.etsi.org
/ftp
/osm-4.0
-four/README.txt
&> /dev
/null
793 # use local devops for containers
794 export OSM_USE_LOCAL_DEVOPS
=true
795 if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
796 echo -e "\nCreating the containers and building from source ..."
797 $OSM_DEVOPS/jenkins
/host
/start_build RO
--notest checkout
$COMMIT_ID || FATAL
"RO container build failed (refspec: '$COMMIT_ID')"
799 $OSM_DEVOPS/jenkins
/host
/start_build VCA || FATAL
"VCA container build failed"
800 vca_is_up
&& track VCA
801 $OSM_DEVOPS/jenkins
/host
/start_build MON || FATAL
"MON install failed"
802 mon_is_up
&& track MON
803 $OSM_DEVOPS/jenkins
/host
/start_build SO checkout
$COMMIT_ID || FATAL
"SO container build failed (refspec: '$COMMIT_ID')"
804 $OSM_DEVOPS/jenkins
/host
/start_build UI checkout
$COMMIT_ID || FATAL
"UI container build failed (refspec: '$COMMIT_ID')"
805 #so_is_up && track SOUI
807 elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
808 echo -e "\nInstalling from lxd images ..."
809 install_from_lxdimages
810 else #install from binaries
811 echo -e "\nCreating the containers and installing from binaries ..."
812 $OSM_DEVOPS/jenkins
/host
/install RO
$REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL
"RO install failed"
814 $OSM_DEVOPS/jenkins
/host
/start_build VCA || FATAL
"VCA install failed"
815 vca_is_up
&& track VCA
816 $OSM_DEVOPS/jenkins
/host
/install MON || FATAL
"MON build failed"
817 mon_is_up
&& track MON
818 $OSM_DEVOPS/jenkins
/host
/install SO
$REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL
"SO install failed"
819 $OSM_DEVOPS/jenkins
/host
/install UI
$REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL
"UI install failed"
820 #so_is_up && track SOUI
824 #Install iptables-persistent and configure NAT rules
825 [ -z "$NOCONFIGURE" ] && nat
827 #Configure components
828 [ -z "$NOCONFIGURE" ] && configure
831 [ -z "$NOCONFIGURE" ] && install_osmclient
833 #Install vim-emu (optional)
834 if [ -n "$INSTALL_VIMEMU" ]; then
835 echo -e "\nInstalling vim-emu ..."
839 wget
-q -O- https
://osm-download.etsi.org
/ftp
/osm-4.0
-four/README2.txt
&> /dev
/null