| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 15 | |
| 16 | # set -eux |
| 17 | |
| 18 | K8S_CLOUD_NAME="k8s-cloud" |
| beierlm | 3749e31 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 19 | KUBECTL="microk8s.kubectl" |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 20 | IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 21 | function check_arguments(){ |
| 22 | while [ $# -gt 0 ] ; do |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 23 | case $1 in |
| 24 | --bundle) BUNDLE="$2" ;; |
| Dominik Fleischmann | 7a97a4c | 2020-06-04 10:52:05 +0200 | [diff] [blame] | 25 | --k8s) KUBECFG="$2" ;; |
| 26 | --vca) CONTROLLER="$2" ;; |
| 27 | --lxd) LXD_CLOUD="$2" ;; |
| 28 | --lxd-cred) LXD_CREDENTIALS="$2" ;; |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 29 | --microstack) MICROSTACK=y ;; |
| David Garcia | cef05e9 | 2020-08-20 12:08:31 +0200 | [diff] [blame] | 30 | --ha) BUNDLE="cs:osm-ha" ;; |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 31 | --tag) TAG="$2" ;; |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 32 | esac |
| 33 | shift |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 34 | done |
| 35 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 36 | # echo $BUNDLE $KUBECONFIG $LXDENDPOINT |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 37 | } |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 38 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 39 | function install_snaps(){ |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 40 | if [ ! -v KUBECFG ]; then |
| 41 | sudo snap install microk8s --classic |
| 42 | sudo usermod -a -G microk8s `whoami` |
| 43 | mkdir -p ~/.kube |
| 44 | sudo chown -f -R `whoami` ~/.kube |
| 45 | KUBEGRP="microk8s" |
| 46 | else |
| 47 | KUBECTL="kubectl" |
| 48 | sudo snap install kubectl --classic |
| 49 | export KUBECONFIG=${KUBECFG} |
| 50 | KUBEGRP=$(id -g -n) |
| 51 | fi |
| 52 | sudo snap install juju --classic --channel=2.8/stable |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | function bootstrap_k8s_lxd(){ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 56 | [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 57 | [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca" |
| 58 | |
| 59 | if [ -v BOOTSTRAP_NEEDED ]; then |
| 60 | CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) |
| 61 | if [ $CONTROLLER_PRESENT -ge 1 ]; then |
| 62 | cat << EOF |
| 63 | Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}". |
| 64 | You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it |
| 65 | using this command: |
| 66 | |
| 67 | juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME} |
| 68 | |
| 69 | Please retry the installation once this conflict has been resolved. |
| 70 | EOF |
| 71 | exit 1 |
| 72 | fi |
| 73 | fi |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 74 | |
| 75 | if [ -v KUBECFG ]; then |
| 76 | cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| beierlm | 2634cd3 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 77 | [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \ |
| 78 | --config controller-service-type=loadbalancer \ |
| 79 | --agent-version=2.8.1 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 80 | else |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 81 | sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" |
| 82 | sg ${KUBEGRP} -c "microk8s.enable storage dns" |
| 83 | TIME_TO_WAIT=30 |
| 84 | start_time="$(date -u +%s)" |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 85 | while true |
| 86 | do |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 87 | now="$(date -u +%s)" |
| 88 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 89 | echo "Microk8s storage failed to enable" |
| 90 | sg ${KUBEGRP} -c "microk8s.status" |
| 91 | exit 1 |
| 92 | fi |
| 93 | storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"` |
| 94 | if [[ $storage_status == "enabled" ]]; then |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 95 | break |
| 96 | fi |
| 97 | sleep 1 |
| 98 | done |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 99 | |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 100 | [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| beierlm | 2634cd3 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 101 | [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \ |
| 102 | "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=2.8.1" \ |
| 103 | && K8S_CLOUD_NAME=microk8s |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 104 | fi |
| 105 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 106 | if [ -v LXD_CLOUD ]; then |
| 107 | if [ ! -v LXD_CREDENTIALS ]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 108 | echo "The installer needs the LXD server certificate if the LXD is external" |
| 109 | exit 1 |
| 110 | fi |
| 111 | else |
| 112 | LXDENDPOINT=$DEFAULT_IP |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 113 | LXD_CLOUD=~/.osm/lxd-cloud.yaml |
| 114 | LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml |
| 115 | # Apply sysctl production values for optimal performance |
| 116 | sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf |
| 117 | sudo sysctl --system |
| 118 | # Install LXD snap |
| 119 | sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client |
| 120 | sudo snap install lxd |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 121 | # Configure LXD |
| 122 | sudo usermod -a -G lxd `whoami` |
| 123 | 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" |
| 124 | sg lxd -c "lxd waitready" |
| 125 | DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 126 | sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU" |
| David Garcia | d00e49c | 2020-06-19 10:33:37 +0200 | [diff] [blame] | 127 | sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 128 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 129 | cat << EOF > $LXD_CLOUD |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 130 | clouds: |
| 131 | lxd-cloud: |
| 132 | type: lxd |
| 133 | auth-types: [certificate] |
| 134 | endpoint: "https://$LXDENDPOINT:8443" |
| 135 | config: |
| 136 | ssl-hostname-verification: false |
| 137 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 138 | openssl req -nodes -new -x509 -keyout ~/.osm/client.key -out ~/.osm/client.crt -days 365 -subj "/C=FR/ST=Nice/L=Nice/O=ETSI/OU=OSM/CN=osm.etsi.org" |
| 139 | local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'` |
| 140 | local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'` |
| 141 | local client_key=`cat ~/.osm/client.key | sed 's/^/ /'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 142 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 143 | cat << EOF > $LXD_CREDENTIALS |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 144 | credentials: |
| 145 | lxd-cloud: |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 146 | lxd-cloud: |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 147 | auth-type: certificate |
| 148 | server-cert: | |
| 149 | $server_cert |
| 150 | client-cert: | |
| 151 | $client_cert |
| 152 | client-key: | |
| 153 | $client_key |
| 154 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 155 | lxc config trust add local: ~/.osm/client.crt |
| 156 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 157 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 158 | juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force |
| 159 | juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS |
| 160 | sg lxd -c "lxd waitready" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 161 | #juju add-model test lxd-cloud || true |
| 162 | juju controller-config features=[k8s-operators] |
| 163 | } |
| 164 | |
| 165 | function wait_for_port(){ |
| 166 | SERVICE=$1 |
| 167 | INDEX=$2 |
| 168 | TIME_TO_WAIT=30 |
| 169 | start_time="$(date -u +%s)" |
| 170 | while true |
| 171 | do |
| 172 | now="$(date -u +%s)" |
| 173 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 174 | echo "Failed to expose external ${SERVICE} interface port" |
| 175 | exit 1 |
| 176 | fi |
| 177 | |
| 178 | if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then |
| 179 | break |
| 180 | fi |
| 181 | sleep 1 |
| 182 | done |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | function deploy_charmed_osm(){ |
| 186 | create_overlay |
| 187 | echo "Creating OSM model" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 188 | if [ -v KUBECFG ]; then |
| 189 | juju add-model osm $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 190 | else |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 191 | sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 192 | fi |
| 193 | echo "Deploying OSM with charms" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 194 | images_overlay="" |
| 195 | [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 196 | if [ -v BUNDLE ]; then |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 197 | juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 198 | else |
| David Garcia | cef05e9 | 2020-08-20 12:08:31 +0200 | [diff] [blame] | 199 | juju deploy cs:osm --overlay ~/.osm/vca-overlay.yaml $images_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 200 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 201 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 202 | echo "Waiting for deployment to finish..." |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 203 | check_osm_deployed |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 204 | echo "OSM with charms deployed" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 205 | if [ ! -v KUBECFG ]; then |
| 206 | sg ${KUBEGRP} -c "microk8s.enable ingress" |
| 207 | API_SERVER=${DEFAULT_IP} |
| 208 | else |
| 209 | API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ") |
| 210 | proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')" |
| 211 | url="$(echo ${API_SERVER/$proto/})" |
| 212 | user="$(echo $url | grep @ | cut -d@ -f1)" |
| 213 | hostport="$(echo ${url/$user@/} | cut -d/ -f1)" |
| 214 | API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')" |
| 215 | fi |
| 216 | |
| David Garcia | de5fc1d | 2020-09-02 11:40:12 +0200 | [diff] [blame] | 217 | # Expose OSM services |
| 218 | # Expose NBI |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 219 | juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io |
| 220 | juju expose nbi-k8s |
| 221 | |
| David Garcia | de5fc1d | 2020-09-02 11:40:12 +0200 | [diff] [blame] | 222 | # Expose NG UI |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 223 | juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io |
| 224 | juju expose ng-ui |
| 225 | |
| David Garcia | de5fc1d | 2020-09-02 11:40:12 +0200 | [diff] [blame] | 226 | # Expose UI |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 227 | juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 228 | juju expose ui-k8s |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 229 | |
| David Garcia | de5fc1d | 2020-09-02 11:40:12 +0200 | [diff] [blame] | 230 | # Wait for ingress resources to be applied |
| 231 | wait_for_port nbi-k8s 0 |
| 232 | wait_for_port ng-ui 1 |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 233 | wait_for_port ui-k8s 2 |
| David Garcia | de5fc1d | 2020-09-02 11:40:12 +0200 | [diff] [blame] | 234 | |
| 235 | # Apply annotations |
| 236 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s" |
| 237 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s" |
| 238 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui" |
| 239 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s" |
| 240 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 241 | |
| 242 | function check_osm_deployed() { |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 243 | TIME_TO_WAIT=600 |
| 244 | start_time="$(date -u +%s)" |
| 245 | total_service_count=14 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 246 | while true |
| 247 | do |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 248 | service_count=$(juju status | grep kubernetes | grep active | wc -l) |
| 249 | echo "$service_count / $total_service_count services active" |
| 250 | if [ $service_count -eq $total_service_count ]; then |
| 251 | break |
| 252 | fi |
| 253 | now="$(date -u +%s)" |
| 254 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 255 | echo "Timed out waiting for OSM services to become ready" |
| 256 | exit 1 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 257 | fi |
| 258 | sleep 10 |
| 259 | done |
| 260 | } |
| 261 | |
| 262 | function create_overlay() { |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 263 | sudo snap install jq |
| 264 | sudo apt install python3-pip -y |
| 265 | python3 -m pip install yq |
| 266 | PATH=$PATH:$HOME/.local/bin # make yq command available |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 267 | local HOME=/home/$USER |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 268 | local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user') |
| 269 | local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password') |
| beierlm | 3749e31 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 270 | local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' --raw-output | cut -d ":" -f 1) |
| 271 | local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' --raw-output | cut -d ":" -f 2) |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 272 | local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\" |
| 273 | local vca_cloud="lxd-cloud" |
| 274 | # Get the VCA Certificate |
| beierlm | 3749e31 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 275 | local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert"]' --raw-output | base64 | tr -d \\n) |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 276 | |
| 277 | # Calculate the default route of this machine |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 278 | local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 279 | |
| 280 | # Generate a new overlay.yaml, overriding any existing one |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 281 | cat << EOF > /tmp/vca-overlay.yaml |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 282 | applications: |
| 283 | lcm-k8s: |
| 284 | options: |
| 285 | vca_user: $vca_user |
| 286 | vca_password: $vca_password |
| 287 | vca_host: $vca_host |
| 288 | vca_port: $vca_port |
| 289 | vca_pubkey: $vca_pubkey |
| 290 | vca_cacert: $vca_cacert |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 291 | vca_cloud: $vca_cloud |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 292 | vca_k8s_cloud: $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 293 | mon-k8s: |
| 294 | options: |
| 295 | vca_user: $vca_user |
| 296 | vca_password: $vca_password |
| 297 | vca_host: $vca_host |
| 298 | vca_cacert: $vca_cacert |
| 299 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 300 | mv /tmp/vca-overlay.yaml ~/.osm/ |
| 301 | OSM_VCA_HOST=$vca_host |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 304 | function generate_images_overlay(){ |
| 305 | cat << EOF > /tmp/images-overlay.yaml |
| 306 | applications: |
| 307 | lcm-k8s: |
| 308 | options: |
| 309 | image: opensourcemano/lcm:$TAG |
| 310 | mon-k8s: |
| 311 | options: |
| 312 | image: opensourcemano/mon:$TAG |
| 313 | ro-k8s: |
| 314 | options: |
| 315 | image: opensourcemano/ro:$TAG |
| 316 | nbi-k8s: |
| 317 | options: |
| 318 | image: opensourcemano/nbi:$TAG |
| 319 | pol-k8s: |
| 320 | options: |
| 321 | image: opensourcemano/pol:$TAG |
| 322 | ui-k8s: |
| 323 | options: |
| 324 | image: opensourcemano/light-ui:$TAG |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 325 | pla: |
| 326 | options: |
| 327 | image: opensourcemano/pla:$TAG |
| 328 | ng-ui: |
| 329 | options: |
| 330 | image: opensourcemano/ng-ui:$TAG |
| David Garcia | 009a5d6 | 2020-08-27 16:53:44 +0200 | [diff] [blame] | 331 | keystone: |
| 332 | options: |
| 333 | image: opensourcemano/keystone:$TAG |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 334 | |
| 335 | EOF |
| 336 | mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE |
| 337 | } |
| 338 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 339 | function install_osmclient() { |
| 340 | sudo snap install osmclient |
| 341 | sudo snap alias osmclient.osm osm |
| 342 | } |
| 343 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 344 | |
| 345 | function install_microstack() { |
| 346 | sudo snap install microstack --classic --beta |
| 347 | sudo microstack.init --auto |
| 348 | wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/ |
| 349 | microstack.openstack image create \ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 350 | --public \ |
| 351 | --disk-format qcow2 \ |
| 352 | --container-format bare \ |
| 353 | --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \ |
| 354 | ubuntu1604 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 355 | ssh-keygen -t rsa -N "" -f ~/.ssh/microstack |
| 356 | microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 357 | export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 358 | osm vim-create --name microstack-site \ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 359 | --user admin \ |
| 360 | --password keystone \ |
| 361 | --auth_url http://10.20.20.1:5000/v3 \ |
| 362 | --tenant admin \ |
| 363 | --account_type openstack \ |
| 364 | --config='{security_groups: default, |
| 365 | keypair: microstack, |
| 366 | project_name: admin, |
| 367 | user_domain_name: default, |
| 368 | region_name: microstack, |
| 369 | insecure: True, |
| 370 | availability_zone: nova, |
| 371 | version: 3}' |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 374 | DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 375 | DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` |
| 376 | |
| 377 | check_arguments $@ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 378 | mkdir -p ~/.osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 379 | install_snaps |
| 380 | bootstrap_k8s_lxd |
| 381 | deploy_charmed_osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 382 | install_osmclient |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 383 | if [ -v MICROSTACK ]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 384 | install_microstack |
| 385 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 386 | |
| 387 | echo "Your installation is now complete, follow these steps for configuring the osmclient:" |
| 388 | echo |
| 389 | echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP" |
| 390 | echo |
| 391 | echo "export OSM_HOSTNAME=nbi.$API_SERVER.xip.io:443" |
| 392 | echo |
| 393 | echo "2. Add the previous command to your .bashrc for other Shell sessions" |
| 394 | echo |
| 395 | echo "echo \"export OSM_HOSTNAME=nbi.$API_SERVER.xip.io:443\" >> ~/.bashrc" |
| 396 | echo |
| 397 | echo "DONE" |