From: garciadeblas Date: Wed, 28 Sep 2016 13:12:48 +0000 (+0200) Subject: New folder installers and new installer to install OSM release 1 from source X-Git-Tag: v1.0.0~12^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F437%2F3;p=osm%2Fdevops.git New folder installers and new installer to install OSM release 1 from source Change-Id: Icfda9b021e01301c5ecdbcb157da5b49729fafac Signed-off-by: garciadeblas --- diff --git a/README b/README index d872f66d..df4b3457 100644 --- a/README +++ b/README @@ -1,4 +1,5 @@ # Copyright 2016 RIFT.IO Inc +# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,6 +19,6 @@ README for https://osm.etsi.org/gerrit/osm/devops.git subdirectories: jenkins -- scripts executed by jenkins on the container host and some initial scripts executed inside the container to start a build see jenkins/README for more - - + installers -- scripts to be executed to install OSM from source, builds or packages + see installers/README for more diff --git a/installers/README b/installers/README new file mode 100644 index 00000000..43662cd2 --- /dev/null +++ b/installers/README @@ -0,0 +1,17 @@ +# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +This directory holds the scripts and tools needed to install OSM + + diff --git a/installers/export_ips b/installers/export_ips new file mode 100644 index 00000000..fcca76ef --- /dev/null +++ b/installers/export_ips @@ -0,0 +1,25 @@ +# This file is meant to be SOURCED +# +# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# 23 Sept 2016 -- Gerardo Garcia -- Genesis + +#Get IP addresses +DEFAULT_IF=`route -n |awk '$1~/0.0.0.0/ {print $8}'` +export DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` +export VCA_CONTAINER_IP=`lxc list VCA -c 4|grep eth0 |awk '{print $2}'` +export SO_CONTAINER_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'` +export RO_CONTAINER_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'` + diff --git a/installers/install_from_source b/installers/install_from_source new file mode 100755 index 00000000..ef910900 --- /dev/null +++ b/installers/install_from_source @@ -0,0 +1,119 @@ +#!/bin/bash +# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function usage(){ + echo -e "usage: $0 [OPTIONS]" + echo -e "Install OSM from source code" + echo -e " OPTIONS" + echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" + echo -e " --develop: install OSM from source code using the master branch" + echo -e " --nat: install only NAT rules" + echo -e " -h / --help: print this help" +} + +UNINSTALL="" +DEVELOP="" +NAT="" +while getopts ":h-:" o; do + case "${o}" in + h) + usage && exit 0 + ;; + -) + [ "${OPTARG}" == "help" ] && usage && exit 0 + [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue + [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue + [ "${OPTARG}" == "nat" ] && NAT="y" && continue + echo -e "Invalid option: '--$OPTARG'\n" >&2 + usage && exit 1 + ;; + \?) + echo -e "Invalid option: '-$OPTARG'\n" >&2 + usage && exit 1 + ;; + *) + usage && exit 1 + ;; + esac +done + +echo -e "\nCreating temporary dir for OSM installation" +TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" +trap 'rm -rf "$TEMPDIR"' EXIT + +echo -e "\nCloning devops repo temporarily" +git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR +RC_CLONE=$? + +OSM_DEVOPS=$TEMPDIR + +if [ -n "$UNINSTALL" ]; then + if $RC_CLONE; then + $OSM_DEVOPS/jenkins/host/clean_container RO + $OSM_DEVOPS/jenkins/host/clean_container VCA + $OSM_DEVOPS/jenkins/host/clean_container SO + #$OSM_DEVOPS/jenkins/host/clean_container UI + else + lxc stop RO && lxc delete RO + lxc stop VCA && lxc delete VCA + lxc stop SO-ub && lxc delete SO-ub + fi + exit 0 +fi + +if [ -n "$NAT" ]; then + $OSM_DEVOPS/installers/nat-osm || FATAL "Failed to run nat-osm" +fi + +#Installation starts here +echo -e "\nInstalling required packages: git, wget, curl, tar" +echo -e "\n Required root privileges" +sudo apt install -y git wget curl tar + +echo -e "\nCreating the containers and building ..." +. $OSM_DEVOPS/jenkins/common/all_funcs +$OSM_DEVOPS/jenkins/host/start_build RO +$OSM_DEVOPS/jenkins/host/start_build VCA +$OSM_DEVOPS/jenkins/host/start_build SO +$OSM_DEVOPS/jenkins/host/start_build UI + +#Configure NAT rules +echo -e "\nConfiguring NAT rules" +echo -e "\n Required root privileges" +sudo $OSM_DEVOPS/installers/nat-osm + +#Configure components +# TO BE DONE +echo -e "\nConfiguring components" +. $OSM_DEVOPS/installers/export_ips + +echo -e "\n Configuring RO" +#RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` + +echo -e "\n Configuring VCA" +#JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` +#lxc exec VCA -- juju change-user-password $JUJUPASSWD +#JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` + +echo -e "\n Configuring SO" +#sudo route add -net $JUJU_CONTROLLER_IP/32 gw $VCA_CONTAINER_IP +#lxc exec SO-ub -- sudo -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode --test-name "launchpad" +#sleep 2 +#lxc exec SO-ub -- resource-orchestrator name openmano account-type openmano openmano host $RO_CONTAINER_IP tenant-id $RO_TENANT_ID port 9090 +#lxc exec SO-ub -- config-agent account juju account-type juju juju ip-address $JUJU_CONTROLLER_IP port 17070 user admin secret $JUJU_PASSWD + +echo "\nDONE" + + diff --git a/installers/nat_osm b/installers/nat_osm new file mode 100755 index 00000000..cacec22c --- /dev/null +++ b/installers/nat_osm @@ -0,0 +1,173 @@ +#!/bin/bash +# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +############ +# Functions +############ +usage(){ + echo -e "usage: $0 [OPTIONS]" + echo -e "Install NAT rules for OSM" + echo -e " OPTIONS" + echo -e " -u: UI/SO (rift) IP address" + echo -e " -r: RO (openmano) IP address" + echo -e " -v: VCA (juju) IP address" + echo -e " -h: show this help" +} + +################### +# End of functions +################### + +#Check root privileges +[ "$USER" != "root" ] && echo "Needed root privileges (run with sudo)" >&2 && exit 1 + +HERE=$(realpath $(dirname $0)) +OSM_DEVOPS=$(dirname $HERE) +. $OSM_DEVOPS/jenkins/common/all_funcs + +#Get default IP address +. $OSM_DEVOPS/installers/export_ips + +UI_IP=$DEFAULT_IP +RO_IP=$DEFAULT_IP +VCA_IP=$DEFAULT_IP + +#read input options +while getopts ":u:r:v:h-:" o; do + case "${o}" in + u) + export UI_IP="$OPTARG" + ;; + r) + export RO_IP="$OPTARG" + ;; + v) + export VCA_IP="$OPTARG" + ;; + h) + usage && exit 0 + ;; + -) + [ "${OPTARG}" == "help" ] && usage && exit 0 + echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 + exit 1 + ;; + \?) + echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2 + exit 1 + ;; + :) + echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2 + exit 1 + ;; + *) + usage >&2 + exit -1 + ;; + esac +done + +############# +# NAT port forwarding configuration +############# +echo +echo "*** Configuring iptables rules ***" + +awk -v RO_IP="$RO_IP" -v VCA_IP="$VCA_IP" -v UI_IP="$UI_IP" -v openmano_ip="$RO_CONTAINER_IP" -v rift_ip="$SO_CONTAINER_IP" -v juju_ip="$VCA_CONTAINER_IP" ' +BEGIN {innat=0; innatpre=0; osmpre=0; donepre=0; innatpost=0; osmpost=0; donepost=0} +/^\*nat/ { + innat=1; + print; + next +} +innat==1 && /\:PREROUTING/ { + innatpre=1; + print; + next; +} +innatpre==1 && /\#Autogenerated by nat_osm/ { + osmpre=1; + next; +} +osmpre==1 && /#End autogeneration by nat_osm/ { + print "#Autogenerated by nat_osm" + print "-A PREROUTING -d "RO_IP" -p tcp -m tcp --dport 9090 -j DNAT --to-destination "openmano_ip + print "-A PREROUTING -d "UI_IP" -p tcp -m tcp --dport 8000 -j DNAT --to-destination "rift_ip + print "-A PREROUTING -d "UI_IP" -p tcp -m tcp --dport 4567 -j DNAT --to-destination "rift_ip + print "-A PREROUTING -d "UI_IP" -p tcp -m tcp --dport 8443 -j DNAT --to-destination "rift_ip + #print "-A PREROUTING -d "VCA_IP" -p tcp -m tcp --dport 443 -j DNAT --to-destination "juju_ip + #print "-A PREROUTING -d "VCA_IP" -p tcp -m tcp --dport 17070 -j DNAT --to-destination "juju_ip + print "#End autogeneration by nat_osm" + osmpre=0; + donepre=1; + next; +} +osmpre==1 {next;} +innatpre==1 && /\:INPUT/ { + innatpre=0; + if (donepre==0) { + print "#Autogenerated by nat_osm" + print "-A PREROUTING -d "RO_IP" -p tcp -m tcp --dport 9090 -j DNAT --to-destination "openmano_ip + print "-A PREROUTING -d "UI_IP" -p tcp -m tcp --dport 8000 -j DNAT --to-destination "rift_ip + print "-A PREROUTING -d "UI_IP" -p tcp -m tcp --dport 4567 -j DNAT --to-destination "rift_ip + print "-A PREROUTING -d "UI_IP" -p tcp -m tcp --dport 8443 -j DNAT --to-destination "rift_ip + #print "-A PREROUTING -d "VCA_IP" -p tcp -m tcp --dport 443 -j DNAT --to-destination "juju_ip + #print "-A PREROUTING -d "VCA_IP" -p tcp -m tcp --dport 17070 -j DNAT --to-destination "juju_ip + print "#End autogeneration by nat_osm" + donepre=1; + } + print; + next; +} + +innat==1 && /\:POSTROUTING/ { + innatpost=1; + print; + next; +} +innatpost==1 && /\#Autogenerated by nat_osm/ { + osmpost=1; + next; +} +osmpost==1 && /#End autogeneration by nat_osm/ { + #print "#Autogenerated by nat_osm" + #print "-A POSTROUTING -s "rift_ip" -p tcp -m tcp --dport 9090 -d "openmano_ip" -j SNAT --to "UI_IP + #print "-A POSTROUTING -s "rift_ip" -p tcp -m tcp --dport 17070 -d "juju_ip" -j SNAT --to "UI_IP + #print "#End autogeneration by nat_osm" + osmpost=0; + donepost=1; + next; +} +osmpost==1 {next;} +innatpost==1 && /COMMIT/ { + innatpost=0; + innat=0; + if (donepost==0) { + #print "#Autogenerated by nat_osm" + #print "-A POSTROUTING -s "rift_ip" -p tcp -m tcp --dport 9090 -d "openmano_ip" -j SNAT --to "UI_IP + #print "-A POSTROUTING -s "rift_ip" -p tcp -m tcp --dport 17070 -d "juju_ip" -j SNAT --to "UI_IP + #print "#End autogeneration by nat_osm" + donepost=1; + } + print; + next; +} +{ + print +} +' /etc/iptables/rules.v4 > testfile.tmp && mv testfile.tmp /etc/iptables/rules.v4 + +service netfilter-persistent restart +