Bug 1530: Limit IP addresses
[osm/devops.git] / installers / charmed_install.sh
index b36d582..bd714a6 100755 (executable)
 
 # set -eux
 
-JUJU_AGENT_VERSION=2.8.9
+LXD_VERSION=4.0
+JUJU_VERSION=2.9
+JUJU_AGENT_VERSION=2.9.17
 K8S_CLOUD_NAME="k8s-cloud"
 KUBECTL="microk8s.kubectl"
-MICROK8S_VERSION=1.19
-OSMCLIENT_VERSION=9.0
+MICROK8S_VERSION=1.20
+OSMCLIENT_VERSION=10.0
 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
 PATH=/snap/bin:${PATH}
 
 MODEL_NAME=osm
 
-OSM_BUNDLE=cs:osm-60
-OSM_HA_BUNDLE=cs:osm-ha-45
+# Latest bundles using old mongodb-k8s
+# OSM_BUNDLE=cs:osm-68
+# OSM_HA_BUNDLE=cs:osm-ha-54
+# The charm store does not support referencing charms from CharmHub,
+# therefore we will point to the local bundles until we migrate all
+# charms to CharmHub.
+OSM_BUNDLE=/usr/share/osm-devops/installers/charm/bundles/osm/bundle.yaml
+OSM_HA_BUNDLE=/usr/share/osm-devops/installers/charm/bundles/osm-ha/bundle.yaml
 TAG=testing-daily
 
 function check_arguments(){
     while [ $# -gt 0 ] ; do
         case $1 in
             --bundle) BUNDLE="$2" ;;
+            --overlay) OVERLAY="$2" ;;
             --k8s) KUBECFG="$2" ;;
             --vca) CONTROLLER="$2" ;;
             --lxd) LXD_CLOUD="$2" ;;
@@ -41,6 +50,7 @@ function check_arguments(){
             --ha) BUNDLE=$OSM_HA_BUNDLE ;;
             --tag) TAG="$2" ;;
             --registry) REGISTRY_INFO="$2" ;;
+            --only-vca) ONLY_VCA=y ;;
         esac
         shift
     done
@@ -69,7 +79,7 @@ function install_snaps(){
         export KUBECONFIG=${KUBECFG}
         KUBEGRP=$(id -g -n)
     fi
-    sudo snap install juju --classic --channel=2.8/stable
+    sudo snap install juju --classic --channel=$JUJU_VERSION/stable
 }
 
 function bootstrap_k8s_lxd(){
@@ -149,7 +159,7 @@ EOF
         sudo sysctl --system
         # Install LXD snap
         sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
-        sudo snap install lxd
+        sudo snap install lxd --channel $LXD_VERSION/stable
         # Configure LXD
         sudo usermod -a -G lxd `whoami`
         cat /usr/share/osm-devops/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n  core.https_address: '$LXDENDPOINT':8443/' | sg lxd -c "lxd init --preseed"
@@ -235,7 +245,6 @@ function deploy_charmed_osm(){
         esac
     fi
 
-    create_overlay
     echo "Creating OSM model"
     if [ -v KUBECFG ]; then
         juju add-model $MODEL_NAME $K8S_CLOUD_NAME
@@ -249,10 +258,14 @@ function deploy_charmed_osm(){
     fi
     [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
 
+    if [ -v OVERLAY ]; then
+        extra_overlay="--overlay $OVERLAY"
+    fi
+
     if [ -v BUNDLE ]; then
-        juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
+        juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
     else
-        juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
+        juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
     fi
 
     if [ ! -v KUBECFG ]; then
@@ -266,13 +279,17 @@ function deploy_charmed_osm(){
         API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
     fi
     # Expose OSM services
-    juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.xip.io
-    juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.xip.io
-    juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.xip.io
-    juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.xip.io
+    juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
+    juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
+    juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
+    juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
 
     echo "Waiting for deployment to finish..."
     check_osm_deployed
+    grafana_leader=`juju status -m $MODEL_NAME grafana | grep "*" | cut -d "*" -f 1`
+    grafana_admin_password=`juju run -m $MODEL_NAME --unit $grafana_leader "echo \\$GF_SECURITY_ADMIN_PASSWORD"`
+    juju config -m $MODEL_NAME mon grafana_password=$grafana_admin_password
+    check_osm_deployed
     echo "OSM with charms deployed"
 }
 
@@ -433,32 +450,47 @@ function install_microstack() {
     version: 3}'
 }
 
-DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
-DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
+DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5; exit}'`
+DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]; exit}'`
 
 check_arguments $@
 mkdir -p ~/.osm
 install_snaps
 bootstrap_k8s_lxd
-deploy_charmed_osm
-install_osmclient
-export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
-sleep 10
-add_local_k8scluster
-
-if [ -v MICROSTACK ]; then
-    install_microstack
-fi
+create_overlay
+if [ -v ONLY_VCA ]; then
+    HOME=/home/$USER
+    vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
+    vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
+    vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
+    vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
+    vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
+    vca_cloud="lxd-cloud"
+    vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
+    hostname=`cat /etc/hostname`
+
+    echo "Use the following command to register the installed VCA to your OSM:"
+    echo -e "  osm vca-add --endpoints $vca_host:$vca_port \\\n         --user $vca_user \\\n         --secret $vca_secret \\\n         --cacert $vca_cacert \\\n         --lxd-cloud lxd-cloud \\\n         --lxd-credentials lxd-cloud \\\n         --k8s-cloud microk8s \\\n         --k8s-credentials microk8s\\\n         $hostname-vca"
+else
+    deploy_charmed_osm
+    install_osmclient
+    export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
+    sleep 10
+    add_local_k8scluster
+    if [ -v MICROSTACK ]; then
+        install_microstack
+    fi
 
+    echo "Your installation is now complete, follow these steps for configuring the osmclient:"
+    echo
+    echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
+    echo
+    echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
+    echo
+    echo "2. Add the previous command to your .bashrc for other Shell sessions"
+    echo
+    echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
+    echo
+    echo "DONE"
+fi
 
-echo "Your installation is now complete, follow these steps for configuring the osmclient:"
-echo
-echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
-echo
-echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
-echo
-echo "2. Add the previous command to your .bashrc for other Shell sessions"
-echo
-echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
-echo
-echo "DONE"