| 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 | dfd4288 | 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 ;; |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 30 | --ha) BUNDLE="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 | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 38 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 39 | function install_snaps(){ |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -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 |
| Dominik Fleischmann | 71997c1 | 2020-06-30 14:25:19 +0200 | [diff] [blame] | 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 | 9425dd2 | 2020-07-16 16:57:09 -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 | dfd4288 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 77 | [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME --config controller-service-type=loadbalancer |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 78 | else |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 79 | sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" |
| 80 | sg ${KUBEGRP} -c "microk8s.enable storage dns" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 81 | TIME_TO_WAIT=30 |
| 82 | start_time="$(date -u +%s)" |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 83 | while true |
| 84 | do |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 85 | now="$(date -u +%s)" |
| 86 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 87 | echo "Microk8s storage failed to enable" |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 88 | sg ${KUBEGRP} -c "microk8s.status" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 89 | exit 1 |
| 90 | fi |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 91 | sg ${KUBEGRP} -c "microk8s.status" | grep 'storage: enabled' |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 92 | if [ $? -eq 0 ]; then |
| 93 | break |
| 94 | fi |
| 95 | sleep 1 |
| 96 | done |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 97 | |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 98 | [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| 99 | [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer" && K8S_CLOUD_NAME=microk8s |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 100 | fi |
| 101 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 102 | if [ -v LXD_CLOUD ]; then |
| 103 | if [ ! -v LXD_CREDENTIALS ]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 104 | echo "The installer needs the LXD server certificate if the LXD is external" |
| 105 | exit 1 |
| 106 | fi |
| 107 | else |
| 108 | LXDENDPOINT=$DEFAULT_IP |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 109 | LXD_CLOUD=~/.osm/lxd-cloud.yaml |
| 110 | LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml |
| 111 | # Apply sysctl production values for optimal performance |
| 112 | sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf |
| 113 | sudo sysctl --system |
| 114 | # Install LXD snap |
| 115 | sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client |
| 116 | sudo snap install lxd |
| 117 | sudo apt-get install zfsutils-linux -y |
| 118 | # Configure LXD |
| 119 | sudo usermod -a -G lxd `whoami` |
| 120 | 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" |
| 121 | sg lxd -c "lxd waitready" |
| 122 | DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 123 | sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU" |
| David Garcia | d00e49c | 2020-06-19 10:33:37 +0200 | [diff] [blame] | 124 | sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 125 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 126 | cat << EOF > $LXD_CLOUD |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 127 | clouds: |
| 128 | lxd-cloud: |
| 129 | type: lxd |
| 130 | auth-types: [certificate] |
| 131 | endpoint: "https://$LXDENDPOINT:8443" |
| 132 | config: |
| 133 | ssl-hostname-verification: false |
| 134 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 135 | 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" |
| 136 | local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'` |
| 137 | local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'` |
| 138 | local client_key=`cat ~/.osm/client.key | sed 's/^/ /'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 139 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 140 | cat << EOF > $LXD_CREDENTIALS |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 141 | credentials: |
| 142 | lxd-cloud: |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 143 | lxd-cloud: |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 144 | auth-type: certificate |
| 145 | server-cert: | |
| 146 | $server_cert |
| 147 | client-cert: | |
| 148 | $client_cert |
| 149 | client-key: | |
| 150 | $client_key |
| 151 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 152 | lxc config trust add local: ~/.osm/client.crt |
| 153 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 154 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 155 | juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force |
| 156 | juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS |
| 157 | sg lxd -c "lxd waitready" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 158 | #juju add-model test lxd-cloud || true |
| Dominik Fleischmann | 71997c1 | 2020-06-30 14:25:19 +0200 | [diff] [blame] | 159 | juju controller-config features=[k8s-operators] |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 162 | function wait_for_port(){ |
| 163 | SERVICE=$1 |
| 164 | INDEX=$2 |
| 165 | TIME_TO_WAIT=30 |
| 166 | start_time="$(date -u +%s)" |
| 167 | while true |
| 168 | do |
| 169 | now="$(date -u +%s)" |
| 170 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 171 | echo "Failed to expose external ${SERVICE} interface port" |
| 172 | exit 1 |
| 173 | fi |
| 174 | |
| 175 | if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then |
| 176 | break |
| 177 | fi |
| 178 | sleep 1 |
| 179 | done |
| 180 | } |
| 181 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 182 | function deploy_charmed_osm(){ |
| 183 | create_overlay |
| 184 | echo "Creating OSM model" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 185 | if [ -v KUBECFG ]; then |
| 186 | juju add-model osm $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 187 | else |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 188 | sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 189 | fi |
| 190 | echo "Deploying OSM with charms" |
| beierlm | b5332cf | 2020-07-08 11:43:59 -0400 | [diff] [blame] | 191 | images_overlay="" |
| 192 | [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 193 | if [ -v BUNDLE ]; then |
| beierlm | b5332cf | 2020-07-08 11:43:59 -0400 | [diff] [blame] | 194 | juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 195 | else |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 196 | juju deploy osm --overlay ~/.osm/vca-overlay.yaml $images_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 197 | fi |
| 198 | echo "Waiting for deployment to finish..." |
| 199 | check_osm_deployed &> /dev/null |
| 200 | echo "OSM with charms deployed" |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 201 | if [ ! -v KUBECFG ]; then |
| 202 | sg ${KUBEGRP} -c "microk8s.enable ingress" |
| 203 | API_SERVER=${DEFAULT_IP} |
| 204 | else |
| 205 | API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ") |
| 206 | proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')" |
| 207 | url="$(echo ${API_SERVER/$proto/})" |
| 208 | user="$(echo $url | grep @ | cut -d@ -f1)" |
| 209 | hostport="$(echo ${url/$user@/} | cut -d/ -f1)" |
| 210 | API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')" |
| 211 | fi |
| 212 | |
| 213 | juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io |
| 214 | juju expose nbi-k8s |
| 215 | |
| 216 | wait_for_port nbi-k8s 0 |
| 217 | sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[0].metadata.annotations += {\"nginx.ingress.kubernetes.io/backend-protocol\": \"HTTPS\"}' | ${KUBECTL} --validate=false replace -f -" |
| 218 | sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[0].metadata.annotations += {\"nginx.ingress.kubernetes.io/proxy-body-size\": \"0\"}' | ${KUBECTL} replace -f -" |
| 219 | |
| 220 | juju config ng-ui juju-external-hostname=ngui.${API_SERVER}.xip.io |
| 221 | juju expose ng-ui |
| 222 | |
| 223 | wait_for_port ng-ui 1 |
| 224 | sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[2].metadata.annotations += {\"nginx.ingress.kubernetes.io/proxy-body-size\": \"0\"}' | ${KUBECTL} replace -f -" |
| 225 | |
| 226 | juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 227 | juju expose ui-k8s |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 228 | |
| 229 | wait_for_port ui-k8s 2 |
| 230 | sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[1].metadata.annotations += {\"nginx.ingress.kubernetes.io/proxy-body-size\": \"0\"}' | ${KUBECTL} replace -f -" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | function check_osm_deployed() { |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 234 | TIME_TO_WAIT=300 |
| 235 | start_time="$(date -u +%s)" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 236 | while true |
| 237 | do |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 238 | pod_name=`sg ${KUBEGRP} -c "${KUBECTL} -n osm get pods | grep ui-k8s | grep -v operator" | awk '{print $1; exit}'` |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 239 | |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 240 | if [[ `sg ${KUBEGRP} -c "${KUBECTL} -n osm wait pod $pod_name --for condition=Ready"` ]]; then |
| 241 | if [[ `sg ${KUBEGRP} -c "${KUBECTL} -n osm wait pod lcm-k8s-0 --for condition=Ready"` ]]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 242 | break |
| 243 | fi |
| 244 | fi |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 245 | now="$(date -u +%s)" |
| 246 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 247 | echo "Timeout waiting for services to enter ready state" |
| 248 | exit 1 |
| 249 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 250 | sleep 10 |
| 251 | done |
| 252 | } |
| 253 | |
| 254 | function create_overlay() { |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 255 | sudo snap install jq |
| 256 | sudo apt install python3-pip -y |
| 257 | python3 -m pip install yq |
| 258 | PATH=$PATH:$HOME/.local/bin # make yq command available |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 259 | local HOME=/home/$USER |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 260 | local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user') |
| 261 | local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password') |
| beierlm | dfd4288 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 262 | 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) |
| 263 | 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] | 264 | local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\" |
| 265 | local vca_cloud="lxd-cloud" |
| 266 | # Get the VCA Certificate |
| beierlm | dfd4288 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 267 | 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] | 268 | |
| 269 | # Calculate the default route of this machine |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 270 | 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] | 271 | |
| 272 | # Generate a new overlay.yaml, overriding any existing one |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 273 | cat << EOF > /tmp/vca-overlay.yaml |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 274 | applications: |
| 275 | lcm-k8s: |
| 276 | options: |
| 277 | vca_user: $vca_user |
| 278 | vca_password: $vca_password |
| 279 | vca_host: $vca_host |
| 280 | vca_port: $vca_port |
| 281 | vca_pubkey: $vca_pubkey |
| 282 | vca_cacert: $vca_cacert |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 283 | vca_cloud: $vca_cloud |
| Dominik Fleischmann | 71997c1 | 2020-06-30 14:25:19 +0200 | [diff] [blame] | 284 | vca_k8s_cloud: $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 285 | mon-k8s: |
| 286 | options: |
| 287 | vca_user: $vca_user |
| 288 | vca_password: $vca_password |
| 289 | vca_host: $vca_host |
| 290 | vca_cacert: $vca_cacert |
| 291 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 292 | mv /tmp/vca-overlay.yaml ~/.osm/ |
| 293 | OSM_VCA_HOST=$vca_host |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 296 | function generate_images_overlay(){ |
| 297 | cat << EOF > /tmp/images-overlay.yaml |
| 298 | applications: |
| 299 | lcm-k8s: |
| 300 | options: |
| 301 | image: opensourcemano/lcm:$TAG |
| 302 | mon-k8s: |
| 303 | options: |
| 304 | image: opensourcemano/mon:$TAG |
| 305 | ro-k8s: |
| 306 | options: |
| 307 | image: opensourcemano/ro:$TAG |
| 308 | nbi-k8s: |
| 309 | options: |
| 310 | image: opensourcemano/nbi:$TAG |
| 311 | pol-k8s: |
| 312 | options: |
| 313 | image: opensourcemano/pol:$TAG |
| 314 | ui-k8s: |
| 315 | options: |
| 316 | image: opensourcemano/light-ui:$TAG |
| David Garcia | 5863d3e | 2020-07-09 13:14:13 +0200 | [diff] [blame] | 317 | pla: |
| 318 | options: |
| 319 | image: opensourcemano/pla:$TAG |
| David Garcia | fa55bd7 | 2020-07-07 11:14:19 +0200 | [diff] [blame] | 320 | ng-ui: |
| 321 | options: |
| 322 | image: opensourcemano/ng-ui:$TAG |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 323 | |
| 324 | EOF |
| 325 | mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE |
| 326 | } |
| 327 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 328 | function install_osmclient() { |
| 329 | sudo snap install osmclient |
| 330 | sudo snap alias osmclient.osm osm |
| 331 | } |
| 332 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 333 | |
| 334 | function install_microstack() { |
| 335 | sudo snap install microstack --classic --beta |
| 336 | sudo microstack.init --auto |
| 337 | wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/ |
| 338 | microstack.openstack image create \ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 339 | --public \ |
| 340 | --disk-format qcow2 \ |
| 341 | --container-format bare \ |
| 342 | --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \ |
| 343 | ubuntu1604 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 344 | ssh-keygen -t rsa -N "" -f ~/.ssh/microstack |
| 345 | microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 346 | 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] | 347 | osm vim-create --name microstack-site \ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 348 | --user admin \ |
| 349 | --password keystone \ |
| 350 | --auth_url http://10.20.20.1:5000/v3 \ |
| 351 | --tenant admin \ |
| 352 | --account_type openstack \ |
| 353 | --config='{security_groups: default, |
| 354 | keypair: microstack, |
| 355 | project_name: admin, |
| 356 | user_domain_name: default, |
| 357 | region_name: microstack, |
| 358 | insecure: True, |
| 359 | availability_zone: nova, |
| 360 | version: 3}' |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 361 | } |
| 362 | |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 363 | 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] | 364 | DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` |
| 365 | |
| 366 | check_arguments $@ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 367 | mkdir -p ~/.osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 368 | install_snaps |
| 369 | bootstrap_k8s_lxd |
| 370 | deploy_charmed_osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 371 | install_osmclient |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 372 | if [ -v MICROSTACK ]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 373 | install_microstack |
| 374 | fi |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 375 | |
| 376 | echo "Your installation is now complete, follow these steps for configuring the osmclient:" |
| 377 | echo |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 378 | echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 379 | echo |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 380 | echo "export OSM_HOSTNAME=nbi.$API_SERVER.xip.io:443" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 381 | echo |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 382 | echo "2. Add the previous command to your .bashrc for other Shell sessions" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 383 | echo |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame^] | 384 | echo "echo \"export OSM_HOSTNAME=nbi.$API_SERVER.xip.io:443\" >> ~/.bashrc" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 385 | echo |
| 386 | echo "DONE" |