| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 1 | #!/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 | |
| 16 | function 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 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 26 | #Uninstall OSM: remove containers |
| 27 | function uninstall(){ |
| 28 | if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then |
| 29 | $OSM_DEVOPS/jenkins/host/clean_container RO |
| 30 | $OSM_DEVOPS/jenkins/host/clean_container VCA |
| 31 | $OSM_DEVOPS/jenkins/host/clean_container SO |
| 32 | #$OSM_DEVOPS/jenkins/host/clean_container UI |
| 33 | else |
| 34 | lxc stop RO && lxc delete RO |
| 35 | lxc stop VCA && lxc delete VCA |
| 36 | lxc stop SO-ub && lxc delete SO-ub |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | #Configure NAT rules, based on the current IP addresses of containers |
| 41 | function nat(){ |
| 42 | echo -e "\nChecking required packages: iptables-persistent" |
| 43 | dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \ |
| 44 | sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent |
| 45 | echo -e "\nConfiguring NAT rules" |
| 46 | echo -e " Required root privileges" |
| 47 | sudo $OSM_DEVOPS/installers/nat_osm |
| 48 | } |
| 49 | |
| 50 | #Configure VCA, SO and RO with the initial configuration: |
| 51 | # RO -> tenant:osm, logs to be sent to SO |
| 52 | # VCA -> juju-password |
| 53 | # SO -> route to Juju Controller, add RO account, add VCA account |
| 54 | function configure(){ |
| 55 | #Configure components |
| 56 | echo -e "\nConfiguring components" |
| 57 | . $OSM_DEVOPS/installers/export_ips |
| 58 | |
| 59 | echo -e " Configuring RO" |
| 60 | lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg |
| 61 | lxc exec RO -- service openmano restart |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 62 | time=0; step=2; timelength=20; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo |
| 63 | lxc exec RO -- openmano tenant-delete -f osm >/dev/null |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 64 | RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` |
| 65 | |
| 66 | echo -e " Configuring VCA" |
| 67 | JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 68 | echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password |
| 69 | JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| 70 | |
| 71 | echo -e " Configuring SO" |
| 72 | sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP |
| garciadeblas | d05ae75 | 2016-12-07 12:13:00 +0100 | [diff] [blame^] | 73 | lxc exec SO-ub -- nohup sudo -b -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode & |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 74 | time=0; step=30; timelength=300; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 75 | |
| 76 | curl -k --request POST \ |
| 77 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ |
| 78 | --header 'accept: application/vnd.yang.data+json' \ |
| 79 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 80 | --header 'cache-control: no-cache' \ |
| 81 | --header 'content-type: application/vnd.yang.data+json' \ |
| 82 | --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}' |
| 83 | |
| 84 | curl -k --request PUT \ |
| 85 | --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \ |
| 86 | --header 'accept: application/vnd.yang.data+json' \ |
| 87 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 88 | --header 'cache-control: no-cache' \ |
| 89 | --header 'content-type: application/vnd.yang.data+json' \ |
| 90 | --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }' |
| 91 | |
| 92 | } |
| 93 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 94 | UNINSTALL="" |
| 95 | DEVELOP="" |
| 96 | NAT="" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 97 | RECONFIGURE="" |
| 98 | TEST_INSTALLER="" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 99 | while getopts ":h-:" o; do |
| 100 | case "${o}" in |
| 101 | h) |
| 102 | usage && exit 0 |
| 103 | ;; |
| 104 | -) |
| 105 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| 106 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| 107 | [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue |
| 108 | [ "${OPTARG}" == "nat" ] && NAT="y" && continue |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 109 | [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue |
| 110 | [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 111 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 112 | usage && exit 1 |
| 113 | ;; |
| 114 | \?) |
| 115 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 116 | usage && exit 1 |
| 117 | ;; |
| 118 | *) |
| 119 | usage && exit 1 |
| 120 | ;; |
| 121 | esac |
| 122 | done |
| 123 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 124 | if [ -n "$TEST_INSTALLER" ]; then |
| 125 | echo -e "\nUsing local devops repo for OSM installation" |
| 126 | TEMPDIR="$(dirname $(realpath $(dirname $0)))" |
| 127 | else |
| 128 | echo -e "\nCreating temporary dir for OSM installation" |
| 129 | TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 130 | trap 'rm -rf "$TEMPDIR"' EXIT |
| 131 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 132 | |
| garciadeblas | 95f164e | 2016-10-19 13:00:54 +0200 | [diff] [blame] | 133 | echo -e "Checking required packages: git" |
| 134 | dpkg -l git &>/dev/null || ! echo -e " git not installed.\nInstalling git requires root privileges" || sudo apt install -y git |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 135 | if [ -z "$TEST_INSTALLER" ]; then |
| 136 | echo -e "\nCloning devops repo temporarily" |
| 137 | git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR |
| 138 | RC_CLONE=$? |
| 139 | DEVOPS_COMMITID="tags/v1.0.1" |
| 140 | git -C $TEMPDIR checkout $DEVOPS_COMMITID |
| 141 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 142 | OSM_DEVOPS=$TEMPDIR |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 143 | OSM_JENKINS="$TEMPDIR/jenkins" |
| 144 | . $OSM_JENKINS/common/all_funcs |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 145 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 146 | [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 |
| 147 | [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0 |
| 148 | [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 149 | |
| 150 | #Installation starts here |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 151 | wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null |
| 152 | |
| garciadeblas | 95f164e | 2016-10-19 13:00:54 +0200 | [diff] [blame] | 153 | echo -e "\nChecking required packages: wget, curl, tar" |
| 154 | dpkg -l wget curl tar &>/dev/null || ! echo -e " One or several packages are not installed.\nInstalling required packages\n Root privileges are required" || sudo apt install -y wget curl tar |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 155 | |
| 156 | echo -e "\nCreating the containers and building ..." |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 157 | COMMIT_ID="tags/v1.0.1" |
| garciadeblas | bad19ac | 2016-10-04 16:35:57 +0200 | [diff] [blame] | 158 | [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 159 | $OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 160 | $OSM_DEVOPS/jenkins/host/start_build VCA |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 161 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID |
| 162 | $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 163 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 164 | #Install iptables-persistent and configure NAT rules |
| 165 | nat |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 166 | |
| 167 | #Configure components |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 168 | configure |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 169 | |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 170 | echo -e "\nDONE" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 171 | |
| 172 | |