blob: b56ed168f7698444ec33cdc7afa82609a26b6190 [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
18K8S_CLOUD_NAME="k8s-cloud"
beierlm3749e312020-07-02 14:21:09 -040019KUBECTL="microk8s.kubectl"
David Garcia69388c22020-05-07 12:14:19 +020020IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050021PATH=/snap/bin:${PATH}
22
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010023function check_arguments(){
24 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020025 case $1 in
26 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020027 --k8s) KUBECFG="$2" ;;
28 --vca) CONTROLLER="$2" ;;
29 --lxd) LXD_CLOUD="$2" ;;
30 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020031 --microstack) MICROSTACK=y ;;
David Garciacef05e92020-08-20 12:08:31 +020032 --ha) BUNDLE="cs:osm-ha" ;;
David Garcia69388c22020-05-07 12:14:19 +020033 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050034 --registry) REGISTRY_INFO="$2" ;;
David Garcia42375212020-04-27 19:07:49 +020035 esac
36 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010037 done
38
David Garcia42375212020-04-27 19:07:49 +020039 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010040}
beierlma4a37f72020-06-26 12:55:01 -040041
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010042function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040043 if [ ! -v KUBECFG ]; then
44 sudo snap install microk8s --classic
45 sudo usermod -a -G microk8s `whoami`
46 mkdir -p ~/.kube
47 sudo chown -f -R `whoami` ~/.kube
48 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050049 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlma4a37f72020-06-26 12:55:01 -040050 else
51 KUBECTL="kubectl"
52 sudo snap install kubectl --classic
53 export KUBECONFIG=${KUBECFG}
54 KUBEGRP=$(id -g -n)
55 fi
56 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010057}
58
59function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020060 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040061 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
62
63 if [ -v BOOTSTRAP_NEEDED ]; then
64 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
65 if [ $CONTROLLER_PRESENT -ge 1 ]; then
66 cat << EOF
67Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
68You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
69using this command:
70
71 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
72
73Please retry the installation once this conflict has been resolved.
74EOF
75 exit 1
76 fi
beierlm9afb0ef2020-10-16 12:53:51 -040077 else
78 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
79 if [ $CONTROLLER_PRESENT -le 0 ]; then
80 cat << EOF
81Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
82that exists, or remove the --vca ${CONTROLLER_NAME} option.
83
84Please retry the installation with one of the solutions applied.
85EOF
86 exit 1
87 fi
beierlma4a37f72020-06-26 12:55:01 -040088 fi
David Garcia42375212020-04-27 19:07:49 +020089
90 if [ -v KUBECFG ]; then
91 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -040092 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
93 --config controller-service-type=loadbalancer \
94 --agent-version=2.8.1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010095 else
beierlma4a37f72020-06-26 12:55:01 -040096 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -040097 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -040098 sg ${KUBEGRP} -c "microk8s.enable storage dns"
99 TIME_TO_WAIT=30
100 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200101 while true
102 do
beierlma4a37f72020-06-26 12:55:01 -0400103 now="$(date -u +%s)"
104 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
105 echo "Microk8s storage failed to enable"
106 sg ${KUBEGRP} -c "microk8s.status"
107 exit 1
108 fi
109 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
110 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200111 break
112 fi
113 sleep 1
114 done
David Garcia42375212020-04-27 19:07:49 +0200115
beierlma4a37f72020-06-26 12:55:01 -0400116 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400117 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
118 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=2.8.1" \
119 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100120 fi
121
David Garcia42375212020-04-27 19:07:49 +0200122 if [ -v LXD_CLOUD ]; then
123 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100124 echo "The installer needs the LXD server certificate if the LXD is external"
125 exit 1
126 fi
127 else
128 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200129 LXD_CLOUD=~/.osm/lxd-cloud.yaml
130 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
131 # Apply sysctl production values for optimal performance
132 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
133 sudo sysctl --system
134 # Install LXD snap
135 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
136 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200137 # Configure LXD
138 sudo usermod -a -G lxd `whoami`
139 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"
140 sg lxd -c "lxd waitready"
141 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
142 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200143 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100144
David Garcia42375212020-04-27 19:07:49 +0200145 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100146clouds:
147 lxd-cloud:
148 type: lxd
149 auth-types: [certificate]
150 endpoint: "https://$LXDENDPOINT:8443"
151 config:
152 ssl-hostname-verification: false
153EOF
David Garcia42375212020-04-27 19:07:49 +0200154 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"
155 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
156 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
157 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100158
David Garcia42375212020-04-27 19:07:49 +0200159 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100160credentials:
161 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200162 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100163 auth-type: certificate
164 server-cert: |
165$server_cert
166 client-cert: |
167$client_cert
168 client-key: |
169$client_key
170EOF
David Garcia42375212020-04-27 19:07:49 +0200171 lxc config trust add local: ~/.osm/client.crt
172 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100173
David Garcia42375212020-04-27 19:07:49 +0200174 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
175 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
176 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400177 juju controller-config features=[k8s-operators]
178}
179
180function wait_for_port(){
181 SERVICE=$1
182 INDEX=$2
183 TIME_TO_WAIT=30
184 start_time="$(date -u +%s)"
185 while true
186 do
187 now="$(date -u +%s)"
188 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
189 echo "Failed to expose external ${SERVICE} interface port"
190 exit 1
191 fi
192
beierlm9afb0ef2020-10-16 12:53:51 -0400193 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 -0400194 break
195 fi
196 sleep 1
197 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100198}
199
200function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500201 if [ -v REGISTRY_INFO ] ; then
202 registry_parts=(${REGISTRY_INFO//@/ })
203 if [ ${#registry_parts[@]} -eq 1 ] ; then
204 # No credentials supplied
205 REGISTRY_USERNAME=""
206 REGISTRY_PASSWORD=""
207 REGISTRY_URL=${registry_parts[0]}
208 else
209 credentials=${registry_parts[0]}
210 credential_parts=(${credentials//:/ })
211 REGISTRY_USERNAME=${credential_parts[0]}
212 REGISTRY_PASSWORD=${credential_parts[1]}
213 REGISTRY_URL=${registry_parts[1]}
214 fi
215 # Ensure the URL ends with a /
216 case $REGISTRY_URL in
217 */) ;;
218 *) REGISTRY_URL=${REGISTRY_URL}/
219 esac
220 fi
221
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100222 create_overlay
223 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200224 if [ -v KUBECFG ]; then
225 juju add-model osm $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100226 else
beierlma4a37f72020-06-26 12:55:01 -0400227 sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100228 fi
229 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400230 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500231 if [ -v REGISTRY_URL ]; then
232 [ ! -v TAG ] && TAG='latest'
233 fi
beierlma4a37f72020-06-26 12:55:01 -0400234 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500235
David Garcia42375212020-04-27 19:07:49 +0200236 if [ -v BUNDLE ]; then
beierlma4a37f72020-06-26 12:55:01 -0400237 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100238 else
David Garciacef05e92020-08-20 12:08:31 +0200239 juju deploy cs:osm --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100240 fi
beierlma4a37f72020-06-26 12:55:01 -0400241
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100242 echo "Waiting for deployment to finish..."
beierlma4a37f72020-06-26 12:55:01 -0400243 check_osm_deployed
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100244 echo "OSM with charms deployed"
beierlma4a37f72020-06-26 12:55:01 -0400245 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400246 API_SERVER=${DEFAULT_IP}
247 else
248 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
249 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
250 url="$(echo ${API_SERVER/$proto/})"
251 user="$(echo $url | grep @ | cut -d@ -f1)"
252 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
253 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
254 fi
255
David Garciade5fc1d2020-09-02 11:40:12 +0200256 # Expose OSM services
beierlm9afb0ef2020-10-16 12:53:51 -0400257 # Expose Grafana
258 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
259 juju expose grafana-k8s
260 wait_for_port grafana-k8s 0
261
David Garciade5fc1d2020-09-02 11:40:12 +0200262 # Expose NBI
beierlma4a37f72020-06-26 12:55:01 -0400263 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
264 juju expose nbi-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400265 wait_for_port nbi-k8s 1
beierlma4a37f72020-06-26 12:55:01 -0400266
David Garciade5fc1d2020-09-02 11:40:12 +0200267 # Expose NG UI
beierlma4a37f72020-06-26 12:55:01 -0400268 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
269 juju expose ng-ui
beierlm9afb0ef2020-10-16 12:53:51 -0400270 wait_for_port ng-ui 2
271
272 # Expose Prometheus
273 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
274 juju expose prometheus-k8s
275 wait_for_port prometheus-k8s 3
beierlma4a37f72020-06-26 12:55:01 -0400276
David Garciade5fc1d2020-09-02 11:40:12 +0200277 # Expose UI
beierlma4a37f72020-06-26 12:55:01 -0400278 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100279 juju expose ui-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400280 wait_for_port ui-k8s 4
David Garciade5fc1d2020-09-02 11:40:12 +0200281
282 # Apply annotations
beierlm9afb0ef2020-10-16 12:53:51 -0400283 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s"
284 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s"
285 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui"
286 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s"
287}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100288
289function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400290 TIME_TO_WAIT=600
291 start_time="$(date -u +%s)"
beierlm7e54dfc2020-09-24 15:27:53 -0400292 total_service_count=15
293 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100294 while true
295 do
beierlma4a37f72020-06-26 12:55:01 -0400296 service_count=$(juju status | grep kubernetes | grep active | wc -l)
297 echo "$service_count / $total_service_count services active"
298 if [ $service_count -eq $total_service_count ]; then
299 break
300 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400301 if [ $service_count -ne $previous_count ]; then
302 previous_count=$service_count
303 start_time="$(date -u +%s)"
304 fi
beierlma4a37f72020-06-26 12:55:01 -0400305 now="$(date -u +%s)"
306 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
307 echo "Timed out waiting for OSM services to become ready"
308 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100309 fi
310 sleep 10
311 done
312}
313
314function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200315 sudo snap install jq
316 sudo apt install python3-pip -y
317 python3 -m pip install yq
318 PATH=$PATH:$HOME/.local/bin # make yq command available
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100319 local HOME=/home/$USER
David Garcia42375212020-04-27 19:07:49 +0200320 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
321 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 -0400322 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)
323 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 +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
beierlm3749e312020-07-02 14:21:09 -0400327 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 +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:
335 lcm-k8s:
336 options:
337 vca_user: $vca_user
338 vca_password: $vca_password
339 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
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100345 mon-k8s:
346 options:
347 vca_user: $vca_user
348 vca_password: $vca_password
349 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(){
beierlmf2782c52020-11-05 17:04:05 -0500357 if [ ! -z "$REGISTRY_USERNAME" ] ; then
358 REGISTRY_CREDENTIALS=$(cat <<EOF
359
360 image_username: $REGISTRY_USERNAME
361 image_password: $REGISTRY_PASSWORD
362EOF
363 );
364fi
365
David Garcia69388c22020-05-07 12:14:19 +0200366 cat << EOF > /tmp/images-overlay.yaml
367applications:
368 lcm-k8s:
369 options:
beierlmf2782c52020-11-05 17:04:05 -0500370 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200371 mon-k8s:
372 options:
beierlmf2782c52020-11-05 17:04:05 -0500373 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200374 ro-k8s:
375 options:
beierlmf2782c52020-11-05 17:04:05 -0500376 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200377 nbi-k8s:
378 options:
beierlmf2782c52020-11-05 17:04:05 -0500379 image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200380 pol-k8s:
381 options:
beierlmf2782c52020-11-05 17:04:05 -0500382 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200383 ui-k8s:
384 options:
beierlmf2782c52020-11-05 17:04:05 -0500385 image: ${REGISTRY_URL}opensourcemano/light-ui:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400386 pla:
387 options:
beierlmf2782c52020-11-05 17:04:05 -0500388 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400389 ng-ui:
390 options:
beierlmf2782c52020-11-05 17:04:05 -0500391 image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
David Garcia009a5d62020-08-27 16:53:44 +0200392 keystone:
393 options:
beierlmf2782c52020-11-05 17:04:05 -0500394 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200395EOF
396 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
397}
398
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100399function install_osmclient() {
400 sudo snap install osmclient
401 sudo snap alias osmclient.osm osm
402}
403
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100404
405function install_microstack() {
406 sudo snap install microstack --classic --beta
407 sudo microstack.init --auto
408 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
409 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200410 --public \
411 --disk-format qcow2 \
412 --container-format bare \
413 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
414 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100415 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
416 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200417 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100418 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200419 --user admin \
420 --password keystone \
421 --auth_url http://10.20.20.1:5000/v3 \
422 --tenant admin \
423 --account_type openstack \
424 --config='{security_groups: default,
425 keypair: microstack,
426 project_name: admin,
427 user_domain_name: default,
428 region_name: microstack,
429 insecure: True,
430 availability_zone: nova,
431 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100432}
433
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200434DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100435DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
436
437check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200438mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100439install_snaps
440bootstrap_k8s_lxd
441deploy_charmed_osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100442install_osmclient
David Garcia42375212020-04-27 19:07:49 +0200443if [ -v MICROSTACK ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100444 install_microstack
445fi
beierlma4a37f72020-06-26 12:55:01 -0400446
beierlm7e54dfc2020-09-24 15:27:53 -0400447OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
448
beierlma4a37f72020-06-26 12:55:01 -0400449echo "Your installation is now complete, follow these steps for configuring the osmclient:"
450echo
451echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
452echo
beierlm7e54dfc2020-09-24 15:27:53 -0400453echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
beierlma4a37f72020-06-26 12:55:01 -0400454echo
455echo "2. Add the previous command to your .bashrc for other Shell sessions"
456echo
beierlm7e54dfc2020-09-24 15:27:53 -0400457echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
beierlma4a37f72020-06-26 12:55:01 -0400458echo
459echo "DONE"