| 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 | |
| 26 | UNINSTALL="" |
| 27 | DEVELOP="" |
| 28 | NAT="" |
| 29 | while 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 |
| 50 | done |
| 51 | |
| 52 | echo -e "\nCreating temporary dir for OSM installation" |
| 53 | TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 54 | trap 'rm -rf "$TEMPDIR"' EXIT |
| 55 | |
| 56 | echo -e "\nCloning devops repo temporarily" |
| 57 | git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR |
| 58 | RC_CLONE=$? |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 59 | OSM_DEVOPS=$TEMPDIR |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 60 | OSM_JENKINS="$TEMPDIR/jenkins" |
| 61 | . $OSM_JENKINS/common/all_funcs |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 62 | |
| 63 | if [ -n "$UNINSTALL" ]; then |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 64 | if [ $RC_CLONE ]; then |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 65 | $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 |
| 75 | fi |
| 76 | |
| 77 | if [ -n "$NAT" ]; then |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 78 | sudo $OSM_DEVOPS/installers/nat_osm |
| 79 | exit 0 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 80 | fi |
| 81 | |
| 82 | #Installation starts here |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 83 | wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null |
| 84 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 85 | echo -e "\nInstalling required packages: git, wget, curl, tar" |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 86 | echo -e " Required root privileges" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 87 | sudo apt install -y git wget curl tar |
| 88 | |
| 89 | echo -e "\nCreating the containers and building ..." |
| garciadeblas | bad19ac | 2016-10-04 16:35:57 +0200 | [diff] [blame] | 90 | COMMIT_ID="tags/v1.0" |
| 91 | #COMMIT_ID="master" |
| 92 | [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 93 | $OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 94 | $OSM_DEVOPS/jenkins/host/start_build VCA |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 95 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID |
| 96 | $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 97 | |
| garciadeblas | 837fc96 | 2016-10-06 01:53:55 +0200 | [diff] [blame] | 98 | #Install iptables-persistent |
| 99 | echo -e "\nInstalling iptables-persistent" |
| 100 | echo -e " Required root privileges" |
| 101 | sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent |
| 102 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 103 | #Configure NAT rules |
| 104 | echo -e "\nConfiguring NAT rules" |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 105 | echo -e " Required root privileges" |
| 106 | sudo $OSM_DEVOPS/installers/nat_osm |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 107 | |
| 108 | #Configure components |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 109 | echo -e "\nConfiguring components" |
| 110 | . $OSM_DEVOPS/installers/export_ips |
| 111 | |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 112 | echo -e " Configuring RO" |
| 113 | lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg |
| 114 | lxc exec RO -- service openmano restart |
| garciadeblas | 018946b | 2016-10-04 19:56:28 +0200 | [diff] [blame] | 115 | time=0; step=1; timelength=10; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 116 | RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 117 | |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 118 | echo -e " Configuring VCA" |
| 119 | JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 120 | echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password |
| 121 | JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 122 | |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 123 | echo -e " Configuring SO" |
| 124 | sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP |
| garciadeblas | bad19ac | 2016-10-04 16:35:57 +0200 | [diff] [blame] | 125 | 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 | 018946b | 2016-10-04 19:56:28 +0200 | [diff] [blame] | 126 | time=0; step=18; timelength=180; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo |
| 127 | |
| garciadeblas | bad19ac | 2016-10-04 16:35:57 +0200 | [diff] [blame] | 128 | curl -k --request POST \ |
| garciadeblas | 2035dd4 | 2016-10-04 18:09:17 +0200 | [diff] [blame] | 129 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ |
| garciadeblas | bad19ac | 2016-10-04 16:35:57 +0200 | [diff] [blame] | 130 | --header 'accept: application/vnd.yang.data+json' \ |
| 131 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 132 | --header 'cache-control: no-cache' \ |
| 133 | --header 'content-type: application/vnd.yang.data+json' \ |
| garciadeblas | 2035dd4 | 2016-10-04 18:09:17 +0200 | [diff] [blame] | 134 | --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}' |
| garciadeblas | bad19ac | 2016-10-04 16:35:57 +0200 | [diff] [blame] | 135 | |
| garciadeblas | 2035dd4 | 2016-10-04 18:09:17 +0200 | [diff] [blame] | 136 | curl -k --request PUT \ |
| 137 | --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \ |
| 138 | --header 'accept: application/vnd.yang.data+json' \ |
| 139 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 140 | --header 'cache-control: no-cache' \ |
| 141 | --header 'content-type: application/vnd.yang.data+json' \ |
| 142 | --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }' |
| 143 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 144 | |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 145 | echo -e "\nDONE" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 146 | |
| 147 | |