blob: ad53042888e9ff738b6fd001b0b21408abce2982 [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 Garciad68e0b42021-06-28 16:50:42 +020018JUJU_VERSION=2.9
19JUJU_AGENT_VERSION=2.9.5
David Garcia42375212020-04-27 19:07:49 +020020K8S_CLOUD_NAME="k8s-cloud"
beierlm3749e312020-07-02 14:21:09 -040021KUBECTL="microk8s.kubectl"
David Garciad68e0b42021-06-28 16:50:42 +020022MICROK8S_VERSION=1.20
23OSMCLIENT_VERSION=10.0
David Garcia69388c22020-05-07 12:14:19 +020024IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050025PATH=/snap/bin:${PATH}
26
David Garciaef349d92020-12-10 21:16:12 +010027MODEL_NAME=osm
28
David Garciad68e0b42021-06-28 16:50:42 +020029# Latest bundles using old mongodb-k8s
30# OSM_BUNDLE=cs:osm-68
31# OSM_HA_BUNDLE=cs:osm-ha-54
32# The charm store does not support referencing charms from CharmHub,
33# therefore we will point to the local bundles until we migrate all
34# charms to CharmHub.
35OSM_BUNDLE=/usr/share/osm-devops/installers/charm/bundles/osm/bundle.yaml
36OSM_HA_BUNDLE=/usr/share/osm-devops/installers/charm/bundles/osm-ha/bundle.yaml
David Garcia49379ce2021-02-24 13:48:22 +010037TAG=testing-daily
David Garciaab11f842020-12-16 17:25:15 +010038
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010039function check_arguments(){
40 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020041 case $1 in
42 --bundle) BUNDLE="$2" ;;
David Garcia4bd2bf02021-05-05 19:01:43 +020043 --overlay) OVERLAY="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020044 --k8s) KUBECFG="$2" ;;
45 --vca) CONTROLLER="$2" ;;
46 --lxd) LXD_CLOUD="$2" ;;
47 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020048 --microstack) MICROSTACK=y ;;
David Garciaab11f842020-12-16 17:25:15 +010049 --ha) BUNDLE=$OSM_HA_BUNDLE ;;
David Garcia69388c22020-05-07 12:14:19 +020050 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050051 --registry) REGISTRY_INFO="$2" ;;
David Garcia1bc71022021-05-03 18:27:18 +020052 --only-vca) ONLY_VCA=y ;;
David Garcia42375212020-04-27 19:07:49 +020053 esac
54 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010055 done
56
David Garcia42375212020-04-27 19:07:49 +020057 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010058}
beierlma4a37f72020-06-26 12:55:01 -040059
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010060function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040061 if [ ! -v KUBECFG ]; then
beierlm481ae7d2020-12-14 09:59:19 -050062 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
David Garcia9a59e3d2021-02-08 15:18:27 +010063 sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
David Garcia107010b2021-01-15 12:58:59 +010064 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
65 microk8s.stop
66 microk8s.start
67 )
beierlma4a37f72020-06-26 12:55:01 -040068 sudo usermod -a -G microk8s `whoami`
69 mkdir -p ~/.kube
70 sudo chown -f -R `whoami` ~/.kube
71 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050072 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlmdf6de3d2020-12-16 08:46:40 -050073 KUBECONFIG=~/.osm/microk8s-config.yaml
David Garcia107010b2021-01-15 12:58:59 +010074 sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
beierlma4a37f72020-06-26 12:55:01 -040075 else
76 KUBECTL="kubectl"
77 sudo snap install kubectl --classic
78 export KUBECONFIG=${KUBECFG}
79 KUBEGRP=$(id -g -n)
80 fi
David Garciad68e0b42021-06-28 16:50:42 +020081 sudo snap install juju --classic --channel=$JUJU_VERSION/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010082}
83
84function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020085 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040086 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
87
88 if [ -v BOOTSTRAP_NEEDED ]; then
89 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
90 if [ $CONTROLLER_PRESENT -ge 1 ]; then
91 cat << EOF
92Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
93You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
94using this command:
95
96 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
97
98Please retry the installation once this conflict has been resolved.
99EOF
100 exit 1
101 fi
beierlm9afb0ef2020-10-16 12:53:51 -0400102 else
103 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
104 if [ $CONTROLLER_PRESENT -le 0 ]; then
105 cat << EOF
106Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
107that exists, or remove the --vca ${CONTROLLER_NAME} option.
108
109Please retry the installation with one of the solutions applied.
110EOF
111 exit 1
112 fi
beierlma4a37f72020-06-26 12:55:01 -0400113 fi
David Garcia42375212020-04-27 19:07:49 +0200114
115 if [ -v KUBECFG ]; then
116 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400117 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
118 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +0200119 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100120 else
beierlma4a37f72020-06-26 12:55:01 -0400121 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -0400122 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -0400123 sg ${KUBEGRP} -c "microk8s.enable storage dns"
124 TIME_TO_WAIT=30
125 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200126 while true
127 do
beierlma4a37f72020-06-26 12:55:01 -0400128 now="$(date -u +%s)"
129 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
130 echo "Microk8s storage failed to enable"
131 sg ${KUBEGRP} -c "microk8s.status"
132 exit 1
133 fi
134 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
135 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200136 break
137 fi
138 sleep 1
139 done
David Garcia42375212020-04-27 19:07:49 +0200140
beierlma4a37f72020-06-26 12:55:01 -0400141 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400142 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200143 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400144 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100145 fi
146
David Garcia42375212020-04-27 19:07:49 +0200147 if [ -v LXD_CLOUD ]; then
148 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100149 echo "The installer needs the LXD server certificate if the LXD is external"
150 exit 1
151 fi
152 else
153 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200154 LXD_CLOUD=~/.osm/lxd-cloud.yaml
155 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
156 # Apply sysctl production values for optimal performance
157 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
158 sudo sysctl --system
159 # Install LXD snap
160 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
161 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200162 # Configure LXD
163 sudo usermod -a -G lxd `whoami`
164 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"
165 sg lxd -c "lxd waitready"
166 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
167 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200168 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100169
David Garcia42375212020-04-27 19:07:49 +0200170 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100171clouds:
172 lxd-cloud:
173 type: lxd
174 auth-types: [certificate]
175 endpoint: "https://$LXDENDPOINT:8443"
176 config:
177 ssl-hostname-verification: false
178EOF
David Garcia42375212020-04-27 19:07:49 +0200179 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"
180 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
181 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
182 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100183
David Garcia42375212020-04-27 19:07:49 +0200184 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100185credentials:
186 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200187 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100188 auth-type: certificate
189 server-cert: |
190$server_cert
191 client-cert: |
192$client_cert
193 client-key: |
194$client_key
195EOF
David Garcia42375212020-04-27 19:07:49 +0200196 lxc config trust add local: ~/.osm/client.crt
197 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100198
David Garcia42375212020-04-27 19:07:49 +0200199 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
200 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
201 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400202 juju controller-config features=[k8s-operators]
203}
204
205function wait_for_port(){
206 SERVICE=$1
207 INDEX=$2
208 TIME_TO_WAIT=30
209 start_time="$(date -u +%s)"
210 while true
211 do
212 now="$(date -u +%s)"
213 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
214 echo "Failed to expose external ${SERVICE} interface port"
215 exit 1
216 fi
217
beierlm9afb0ef2020-10-16 12:53:51 -0400218 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 -0400219 break
220 fi
221 sleep 1
222 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100223}
224
225function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500226 if [ -v REGISTRY_INFO ] ; then
227 registry_parts=(${REGISTRY_INFO//@/ })
228 if [ ${#registry_parts[@]} -eq 1 ] ; then
229 # No credentials supplied
230 REGISTRY_USERNAME=""
231 REGISTRY_PASSWORD=""
232 REGISTRY_URL=${registry_parts[0]}
233 else
234 credentials=${registry_parts[0]}
235 credential_parts=(${credentials//:/ })
236 REGISTRY_USERNAME=${credential_parts[0]}
237 REGISTRY_PASSWORD=${credential_parts[1]}
238 REGISTRY_URL=${registry_parts[1]}
239 fi
240 # Ensure the URL ends with a /
241 case $REGISTRY_URL in
242 */) ;;
243 *) REGISTRY_URL=${REGISTRY_URL}/
244 esac
245 fi
246
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100247 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200248 if [ -v KUBECFG ]; then
David Garciaef349d92020-12-10 21:16:12 +0100249 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100250 else
David Garciaef349d92020-12-10 21:16:12 +0100251 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100252 fi
253 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400254 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500255 if [ -v REGISTRY_URL ]; then
256 [ ! -v TAG ] && TAG='latest'
257 fi
beierlma4a37f72020-06-26 12:55:01 -0400258 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500259
David Garcia4bd2bf02021-05-05 19:01:43 +0200260 if [ -v OVERLAY ]; then
261 extra_overlay="--overlay $OVERLAY"
262 fi
263
David Garcia42375212020-04-27 19:07:49 +0200264 if [ -v BUNDLE ]; then
David Garcia4bd2bf02021-05-05 19:01:43 +0200265 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100266 else
David Garcia4bd2bf02021-05-05 19:01:43 +0200267 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100268 fi
beierlma4a37f72020-06-26 12:55:01 -0400269
beierlma4a37f72020-06-26 12:55:01 -0400270 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400271 API_SERVER=${DEFAULT_IP}
272 else
273 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
274 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
275 url="$(echo ${API_SERVER/$proto/})"
276 user="$(echo $url | grep @ | cut -d@ -f1)"
277 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
278 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
279 fi
David Garciade5fc1d2020-09-02 11:40:12 +0200280 # Expose OSM services
David Garciac395a452021-05-05 14:22:26 +0200281 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
282 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
283 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
288 echo "OSM with charms deployed"
beierlm9afb0ef2020-10-16 12:53:51 -0400289}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100290
291function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400292 TIME_TO_WAIT=600
293 start_time="$(date -u +%s)"
David Garcia02a5eb92020-11-28 14:41:22 +0100294 total_service_count=14
beierlm7e54dfc2020-09-24 15:27:53 -0400295 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100296 while true
297 do
David Garciaef349d92020-12-10 21:16:12 +0100298 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
beierlma4a37f72020-06-26 12:55:01 -0400299 echo "$service_count / $total_service_count services active"
300 if [ $service_count -eq $total_service_count ]; then
301 break
302 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400303 if [ $service_count -ne $previous_count ]; then
304 previous_count=$service_count
305 start_time="$(date -u +%s)"
306 fi
beierlma4a37f72020-06-26 12:55:01 -0400307 now="$(date -u +%s)"
308 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
309 echo "Timed out waiting for OSM services to become ready"
310 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100311 fi
312 sleep 10
313 done
314}
315
316function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200317 sudo snap install jq
David Garciac8660ad2020-12-16 13:13:20 +0100318 sudo snap install yq
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100319 local HOME=/home/$USER
calvinosanc183ea27a2021-01-04 11:42:18 +0100320 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
David Garciac753dc52021-03-17 15:28:47 +0100321 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
calvinosanc183ea27a2021-01-04 11:42:18 +0100322 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
323 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 +0100324 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
325 local vca_cloud="lxd-cloud"
326 # Get the VCA Certificate
calvinosanc183ea27a2021-01-04 11:42:18 +0100327 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 +0100328
329 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200330 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100331
332 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200333 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100334applications:
David Garcia49379ce2021-02-24 13:48:22 +0100335 lcm:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100336 options:
337 vca_user: $vca_user
David Garciac753dc52021-03-17 15:28:47 +0100338 vca_secret: $vca_secret
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100339 vca_host: $vca_host
340 vca_port: $vca_port
341 vca_pubkey: $vca_pubkey
342 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100343 vca_cloud: $vca_cloud
beierlma4a37f72020-06-26 12:55:01 -0400344 vca_k8s_cloud: $K8S_CLOUD_NAME
David Garcia49379ce2021-02-24 13:48:22 +0100345 mon:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100346 options:
347 vca_user: $vca_user
David Garciac753dc52021-03-17 15:28:47 +0100348 vca_secret: $vca_secret
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100349 vca_host: $vca_host
350 vca_cacert: $vca_cacert
351EOF
David Garcia42375212020-04-27 19:07:49 +0200352 mv /tmp/vca-overlay.yaml ~/.osm/
353 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100354}
355
David Garcia69388c22020-05-07 12:14:19 +0200356function generate_images_overlay(){
David Garcia49379ce2021-02-24 13:48:22 +0100357 echo "applications:" > /tmp/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -0500358
David Garcia49379ce2021-02-24 13:48:22 +0100359 charms_with_resources="nbi lcm mon pol ng-ui ro pla keystone"
360 for charm in $charms_with_resources; do
361 cat << EOF > /tmp/${charm}_registry.yaml
362registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
beierlmf2782c52020-11-05 17:04:05 -0500363EOF
David Garcia49379ce2021-02-24 13:48:22 +0100364 if [ ! -z "$REGISTRY_USERNAME" ] ; then
365 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
366 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
367 fi
beierlmf2782c52020-11-05 17:04:05 -0500368
David Garcia49379ce2021-02-24 13:48:22 +0100369 cat << EOF >> /tmp/images-overlay.yaml
370 ${charm}:
David Garciaef349d92020-12-10 21:16:12 +0100371 resources:
David Garcia49379ce2021-02-24 13:48:22 +0100372 image: /tmp/${charm}_registry.yaml
373
David Garcia69388c22020-05-07 12:14:19 +0200374EOF
David Garcia49379ce2021-02-24 13:48:22 +0100375 done
376
David Garcia69388c22020-05-07 12:14:19 +0200377 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
378}
379
David Garcia107010b2021-01-15 12:58:59 +0100380function refresh_osmclient_snap() {
381 osmclient_snap_install_refresh refresh
382}
383
384function install_osm_client_snap() {
385 osmclient_snap_install_refresh install
386}
387
388function osmclient_snap_install_refresh() {
389 channel_preference="stable candidate beta edge"
390 for channel in $channel_preference; do
391 echo "Trying to install osmclient from channel $OSMCLIENT_VERSION/$channel"
392 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
393 done
394}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100395function install_osmclient() {
David Garcia107010b2021-01-15 12:58:59 +0100396 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100397}
398
beierlmdf6de3d2020-12-16 08:46:40 -0500399function add_local_k8scluster() {
400 osm --all-projects vim-create \
401 --name _system-osm-vim \
402 --account_type dummy \
403 --auth_url http://dummy \
404 --user osm --password osm --tenant osm \
405 --description "dummy" \
406 --config '{management_network_name: mgmt}'
407 tmpfile=$(mktemp --tmpdir=${HOME})
408 cp ${KUBECONFIG} ${tmpfile}
409 osm --all-projects k8scluster-add \
410 --creds ${tmpfile} \
411 --vim _system-osm-vim \
412 --k8s-nets '{"net1": null}' \
413 --version '1.19' \
414 --description "OSM Internal Cluster" \
415 _system-osm-k8s
416 rm -f ${tmpfile}
417}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100418
419function install_microstack() {
420 sudo snap install microstack --classic --beta
421 sudo microstack.init --auto
422 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
423 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200424 --public \
425 --disk-format qcow2 \
426 --container-format bare \
427 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
428 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100429 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
430 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
David Garcia49379ce2021-02-24 13:48:22 +0100431 export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100432 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200433 --user admin \
434 --password keystone \
435 --auth_url http://10.20.20.1:5000/v3 \
436 --tenant admin \
437 --account_type openstack \
438 --config='{security_groups: default,
439 keypair: microstack,
440 project_name: admin,
441 user_domain_name: default,
442 region_name: microstack,
443 insecure: True,
444 availability_zone: nova,
445 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100446}
447
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200448DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100449DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
450
451check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200452mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100453install_snaps
454bootstrap_k8s_lxd
David Garcia1bc71022021-05-03 18:27:18 +0200455create_overlay
456if [ -v ONLY_VCA ]; then
457 HOME=/home/$USER
458 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
459 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
460 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
461 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
462 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
463 vca_cloud="lxd-cloud"
464 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
465 hostname=`cat /etc/hostname`
beierlmdf6de3d2020-12-16 08:46:40 -0500466
David Garcia1bc71022021-05-03 18:27:18 +0200467 echo "Use the following command to register the installed VCA to your OSM:"
David Garciad68e0b42021-06-28 16:50:42 +0200468 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"
David Garcia1bc71022021-05-03 18:27:18 +0200469else
470 deploy_charmed_osm
471 install_osmclient
472 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
473 sleep 10
474 add_local_k8scluster
475 if [ -v MICROSTACK ]; then
476 install_microstack
477 fi
478
479 echo "Your installation is now complete, follow these steps for configuring the osmclient:"
480 echo
481 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
482 echo
483 echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
484 echo
485 echo "2. Add the previous command to your .bashrc for other Shell sessions"
486 echo
487 echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
488 echo
489 echo "DONE"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100490fi
beierlma4a37f72020-06-26 12:55:01 -0400491