blob: 00e4112bf8580a34d8878e79be267f8ba93977f0 [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 Garciaa1376012020-10-19 15:42:42 +020018JUJU_AGENT_VERSION=2.8.6
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 Garcia69388c22020-05-07 12:14:19 +020022IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050023PATH=/snap/bin:${PATH}
24
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010025function check_arguments(){
26 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020027 case $1 in
28 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020029 --k8s) KUBECFG="$2" ;;
30 --vca) CONTROLLER="$2" ;;
31 --lxd) LXD_CLOUD="$2" ;;
32 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020033 --microstack) MICROSTACK=y ;;
David Garciacef05e92020-08-20 12:08:31 +020034 --ha) BUNDLE="cs:osm-ha" ;;
David Garcia69388c22020-05-07 12:14:19 +020035 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050036 --registry) REGISTRY_INFO="$2" ;;
David Garcia42375212020-04-27 19:07:49 +020037 esac
38 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010039 done
40
David Garcia42375212020-04-27 19:07:49 +020041 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010042}
beierlma4a37f72020-06-26 12:55:01 -040043
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010044function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040045 if [ ! -v KUBECFG ]; then
beierlm481ae7d2020-12-14 09:59:19 -050046 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
beierlma4a37f72020-06-26 12:55:01 -040047 sudo usermod -a -G microk8s `whoami`
48 mkdir -p ~/.kube
49 sudo chown -f -R `whoami` ~/.kube
50 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050051 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlma4a37f72020-06-26 12:55:01 -040052 else
53 KUBECTL="kubectl"
54 sudo snap install kubectl --classic
55 export KUBECONFIG=${KUBECFG}
56 KUBEGRP=$(id -g -n)
57 fi
58 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010059}
60
61function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020062 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040063 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
64
65 if [ -v BOOTSTRAP_NEEDED ]; then
66 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
67 if [ $CONTROLLER_PRESENT -ge 1 ]; then
68 cat << EOF
69Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
70You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
71using this command:
72
73 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
74
75Please retry the installation once this conflict has been resolved.
76EOF
77 exit 1
78 fi
beierlm9afb0ef2020-10-16 12:53:51 -040079 else
80 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
81 if [ $CONTROLLER_PRESENT -le 0 ]; then
82 cat << EOF
83Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
84that exists, or remove the --vca ${CONTROLLER_NAME} option.
85
86Please retry the installation with one of the solutions applied.
87EOF
88 exit 1
89 fi
beierlma4a37f72020-06-26 12:55:01 -040090 fi
David Garcia42375212020-04-27 19:07:49 +020091
92 if [ -v KUBECFG ]; then
93 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -040094 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
95 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +020096 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010097 else
beierlma4a37f72020-06-26 12:55:01 -040098 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -040099 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -0400100 sg ${KUBEGRP} -c "microk8s.enable storage dns"
101 TIME_TO_WAIT=30
102 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200103 while true
104 do
beierlma4a37f72020-06-26 12:55:01 -0400105 now="$(date -u +%s)"
106 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
107 echo "Microk8s storage failed to enable"
108 sg ${KUBEGRP} -c "microk8s.status"
109 exit 1
110 fi
111 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
112 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200113 break
114 fi
115 sleep 1
116 done
David Garcia42375212020-04-27 19:07:49 +0200117
beierlma4a37f72020-06-26 12:55:01 -0400118 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400119 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200120 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400121 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100122 fi
123
David Garcia42375212020-04-27 19:07:49 +0200124 if [ -v LXD_CLOUD ]; then
125 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100126 echo "The installer needs the LXD server certificate if the LXD is external"
127 exit 1
128 fi
129 else
130 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200131 LXD_CLOUD=~/.osm/lxd-cloud.yaml
132 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
133 # Apply sysctl production values for optimal performance
134 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
135 sudo sysctl --system
136 # Install LXD snap
137 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
138 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200139 # Configure LXD
140 sudo usermod -a -G lxd `whoami`
141 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"
142 sg lxd -c "lxd waitready"
143 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
144 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200145 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100146
David Garcia42375212020-04-27 19:07:49 +0200147 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100148clouds:
149 lxd-cloud:
150 type: lxd
151 auth-types: [certificate]
152 endpoint: "https://$LXDENDPOINT:8443"
153 config:
154 ssl-hostname-verification: false
155EOF
David Garcia42375212020-04-27 19:07:49 +0200156 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"
157 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
158 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
159 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100160
David Garcia42375212020-04-27 19:07:49 +0200161 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100162credentials:
163 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200164 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100165 auth-type: certificate
166 server-cert: |
167$server_cert
168 client-cert: |
169$client_cert
170 client-key: |
171$client_key
172EOF
David Garcia42375212020-04-27 19:07:49 +0200173 lxc config trust add local: ~/.osm/client.crt
174 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100175
David Garcia42375212020-04-27 19:07:49 +0200176 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
177 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
178 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400179 juju controller-config features=[k8s-operators]
180}
181
182function wait_for_port(){
183 SERVICE=$1
184 INDEX=$2
185 TIME_TO_WAIT=30
186 start_time="$(date -u +%s)"
187 while true
188 do
189 now="$(date -u +%s)"
190 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
191 echo "Failed to expose external ${SERVICE} interface port"
192 exit 1
193 fi
194
beierlm9afb0ef2020-10-16 12:53:51 -0400195 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 -0400196 break
197 fi
198 sleep 1
199 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100200}
201
202function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500203 if [ -v REGISTRY_INFO ] ; then
204 registry_parts=(${REGISTRY_INFO//@/ })
205 if [ ${#registry_parts[@]} -eq 1 ] ; then
206 # No credentials supplied
207 REGISTRY_USERNAME=""
208 REGISTRY_PASSWORD=""
209 REGISTRY_URL=${registry_parts[0]}
210 else
211 credentials=${registry_parts[0]}
212 credential_parts=(${credentials//:/ })
213 REGISTRY_USERNAME=${credential_parts[0]}
214 REGISTRY_PASSWORD=${credential_parts[1]}
215 REGISTRY_URL=${registry_parts[1]}
216 fi
217 # Ensure the URL ends with a /
218 case $REGISTRY_URL in
219 */) ;;
220 *) REGISTRY_URL=${REGISTRY_URL}/
221 esac
222 fi
223
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100224 create_overlay
225 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200226 if [ -v KUBECFG ]; then
227 juju add-model osm $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100228 else
beierlma4a37f72020-06-26 12:55:01 -0400229 sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100230 fi
231 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400232 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500233 if [ -v REGISTRY_URL ]; then
234 [ ! -v TAG ] && TAG='latest'
235 fi
beierlma4a37f72020-06-26 12:55:01 -0400236 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500237
David Garcia42375212020-04-27 19:07:49 +0200238 if [ -v BUNDLE ]; then
beierlma4a37f72020-06-26 12:55:01 -0400239 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100240 else
beierlmdb7a2ba2020-11-29 08:16:00 -0500241 juju deploy cs:osm --channel edge --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100242 fi
beierlma4a37f72020-06-26 12:55:01 -0400243
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100244 echo "Waiting for deployment to finish..."
beierlma4a37f72020-06-26 12:55:01 -0400245 check_osm_deployed
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100246 echo "OSM with charms deployed"
beierlma4a37f72020-06-26 12:55:01 -0400247 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400248 API_SERVER=${DEFAULT_IP}
249 else
250 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
251 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
252 url="$(echo ${API_SERVER/$proto/})"
253 user="$(echo $url | grep @ | cut -d@ -f1)"
254 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
255 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
256 fi
257
David Garciade5fc1d2020-09-02 11:40:12 +0200258 # Expose OSM services
beierlm9afb0ef2020-10-16 12:53:51 -0400259 # Expose Grafana
260 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
261 juju expose grafana-k8s
262 wait_for_port grafana-k8s 0
263
David Garciade5fc1d2020-09-02 11:40:12 +0200264 # Expose NBI
beierlma4a37f72020-06-26 12:55:01 -0400265 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
266 juju expose nbi-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400267 wait_for_port nbi-k8s 1
beierlma4a37f72020-06-26 12:55:01 -0400268
David Garciade5fc1d2020-09-02 11:40:12 +0200269 # Expose NG UI
beierlma4a37f72020-06-26 12:55:01 -0400270 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
271 juju expose ng-ui
beierlm9afb0ef2020-10-16 12:53:51 -0400272 wait_for_port ng-ui 2
273
274 # Expose Prometheus
275 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
276 juju expose prometheus-k8s
277 wait_for_port prometheus-k8s 3
beierlma4a37f72020-06-26 12:55:01 -0400278
David Garciade5fc1d2020-09-02 11:40:12 +0200279 # Apply annotations
beierlm9afb0ef2020-10-16 12:53:51 -0400280 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s"
281 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s"
282 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui"
beierlm9afb0ef2020-10-16 12:53:51 -0400283}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100284
285function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400286 TIME_TO_WAIT=600
287 start_time="$(date -u +%s)"
David Garcia02a5eb92020-11-28 14:41:22 +0100288 total_service_count=14
beierlm7e54dfc2020-09-24 15:27:53 -0400289 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100290 while true
291 do
beierlma4a37f72020-06-26 12:55:01 -0400292 service_count=$(juju status | grep kubernetes | grep active | wc -l)
293 echo "$service_count / $total_service_count services active"
294 if [ $service_count -eq $total_service_count ]; then
295 break
296 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400297 if [ $service_count -ne $previous_count ]; then
298 previous_count=$service_count
299 start_time="$(date -u +%s)"
300 fi
beierlma4a37f72020-06-26 12:55:01 -0400301 now="$(date -u +%s)"
302 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
303 echo "Timed out waiting for OSM services to become ready"
304 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100305 fi
306 sleep 10
307 done
308}
309
310function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200311 sudo snap install jq
312 sudo apt install python3-pip -y
313 python3 -m pip install yq
314 PATH=$PATH:$HOME/.local/bin # make yq command available
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100315 local HOME=/home/$USER
David Garcia42375212020-04-27 19:07:49 +0200316 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
317 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
beierlm3749e312020-07-02 14:21:09 -0400318 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' --raw-output | cut -d ":" -f 1)
319 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' --raw-output | cut -d ":" -f 2)
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100320 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
321 local vca_cloud="lxd-cloud"
322 # Get the VCA Certificate
beierlm3749e312020-07-02 14:21:09 -0400323 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert"]' --raw-output | base64 | tr -d \\n)
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100324
325 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200326 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100327
328 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200329 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100330applications:
331 lcm-k8s:
332 options:
333 vca_user: $vca_user
334 vca_password: $vca_password
335 vca_host: $vca_host
336 vca_port: $vca_port
337 vca_pubkey: $vca_pubkey
338 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100339 vca_cloud: $vca_cloud
beierlma4a37f72020-06-26 12:55:01 -0400340 vca_k8s_cloud: $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100341 mon-k8s:
342 options:
343 vca_user: $vca_user
344 vca_password: $vca_password
345 vca_host: $vca_host
346 vca_cacert: $vca_cacert
347EOF
David Garcia42375212020-04-27 19:07:49 +0200348 mv /tmp/vca-overlay.yaml ~/.osm/
349 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100350}
351
David Garcia69388c22020-05-07 12:14:19 +0200352function generate_images_overlay(){
beierlmf2782c52020-11-05 17:04:05 -0500353 if [ ! -z "$REGISTRY_USERNAME" ] ; then
354 REGISTRY_CREDENTIALS=$(cat <<EOF
355
356 image_username: $REGISTRY_USERNAME
357 image_password: $REGISTRY_PASSWORD
358EOF
359 );
360fi
361
David Garcia69388c22020-05-07 12:14:19 +0200362 cat << EOF > /tmp/images-overlay.yaml
363applications:
364 lcm-k8s:
365 options:
beierlmf2782c52020-11-05 17:04:05 -0500366 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200367 mon-k8s:
368 options:
beierlmf2782c52020-11-05 17:04:05 -0500369 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200370 ro-k8s:
371 options:
beierlmf2782c52020-11-05 17:04:05 -0500372 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200373 nbi-k8s:
374 options:
beierlmf2782c52020-11-05 17:04:05 -0500375 image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200376 pol-k8s:
377 options:
beierlmf2782c52020-11-05 17:04:05 -0500378 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400379 pla:
380 options:
beierlmf2782c52020-11-05 17:04:05 -0500381 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400382 ng-ui:
383 options:
beierlmf2782c52020-11-05 17:04:05 -0500384 image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
David Garcia009a5d62020-08-27 16:53:44 +0200385 keystone:
386 options:
beierlmf2782c52020-11-05 17:04:05 -0500387 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200388EOF
389 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
390}
391
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100392function install_osmclient() {
393 sudo snap install osmclient
394 sudo snap alias osmclient.osm osm
395}
396
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100397
398function install_microstack() {
399 sudo snap install microstack --classic --beta
400 sudo microstack.init --auto
401 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
402 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200403 --public \
404 --disk-format qcow2 \
405 --container-format bare \
406 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
407 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100408 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
409 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200410 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100411 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200412 --user admin \
413 --password keystone \
414 --auth_url http://10.20.20.1:5000/v3 \
415 --tenant admin \
416 --account_type openstack \
417 --config='{security_groups: default,
418 keypair: microstack,
419 project_name: admin,
420 user_domain_name: default,
421 region_name: microstack,
422 insecure: True,
423 availability_zone: nova,
424 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100425}
426
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200427DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100428DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
429
430check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200431mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100432install_snaps
433bootstrap_k8s_lxd
434deploy_charmed_osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100435install_osmclient
David Garcia42375212020-04-27 19:07:49 +0200436if [ -v MICROSTACK ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100437 install_microstack
438fi
beierlma4a37f72020-06-26 12:55:01 -0400439
beierlm7e54dfc2020-09-24 15:27:53 -0400440OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
441
beierlma4a37f72020-06-26 12:55:01 -0400442echo "Your installation is now complete, follow these steps for configuring the osmclient:"
443echo
444echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
445echo
beierlm7e54dfc2020-09-24 15:27:53 -0400446echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
beierlma4a37f72020-06-26 12:55:01 -0400447echo
448echo "2. Add the previous command to your .bashrc for other Shell sessions"
449echo
beierlm7e54dfc2020-09-24 15:27:53 -0400450echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
beierlma4a37f72020-06-26 12:55:01 -0400451echo
452echo "DONE"