blob: e1a45d0b30ff139d786bbd47b9236c27a15f2ccb [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 Garcia49379ce2021-02-24 13:48:22 +010018JUJU_AGENT_VERSION=2.8.9
David Garcia42375212020-04-27 19:07:49 +020019K8S_CLOUD_NAME="k8s-cloud"
beierlm3749e312020-07-02 14:21:09 -040020KUBECTL="microk8s.kubectl"
beierlm481ae7d2020-12-14 09:59:19 -050021MICROK8S_VERSION=1.19
David Garcia107010b2021-01-15 12:58:59 +010022OSMCLIENT_VERSION=9.0
David Garcia69388c22020-05-07 12:14:19 +020023IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050024PATH=/snap/bin:${PATH}
25
David Garciaef349d92020-12-10 21:16:12 +010026MODEL_NAME=osm
27
David Garcia23264292021-05-05 19:09:18 +020028OSM_BUNDLE=cs:osm-61
29OSM_HA_BUNDLE=cs:osm-ha-46
David Garcia49379ce2021-02-24 13:48:22 +010030TAG=testing-daily
David Garciaab11f842020-12-16 17:25:15 +010031
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010032function check_arguments(){
33 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020034 case $1 in
35 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020036 --k8s) KUBECFG="$2" ;;
37 --vca) CONTROLLER="$2" ;;
38 --lxd) LXD_CLOUD="$2" ;;
39 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020040 --microstack) MICROSTACK=y ;;
David Garciaab11f842020-12-16 17:25:15 +010041 --ha) BUNDLE=$OSM_HA_BUNDLE ;;
David Garcia69388c22020-05-07 12:14:19 +020042 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050043 --registry) REGISTRY_INFO="$2" ;;
David Garcia1bc71022021-05-03 18:27:18 +020044 --only-vca) ONLY_VCA=y ;;
David Garcia42375212020-04-27 19:07:49 +020045 esac
46 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010047 done
48
David Garcia42375212020-04-27 19:07:49 +020049 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010050}
beierlma4a37f72020-06-26 12:55:01 -040051
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010052function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040053 if [ ! -v KUBECFG ]; then
beierlm481ae7d2020-12-14 09:59:19 -050054 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
David Garcia9a59e3d2021-02-08 15:18:27 +010055 sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
David Garcia107010b2021-01-15 12:58:59 +010056 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
57 microk8s.stop
58 microk8s.start
59 )
beierlma4a37f72020-06-26 12:55:01 -040060 sudo usermod -a -G microk8s `whoami`
61 mkdir -p ~/.kube
62 sudo chown -f -R `whoami` ~/.kube
63 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050064 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlmdf6de3d2020-12-16 08:46:40 -050065 KUBECONFIG=~/.osm/microk8s-config.yaml
David Garcia107010b2021-01-15 12:58:59 +010066 sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
beierlma4a37f72020-06-26 12:55:01 -040067 else
68 KUBECTL="kubectl"
69 sudo snap install kubectl --classic
70 export KUBECONFIG=${KUBECFG}
71 KUBEGRP=$(id -g -n)
72 fi
73 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010074}
75
76function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020077 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040078 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
79
80 if [ -v BOOTSTRAP_NEEDED ]; then
81 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
82 if [ $CONTROLLER_PRESENT -ge 1 ]; then
83 cat << EOF
84Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
85You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
86using this command:
87
88 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
89
90Please retry the installation once this conflict has been resolved.
91EOF
92 exit 1
93 fi
beierlm9afb0ef2020-10-16 12:53:51 -040094 else
95 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
96 if [ $CONTROLLER_PRESENT -le 0 ]; then
97 cat << EOF
98Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
99that exists, or remove the --vca ${CONTROLLER_NAME} option.
100
101Please retry the installation with one of the solutions applied.
102EOF
103 exit 1
104 fi
beierlma4a37f72020-06-26 12:55:01 -0400105 fi
David Garcia42375212020-04-27 19:07:49 +0200106
107 if [ -v KUBECFG ]; then
108 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400109 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
110 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +0200111 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100112 else
beierlma4a37f72020-06-26 12:55:01 -0400113 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -0400114 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -0400115 sg ${KUBEGRP} -c "microk8s.enable storage dns"
116 TIME_TO_WAIT=30
117 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200118 while true
119 do
beierlma4a37f72020-06-26 12:55:01 -0400120 now="$(date -u +%s)"
121 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
122 echo "Microk8s storage failed to enable"
123 sg ${KUBEGRP} -c "microk8s.status"
124 exit 1
125 fi
126 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
127 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200128 break
129 fi
130 sleep 1
131 done
David Garcia42375212020-04-27 19:07:49 +0200132
beierlma4a37f72020-06-26 12:55:01 -0400133 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400134 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200135 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400136 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100137 fi
138
David Garcia42375212020-04-27 19:07:49 +0200139 if [ -v LXD_CLOUD ]; then
140 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100141 echo "The installer needs the LXD server certificate if the LXD is external"
142 exit 1
143 fi
144 else
145 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200146 LXD_CLOUD=~/.osm/lxd-cloud.yaml
147 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
148 # Apply sysctl production values for optimal performance
149 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
150 sudo sysctl --system
151 # Install LXD snap
152 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
153 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200154 # Configure LXD
155 sudo usermod -a -G lxd `whoami`
156 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"
157 sg lxd -c "lxd waitready"
158 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
159 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200160 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100161
David Garcia42375212020-04-27 19:07:49 +0200162 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100163clouds:
164 lxd-cloud:
165 type: lxd
166 auth-types: [certificate]
167 endpoint: "https://$LXDENDPOINT:8443"
168 config:
169 ssl-hostname-verification: false
170EOF
David Garcia42375212020-04-27 19:07:49 +0200171 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"
172 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
173 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
174 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100175
David Garcia42375212020-04-27 19:07:49 +0200176 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100177credentials:
178 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200179 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100180 auth-type: certificate
181 server-cert: |
182$server_cert
183 client-cert: |
184$client_cert
185 client-key: |
186$client_key
187EOF
David Garcia42375212020-04-27 19:07:49 +0200188 lxc config trust add local: ~/.osm/client.crt
189 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100190
David Garcia42375212020-04-27 19:07:49 +0200191 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
192 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
193 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400194 juju controller-config features=[k8s-operators]
195}
196
197function wait_for_port(){
198 SERVICE=$1
199 INDEX=$2
200 TIME_TO_WAIT=30
201 start_time="$(date -u +%s)"
202 while true
203 do
204 now="$(date -u +%s)"
205 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
206 echo "Failed to expose external ${SERVICE} interface port"
207 exit 1
208 fi
209
beierlm9afb0ef2020-10-16 12:53:51 -0400210 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 -0400211 break
212 fi
213 sleep 1
214 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100215}
216
217function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500218 if [ -v REGISTRY_INFO ] ; then
219 registry_parts=(${REGISTRY_INFO//@/ })
220 if [ ${#registry_parts[@]} -eq 1 ] ; then
221 # No credentials supplied
222 REGISTRY_USERNAME=""
223 REGISTRY_PASSWORD=""
224 REGISTRY_URL=${registry_parts[0]}
225 else
226 credentials=${registry_parts[0]}
227 credential_parts=(${credentials//:/ })
228 REGISTRY_USERNAME=${credential_parts[0]}
229 REGISTRY_PASSWORD=${credential_parts[1]}
230 REGISTRY_URL=${registry_parts[1]}
231 fi
232 # Ensure the URL ends with a /
233 case $REGISTRY_URL in
234 */) ;;
235 *) REGISTRY_URL=${REGISTRY_URL}/
236 esac
237 fi
238
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100239 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200240 if [ -v KUBECFG ]; then
David Garciaef349d92020-12-10 21:16:12 +0100241 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100242 else
David Garciaef349d92020-12-10 21:16:12 +0100243 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100244 fi
245 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400246 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500247 if [ -v REGISTRY_URL ]; then
248 [ ! -v TAG ] && TAG='latest'
249 fi
beierlma4a37f72020-06-26 12:55:01 -0400250 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500251
David Garcia42375212020-04-27 19:07:49 +0200252 if [ -v BUNDLE ]; then
David Garciaef349d92020-12-10 21:16:12 +0100253 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100254 else
David Garciaab11f842020-12-16 17:25:15 +0100255 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100256 fi
beierlma4a37f72020-06-26 12:55:01 -0400257
beierlma4a37f72020-06-26 12:55:01 -0400258 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400259 API_SERVER=${DEFAULT_IP}
260 else
261 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
262 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
263 url="$(echo ${API_SERVER/$proto/})"
264 user="$(echo $url | grep @ | cut -d@ -f1)"
265 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
266 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
267 fi
David Garciade5fc1d2020-09-02 11:40:12 +0200268 # Expose OSM services
David Garciac395a452021-05-05 14:22:26 +0200269 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
270 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
271 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
272 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
David Garciaef349d92020-12-10 21:16:12 +0100273
David Garcia49379ce2021-02-24 13:48:22 +0100274 echo "Waiting for deployment to finish..."
275 check_osm_deployed
276 echo "OSM with charms deployed"
beierlm9afb0ef2020-10-16 12:53:51 -0400277}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100278
279function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400280 TIME_TO_WAIT=600
281 start_time="$(date -u +%s)"
David Garcia02a5eb92020-11-28 14:41:22 +0100282 total_service_count=14
beierlm7e54dfc2020-09-24 15:27:53 -0400283 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100284 while true
285 do
David Garciaef349d92020-12-10 21:16:12 +0100286 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
beierlma4a37f72020-06-26 12:55:01 -0400287 echo "$service_count / $total_service_count services active"
288 if [ $service_count -eq $total_service_count ]; then
289 break
290 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400291 if [ $service_count -ne $previous_count ]; then
292 previous_count=$service_count
293 start_time="$(date -u +%s)"
294 fi
beierlma4a37f72020-06-26 12:55:01 -0400295 now="$(date -u +%s)"
296 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
297 echo "Timed out waiting for OSM services to become ready"
298 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100299 fi
300 sleep 10
301 done
302}
303
304function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200305 sudo snap install jq
David Garciac8660ad2020-12-16 13:13:20 +0100306 sudo snap install yq
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100307 local HOME=/home/$USER
calvinosanc183ea27a2021-01-04 11:42:18 +0100308 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
David Garciac753dc52021-03-17 15:28:47 +0100309 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
calvinosanc183ea27a2021-01-04 11:42:18 +0100310 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
311 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100312 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
313 local vca_cloud="lxd-cloud"
314 # Get the VCA Certificate
calvinosanc183ea27a2021-01-04 11:42:18 +0100315 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100316
317 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200318 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100319
320 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200321 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100322applications:
David Garcia49379ce2021-02-24 13:48:22 +0100323 lcm:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100324 options:
325 vca_user: $vca_user
David Garciac753dc52021-03-17 15:28:47 +0100326 vca_secret: $vca_secret
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100327 vca_host: $vca_host
328 vca_port: $vca_port
329 vca_pubkey: $vca_pubkey
330 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100331 vca_cloud: $vca_cloud
beierlma4a37f72020-06-26 12:55:01 -0400332 vca_k8s_cloud: $K8S_CLOUD_NAME
David Garcia49379ce2021-02-24 13:48:22 +0100333 mon:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100334 options:
335 vca_user: $vca_user
David Garciac753dc52021-03-17 15:28:47 +0100336 vca_secret: $vca_secret
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100337 vca_host: $vca_host
338 vca_cacert: $vca_cacert
339EOF
David Garcia42375212020-04-27 19:07:49 +0200340 mv /tmp/vca-overlay.yaml ~/.osm/
341 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100342}
343
David Garcia69388c22020-05-07 12:14:19 +0200344function generate_images_overlay(){
David Garcia49379ce2021-02-24 13:48:22 +0100345 echo "applications:" > /tmp/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -0500346
David Garcia49379ce2021-02-24 13:48:22 +0100347 charms_with_resources="nbi lcm mon pol ng-ui ro pla keystone"
348 for charm in $charms_with_resources; do
349 cat << EOF > /tmp/${charm}_registry.yaml
350registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
beierlmf2782c52020-11-05 17:04:05 -0500351EOF
David Garcia49379ce2021-02-24 13:48:22 +0100352 if [ ! -z "$REGISTRY_USERNAME" ] ; then
353 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
354 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
355 fi
beierlmf2782c52020-11-05 17:04:05 -0500356
David Garcia49379ce2021-02-24 13:48:22 +0100357 cat << EOF >> /tmp/images-overlay.yaml
358 ${charm}:
David Garciaef349d92020-12-10 21:16:12 +0100359 resources:
David Garcia49379ce2021-02-24 13:48:22 +0100360 image: /tmp/${charm}_registry.yaml
361
David Garcia69388c22020-05-07 12:14:19 +0200362EOF
David Garcia49379ce2021-02-24 13:48:22 +0100363 done
364
David Garcia69388c22020-05-07 12:14:19 +0200365 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
366}
367
David Garcia107010b2021-01-15 12:58:59 +0100368function refresh_osmclient_snap() {
369 osmclient_snap_install_refresh refresh
370}
371
372function install_osm_client_snap() {
373 osmclient_snap_install_refresh install
374}
375
376function osmclient_snap_install_refresh() {
377 channel_preference="stable candidate beta edge"
378 for channel in $channel_preference; do
379 echo "Trying to install osmclient from channel $OSMCLIENT_VERSION/$channel"
380 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
381 done
382}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100383function install_osmclient() {
David Garcia107010b2021-01-15 12:58:59 +0100384 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100385}
386
beierlmdf6de3d2020-12-16 08:46:40 -0500387function add_local_k8scluster() {
388 osm --all-projects vim-create \
389 --name _system-osm-vim \
390 --account_type dummy \
391 --auth_url http://dummy \
392 --user osm --password osm --tenant osm \
393 --description "dummy" \
394 --config '{management_network_name: mgmt}'
395 tmpfile=$(mktemp --tmpdir=${HOME})
396 cp ${KUBECONFIG} ${tmpfile}
397 osm --all-projects k8scluster-add \
398 --creds ${tmpfile} \
399 --vim _system-osm-vim \
400 --k8s-nets '{"net1": null}' \
401 --version '1.19' \
402 --description "OSM Internal Cluster" \
403 _system-osm-k8s
404 rm -f ${tmpfile}
405}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100406
407function install_microstack() {
408 sudo snap install microstack --classic --beta
409 sudo microstack.init --auto
410 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
411 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200412 --public \
413 --disk-format qcow2 \
414 --container-format bare \
415 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
416 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100417 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
418 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
David Garcia49379ce2021-02-24 13:48:22 +0100419 export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100420 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200421 --user admin \
422 --password keystone \
423 --auth_url http://10.20.20.1:5000/v3 \
424 --tenant admin \
425 --account_type openstack \
426 --config='{security_groups: default,
427 keypair: microstack,
428 project_name: admin,
429 user_domain_name: default,
430 region_name: microstack,
431 insecure: True,
432 availability_zone: nova,
433 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100434}
435
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200436DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100437DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
438
439check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200440mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100441install_snaps
442bootstrap_k8s_lxd
David Garcia1bc71022021-05-03 18:27:18 +0200443create_overlay
444if [ -v ONLY_VCA ]; then
445 HOME=/home/$USER
446 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
447 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
448 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
449 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
450 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
451 vca_cloud="lxd-cloud"
452 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
453 hostname=`cat /etc/hostname`
beierlmdf6de3d2020-12-16 08:46:40 -0500454
David Garcia1bc71022021-05-03 18:27:18 +0200455 echo "Use the following command to register the installed VCA to your OSM:"
456 echo -e " osm vca-add --endpoints $vca_host:$vca_port \ \n --user $vca_user \ \n --secret $vca_secret \ \n --cacert $vca_cacert \ \n --lxd-cloud lxd-cloud \ \n --lxd-credentials lxd-cloud \ \n --k8s-cloud microk8s \ \n --k8s-credentials microk8s\ \n $hostname-vca"
457else
458 deploy_charmed_osm
459 install_osmclient
460 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
461 sleep 10
462 add_local_k8scluster
463 if [ -v MICROSTACK ]; then
464 install_microstack
465 fi
466
467 echo "Your installation is now complete, follow these steps for configuring the osmclient:"
468 echo
469 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
470 echo
471 echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
472 echo
473 echo "2. Add the previous command to your .bashrc for other Shell sessions"
474 echo
475 echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
476 echo
477 echo "DONE"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100478fi
beierlma4a37f72020-06-26 12:55:01 -0400479