Proper tracking of Charmed Install
[osm/devops.git] / installers / charmed_install.sh
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 #
15
16 # set -eux
17
18 LXD_VERSION=4.0
19 JUJU_VERSION=2.9
20 JUJU_AGENT_VERSION=2.9.22
21 K8S_CLOUD_NAME="k8s-cloud"
22 KUBECTL="microk8s.kubectl"
23 MICROK8S_VERSION=1.23
24 OSMCLIENT_VERSION=latest
25 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
26 PASSWORD_OVERLAY_FILE=~/.osm/password-overlay.yaml
27 PATH=/snap/bin:${PATH}
28 OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )"
29 if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then
30 source ${OSM_DEVOPS}/common/all_funcs
31 else
32 function track(){
33 true
34 }
35 function FATAL_TRACK(){
36 exit 1
37 }
38 fi
39
40 MODEL_NAME=osm
41
42 OSM_BUNDLE=ch:osm
43 OSM_HA_BUNDLE=ch:osm-ha
44 CHARMHUB_CHANNEL=latest/edge
45 unset TAG
46
47 function check_arguments(){
48 while [ $# -gt 0 ] ; do
49 case $1 in
50 --bundle) BUNDLE="$2" ;;
51 --overlay) OVERLAY="$2" ;;
52 --k8s) KUBECFG="$2" ;;
53 --vca) CONTROLLER="$2" ;;
54 --lxd) LXD_CLOUD="$2" ;;
55 --lxd-cred) LXD_CREDENTIALS="$2" ;;
56 --microstack) MICROSTACK=y ;;
57 --ha) BUNDLE=$OSM_HA_BUNDLE ;;
58 --tag) TAG="$2" ;;
59 --registry) REGISTRY_INFO="$2" ;;
60 --only-vca) ONLY_VCA=y ;;
61 esac
62 shift
63 done
64
65 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
66 }
67
68 function install_snaps(){
69 if [ ! -v KUBECFG ]; then
70 KUBEGRP="microk8s"
71 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable ||
72 FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed"
73 sudo usermod -a -G microk8s `whoami`
74 sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
75 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
76 sg ${KUBEGRP} -c microk8s.stop
77 sg ${KUBEGRP} -c microk8s.start
78 )
79 mkdir -p ~/.kube
80 sudo chown -f -R `whoami` ~/.kube
81 sg ${KUBEGRP} -c "microk8s status --wait-ready"
82 KUBECONFIG=~/.osm/microk8s-config.yaml
83 sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
84 track k8scluster k8scluster_ok
85 else
86 KUBECTL="kubectl"
87 sudo snap install kubectl --classic
88 export KUBECONFIG=${KUBECFG}
89 KUBEGRP=$(id -g -n)
90 fi
91 sudo snap install juju --classic --channel=$JUJU_VERSION/stable ||
92 FATAL_TRACK juju "snap install juju ${JUJU_VERSION}/stable failed"
93 track juju juju_ok
94 }
95
96 function bootstrap_k8s_lxd(){
97 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
98 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
99
100 if [ -v BOOTSTRAP_NEEDED ]; then
101 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
102 if [ $CONTROLLER_PRESENT -ge 1 ]; then
103 cat << EOF
104 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
105 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
106 using this command:
107
108 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
109
110 Please retry the installation once this conflict has been resolved.
111 EOF
112 FATAL_TRACK bootstrap_k8s "VCA already present"
113 fi
114 else
115 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
116 if [ $CONTROLLER_PRESENT -le 0 ]; then
117 cat << EOF
118 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
119 that exists, or remove the --vca ${CONTROLLER_NAME} option.
120
121 Please retry the installation with one of the solutions applied.
122 EOF
123 FATAL_TRACK bootstrap_k8s "Requested VCA not present"
124 fi
125 fi
126
127 if [ -v KUBECFG ]; then
128 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
129 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
130 --config controller-service-type=loadbalancer \
131 --agent-version=$JUJU_AGENT_VERSION
132 else
133 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
134 sg ${KUBEGRP} -c "microk8s.enable ingress"
135 sg ${KUBEGRP} -c "microk8s.enable storage dns"
136 TIME_TO_WAIT=30
137 start_time="$(date -u +%s)"
138 while true
139 do
140 now="$(date -u +%s)"
141 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
142 echo "Microk8s storage failed to enable"
143 sg ${KUBEGRP} -c "microk8s.status"
144 FATAL_TRACK bootstrap_k8s "Microk8s storage failed to enable"
145 fi
146 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
147 if [[ $storage_status == "enabled" ]]; then
148 break
149 fi
150 sleep 1
151 done
152
153 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
154 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
155 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
156 && K8S_CLOUD_NAME=microk8s
157 fi
158 track bootstrap_k8s bootstrap_k8s_ok
159
160 if [ -v LXD_CLOUD ]; then
161 if [ ! -v LXD_CREDENTIALS ]; then
162 echo "The installer needs the LXD server certificate if the LXD is external"
163 FATAL_TRACK bootstrap_lxd "No LXD certificate supplied"
164 fi
165 else
166 LXDENDPOINT=$DEFAULT_IP
167 LXD_CLOUD=~/.osm/lxd-cloud.yaml
168 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
169 # Apply sysctl production values for optimal performance
170 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
171 sudo sysctl --system
172 # Install LXD snap
173 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
174 sudo snap install lxd --channel $LXD_VERSION/stable
175 # Configure LXD
176 sudo usermod -a -G lxd `whoami`
177 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"
178 sg lxd -c "lxd waitready"
179 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
180 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
181 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
182
183 cat << EOF > $LXD_CLOUD
184 clouds:
185 lxd-cloud:
186 type: lxd
187 auth-types: [certificate]
188 endpoint: "https://$LXDENDPOINT:8443"
189 config:
190 ssl-hostname-verification: false
191 EOF
192 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"
193 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
194 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
195 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
196
197 cat << EOF > $LXD_CREDENTIALS
198 credentials:
199 lxd-cloud:
200 lxd-cloud:
201 auth-type: certificate
202 server-cert: |
203 $server_cert
204 client-cert: |
205 $client_cert
206 client-key: |
207 $client_key
208 EOF
209 lxc config trust add local: ~/.osm/client.crt
210 fi
211
212 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
213 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
214 sg lxd -c "lxd waitready"
215 juju controller-config features=[k8s-operators]
216 track bootstrap_lxd bootstrap_lxd_ok
217 }
218
219 function deploy_charmed_osm(){
220 if [ -v REGISTRY_INFO ] ; then
221 registry_parts=(${REGISTRY_INFO//@/ })
222 if [ ${#registry_parts[@]} -eq 1 ] ; then
223 # No credentials supplied
224 REGISTRY_USERNAME=""
225 REGISTRY_PASSWORD=""
226 REGISTRY_URL=${registry_parts[0]}
227 else
228 credentials=${registry_parts[0]}
229 credential_parts=(${credentials//:/ })
230 REGISTRY_USERNAME=${credential_parts[0]}
231 REGISTRY_PASSWORD=${credential_parts[1]}
232 REGISTRY_URL=${registry_parts[1]}
233 fi
234 # Ensure the URL ends with a /
235 case $REGISTRY_URL in
236 */) ;;
237 *) REGISTRY_URL=${REGISTRY_URL}/
238 esac
239 fi
240
241 echo "Creating OSM model"
242 if [ -v KUBECFG ]; then
243 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
244 else
245 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
246 fi
247 echo "Deploying OSM with charms"
248 images_overlay=""
249 if [ -v REGISTRY_URL ]; then
250 [ ! -v TAG ] && TAG='latest'
251 fi
252 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
253
254 if [ -v OVERLAY ]; then
255 extra_overlay="--overlay $OVERLAY"
256 fi
257 echo "Creating Password Overlay"
258
259 generate_password_overlay && secret_overlay="--overlay $PASSWORD_OVERLAY_FILE"
260
261 if [ -v BUNDLE ]; then
262 juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay $secret_overlay
263 else
264 juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay $secret_overlay
265 fi
266
267 if [ ! -v KUBECFG ]; then
268 API_SERVER=${DEFAULT_IP}
269 else
270 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
271 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
272 url="$(echo ${API_SERVER/$proto/})"
273 user="$(echo $url | grep @ | cut -d@ -f1)"
274 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
275 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
276 fi
277 # Expose OSM services
278 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
279 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
280 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
281 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
282
283 echo "Waiting for deployment to finish..."
284 check_osm_deployed
285 grafana_leader=`juju status -m $MODEL_NAME grafana | grep "*" | cut -d "*" -f 1`
286 grafana_admin_password=`juju run -m $MODEL_NAME --unit $grafana_leader "echo \\$GF_SECURITY_ADMIN_PASSWORD"`
287 juju config -m $MODEL_NAME mon grafana_password=$grafana_admin_password
288 check_osm_deployed
289 echo "OSM with charms deployed"
290 }
291
292 function check_osm_deployed() {
293 TIME_TO_WAIT=600
294 start_time="$(date -u +%s)"
295 total_service_count=14
296 previous_count=0
297 while true
298 do
299 service_count=$(juju status --format json -m $MODEL_NAME | jq '.applications[]."application-status".current' | grep active | wc -l)
300 echo "$service_count / $total_service_count services active"
301 if [ $service_count -eq $total_service_count ]; then
302 break
303 fi
304 if [ $service_count -ne $previous_count ]; then
305 previous_count=$service_count
306 start_time="$(date -u +%s)"
307 fi
308 now="$(date -u +%s)"
309 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
310 echo "Timed out waiting for OSM services to become ready"
311 FATAL_TRACK deploy_osm "Timed out waiting for services to become ready"
312 fi
313 sleep 10
314 done
315 }
316
317 function generate_password_overlay() {
318 # prometheus
319 web_config_password=`openssl rand -base64 16`
320 # keystone
321 keystone_db_password=`openssl rand -base64 16`
322 keystone_admin_password=`openssl rand -base64 16`
323 keystone_service_password=`openssl rand -base64 16`
324 # mariadb
325 mariadb_password=`openssl rand -hex 16`
326 mariadb_root_password=`openssl rand -hex 16`
327 cat << EOF > /tmp/password-overlay.yaml
328 applications:
329 prometheus:
330 options:
331 web_config_password: $web_config_password
332 keystone:
333 options:
334 keystone-db-password: $keystone_db_password
335 admin-password: $keystone_admin_password
336 service-password: $keystone_service_password
337 mariadb:
338 options:
339 password: $mariadb_password
340 root_password: $mariadb_root_password
341 EOF
342 mv /tmp/password-overlay.yaml $PASSWORD_OVERLAY_FILE
343 }
344
345 function create_overlay() {
346 sudo snap install jq
347 sudo snap install yq
348 local HOME=/home/$USER
349 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
350 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
351 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
352 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
353 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
354 local vca_cloud="lxd-cloud"
355 # Get the VCA Certificate
356 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
357
358 # Calculate the default route of this machine
359 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
360
361 # Generate a new overlay.yaml, overriding any existing one
362 cat << EOF > /tmp/vca-overlay.yaml
363 applications:
364 lcm:
365 options:
366 vca_user: $vca_user
367 vca_secret: $vca_secret
368 vca_host: $vca_host
369 vca_port: $vca_port
370 vca_pubkey: $vca_pubkey
371 vca_cacert: $vca_cacert
372 vca_cloud: $vca_cloud
373 vca_k8s_cloud: $K8S_CLOUD_NAME
374 mon:
375 options:
376 vca_user: $vca_user
377 vca_secret: $vca_secret
378 vca_host: $vca_host
379 vca_cacert: $vca_cacert
380 EOF
381 mv /tmp/vca-overlay.yaml ~/.osm/
382 OSM_VCA_HOST=$vca_host
383 }
384
385 function generate_images_overlay(){
386 echo "applications:" > /tmp/images-overlay.yaml
387
388 charms_with_resources="nbi lcm mon pol ng-ui ro pla"
389 for charm in $charms_with_resources; do
390 cat << EOF > /tmp/${charm}_registry.yaml
391 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
392 EOF
393 if [ ! -z "$REGISTRY_USERNAME" ] ; then
394 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
395 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
396 fi
397
398 cat << EOF >> /tmp/images-overlay.yaml
399 ${charm}:
400 resources:
401 image: /tmp/${charm}_registry.yaml
402
403 EOF
404 done
405 ch_charms_with_resources="keystone"
406 for charm in $ch_charms_with_resources; do
407 cat << EOF > /tmp/${charm}_registry.yaml
408 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
409 EOF
410 if [ ! -z "$REGISTRY_USERNAME" ] ; then
411 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
412 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
413 fi
414
415 cat << EOF >> /tmp/images-overlay.yaml
416 ${charm}:
417 resources:
418 ${charm}-image: /tmp/${charm}_registry.yaml
419
420 EOF
421 done
422
423 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
424 }
425
426 function refresh_osmclient_snap() {
427 osmclient_snap_install_refresh refresh
428 }
429
430 function install_osm_client_snap() {
431 osmclient_snap_install_refresh install
432 }
433
434 function osmclient_snap_install_refresh() {
435 channel_preference="stable candidate beta edge"
436 for channel in $channel_preference; do
437 echo "Trying to install osmclient from channel $OSMCLIENT_VERSION/$channel"
438 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
439 done
440 }
441 function install_osmclient() {
442 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
443 }
444
445 function add_local_k8scluster() {
446 osm --all-projects vim-create \
447 --name _system-osm-vim \
448 --account_type dummy \
449 --auth_url http://dummy \
450 --user osm --password osm --tenant osm \
451 --description "dummy" \
452 --config '{management_network_name: mgmt}'
453 tmpfile=$(mktemp --tmpdir=${HOME})
454 cp ${KUBECONFIG} ${tmpfile}
455 osm --all-projects k8scluster-add \
456 --creds ${tmpfile} \
457 --vim _system-osm-vim \
458 --k8s-nets '{"net1": null}' \
459 --version '1.19' \
460 --description "OSM Internal Cluster" \
461 _system-osm-k8s
462 rm -f ${tmpfile}
463 }
464
465 function install_microstack() {
466 sudo snap install microstack --beta --devmode
467
468 CHECK=$(microstack.openstack server list)
469 if [ $? -ne 0 ] ; then
470 if [[ $CHECK == *"not initialized"* ]]; then
471 echo "Setting MicroStack dashboard to listen to port 8080"
472 sudo snap set microstack config.network.ports.dashboard=8080
473 echo "Initializing MicroStack. This can take several minutes"
474 sudo microstack.init --auto --control
475 fi
476 fi
477
478 sudo snap alias microstack.openstack openstack
479
480 echo "Updating default security group in MicroStack to allow all access"
481
482 for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do
483 for PROTO in icmp tcp udp ; do
484 echo " $PROTO ingress"
485 CHECK=$(microstack.openstack security group rule create $i --protocol $PROTO --remote-ip 0.0.0.0/0 2>&1)
486 if [ $? -ne 0 ] ; then
487 if [[ $CHECK != *"409"* ]]; then
488 echo "Error creating ingress rule for $PROTO"
489 echo $CHECK
490 fi
491 fi
492 done
493 done
494
495 microstack.openstack network show osm-ext &>/dev/null
496 if [ $? -ne 0 ]; then
497 echo "Creating osm-ext network with router to bridge to MicroStack external network"
498 microstack.openstack network create --enable --no-share osm-ext
499 microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \
500 --subnet-range 172.30.0.0/24
501 microstack.openstack router create external-router
502 microstack.openstack router add subnet external-router osm-ext-subnet
503 microstack.openstack router set --external-gateway external external-router
504 fi
505
506 microstack.openstack image list | grep ubuntu20.04 &> /dev/null
507 if [ $? -ne 0 ] ; then
508 echo "Fetching Ubuntu 20.04 image and upLoading to MicroStack"
509 wget -q -O- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \
510 | microstack.openstack image create --public --container-format=bare \
511 --disk-format=qcow2 ubuntu20.04 | grep status
512 fi
513
514 if [ ! -f ~/.ssh/microstack ]; then
515 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
516 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
517 fi
518
519 echo "Creating VIM microstack-site in OSM"
520 . /var/snap/microstack/common/etc/microstack.rc
521
522 osm vim-create \
523 --name microstack-site \
524 --user "$OS_USERNAME" \
525 --password "$OS_PASSWORD" \
526 --auth_url "$OS_AUTH_URL" \
527 --tenant "$OS_USERNAME" \
528 --account_type openstack \
529 --config='{use_floating_ip: True,
530 insecure: True,
531 keypair: microstack,
532 management_network_name: osm-ext}'
533 }
534
535 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5; exit}'`
536 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]; exit}'`
537
538 check_arguments $@
539 mkdir -p ~/.osm
540 install_snaps
541 bootstrap_k8s_lxd
542 create_overlay
543 if [ -v ONLY_VCA ]; then
544 HOME=/home/$USER
545 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
546 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
547 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
548 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
549 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
550 vca_cloud="lxd-cloud"
551 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
552 hostname=`cat /etc/hostname`
553
554 echo "Use the following command to register the installed VCA to your OSM:"
555 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"
556 track deploy_osm deploy_vca_only_ok
557 else
558 deploy_charmed_osm
559 track deploy_osm deploy_osm_services_k8s_ok
560 install_osmclient
561 track osmclient osmclient_ok
562 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
563 export OSM_PASSWORD=$keystone_admin_password
564 sleep 10
565 add_local_k8scluster
566 track final_ops add_local_k8scluster_ok
567 if [ -v MICROSTACK ]; then
568 install_microstack
569 track final_ops install_microstack_ok
570 fi
571
572 echo "Your installation is now complete, follow these steps for configuring the osmclient:"
573 echo
574 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
575 echo
576 echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
577 echo "export OSM_PASSWORD=$OSM_PASSWORD"
578 echo
579 echo "2. Add the previous commands to your .bashrc for other Shell sessions"
580 echo
581 echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
582 echo "echo \"export OSM_PASSWORD=$OSM_PASSWORD\" >> ~/.bashrc"
583 echo
584 echo "3. Login OSM GUI by using admin password: $OSM_PASSWORD"
585 echo
586 echo "DONE"
587 track end
588 fi
589