blob: c57897e96d82c697d96934e9d2061589662c349e [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]"
18 echo -e "Install OSM from source code"
19 echo -e " OPTIONS"
20 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
21 echo -e " --develop: install OSM from source code using the master branch"
22 echo -e " --nat: install only NAT rules"
23 echo -e " -h / --help: print this help"
24}
25
26UNINSTALL=""
27DEVELOP=""
28NAT=""
29while getopts ":h-:" o; do
30 case "${o}" in
31 h)
32 usage && exit 0
33 ;;
34 -)
35 [ "${OPTARG}" == "help" ] && usage && exit 0
36 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
37 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
38 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
39 echo -e "Invalid option: '--$OPTARG'\n" >&2
40 usage && exit 1
41 ;;
42 \?)
43 echo -e "Invalid option: '-$OPTARG'\n" >&2
44 usage && exit 1
45 ;;
46 *)
47 usage && exit 1
48 ;;
49 esac
50done
51
52echo -e "\nCreating temporary dir for OSM installation"
53TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
54trap 'rm -rf "$TEMPDIR"' EXIT
55
56echo -e "\nCloning devops repo temporarily"
57git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
58RC_CLONE=$?
garciadeblas93c61312016-09-28 15:12:48 +020059OSM_DEVOPS=$TEMPDIR
garciadeblas0fe45dd2016-10-04 07:54:17 +020060OSM_JENKINS="$TEMPDIR/jenkins"
61. $OSM_JENKINS/common/all_funcs
garciadeblas93c61312016-09-28 15:12:48 +020062
63if [ -n "$UNINSTALL" ]; then
garciadeblas0fe45dd2016-10-04 07:54:17 +020064 if [ $RC_CLONE ]; then
garciadeblas93c61312016-09-28 15:12:48 +020065 $OSM_DEVOPS/jenkins/host/clean_container RO
66 $OSM_DEVOPS/jenkins/host/clean_container VCA
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 SO-ub && lxc delete SO-ub
73 fi
74 exit 0
75fi
76
77if [ -n "$NAT" ]; then
garciadeblas0fe45dd2016-10-04 07:54:17 +020078 sudo $OSM_DEVOPS/installers/nat_osm
79 exit 0
garciadeblas93c61312016-09-28 15:12:48 +020080fi
81
82#Installation starts here
garciadeblas0fe45dd2016-10-04 07:54:17 +020083wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null
84
garciadeblas93c61312016-09-28 15:12:48 +020085echo -e "\nInstalling required packages: git, wget, curl, tar"
garciadeblas0fe45dd2016-10-04 07:54:17 +020086echo -e " Required root privileges"
garciadeblas93c61312016-09-28 15:12:48 +020087sudo apt install -y git wget curl tar
88
89echo -e "\nCreating the containers and building ..."
garciadeblas0fe45dd2016-10-04 07:54:17 +020090COMMIT_ID="master"
91$OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID
garciadeblas93c61312016-09-28 15:12:48 +020092$OSM_DEVOPS/jenkins/host/start_build VCA
garciadeblas0fe45dd2016-10-04 07:54:17 +020093$OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID
94$OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID
garciadeblas93c61312016-09-28 15:12:48 +020095
96#Configure NAT rules
97echo -e "\nConfiguring NAT rules"
garciadeblas0fe45dd2016-10-04 07:54:17 +020098echo -e " Required root privileges"
99sudo $OSM_DEVOPS/installers/nat_osm
garciadeblas93c61312016-09-28 15:12:48 +0200100
101#Configure components
garciadeblas93c61312016-09-28 15:12:48 +0200102echo -e "\nConfiguring components"
103. $OSM_DEVOPS/installers/export_ips
104
garciadeblas0fe45dd2016-10-04 07:54:17 +0200105echo -e " Configuring RO"
106lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg
107lxc exec RO -- service openmano restart
108sleep 5
109RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'`
garciadeblas93c61312016-09-28 15:12:48 +0200110
garciadeblas0fe45dd2016-10-04 07:54:17 +0200111echo -e " Configuring VCA"
112JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
113echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
114JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
garciadeblas93c61312016-09-28 15:12:48 +0200115
garciadeblas0fe45dd2016-10-04 07:54:17 +0200116echo -e " Configuring SO"
117sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
118#lxc exec SO-ub -- nohup sudo -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode &
119lxc exec SO-ub -- nohup sudo -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode
120sleep 60
garciadeblas93c61312016-09-28 15:12:48 +0200121#lxc exec SO-ub -- resource-orchestrator name openmano account-type openmano openmano host $RO_CONTAINER_IP tenant-id $RO_TENANT_ID port 9090
122#lxc exec SO-ub -- config-agent account juju account-type juju juju ip-address $JUJU_CONTROLLER_IP port 17070 user admin secret $JUJU_PASSWD
garciadeblas0fe45dd2016-10-04 07:54:17 +0200123#curl --request POST --url http://$SO_CONTAINER_IP:8008/api/config/config-agent --header 'accept: application/vnd.yang.data+json' --header 'authorization: Basic YWRtaW46YWRtaW4=' --header 'cache-control: no-cache' --header 'content-type: application/vnd.yang.data+json' --data '{\n "account": [\n {\n "name": "osmjuju",\n "juju": {\n "ip-address": "$JUJU_CONTROLLER_IP",\n "port": "17070",\n "user": "admin",\n "secret": "$JUJU_PASSWD"\n }\n }\n ]\n}'
124#curl --request PUT --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator --header 'accept: application/vnd.yang.data+json' --header 'authorization: Basic YWRtaW46YWRtaW4=' --header 'cache-control: no-cache' --header 'content-type: application/vnd.yang.data+json' --data '{\n "openmano": {\n "host": "$RO_CONTAINER_IP",\n "port": "9090",\n "tenant-id": "$RO_TENANT_ID"\n },\n "name": "osmopenmano",\n "account-type": "openmano"\n}'
garciadeblas93c61312016-09-28 15:12:48 +0200125
garciadeblas0fe45dd2016-10-04 07:54:17 +0200126echo -e "\nDONE"
garciadeblas93c61312016-09-28 15:12:48 +0200127
128