updated juju bootstrap to use xenial series
[osm/devops.git] / installers / full_install_osm.sh
index 3d41b21..d9d1e7d 100755 (executable)
@@ -32,8 +32,11 @@ function usage(){
     echo -e "     -l <lxd_repo>:  use specified repository url for lxd images"
     echo -e "     -p <path>:      use specified repository path for lxd images"
     echo -e "     --lightweight:  install lightweight build of OSM (default installation)"
-    echo -e "     --soui:         install classic build of OSM (based on LXD containers, with SO and UI)"
-    echo -e "     --vimemu:       additionally fetch, build, and deploy the VIM emulator as a docker container"
+    echo -e "     --soui:         install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
+    echo -e "     --vimemu:       additionally deploy the VIM emulator as a docker container"
+    echo -e "     --elk_stack:    additionally deploy an ELK docker stack for event logging"
+    echo -e "     --pm_stack:     additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
+    echo -e "     -o <ADDON>:     do not install OSM, but ONLY one of the addons (vimemu, elk_stack, pm_stack) (assumes OSM is already installed)"
     echo -e "     --develop:      (deprecated, use '-b master') install OSM from source code using the master branch"
 #    echo -e "     --reconfigure:  reconfigure the modules (DO NOT change NAT rules)"
     echo -e "     --nat:          install only NAT rules"
@@ -312,7 +315,9 @@ function configure_SOUI(){
 
     echo -e "       Configuring SO"
     sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
+    sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
     sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
+    sudo sed -i "$ i ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP" /etc/rc.local
     # make journaling persistent
     lxc exec SO-ub -- mkdir -p /var/log/journal
     lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
@@ -460,7 +465,7 @@ function install_osmclient(){
     #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
     [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
     [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
-    [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=localhost
+    [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
     echo -e "\nOSM client installed"
     echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
     echo "     export OSM_HOSTNAME=${OSM_HOSTNAME}"
@@ -516,10 +521,12 @@ function install_docker_ce() {
     echo "Adding user to group 'docker'"
     sudo groupadd -f docker
     sudo usermod -aG docker $USER
-    echo "... Docker CE installation done"
     sleep 2
     sudo service docker restart
     echo "... restarted Docker service"
+    sg docker -c "docker version" || FATAL "Docker installation failed"
+    echo "... Docker CE installation done"
+    return 0
 }
 
 function install_docker_compose() {
@@ -534,7 +541,8 @@ function install_juju() {
     echo "Installing juju"
     sudo snap install juju --classic
     sudo dpkg-reconfigure -p medium lxd
-    sg lxd -c "juju bootstrap localhost osm"
+    sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost osm"
+    [ $(juju status |grep "osm" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
     echo "Finished installation of juju"
 }
 
@@ -552,7 +560,8 @@ function generate_docker_images() {
     docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2
     git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
     docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2
-    docker build ${LWTEMPDIR}/RO/lcm -t osm/lcm || ! echo "cannot build LCM docker image" >&2
+    git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
+    docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm || ! echo "cannot build LCM docker image" >&2
 #    git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git
 #    docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile
     git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
@@ -590,7 +599,58 @@ EONG
     echo "Finished deployment of lightweight build"
 }
 
+function deploy_elk() {
+    echo "Deploying ELK stack"
+    sg docker -c "docker stack deploy -c ${OSM_DEVOPS}/installers/docker/osm_elk/docker-compose.yml osm_elk"
+    echo "Waiting for ELK stack to be up and running"
+    time=0
+    step=2
+    timelength=20
+    elk_is_up=1
+    while [ $time -le $timelength ]; do
+        if [[ $(curl -XGET http://localhost:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
+            elk_is_up=0
+            break
+        fi
+        sleep $step
+        time=$((time+step))
+    done
+    if [ $elk_is_up -eq 0 ]; then
+        echo "ELK is up and running. Trying to create index pattern..."
+        #Create index pattern
+        curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+          "http://localhost:5601/api/saved_objects/index-pattern/logstash-*" \
+          -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"
+        #Make it the default index
+        curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+          "http://localhost:5601/api/kibana/settings/defaultIndex" \
+          -d"{\"value\":\"logstash-*\"}"
+    else
+        echo "Cannot connect to Kibana to create index pattern."
+        echo "Once Kibana is running, you can use the following instructions to create index pattern:"
+        echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+          "http://localhost:5601/api/saved_objects/index-pattern/logstash-*" \
+          -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
+        echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+          "http://localhost:5601/api/kibana/settings/defaultIndex" \
+          -d"{\"value\":\"logstash-*\"}"'
+    fi
+    echo "Finished deployment of ELK stack"
+    return 0
+}
+
+function deploy_perfmon() {
+    echo "Generating osm/kafka-exporter docker image"
+    sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter || ! echo 'cannot build kafka-exporter docker image' >&2"
+    echo "Finished generation of osm/kafka-exporter docker image"
+    echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
+    sg docker -c "docker stack deploy -c ${OSM_DEVOPS}/installers/docker/osm_metrics/docker-compose.yml osm_metrics"
+    echo "Finished deployment of PM stack"
+    return 0
+}
+
 function install_lightweight() {
+    [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
     echo "Installing lightweight build of OSM"
     LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
     trap 'rm -rf "${LWTEMPDIR}"' EXIT
@@ -608,37 +668,52 @@ function install_lightweight() {
       || sudo apt-get install -y $need_packages_lw \
       || FATAL "failed to install $need_packages_lw"
     install_juju
+    track juju
     install_docker_ce
+    track docker_ce
     #install_docker_compose
     generate_docker_images
+    track docker_build
     generate_docker_env_files
     deploy_lightweight
+    track docker_deploy
+    [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
+    [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
+    [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
     install_osmclient
+    track osmclient
+    wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
+    track end
     return 0
 }
 
 function install_vimemu() {
-    # install Docker
-    install_docker_ce
+    echo "\nInstalling vim-emu"
+    EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
+    trap 'rm -rf "${EMUTEMPDIR}"' EXIT
     # clone vim-emu repository (attention: branch is currently master only)
     echo "Cloning vim-emu repository ..."
-    git clone https://osm.etsi.org/gerrit/osm/vim-emu.git
+    git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
     # build vim-emu docker
     echo "Building vim-emu Docker container..."
-    sudo docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
+    sudo docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile $EMUTEMPDIR/
     # start vim-emu container as daemon
     echo "Starting vim-emu Docker container 'vim-emu' ..."
-    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
+    if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
+        # in lightweight mode, the emulator needs to be attached to netOSM
+        sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
+    else
+        # classic build mode
+        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
+    fi
     echo "Waiting for 'vim-emu' container to start ..."
     sleep 5
     export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
     echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
-    echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
-    echo "     export OSM_HOSTNAME=${OSM_HOSTNAME}"
-    echo "     export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
-    echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:"
+    # print vim-emu connection info
+    echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
     echo "     export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
-    echo -e "\nTo add the emulated VIM to OSM you should do:"
+    echo -e "To add the emulated VIM to OSM you should do:"
     echo "     osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
 }
 
@@ -656,6 +731,9 @@ function dump_vars(){
     echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
     echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
     echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
+    echo "INSTALL_ONLY=$INSTALL_ONLY"
+    echo "INSTALL_ELK=$INSTALL_ELK"
+    echo "INSTALL_PERFMON=$INSTALL_PERFMON"
     echo "RELEASE=$RELEASE"
     echo "REPOSITORY=$REPOSITORY"
     echo "REPOSITORY_BASE=$REPOSITORY_BASE"
@@ -671,8 +749,9 @@ function track(){
     url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
     #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
     event_name="bin"
-    [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src"
-    [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
+    [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
+    [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
+    [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
     event_name="${event_name}_$1"
     url="${url}&event=${event_name}&ce_duration=${duration}"
     wget -q -O /dev/null $url
@@ -696,12 +775,15 @@ INSTALL_FROM_LXDIMAGES=""
 LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
 LXD_REPOSITORY_PATH=""
 INSTALL_LIGHTWEIGHT="y"
+INSTALL_ONLY=""
+INSTALL_ELK=""
+INSTALL_PERFMON=""
 NOCONFIGURE=""
 RELEASE_DAILY=""
 SESSION_ID=`date +%s`
 OSM_DEVOPS=
 
-while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
+while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
     case "${o}" in
         h)
             usage && exit 0
@@ -730,6 +812,12 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
         D)
             OSM_DEVOPS="${OPTARG}"
             ;;
+        o)
+            INSTALL_ONLY="y"
+            [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
+            [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
+            [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
+            ;;
         -)
             [ "${OPTARG}" == "help" ] && usage && exit 0
             [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
@@ -742,8 +830,10 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
             [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
             [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
             [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
-            [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && continue
+            [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE-Classic" && REPOSITORY="-r testing" && continue
             [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
+            [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
+            [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
             [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
             [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
             [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
@@ -763,6 +853,8 @@ while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
     esac
 done
 
+[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
+
 if [ -n "$SHOWOPTS" ]; then
     dump_vars
     exit 0
@@ -828,8 +920,15 @@ OSM_JENKINS="$OSM_DEVOPS/jenkins"
 [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
 [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
 [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
+[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
+[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
+[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
+[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
 
 #Installation starts here
+wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
+track start
+
 [ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
 echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
 if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
@@ -840,9 +939,6 @@ echo -e "Checking required packages: lxd"
 lxd --version &>/dev/null || FATAL "lxd not present, exiting."
 [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
 
-wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
-track start
-
 # use local devops for containers
 export OSM_USE_LOCAL_DEVOPS=true
 if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
@@ -884,10 +980,7 @@ fi
 [ -z "$NOCONFIGURE" ] && install_osmclient
 
 #Install vim-emu (optional)
-if [ -n "$INSTALL_VIMEMU" ]; then
-    echo -e "\nInstalling vim-emu ..."
-    install_vimemu
-fi
+[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
 
 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
 track end