blob: 7d03fc77f8b9a881b2c56779c955287f835e986b [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 Garcia7406dee2020-10-19 15:42:42 +020018JUJU_AGENT_VERSION=2.8.6
David Garcia42375212020-04-27 19:07:49 +020019K8S_CLOUD_NAME="k8s-cloud"
beierlmdfd42882020-07-02 14:21:09 -040020KUBECTL="microk8s.kubectl"
David Garcia69388c22020-05-07 12:14:19 +020021IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010022function check_arguments(){
23 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020024 case $1 in
25 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020026 --k8s) KUBECFG="$2" ;;
27 --vca) CONTROLLER="$2" ;;
28 --lxd) LXD_CLOUD="$2" ;;
29 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020030 --microstack) MICROSTACK=y ;;
beierlm7e54dfc2020-09-24 15:27:53 -040031 --ha) BUNDLE="cs:osm-ha-39" ;;
David Garcia69388c22020-05-07 12:14:19 +020032 --tag) TAG="$2" ;;
David Garcia42375212020-04-27 19:07:49 +020033 esac
34 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010035 done
36
David Garcia42375212020-04-27 19:07:49 +020037 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010038}
beierlm838e3fd2020-07-28 09:21:07 -040039
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010040function install_snaps(){
beierlm838e3fd2020-07-28 09:21:07 -040041 if [ ! -v KUBECFG ]; then
42 sudo snap install microk8s --classic
43 sudo usermod -a -G microk8s `whoami`
44 mkdir -p ~/.kube
45 sudo chown -f -R `whoami` ~/.kube
46 KUBEGRP="microk8s"
beierlmc5233962020-10-16 12:53:51 -040047 microk8s status --wait-ready
beierlm838e3fd2020-07-28 09:21:07 -040048 else
49 KUBECTL="kubectl"
50 sudo snap install kubectl --classic
51 export KUBECONFIG=${KUBECFG}
52 KUBEGRP=$(id -g -n)
53 fi
Dominik Fleischmann71997c12020-06-30 14:25:19 +020054 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010055}
56
57function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020058 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlm9425dd22020-07-16 16:57:09 -040059 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
60
61 if [ -v BOOTSTRAP_NEEDED ]; then
62 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
63 if [ $CONTROLLER_PRESENT -ge 1 ]; then
64 cat << EOF
65Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
66You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
67using this command:
68
69 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
70
71Please retry the installation once this conflict has been resolved.
72EOF
73 exit 1
74 fi
beierlmc5233962020-10-16 12:53:51 -040075 else
76 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
77 if [ $CONTROLLER_PRESENT -le 0 ]; then
78 cat << EOF
79Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
80that exists, or remove the --vca ${CONTROLLER_NAME} option.
81
82Please retry the installation with one of the solutions applied.
83EOF
84 exit 1
85 fi
beierlm9425dd22020-07-16 16:57:09 -040086 fi
David Garcia42375212020-04-27 19:07:49 +020087
88 if [ -v KUBECFG ]; then
89 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm62e60442020-09-15 16:00:34 -040090 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
91 --config controller-service-type=loadbalancer \
David Garcia7406dee2020-10-19 15:42:42 +020092 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010093 else
beierlm838e3fd2020-07-28 09:21:07 -040094 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlmc5233962020-10-16 12:53:51 -040095 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlm838e3fd2020-07-28 09:21:07 -040096 sg ${KUBEGRP} -c "microk8s.enable storage dns"
beierlm9425dd22020-07-16 16:57:09 -040097 TIME_TO_WAIT=30
98 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +020099 while true
100 do
beierlm9425dd22020-07-16 16:57:09 -0400101 now="$(date -u +%s)"
102 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
103 echo "Microk8s storage failed to enable"
beierlm838e3fd2020-07-28 09:21:07 -0400104 sg ${KUBEGRP} -c "microk8s.status"
beierlm9425dd22020-07-16 16:57:09 -0400105 exit 1
106 fi
calvinosanc1698b5b32020-08-21 12:12:52 +0200107 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
108 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200109 break
110 fi
111 sleep 1
112 done
David Garcia42375212020-04-27 19:07:49 +0200113
beierlm838e3fd2020-07-28 09:21:07 -0400114 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm62e60442020-09-15 16:00:34 -0400115 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garcia7406dee2020-10-19 15:42:42 +0200116 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm62e60442020-09-15 16:00:34 -0400117 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100118 fi
119
David Garcia42375212020-04-27 19:07:49 +0200120 if [ -v LXD_CLOUD ]; then
121 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100122 echo "The installer needs the LXD server certificate if the LXD is external"
123 exit 1
124 fi
125 else
126 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200127 LXD_CLOUD=~/.osm/lxd-cloud.yaml
128 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
129 # Apply sysctl production values for optimal performance
130 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
131 sudo sysctl --system
132 # Install LXD snap
133 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
134 sudo snap install lxd
135 sudo apt-get install zfsutils-linux -y
136 # Configure LXD
137 sudo usermod -a -G lxd `whoami`
138 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"
139 sg lxd -c "lxd waitready"
140 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
141 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200142 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100143
David Garcia42375212020-04-27 19:07:49 +0200144 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100145clouds:
146 lxd-cloud:
147 type: lxd
148 auth-types: [certificate]
149 endpoint: "https://$LXDENDPOINT:8443"
150 config:
151 ssl-hostname-verification: false
152EOF
David Garcia42375212020-04-27 19:07:49 +0200153 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"
154 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
155 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
156 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100157
David Garcia42375212020-04-27 19:07:49 +0200158 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100159credentials:
160 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200161 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100162 auth-type: certificate
163 server-cert: |
164$server_cert
165 client-cert: |
166$client_cert
167 client-key: |
168$client_key
169EOF
David Garcia42375212020-04-27 19:07:49 +0200170 lxc config trust add local: ~/.osm/client.crt
171 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100172
David Garcia42375212020-04-27 19:07:49 +0200173 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
174 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
175 sg lxd -c "lxd waitready"
Dominik Fleischmann71997c12020-06-30 14:25:19 +0200176 juju controller-config features=[k8s-operators]
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100177}
178
beierlm838e3fd2020-07-28 09:21:07 -0400179function wait_for_port(){
180 SERVICE=$1
181 INDEX=$2
182 TIME_TO_WAIT=30
183 start_time="$(date -u +%s)"
184 while true
185 do
186 now="$(date -u +%s)"
187 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
188 echo "Failed to expose external ${SERVICE} interface port"
189 exit 1
190 fi
191
beierlmc5233962020-10-16 12:53:51 -0400192 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
beierlm838e3fd2020-07-28 09:21:07 -0400193 break
194 fi
195 sleep 1
196 done
197}
198
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100199function deploy_charmed_osm(){
200 create_overlay
201 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200202 if [ -v KUBECFG ]; then
203 juju add-model osm $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100204 else
beierlm838e3fd2020-07-28 09:21:07 -0400205 sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100206 fi
207 echo "Deploying OSM with charms"
beierlmb5332cf2020-07-08 11:43:59 -0400208 images_overlay=""
209 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
David Garcia42375212020-04-27 19:07:49 +0200210 if [ -v BUNDLE ]; then
beierlmb5332cf2020-07-08 11:43:59 -0400211 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100212 else
beierlm7e54dfc2020-09-24 15:27:53 -0400213 juju deploy cs:osm-49 --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100214 fi
beierlm51b71282020-08-14 09:26:27 -0400215
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100216 echo "Waiting for deployment to finish..."
beierlm51b71282020-08-14 09:26:27 -0400217 check_osm_deployed
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100218 echo "OSM with charms deployed"
beierlm838e3fd2020-07-28 09:21:07 -0400219 if [ ! -v KUBECFG ]; then
beierlm838e3fd2020-07-28 09:21:07 -0400220 API_SERVER=${DEFAULT_IP}
221 else
222 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
223 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
224 url="$(echo ${API_SERVER/$proto/})"
225 user="$(echo $url | grep @ | cut -d@ -f1)"
226 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
227 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
228 fi
229
beierlmc5233962020-10-16 12:53:51 -0400230 # Expose OSM services
231 # Expose Grafana
232 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
233 juju expose grafana-k8s
234 wait_for_port grafana-k8s 0
235
236 # Expose NBI
beierlm838e3fd2020-07-28 09:21:07 -0400237 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
238 juju expose nbi-k8s
beierlmc5233962020-10-16 12:53:51 -0400239 wait_for_port nbi-k8s 1
beierlm838e3fd2020-07-28 09:21:07 -0400240
beierlmc5233962020-10-16 12:53:51 -0400241 # Expose NG UI
beierlm51b71282020-08-14 09:26:27 -0400242 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
beierlm838e3fd2020-07-28 09:21:07 -0400243 juju expose ng-ui
beierlmc5233962020-10-16 12:53:51 -0400244 wait_for_port ng-ui 2
beierlm838e3fd2020-07-28 09:21:07 -0400245
beierlmc5233962020-10-16 12:53:51 -0400246 # Expose Prometheus
247 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
248 juju expose prometheus-k8s
249 wait_for_port prometheus-k8s 3
beierlm838e3fd2020-07-28 09:21:07 -0400250
beierlmc5233962020-10-16 12:53:51 -0400251 # Expose UI
beierlm838e3fd2020-07-28 09:21:07 -0400252 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100253 juju expose ui-k8s
beierlmc5233962020-10-16 12:53:51 -0400254 wait_for_port ui-k8s 4
beierlm838e3fd2020-07-28 09:21:07 -0400255
beierlmc5233962020-10-16 12:53:51 -0400256 # Apply annotations
257 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s"
258 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s"
259 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui"
260 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100261}
262
263function check_osm_deployed() {
beierlm51b71282020-08-14 09:26:27 -0400264 TIME_TO_WAIT=600
beierlm838e3fd2020-07-28 09:21:07 -0400265 start_time="$(date -u +%s)"
beierlm7e54dfc2020-09-24 15:27:53 -0400266 total_service_count=15
267 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100268 while true
269 do
beierlm51b71282020-08-14 09:26:27 -0400270 service_count=$(juju status | grep kubernetes | grep active | wc -l)
271 echo "$service_count / $total_service_count services active"
272 if [ $service_count -eq $total_service_count ]; then
273 break
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100274 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400275 if [ $service_count -ne $previous_count ]; then
276 previous_count=$service_count
277 start_time="$(date -u +%s)"
278 fi
beierlm838e3fd2020-07-28 09:21:07 -0400279 now="$(date -u +%s)"
280 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
beierlm51b71282020-08-14 09:26:27 -0400281 echo "Timed out waiting for OSM services to become ready"
beierlm838e3fd2020-07-28 09:21:07 -0400282 exit 1
283 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100284 sleep 10
285 done
286}
287
288function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200289 sudo snap install jq
290 sudo apt install python3-pip -y
291 python3 -m pip install yq
292 PATH=$PATH:$HOME/.local/bin # make yq command available
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100293 local HOME=/home/$USER
David Garcia42375212020-04-27 19:07:49 +0200294 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
295 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
beierlmdfd42882020-07-02 14:21:09 -0400296 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)
297 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 +0100298 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
299 local vca_cloud="lxd-cloud"
300 # Get the VCA Certificate
beierlmdfd42882020-07-02 14:21:09 -0400301 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 +0100302
303 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200304 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100305
306 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200307 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100308applications:
309 lcm-k8s:
310 options:
311 vca_user: $vca_user
312 vca_password: $vca_password
313 vca_host: $vca_host
314 vca_port: $vca_port
315 vca_pubkey: $vca_pubkey
316 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100317 vca_cloud: $vca_cloud
Dominik Fleischmann71997c12020-06-30 14:25:19 +0200318 vca_k8s_cloud: $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100319 mon-k8s:
320 options:
321 vca_user: $vca_user
322 vca_password: $vca_password
323 vca_host: $vca_host
324 vca_cacert: $vca_cacert
325EOF
David Garcia42375212020-04-27 19:07:49 +0200326 mv /tmp/vca-overlay.yaml ~/.osm/
327 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100328}
329
David Garcia69388c22020-05-07 12:14:19 +0200330function generate_images_overlay(){
331 cat << EOF > /tmp/images-overlay.yaml
332applications:
333 lcm-k8s:
334 options:
335 image: opensourcemano/lcm:$TAG
336 mon-k8s:
337 options:
338 image: opensourcemano/mon:$TAG
339 ro-k8s:
340 options:
341 image: opensourcemano/ro:$TAG
342 nbi-k8s:
343 options:
344 image: opensourcemano/nbi:$TAG
345 pol-k8s:
346 options:
347 image: opensourcemano/pol:$TAG
348 ui-k8s:
349 options:
350 image: opensourcemano/light-ui:$TAG
David Garcia5863d3e2020-07-09 13:14:13 +0200351 pla:
352 options:
353 image: opensourcemano/pla:$TAG
David Garciafa55bd72020-07-07 11:14:19 +0200354 ng-ui:
355 options:
356 image: opensourcemano/ng-ui:$TAG
David Garcia69388c22020-05-07 12:14:19 +0200357
358EOF
359 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
360}
361
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100362function install_osmclient() {
363 sudo snap install osmclient
364 sudo snap alias osmclient.osm osm
365}
366
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100367
368function install_microstack() {
369 sudo snap install microstack --classic --beta
370 sudo microstack.init --auto
371 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
372 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200373 --public \
374 --disk-format qcow2 \
375 --container-format bare \
376 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
377 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100378 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
379 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200380 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100381 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200382 --user admin \
383 --password keystone \
384 --auth_url http://10.20.20.1:5000/v3 \
385 --tenant admin \
386 --account_type openstack \
387 --config='{security_groups: default,
388 keypair: microstack,
389 project_name: admin,
390 user_domain_name: default,
391 region_name: microstack,
392 insecure: True,
393 availability_zone: nova,
394 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100395}
396
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200397DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100398DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
399
400check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200401mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100402install_snaps
403bootstrap_k8s_lxd
404deploy_charmed_osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100405install_osmclient
David Garcia42375212020-04-27 19:07:49 +0200406if [ -v MICROSTACK ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100407 install_microstack
408fi
beierlm9425dd22020-07-16 16:57:09 -0400409
beierlm7e54dfc2020-09-24 15:27:53 -0400410OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
411
beierlm9425dd22020-07-16 16:57:09 -0400412echo "Your installation is now complete, follow these steps for configuring the osmclient:"
413echo
beierlm838e3fd2020-07-28 09:21:07 -0400414echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
beierlm9425dd22020-07-16 16:57:09 -0400415echo
beierlm7e54dfc2020-09-24 15:27:53 -0400416echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
beierlm9425dd22020-07-16 16:57:09 -0400417echo
beierlm838e3fd2020-07-28 09:21:07 -0400418echo "2. Add the previous command to your .bashrc for other Shell sessions"
beierlm9425dd22020-07-16 16:57:09 -0400419echo
beierlm7e54dfc2020-09-24 15:27:53 -0400420echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
beierlm9425dd22020-07-16 16:57:09 -0400421echo
422echo "DONE"