blob: 9d41e3ee68e0d1c17cda13a51261c7a85ae31f5c [file] [log] [blame]
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +01001#! /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 Garcia42375212020-04-27 19:07:49 +020015
16# set -eux
17
David Garciaa1376012020-10-19 15:42:42 +020018JUJU_AGENT_VERSION=2.8.6
David Garcia42375212020-04-27 19:07:49 +020019K8S_CLOUD_NAME="k8s-cloud"
beierlm3749e312020-07-02 14:21:09 -040020KUBECTL="microk8s.kubectl"
David Garcia69388c22020-05-07 12:14:19 +020021IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050022PATH=/snap/bin:${PATH}
23
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010024function check_arguments(){
25 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020026 case $1 in
27 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020028 --k8s) KUBECFG="$2" ;;
29 --vca) CONTROLLER="$2" ;;
30 --lxd) LXD_CLOUD="$2" ;;
31 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020032 --microstack) MICROSTACK=y ;;
David Garciacef05e92020-08-20 12:08:31 +020033 --ha) BUNDLE="cs:osm-ha" ;;
David Garcia69388c22020-05-07 12:14:19 +020034 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050035 --registry) REGISTRY_INFO="$2" ;;
David Garcia42375212020-04-27 19:07:49 +020036 esac
37 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010038 done
39
David Garcia42375212020-04-27 19:07:49 +020040 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010041}
beierlma4a37f72020-06-26 12:55:01 -040042
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010043function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040044 if [ ! -v KUBECFG ]; then
45 sudo snap install microk8s --classic
46 sudo usermod -a -G microk8s `whoami`
47 mkdir -p ~/.kube
48 sudo chown -f -R `whoami` ~/.kube
49 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050050 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlma4a37f72020-06-26 12:55:01 -040051 else
52 KUBECTL="kubectl"
53 sudo snap install kubectl --classic
54 export KUBECONFIG=${KUBECFG}
55 KUBEGRP=$(id -g -n)
56 fi
57 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010058}
59
60function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020061 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040062 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
63
64 if [ -v BOOTSTRAP_NEEDED ]; then
65 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
66 if [ $CONTROLLER_PRESENT -ge 1 ]; then
67 cat << EOF
68Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
69You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
70using this command:
71
72 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
73
74Please retry the installation once this conflict has been resolved.
75EOF
76 exit 1
77 fi
beierlm9afb0ef2020-10-16 12:53:51 -040078 else
79 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
80 if [ $CONTROLLER_PRESENT -le 0 ]; then
81 cat << EOF
82Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
83that exists, or remove the --vca ${CONTROLLER_NAME} option.
84
85Please retry the installation with one of the solutions applied.
86EOF
87 exit 1
88 fi
beierlma4a37f72020-06-26 12:55:01 -040089 fi
David Garcia42375212020-04-27 19:07:49 +020090
91 if [ -v KUBECFG ]; then
92 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -040093 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
94 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +020095 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010096 else
beierlma4a37f72020-06-26 12:55:01 -040097 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -040098 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -040099 sg ${KUBEGRP} -c "microk8s.enable storage dns"
100 TIME_TO_WAIT=30
101 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200102 while true
103 do
beierlma4a37f72020-06-26 12:55:01 -0400104 now="$(date -u +%s)"
105 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
106 echo "Microk8s storage failed to enable"
107 sg ${KUBEGRP} -c "microk8s.status"
108 exit 1
109 fi
110 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
111 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200112 break
113 fi
114 sleep 1
115 done
David Garcia42375212020-04-27 19:07:49 +0200116
beierlma4a37f72020-06-26 12:55:01 -0400117 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400118 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200119 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400120 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100121 fi
122
David Garcia42375212020-04-27 19:07:49 +0200123 if [ -v LXD_CLOUD ]; then
124 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100125 echo "The installer needs the LXD server certificate if the LXD is external"
126 exit 1
127 fi
128 else
129 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200130 LXD_CLOUD=~/.osm/lxd-cloud.yaml
131 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
132 # Apply sysctl production values for optimal performance
133 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
134 sudo sysctl --system
135 # Install LXD snap
136 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
137 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200138 # Configure LXD
139 sudo usermod -a -G lxd `whoami`
140 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"
141 sg lxd -c "lxd waitready"
142 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
143 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200144 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100145
David Garcia42375212020-04-27 19:07:49 +0200146 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100147clouds:
148 lxd-cloud:
149 type: lxd
150 auth-types: [certificate]
151 endpoint: "https://$LXDENDPOINT:8443"
152 config:
153 ssl-hostname-verification: false
154EOF
David Garcia42375212020-04-27 19:07:49 +0200155 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"
156 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
157 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
158 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100159
David Garcia42375212020-04-27 19:07:49 +0200160 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100161credentials:
162 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200163 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100164 auth-type: certificate
165 server-cert: |
166$server_cert
167 client-cert: |
168$client_cert
169 client-key: |
170$client_key
171EOF
David Garcia42375212020-04-27 19:07:49 +0200172 lxc config trust add local: ~/.osm/client.crt
173 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100174
David Garcia42375212020-04-27 19:07:49 +0200175 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
176 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
177 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400178 juju controller-config features=[k8s-operators]
179}
180
181function wait_for_port(){
182 SERVICE=$1
183 INDEX=$2
184 TIME_TO_WAIT=30
185 start_time="$(date -u +%s)"
186 while true
187 do
188 now="$(date -u +%s)"
189 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
190 echo "Failed to expose external ${SERVICE} interface port"
191 exit 1
192 fi
193
beierlm9afb0ef2020-10-16 12:53:51 -0400194 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
beierlma4a37f72020-06-26 12:55:01 -0400195 break
196 fi
197 sleep 1
198 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100199}
200
201function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500202 if [ -v REGISTRY_INFO ] ; then
203 registry_parts=(${REGISTRY_INFO//@/ })
204 if [ ${#registry_parts[@]} -eq 1 ] ; then
205 # No credentials supplied
206 REGISTRY_USERNAME=""
207 REGISTRY_PASSWORD=""
208 REGISTRY_URL=${registry_parts[0]}
209 else
210 credentials=${registry_parts[0]}
211 credential_parts=(${credentials//:/ })
212 REGISTRY_USERNAME=${credential_parts[0]}
213 REGISTRY_PASSWORD=${credential_parts[1]}
214 REGISTRY_URL=${registry_parts[1]}
215 fi
216 # Ensure the URL ends with a /
217 case $REGISTRY_URL in
218 */) ;;
219 *) REGISTRY_URL=${REGISTRY_URL}/
220 esac
221 fi
222
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100223 create_overlay
224 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200225 if [ -v KUBECFG ]; then
226 juju add-model osm $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100227 else
beierlma4a37f72020-06-26 12:55:01 -0400228 sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100229 fi
230 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400231 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500232 if [ -v REGISTRY_URL ]; then
233 [ ! -v TAG ] && TAG='latest'
234 fi
beierlma4a37f72020-06-26 12:55:01 -0400235 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500236
David Garcia42375212020-04-27 19:07:49 +0200237 if [ -v BUNDLE ]; then
beierlma4a37f72020-06-26 12:55:01 -0400238 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100239 else
David Garciacef05e92020-08-20 12:08:31 +0200240 juju deploy cs:osm --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100241 fi
beierlma4a37f72020-06-26 12:55:01 -0400242
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100243 echo "Waiting for deployment to finish..."
beierlma4a37f72020-06-26 12:55:01 -0400244 check_osm_deployed
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100245 echo "OSM with charms deployed"
beierlma4a37f72020-06-26 12:55:01 -0400246 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400247 API_SERVER=${DEFAULT_IP}
248 else
249 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
250 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
251 url="$(echo ${API_SERVER/$proto/})"
252 user="$(echo $url | grep @ | cut -d@ -f1)"
253 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
254 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
255 fi
256
David Garciade5fc1d2020-09-02 11:40:12 +0200257 # Expose OSM services
beierlm9afb0ef2020-10-16 12:53:51 -0400258 # Expose Grafana
259 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
260 juju expose grafana-k8s
261 wait_for_port grafana-k8s 0
262
David Garciade5fc1d2020-09-02 11:40:12 +0200263 # Expose NBI
beierlma4a37f72020-06-26 12:55:01 -0400264 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
265 juju expose nbi-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400266 wait_for_port nbi-k8s 1
beierlma4a37f72020-06-26 12:55:01 -0400267
David Garciade5fc1d2020-09-02 11:40:12 +0200268 # Expose NG UI
beierlma4a37f72020-06-26 12:55:01 -0400269 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
270 juju expose ng-ui
beierlm9afb0ef2020-10-16 12:53:51 -0400271 wait_for_port ng-ui 2
272
273 # Expose Prometheus
274 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
275 juju expose prometheus-k8s
276 wait_for_port prometheus-k8s 3
beierlma4a37f72020-06-26 12:55:01 -0400277
David Garciade5fc1d2020-09-02 11:40:12 +0200278 # Expose UI
beierlma4a37f72020-06-26 12:55:01 -0400279 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100280 juju expose ui-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400281 wait_for_port ui-k8s 4
David Garciade5fc1d2020-09-02 11:40:12 +0200282
283 # Apply annotations
beierlm9afb0ef2020-10-16 12:53:51 -0400284 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s"
285 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s"
286 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui"
287 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s"
288}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100289
290function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400291 TIME_TO_WAIT=600
292 start_time="$(date -u +%s)"
beierlm7e54dfc2020-09-24 15:27:53 -0400293 total_service_count=15
294 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100295 while true
296 do
beierlma4a37f72020-06-26 12:55:01 -0400297 service_count=$(juju status | grep kubernetes | grep active | wc -l)
298 echo "$service_count / $total_service_count services active"
299 if [ $service_count -eq $total_service_count ]; then
300 break
301 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400302 if [ $service_count -ne $previous_count ]; then
303 previous_count=$service_count
304 start_time="$(date -u +%s)"
305 fi
beierlma4a37f72020-06-26 12:55:01 -0400306 now="$(date -u +%s)"
307 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
308 echo "Timed out waiting for OSM services to become ready"
309 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100310 fi
311 sleep 10
312 done
313}
314
315function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200316 sudo snap install jq
317 sudo apt install python3-pip -y
318 python3 -m pip install yq
319 PATH=$PATH:$HOME/.local/bin # make yq command available
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100320 local HOME=/home/$USER
David Garcia42375212020-04-27 19:07:49 +0200321 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
322 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
beierlm3749e312020-07-02 14:21:09 -0400323 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)
324 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 Fleischmann5e4a7512020-03-06 14:05:06 +0100325 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
326 local vca_cloud="lxd-cloud"
327 # Get the VCA Certificate
beierlm3749e312020-07-02 14:21:09 -0400328 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 Fleischmann5e4a7512020-03-06 14:05:06 +0100329
330 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200331 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100332
333 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200334 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100335applications:
336 lcm-k8s:
337 options:
338 vca_user: $vca_user
339 vca_password: $vca_password
340 vca_host: $vca_host
341 vca_port: $vca_port
342 vca_pubkey: $vca_pubkey
343 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100344 vca_cloud: $vca_cloud
beierlma4a37f72020-06-26 12:55:01 -0400345 vca_k8s_cloud: $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100346 mon-k8s:
347 options:
348 vca_user: $vca_user
349 vca_password: $vca_password
350 vca_host: $vca_host
351 vca_cacert: $vca_cacert
352EOF
David Garcia42375212020-04-27 19:07:49 +0200353 mv /tmp/vca-overlay.yaml ~/.osm/
354 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100355}
356
David Garcia69388c22020-05-07 12:14:19 +0200357function generate_images_overlay(){
beierlmf2782c52020-11-05 17:04:05 -0500358 if [ ! -z "$REGISTRY_USERNAME" ] ; then
359 REGISTRY_CREDENTIALS=$(cat <<EOF
360
361 image_username: $REGISTRY_USERNAME
362 image_password: $REGISTRY_PASSWORD
363EOF
364 );
365fi
366
David Garcia69388c22020-05-07 12:14:19 +0200367 cat << EOF > /tmp/images-overlay.yaml
368applications:
369 lcm-k8s:
370 options:
beierlmf2782c52020-11-05 17:04:05 -0500371 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200372 mon-k8s:
373 options:
beierlmf2782c52020-11-05 17:04:05 -0500374 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200375 ro-k8s:
376 options:
beierlmf2782c52020-11-05 17:04:05 -0500377 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200378 nbi-k8s:
379 options:
beierlmf2782c52020-11-05 17:04:05 -0500380 image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200381 pol-k8s:
382 options:
beierlmf2782c52020-11-05 17:04:05 -0500383 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200384 ui-k8s:
385 options:
beierlmf2782c52020-11-05 17:04:05 -0500386 image: ${REGISTRY_URL}opensourcemano/light-ui:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400387 pla:
388 options:
beierlmf2782c52020-11-05 17:04:05 -0500389 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400390 ng-ui:
391 options:
beierlmf2782c52020-11-05 17:04:05 -0500392 image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
David Garcia009a5d62020-08-27 16:53:44 +0200393 keystone:
394 options:
beierlmf2782c52020-11-05 17:04:05 -0500395 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200396EOF
397 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
398}
399
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100400function install_osmclient() {
401 sudo snap install osmclient
402 sudo snap alias osmclient.osm osm
403}
404
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100405
406function install_microstack() {
407 sudo snap install microstack --classic --beta
408 sudo microstack.init --auto
409 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
410 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200411 --public \
412 --disk-format qcow2 \
413 --container-format bare \
414 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
415 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100416 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
417 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200418 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100419 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200420 --user admin \
421 --password keystone \
422 --auth_url http://10.20.20.1:5000/v3 \
423 --tenant admin \
424 --account_type openstack \
425 --config='{security_groups: default,
426 keypair: microstack,
427 project_name: admin,
428 user_domain_name: default,
429 region_name: microstack,
430 insecure: True,
431 availability_zone: nova,
432 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100433}
434
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200435DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100436DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
437
438check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200439mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100440install_snaps
441bootstrap_k8s_lxd
442deploy_charmed_osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100443install_osmclient
David Garcia42375212020-04-27 19:07:49 +0200444if [ -v MICROSTACK ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100445 install_microstack
446fi
beierlma4a37f72020-06-26 12:55:01 -0400447
beierlm7e54dfc2020-09-24 15:27:53 -0400448OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
449
beierlma4a37f72020-06-26 12:55:01 -0400450echo "Your installation is now complete, follow these steps for configuring the osmclient:"
451echo
452echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
453echo
beierlm7e54dfc2020-09-24 15:27:53 -0400454echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
beierlma4a37f72020-06-26 12:55:01 -0400455echo
456echo "2. Add the previous command to your .bashrc for other Shell sessions"
457echo
beierlm7e54dfc2020-09-24 15:27:53 -0400458echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
beierlma4a37f72020-06-26 12:55:01 -0400459echo
460echo "DONE"