blob: 844e64630e0cee3b58402ca9c382dc8b34034e78 [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 Garcia0db6e9f2021-10-05 16:13:08 +020018LXD_VERSION=4.0
David Garciad68e0b42021-06-28 16:50:42 +020019JUJU_VERSION=2.9
aticigabef99c2022-08-23 15:13:23 +030020JUJU_AGENT_VERSION=2.9.33
David Garcia42375212020-04-27 19:07:49 +020021K8S_CLOUD_NAME="k8s-cloud"
beierlm3749e312020-07-02 14:21:09 -040022KUBECTL="microk8s.kubectl"
aticig1f2e2e92022-02-03 16:42:39 +030023MICROK8S_VERSION=1.23
David Garcia53a09d82022-02-01 16:39:44 +010024OSMCLIENT_VERSION=latest
David Garcia69388c22020-05-07 12:14:19 +020025IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
aticig6eb39282022-02-24 00:34:52 +030026PASSWORD_OVERLAY_FILE=~/.osm/password-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050027PATH=/snap/bin:${PATH}
beierlmce7b4602022-04-13 08:19:40 -040028OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )"
29if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then
30 source ${OSM_DEVOPS}/common/all_funcs
31else
32 function track(){
33 true
34 }
35 function FATAL_TRACK(){
36 exit 1
37 }
38fi
beierlmf2782c52020-11-05 17:04:05 -050039
David Garciaef349d92020-12-10 21:16:12 +010040MODEL_NAME=osm
41
David Garcia4a0db7c2022-02-21 11:48:11 +010042OSM_BUNDLE=ch:osm
43OSM_HA_BUNDLE=ch:osm-ha
aticigabef99c2022-08-23 15:13:23 +030044CHARMHUB_CHANNEL=latest/beta
David Garcia4a0db7c2022-02-21 11:48:11 +010045unset TAG
David Garciaab11f842020-12-16 17:25:15 +010046
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010047function check_arguments(){
48 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020049 case $1 in
50 --bundle) BUNDLE="$2" ;;
David Garcia4bd2bf02021-05-05 19:01:43 +020051 --overlay) OVERLAY="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020052 --k8s) KUBECFG="$2" ;;
53 --vca) CONTROLLER="$2" ;;
aticig5d19ac22022-05-06 13:46:22 +030054 --small-profile) INSTALL_NOLXD=y;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020055 --lxd) LXD_CLOUD="$2" ;;
56 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020057 --microstack) MICROSTACK=y ;;
David Garciaab11f842020-12-16 17:25:15 +010058 --ha) BUNDLE=$OSM_HA_BUNDLE ;;
David Garcia69388c22020-05-07 12:14:19 +020059 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050060 --registry) REGISTRY_INFO="$2" ;;
David Garcia1bc71022021-05-03 18:27:18 +020061 --only-vca) ONLY_VCA=y ;;
David Garcia42375212020-04-27 19:07:49 +020062 esac
63 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010064 done
65
David Garcia42375212020-04-27 19:07:49 +020066 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010067}
beierlma4a37f72020-06-26 12:55:01 -040068
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010069function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040070 if [ ! -v KUBECFG ]; then
beierlmce7b4602022-04-13 08:19:40 -040071 KUBEGRP="microk8s"
72 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable ||
73 FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed"
74 sudo usermod -a -G microk8s `whoami`
David Garcia9a59e3d2021-02-08 15:18:27 +010075 sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
David Garcia107010b2021-01-15 12:58:59 +010076 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
beierlmce7b4602022-04-13 08:19:40 -040077 sg ${KUBEGRP} -c microk8s.stop
78 sg ${KUBEGRP} -c microk8s.start
David Garcia107010b2021-01-15 12:58:59 +010079 )
beierlma4a37f72020-06-26 12:55:01 -040080 mkdir -p ~/.kube
81 sudo chown -f -R `whoami` ~/.kube
beierlmf2782c52020-11-05 17:04:05 -050082 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlmdf6de3d2020-12-16 08:46:40 -050083 KUBECONFIG=~/.osm/microk8s-config.yaml
David Garcia107010b2021-01-15 12:58:59 +010084 sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
beierlmce7b4602022-04-13 08:19:40 -040085 track k8scluster k8scluster_ok
beierlma4a37f72020-06-26 12:55:01 -040086 else
87 KUBECTL="kubectl"
88 sudo snap install kubectl --classic
89 export KUBECONFIG=${KUBECFG}
90 KUBEGRP=$(id -g -n)
91 fi
beierlmce7b4602022-04-13 08:19:40 -040092 sudo snap install juju --classic --channel=$JUJU_VERSION/stable ||
93 FATAL_TRACK juju "snap install juju ${JUJU_VERSION}/stable failed"
94 track juju juju_ok
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010095}
96
97function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020098 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040099 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
100
101 if [ -v BOOTSTRAP_NEEDED ]; then
102 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
103 if [ $CONTROLLER_PRESENT -ge 1 ]; then
104 cat << EOF
105Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
106You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
107using this command:
108
109 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
110
111Please retry the installation once this conflict has been resolved.
112EOF
beierlmce7b4602022-04-13 08:19:40 -0400113 FATAL_TRACK bootstrap_k8s "VCA already present"
beierlma4a37f72020-06-26 12:55:01 -0400114 fi
beierlm9afb0ef2020-10-16 12:53:51 -0400115 else
116 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
117 if [ $CONTROLLER_PRESENT -le 0 ]; then
118 cat << EOF
119Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
120that exists, or remove the --vca ${CONTROLLER_NAME} option.
121
122Please retry the installation with one of the solutions applied.
123EOF
beierlmce7b4602022-04-13 08:19:40 -0400124 FATAL_TRACK bootstrap_k8s "Requested VCA not present"
beierlm9afb0ef2020-10-16 12:53:51 -0400125 fi
beierlma4a37f72020-06-26 12:55:01 -0400126 fi
David Garcia42375212020-04-27 19:07:49 +0200127
128 if [ -v KUBECFG ]; then
129 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400130 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
131 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +0200132 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100133 else
beierlma4a37f72020-06-26 12:55:01 -0400134 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -0400135 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -0400136 sg ${KUBEGRP} -c "microk8s.enable storage dns"
137 TIME_TO_WAIT=30
138 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200139 while true
140 do
beierlma4a37f72020-06-26 12:55:01 -0400141 now="$(date -u +%s)"
142 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
143 echo "Microk8s storage failed to enable"
144 sg ${KUBEGRP} -c "microk8s.status"
beierlmce7b4602022-04-13 08:19:40 -0400145 FATAL_TRACK bootstrap_k8s "Microk8s storage failed to enable"
beierlma4a37f72020-06-26 12:55:01 -0400146 fi
147 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
148 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200149 break
150 fi
151 sleep 1
152 done
David Garcia42375212020-04-27 19:07:49 +0200153
beierlma4a37f72020-06-26 12:55:01 -0400154 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400155 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200156 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400157 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100158 fi
beierlmce7b4602022-04-13 08:19:40 -0400159 track bootstrap_k8s bootstrap_k8s_ok
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100160
aticig5d19ac22022-05-06 13:46:22 +0300161 if [ ! -v INSTALL_NOLXD ]; then
162 if [ -v LXD_CLOUD ]; then
163 if [ ! -v LXD_CREDENTIALS ]; then
164 echo "The installer needs the LXD server certificate if the LXD is external"
165 FATAL_TRACK bootstrap_lxd "No LXD certificate supplied"
166 fi
167 else
168 LXDENDPOINT=$DEFAULT_IP
169 LXD_CLOUD=~/.osm/lxd-cloud.yaml
170 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
171 # Apply sysctl production values for optimal performance
172 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
173 sudo sysctl --system
174 # Install LXD snap
175 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
176 sudo snap install lxd --channel $LXD_VERSION/stable
177 # Configure LXD
178 sudo usermod -a -G lxd `whoami`
179 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"
180 sg lxd -c "lxd waitready"
181 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
182 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
183 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100184
aticig5d19ac22022-05-06 13:46:22 +0300185 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100186clouds:
187 lxd-cloud:
188 type: lxd
189 auth-types: [certificate]
190 endpoint: "https://$LXDENDPOINT:8443"
191 config:
192 ssl-hostname-verification: false
193EOF
aticig5d19ac22022-05-06 13:46:22 +0300194 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"
aticig5d19ac22022-05-06 13:46:22 +0300195 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100196credentials:
197 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200198 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100199 auth-type: certificate
David Garciaf82897c2022-06-01 13:01:43 +0200200 server-cert: /var/snap/lxd/common/lxd/server.crt
201 client-cert: ~/.osm/client.crt
202 client-key: ~/.osm/client.key
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100203EOF
aticig5d19ac22022-05-06 13:46:22 +0300204 lxc config trust add local: ~/.osm/client.crt
205 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100206
aticig5d19ac22022-05-06 13:46:22 +0300207 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
208 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
209 sg lxd -c "lxd waitready"
210 juju controller-config features=[k8s-operators]
211 track bootstrap_lxd bootstrap_lxd_ok
212 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100213}
214
215function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500216 if [ -v REGISTRY_INFO ] ; then
217 registry_parts=(${REGISTRY_INFO//@/ })
218 if [ ${#registry_parts[@]} -eq 1 ] ; then
219 # No credentials supplied
220 REGISTRY_USERNAME=""
221 REGISTRY_PASSWORD=""
222 REGISTRY_URL=${registry_parts[0]}
223 else
224 credentials=${registry_parts[0]}
225 credential_parts=(${credentials//:/ })
226 REGISTRY_USERNAME=${credential_parts[0]}
227 REGISTRY_PASSWORD=${credential_parts[1]}
228 REGISTRY_URL=${registry_parts[1]}
229 fi
230 # Ensure the URL ends with a /
231 case $REGISTRY_URL in
232 */) ;;
233 *) REGISTRY_URL=${REGISTRY_URL}/
234 esac
235 fi
236
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100237 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200238 if [ -v KUBECFG ]; then
David Garciaef349d92020-12-10 21:16:12 +0100239 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100240 else
David Garciaef349d92020-12-10 21:16:12 +0100241 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100242 fi
243 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400244 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500245 if [ -v REGISTRY_URL ]; then
246 [ ! -v TAG ] && TAG='latest'
247 fi
beierlma4a37f72020-06-26 12:55:01 -0400248 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500249
David Garcia4bd2bf02021-05-05 19:01:43 +0200250 if [ -v OVERLAY ]; then
251 extra_overlay="--overlay $OVERLAY"
252 fi
aticig6eb39282022-02-24 00:34:52 +0300253 echo "Creating Password Overlay"
254
255 generate_password_overlay && secret_overlay="--overlay $PASSWORD_OVERLAY_FILE"
David Garcia4bd2bf02021-05-05 19:01:43 +0200256
David Garcia42375212020-04-27 19:07:49 +0200257 if [ -v BUNDLE ]; then
aticigabef99c2022-08-23 15:13:23 +0300258 juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $BUNDLE $images_overlay $extra_overlay $secret_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100259 else
aticigabef99c2022-08-23 15:13:23 +0300260 juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $OSM_BUNDLE $images_overlay $extra_overlay $secret_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100261 fi
beierlma4a37f72020-06-26 12:55:01 -0400262
beierlma4a37f72020-06-26 12:55:01 -0400263 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400264 API_SERVER=${DEFAULT_IP}
265 else
266 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
267 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
268 url="$(echo ${API_SERVER/$proto/})"
269 user="$(echo $url | grep @ | cut -d@ -f1)"
270 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
271 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
272 fi
aticigabef99c2022-08-23 15:13:23 +0300273 # Configure VCA Integrator
274 juju config vca \
275 k8s-cloud=microk8s \
276 lxd-cloud=lxd-cloud:lxd-cloud \
277 controllers="`cat ~/.local/share/juju/controllers.yaml`" \
278 accounts="`cat ~/.local/share/juju/accounts.yaml`" \
279 public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
David Garciade5fc1d2020-09-02 11:40:12 +0200280 # Expose OSM services
aticigabef99c2022-08-23 15:13:23 +0300281 juju config -m $MODEL_NAME nbi external-hostname=nbi.${API_SERVER}.nip.io
282 juju config -m $MODEL_NAME ng-ui external-hostname=ui.${API_SERVER}.nip.io
David Garciac395a452021-05-05 14:22:26 +0200283 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
284 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
David Garciaef349d92020-12-10 21:16:12 +0100285
David Garcia49379ce2021-02-24 13:48:22 +0100286 echo "Waiting for deployment to finish..."
287 check_osm_deployed
David Garciac537fa62021-11-09 08:45:49 +0100288 grafana_leader=`juju status -m $MODEL_NAME grafana | grep "*" | cut -d "*" -f 1`
289 grafana_admin_password=`juju run -m $MODEL_NAME --unit $grafana_leader "echo \\$GF_SECURITY_ADMIN_PASSWORD"`
aticigabef99c2022-08-23 15:13:23 +0300290 juju config -m $MODEL_NAME mon grafana-password=$grafana_admin_password
David Garciac537fa62021-11-09 08:45:49 +0100291 check_osm_deployed
David Garcia49379ce2021-02-24 13:48:22 +0100292 echo "OSM with charms deployed"
beierlm9afb0ef2020-10-16 12:53:51 -0400293}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100294
295function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400296 TIME_TO_WAIT=600
297 start_time="$(date -u +%s)"
aticigabef99c2022-08-23 15:13:23 +0300298 total_service_count=16
beierlm7e54dfc2020-09-24 15:27:53 -0400299 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100300 while true
301 do
beierlm67a34472022-03-25 12:23:36 -0400302 service_count=$(juju status --format json -m $MODEL_NAME | jq '.applications[]."application-status".current' | grep active | wc -l)
beierlma4a37f72020-06-26 12:55:01 -0400303 echo "$service_count / $total_service_count services active"
304 if [ $service_count -eq $total_service_count ]; then
305 break
306 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400307 if [ $service_count -ne $previous_count ]; then
308 previous_count=$service_count
309 start_time="$(date -u +%s)"
310 fi
beierlma4a37f72020-06-26 12:55:01 -0400311 now="$(date -u +%s)"
312 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
313 echo "Timed out waiting for OSM services to become ready"
beierlmce7b4602022-04-13 08:19:40 -0400314 FATAL_TRACK deploy_osm "Timed out waiting for services to become ready"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100315 fi
316 sleep 10
317 done
318}
319
aticig6eb39282022-02-24 00:34:52 +0300320function generate_password_overlay() {
321 # prometheus
David Garcia8fa78072022-04-27 13:43:42 +0200322 web_config_password=`openssl rand -hex 16`
aticig6eb39282022-02-24 00:34:52 +0300323 # keystone
David Garcia8fa78072022-04-27 13:43:42 +0200324 keystone_db_password=`openssl rand -hex 16`
325 keystone_admin_password=`openssl rand -hex 16`
326 keystone_service_password=`openssl rand -hex 16`
aticig6eb39282022-02-24 00:34:52 +0300327 # mariadb
328 mariadb_password=`openssl rand -hex 16`
329 mariadb_root_password=`openssl rand -hex 16`
330 cat << EOF > /tmp/password-overlay.yaml
331applications:
332 prometheus:
333 options:
334 web_config_password: $web_config_password
335 keystone:
336 options:
337 keystone-db-password: $keystone_db_password
338 admin-password: $keystone_admin_password
339 service-password: $keystone_service_password
340 mariadb:
341 options:
342 password: $mariadb_password
343 root_password: $mariadb_root_password
344EOF
345 mv /tmp/password-overlay.yaml $PASSWORD_OVERLAY_FILE
346}
347
David Garcia69388c22020-05-07 12:14:19 +0200348function generate_images_overlay(){
David Garcia49379ce2021-02-24 13:48:22 +0100349 echo "applications:" > /tmp/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -0500350
David Garcia53a09d82022-02-01 16:39:44 +0100351 charms_with_resources="nbi lcm mon pol ng-ui ro pla"
David Garcia49379ce2021-02-24 13:48:22 +0100352 for charm in $charms_with_resources; do
353 cat << EOF > /tmp/${charm}_registry.yaml
354registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
beierlmf2782c52020-11-05 17:04:05 -0500355EOF
David Garcia49379ce2021-02-24 13:48:22 +0100356 if [ ! -z "$REGISTRY_USERNAME" ] ; then
357 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
358 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
359 fi
beierlmf2782c52020-11-05 17:04:05 -0500360
David Garcia49379ce2021-02-24 13:48:22 +0100361 cat << EOF >> /tmp/images-overlay.yaml
362 ${charm}:
David Garciaef349d92020-12-10 21:16:12 +0100363 resources:
David Garcia49379ce2021-02-24 13:48:22 +0100364 image: /tmp/${charm}_registry.yaml
365
David Garcia69388c22020-05-07 12:14:19 +0200366EOF
David Garcia49379ce2021-02-24 13:48:22 +0100367 done
David Garcia53a09d82022-02-01 16:39:44 +0100368 ch_charms_with_resources="keystone"
369 for charm in $ch_charms_with_resources; do
370 cat << EOF > /tmp/${charm}_registry.yaml
371registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
372EOF
373 if [ ! -z "$REGISTRY_USERNAME" ] ; then
374 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
375 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
376 fi
377
378 cat << EOF >> /tmp/images-overlay.yaml
379 ${charm}:
380 resources:
381 ${charm}-image: /tmp/${charm}_registry.yaml
382
383EOF
384 done
David Garcia49379ce2021-02-24 13:48:22 +0100385
David Garcia69388c22020-05-07 12:14:19 +0200386 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
387}
388
David Garcia107010b2021-01-15 12:58:59 +0100389function refresh_osmclient_snap() {
390 osmclient_snap_install_refresh refresh
391}
392
393function install_osm_client_snap() {
394 osmclient_snap_install_refresh install
395}
396
397function osmclient_snap_install_refresh() {
398 channel_preference="stable candidate beta edge"
399 for channel in $channel_preference; do
400 echo "Trying to install osmclient from channel $OSMCLIENT_VERSION/$channel"
401 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
402 done
403}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100404function install_osmclient() {
David Garcia107010b2021-01-15 12:58:59 +0100405 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100406}
407
beierlmdf6de3d2020-12-16 08:46:40 -0500408function add_local_k8scluster() {
409 osm --all-projects vim-create \
410 --name _system-osm-vim \
411 --account_type dummy \
412 --auth_url http://dummy \
413 --user osm --password osm --tenant osm \
414 --description "dummy" \
415 --config '{management_network_name: mgmt}'
416 tmpfile=$(mktemp --tmpdir=${HOME})
417 cp ${KUBECONFIG} ${tmpfile}
418 osm --all-projects k8scluster-add \
419 --creds ${tmpfile} \
420 --vim _system-osm-vim \
421 --k8s-nets '{"net1": null}' \
422 --version '1.19' \
423 --description "OSM Internal Cluster" \
424 _system-osm-k8s
425 rm -f ${tmpfile}
426}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100427
428function install_microstack() {
beierlmb403f062021-12-09 08:47:59 -0500429 sudo snap install microstack --beta --devmode
430
431 CHECK=$(microstack.openstack server list)
432 if [ $? -ne 0 ] ; then
433 if [[ $CHECK == *"not initialized"* ]]; then
434 echo "Setting MicroStack dashboard to listen to port 8080"
435 sudo snap set microstack config.network.ports.dashboard=8080
436 echo "Initializing MicroStack. This can take several minutes"
437 sudo microstack.init --auto --control
438 fi
439 fi
440
441 sudo snap alias microstack.openstack openstack
442
443 echo "Updating default security group in MicroStack to allow all access"
444
445 for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do
446 for PROTO in icmp tcp udp ; do
447 echo " $PROTO ingress"
448 CHECK=$(microstack.openstack security group rule create $i --protocol $PROTO --remote-ip 0.0.0.0/0 2>&1)
449 if [ $? -ne 0 ] ; then
450 if [[ $CHECK != *"409"* ]]; then
451 echo "Error creating ingress rule for $PROTO"
452 echo $CHECK
453 fi
454 fi
455 done
456 done
457
458 microstack.openstack network show osm-ext &>/dev/null
459 if [ $? -ne 0 ]; then
460 echo "Creating osm-ext network with router to bridge to MicroStack external network"
461 microstack.openstack network create --enable --no-share osm-ext
462 microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \
463 --subnet-range 172.30.0.0/24
464 microstack.openstack router create external-router
465 microstack.openstack router add subnet external-router osm-ext-subnet
466 microstack.openstack router set --external-gateway external external-router
467 fi
468
469 microstack.openstack image list | grep ubuntu20.04 &> /dev/null
470 if [ $? -ne 0 ] ; then
471 echo "Fetching Ubuntu 20.04 image and upLoading to MicroStack"
472 wget -q -O- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \
473 | microstack.openstack image create --public --container-format=bare \
474 --disk-format=qcow2 ubuntu20.04 | grep status
475 fi
476
477 if [ ! -f ~/.ssh/microstack ]; then
478 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
479 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
480 fi
481
482 echo "Creating VIM microstack-site in OSM"
483 . /var/snap/microstack/common/etc/microstack.rc
484
485 osm vim-create \
486 --name microstack-site \
487 --user "$OS_USERNAME" \
488 --password "$OS_PASSWORD" \
489 --auth_url "$OS_AUTH_URL" \
490 --tenant "$OS_USERNAME" \
491 --account_type openstack \
492 --config='{use_floating_ip: True,
493 insecure: True,
494 keypair: microstack,
495 management_network_name: osm-ext}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100496}
497
beierlm4aad47b2021-12-07 16:15:53 -0500498DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5; exit}'`
499DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]; exit}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100500
501check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200502mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100503install_snaps
504bootstrap_k8s_lxd
David Garcia1bc71022021-05-03 18:27:18 +0200505if [ -v ONLY_VCA ]; then
506 HOME=/home/$USER
aticigabef99c2022-08-23 15:13:23 +0300507 k8scloud=microk8s
508 lxdcloud=lxd-cloud:lxd-cloud
509 controllers="`cat $HOME/.local/share/juju/controllers.yaml`"
510 accounts="`cat $HOME/.local/share/juju/accounts.yaml`"
511 publickey="`cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub`"
512 echo "Use the following command to register the installed VCA to your OSM VCA integrator charm"
513 echo -e " juju config vca \\\n k8s-cloud=$k8scloud \\\n lxd-cloud=$lxdcloud \\\n controllers=$controllers \\\n accounts=$accounts \\\n public-key=$publickey"
beierlmce7b4602022-04-13 08:19:40 -0400514 track deploy_osm deploy_vca_only_ok
David Garcia1bc71022021-05-03 18:27:18 +0200515else
516 deploy_charmed_osm
beierlmce7b4602022-04-13 08:19:40 -0400517 track deploy_osm deploy_osm_services_k8s_ok
David Garcia1bc71022021-05-03 18:27:18 +0200518 install_osmclient
beierlmce7b4602022-04-13 08:19:40 -0400519 track osmclient osmclient_ok
aticigabef99c2022-08-23 15:13:23 +0300520 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi external-hostname):443
aticig6eb39282022-02-24 00:34:52 +0300521 export OSM_PASSWORD=$keystone_admin_password
David Garcia1bc71022021-05-03 18:27:18 +0200522 sleep 10
523 add_local_k8scluster
beierlmce7b4602022-04-13 08:19:40 -0400524 track final_ops add_local_k8scluster_ok
David Garcia1bc71022021-05-03 18:27:18 +0200525 if [ -v MICROSTACK ]; then
526 install_microstack
beierlmce7b4602022-04-13 08:19:40 -0400527 track final_ops install_microstack_ok
David Garcia1bc71022021-05-03 18:27:18 +0200528 fi
529
530 echo "Your installation is now complete, follow these steps for configuring the osmclient:"
531 echo
532 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
533 echo
534 echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
aticig6eb39282022-02-24 00:34:52 +0300535 echo "export OSM_PASSWORD=$OSM_PASSWORD"
David Garcia1bc71022021-05-03 18:27:18 +0200536 echo
aticig6eb39282022-02-24 00:34:52 +0300537 echo "2. Add the previous commands to your .bashrc for other Shell sessions"
David Garcia1bc71022021-05-03 18:27:18 +0200538 echo
539 echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
aticig6eb39282022-02-24 00:34:52 +0300540 echo "echo \"export OSM_PASSWORD=$OSM_PASSWORD\" >> ~/.bashrc"
541 echo
542 echo "3. Login OSM GUI by using admin password: $OSM_PASSWORD"
David Garcia1bc71022021-05-03 18:27:18 +0200543 echo
544 echo "DONE"
beierlmce7b4602022-04-13 08:19:40 -0400545 track end
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100546fi
beierlma4a37f72020-06-26 12:55:01 -0400547