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