Minor changes in installer to guarantee idempotency in configuration
[osm/devops.git] / installers / install_osm.sh
index 9fb7d81..947c637 100755 (executable)
@@ -30,6 +30,7 @@ function usage(){
     echo -e "                     ..."
     echo -e "     --lxdimages:    download lxd images from OSM repository instead of creating them from scratch"
     echo -e "     -l <lxd_repo>:  use specified repository url for lxd images"
+    echo -e "     --vimemu:       additionally fetch, build, and deploy the VIM emulator as a docker container"
     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"
@@ -211,9 +212,10 @@ function configure_RO(){
     ro_is_up
 
     lxc exec RO -- openmano tenant-delete -f osm >/dev/null
+    lxc exec RO -- openmano tenant-create osm > /dev/null
     lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc 
     lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
-    #lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
+    lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
 }
 
 function configure_VCA(){
@@ -225,7 +227,7 @@ function configure_VCA(){
 function configure_SOUI(){
     . $OSM_DEVOPS/installers/export_ips
     JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
-    RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'`
+    RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
 
     echo -e "       Configuring SO"
     sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
@@ -402,16 +404,19 @@ function install_from_lxdimages(){
 function install_docker_ce() {
     # installs and configures Docker CE
     echo "Installing Docker CE ..."
-    sudo apt-get install apt-transport-https ca-certificates software-properties-common
+    sudo apt-get -qq update
+    sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
     sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
     sudo apt-get -qq update
-    sudo apt-get install docker-ce
-    # user management
+    sudo apt-get install -y docker-ce
     echo "Adding user to group 'docker'"
-    sudo groupadd 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"
 }
 
 function install_vimemu() {
@@ -422,18 +427,21 @@ function install_vimemu() {
     git clone https://osm.etsi.org/gerrit/osm/vim-emu.git
     # build vim-emu docker
     echo "Building vim-emu Docker container..."
-    docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
+    sudo docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
     # start vim-emu container as daemon
     echo "Starting vim-emu Docker container 'vim-emu' ..."
-    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
+    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
     echo "Waiting for 'vim-emu' container to start ..."
     sleep 5
-    export VIMEMU_HOSTNAME=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
+    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 env variables to your .bashrc file:"
+    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:"
     echo "     export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
     echo -e "\nTo add the emulated VIM to OSM you should do:"
-    echo "     osm vim-create --name emu-vim1 --user username --password password --auth_url http://$VIM_EMU_IP:6001/v2.0 --tenant tenantName --account_type openstack"
+    echo "     osm vim-create --name emu-vim1 --user username --password password --auth_url http://$VIMEMU_HOSTNAME:6001/v2.0 --tenant tenantName --account_type openstack"
 }
 
 function dump_vars(){