blob: 4d04a913ceb3710ba9c1162deb14f2dd9ef13482 [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
David Garciaef349d92020-12-10 21:16:12 +010025MODEL_NAME=osm
26
David Garciaab11f842020-12-16 17:25:15 +010027OSM_BUNDLE=cs:osm-54
28OSM_HA_BUNDLE=cs:osm-ha-40
29
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010030function check_arguments(){
31 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020032 case $1 in
33 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020034 --k8s) KUBECFG="$2" ;;
35 --vca) CONTROLLER="$2" ;;
36 --lxd) LXD_CLOUD="$2" ;;
37 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020038 --microstack) MICROSTACK=y ;;
David Garciaab11f842020-12-16 17:25:15 +010039 --ha) BUNDLE=$OSM_HA_BUNDLE ;;
David Garcia69388c22020-05-07 12:14:19 +020040 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050041 --registry) REGISTRY_INFO="$2" ;;
David Garcia42375212020-04-27 19:07:49 +020042 esac
43 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010044 done
45
David Garcia42375212020-04-27 19:07:49 +020046 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010047}
beierlma4a37f72020-06-26 12:55:01 -040048
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010049function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040050 if [ ! -v KUBECFG ]; then
beierlm481ae7d2020-12-14 09:59:19 -050051 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
beierlma4a37f72020-06-26 12:55:01 -040052 sudo usermod -a -G microk8s `whoami`
53 mkdir -p ~/.kube
54 sudo chown -f -R `whoami` ~/.kube
55 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050056 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlmdf6de3d2020-12-16 08:46:40 -050057 KUBECONFIG=~/.osm/microk8s-config.yaml
58 sg ${KUBEGRP} -c "microk8s config" > ${KUBECONFIG}
beierlma4a37f72020-06-26 12:55:01 -040059 else
60 KUBECTL="kubectl"
61 sudo snap install kubectl --classic
62 export KUBECONFIG=${KUBECFG}
63 KUBEGRP=$(id -g -n)
64 fi
65 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010066}
67
68function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020069 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040070 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
71
72 if [ -v BOOTSTRAP_NEEDED ]; then
73 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
74 if [ $CONTROLLER_PRESENT -ge 1 ]; then
75 cat << EOF
76Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
77You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
78using this command:
79
80 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
81
82Please retry the installation once this conflict has been resolved.
83EOF
84 exit 1
85 fi
beierlm9afb0ef2020-10-16 12:53:51 -040086 else
87 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
88 if [ $CONTROLLER_PRESENT -le 0 ]; then
89 cat << EOF
90Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
91that exists, or remove the --vca ${CONTROLLER_NAME} option.
92
93Please retry the installation with one of the solutions applied.
94EOF
95 exit 1
96 fi
beierlma4a37f72020-06-26 12:55:01 -040097 fi
David Garcia42375212020-04-27 19:07:49 +020098
99 if [ -v KUBECFG ]; then
100 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400101 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
102 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +0200103 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100104 else
beierlma4a37f72020-06-26 12:55:01 -0400105 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -0400106 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -0400107 sg ${KUBEGRP} -c "microk8s.enable storage dns"
108 TIME_TO_WAIT=30
109 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200110 while true
111 do
beierlma4a37f72020-06-26 12:55:01 -0400112 now="$(date -u +%s)"
113 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
114 echo "Microk8s storage failed to enable"
115 sg ${KUBEGRP} -c "microk8s.status"
116 exit 1
117 fi
118 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
119 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200120 break
121 fi
122 sleep 1
123 done
David Garcia42375212020-04-27 19:07:49 +0200124
beierlma4a37f72020-06-26 12:55:01 -0400125 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400126 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200127 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400128 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100129 fi
130
David Garcia42375212020-04-27 19:07:49 +0200131 if [ -v LXD_CLOUD ]; then
132 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100133 echo "The installer needs the LXD server certificate if the LXD is external"
134 exit 1
135 fi
136 else
137 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200138 LXD_CLOUD=~/.osm/lxd-cloud.yaml
139 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
140 # Apply sysctl production values for optimal performance
141 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
142 sudo sysctl --system
143 # Install LXD snap
144 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
145 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200146 # Configure LXD
147 sudo usermod -a -G lxd `whoami`
148 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"
149 sg lxd -c "lxd waitready"
150 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
151 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200152 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100153
David Garcia42375212020-04-27 19:07:49 +0200154 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100155clouds:
156 lxd-cloud:
157 type: lxd
158 auth-types: [certificate]
159 endpoint: "https://$LXDENDPOINT:8443"
160 config:
161 ssl-hostname-verification: false
162EOF
David Garcia42375212020-04-27 19:07:49 +0200163 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"
164 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
165 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
166 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100167
David Garcia42375212020-04-27 19:07:49 +0200168 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100169credentials:
170 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200171 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100172 auth-type: certificate
173 server-cert: |
174$server_cert
175 client-cert: |
176$client_cert
177 client-key: |
178$client_key
179EOF
David Garcia42375212020-04-27 19:07:49 +0200180 lxc config trust add local: ~/.osm/client.crt
181 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100182
David Garcia42375212020-04-27 19:07:49 +0200183 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
184 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
185 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400186 juju controller-config features=[k8s-operators]
187}
188
189function wait_for_port(){
190 SERVICE=$1
191 INDEX=$2
192 TIME_TO_WAIT=30
193 start_time="$(date -u +%s)"
194 while true
195 do
196 now="$(date -u +%s)"
197 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
198 echo "Failed to expose external ${SERVICE} interface port"
199 exit 1
200 fi
201
beierlm9afb0ef2020-10-16 12:53:51 -0400202 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 -0400203 break
204 fi
205 sleep 1
206 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100207}
208
209function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500210 if [ -v REGISTRY_INFO ] ; then
211 registry_parts=(${REGISTRY_INFO//@/ })
212 if [ ${#registry_parts[@]} -eq 1 ] ; then
213 # No credentials supplied
214 REGISTRY_USERNAME=""
215 REGISTRY_PASSWORD=""
216 REGISTRY_URL=${registry_parts[0]}
217 else
218 credentials=${registry_parts[0]}
219 credential_parts=(${credentials//:/ })
220 REGISTRY_USERNAME=${credential_parts[0]}
221 REGISTRY_PASSWORD=${credential_parts[1]}
222 REGISTRY_URL=${registry_parts[1]}
223 fi
224 # Ensure the URL ends with a /
225 case $REGISTRY_URL in
226 */) ;;
227 *) REGISTRY_URL=${REGISTRY_URL}/
228 esac
229 fi
230
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100231 create_overlay
232 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200233 if [ -v KUBECFG ]; then
David Garciaef349d92020-12-10 21:16:12 +0100234 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100235 else
David Garciaef349d92020-12-10 21:16:12 +0100236 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100237 fi
238 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400239 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500240 if [ -v REGISTRY_URL ]; then
241 [ ! -v TAG ] && TAG='latest'
242 fi
beierlma4a37f72020-06-26 12:55:01 -0400243 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500244
David Garcia42375212020-04-27 19:07:49 +0200245 if [ -v BUNDLE ]; then
David Garciaef349d92020-12-10 21:16:12 +0100246 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100247 else
David Garciaab11f842020-12-16 17:25:15 +0100248 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100249 fi
beierlma4a37f72020-06-26 12:55:01 -0400250
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100251 echo "Waiting for deployment to finish..."
beierlma4a37f72020-06-26 12:55:01 -0400252 check_osm_deployed
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100253 echo "OSM with charms deployed"
beierlma4a37f72020-06-26 12:55:01 -0400254 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400255 API_SERVER=${DEFAULT_IP}
256 else
257 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
258 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
259 url="$(echo ${API_SERVER/$proto/})"
260 user="$(echo $url | grep @ | cut -d@ -f1)"
261 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
262 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
263 fi
264
David Garciade5fc1d2020-09-02 11:40:12 +0200265 # Expose OSM services
David Garciaef349d92020-12-10 21:16:12 +0100266 # Expose NBI
267 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.xip.io
268 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.xip.io
269
beierlm9afb0ef2020-10-16 12:53:51 -0400270 # Expose Grafana
David Garciaef349d92020-12-10 21:16:12 +0100271 juju config -m $MODEL_NAME grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
272 juju expose -m $MODEL_NAME grafana-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400273 wait_for_port grafana-k8s 0
274
beierlm9afb0ef2020-10-16 12:53:51 -0400275 # Expose Prometheus
David Garciaef349d92020-12-10 21:16:12 +0100276 juju config -m $MODEL_NAME prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
277 juju expose -m $MODEL_NAME prometheus-k8s
278 wait_for_port prometheus-k8s 1
beierlma4a37f72020-06-26 12:55:01 -0400279
David Garciade5fc1d2020-09-02 11:40:12 +0200280 # Apply annotations
beierlm9afb0ef2020-10-16 12:53:51 -0400281 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 -0400282}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100283
284function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400285 TIME_TO_WAIT=600
286 start_time="$(date -u +%s)"
David Garcia02a5eb92020-11-28 14:41:22 +0100287 total_service_count=14
beierlm7e54dfc2020-09-24 15:27:53 -0400288 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100289 while true
290 do
David Garciaef349d92020-12-10 21:16:12 +0100291 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
beierlma4a37f72020-06-26 12:55:01 -0400292 echo "$service_count / $total_service_count services active"
293 if [ $service_count -eq $total_service_count ]; then
294 break
295 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400296 if [ $service_count -ne $previous_count ]; then
297 previous_count=$service_count
298 start_time="$(date -u +%s)"
299 fi
beierlma4a37f72020-06-26 12:55:01 -0400300 now="$(date -u +%s)"
301 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
302 echo "Timed out waiting for OSM services to become ready"
303 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100304 fi
305 sleep 10
306 done
307}
308
309function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200310 sudo snap install jq
David Garciac8660ad2020-12-16 13:13:20 +0100311 sudo snap install yq
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100312 local HOME=/home/$USER
David Garciac8660ad2020-12-16 13:13:20 +0100313 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq r - controllers.$CONTROLLER_NAME.user)
314 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq r - controllers.$CONTROLLER_NAME.password)
315 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.api-endpoints[0] | cut -d ":" -f 1)
316 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.api-endpoints[0] | cut -d ":" -f 2)
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100317 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
318 local vca_cloud="lxd-cloud"
319 # Get the VCA Certificate
David Garciac8660ad2020-12-16 13:13:20 +0100320 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.ca-cert | base64 | tr -d \\n)
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100321
322 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200323 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100324
325 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200326 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100327applications:
328 lcm-k8s:
329 options:
330 vca_user: $vca_user
331 vca_password: $vca_password
332 vca_host: $vca_host
333 vca_port: $vca_port
334 vca_pubkey: $vca_pubkey
335 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100336 vca_cloud: $vca_cloud
beierlma4a37f72020-06-26 12:55:01 -0400337 vca_k8s_cloud: $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100338 mon-k8s:
339 options:
340 vca_user: $vca_user
341 vca_password: $vca_password
342 vca_host: $vca_host
343 vca_cacert: $vca_cacert
344EOF
David Garcia42375212020-04-27 19:07:49 +0200345 mv /tmp/vca-overlay.yaml ~/.osm/
346 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100347}
348
David Garcia69388c22020-05-07 12:14:19 +0200349function generate_images_overlay(){
David Garciaef349d92020-12-10 21:16:12 +0100350 cat << EOF > /tmp/nbi_registry.yaml
351registrypath: ${REGISTRY_URL}opensourcemano/nbi:$TAG
352EOF
353 cat << EOF > /tmp/ng_ui_registry.yaml
354registrypath: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG
355EOF
beierlmf2782c52020-11-05 17:04:05 -0500356 if [ ! -z "$REGISTRY_USERNAME" ] ; then
357 REGISTRY_CREDENTIALS=$(cat <<EOF
358
359 image_username: $REGISTRY_USERNAME
360 image_password: $REGISTRY_PASSWORD
361EOF
362 );
David Garciaef349d92020-12-10 21:16:12 +0100363 echo username: $REGISTRY_USERNAME >> /tmp/nbi_registry.yaml
364 echo password: $REGISTRY_PASSWORD >> /tmp/nbi_registry.yaml
365 echo username: $REGISTRY_USERNAME >> /tmp/ng_ui_registry.yaml
366 echo password: $REGISTRY_PASSWORD >> /tmp/ng_ui_registry.yaml
beierlmf2782c52020-11-05 17:04:05 -0500367fi
368
David Garcia69388c22020-05-07 12:14:19 +0200369 cat << EOF > /tmp/images-overlay.yaml
370applications:
371 lcm-k8s:
372 options:
beierlmf2782c52020-11-05 17:04:05 -0500373 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200374 mon-k8s:
375 options:
beierlmf2782c52020-11-05 17:04:05 -0500376 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200377 ro-k8s:
378 options:
beierlmf2782c52020-11-05 17:04:05 -0500379 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
David Garciaef349d92020-12-10 21:16:12 +0100380 nbi:
381 resources:
382 image: /tmp/nbi_registry.yaml
David Garcia69388c22020-05-07 12:14:19 +0200383 pol-k8s:
384 options:
beierlmf2782c52020-11-05 17:04:05 -0500385 image: ${REGISTRY_URL}opensourcemano/pol:$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:
David Garciaef349d92020-12-10 21:16:12 +0100390 resources:
391 image: /tmp/ng_ui_registry.yaml
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
beierlmdf6de3d2020-12-16 08:46:40 -0500404function add_local_k8scluster() {
405 osm --all-projects vim-create \
406 --name _system-osm-vim \
407 --account_type dummy \
408 --auth_url http://dummy \
409 --user osm --password osm --tenant osm \
410 --description "dummy" \
411 --config '{management_network_name: mgmt}'
412 tmpfile=$(mktemp --tmpdir=${HOME})
413 cp ${KUBECONFIG} ${tmpfile}
414 osm --all-projects k8scluster-add \
415 --creds ${tmpfile} \
416 --vim _system-osm-vim \
417 --k8s-nets '{"net1": null}' \
418 --version '1.19' \
419 --description "OSM Internal Cluster" \
420 _system-osm-k8s
421 rm -f ${tmpfile}
422}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100423
424function install_microstack() {
425 sudo snap install microstack --classic --beta
426 sudo microstack.init --auto
427 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
428 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200429 --public \
430 --disk-format qcow2 \
431 --container-format bare \
432 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
433 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100434 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
435 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
David Garciaef349d92020-12-10 21:16:12 +0100436 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100437 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200438 --user admin \
439 --password keystone \
440 --auth_url http://10.20.20.1:5000/v3 \
441 --tenant admin \
442 --account_type openstack \
443 --config='{security_groups: default,
444 keypair: microstack,
445 project_name: admin,
446 user_domain_name: default,
447 region_name: microstack,
448 insecure: True,
449 availability_zone: nova,
450 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100451}
452
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200453DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100454DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
455
456check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200457mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100458install_snaps
459bootstrap_k8s_lxd
460deploy_charmed_osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100461install_osmclient
beierlmdf6de3d2020-12-16 08:46:40 -0500462OSM_HOSTNAME=$(juju config nbi site_url | sed "s/http.*\?:\/\///"):443
463add_local_k8scluster
464
David Garcia42375212020-04-27 19:07:49 +0200465if [ -v MICROSTACK ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100466 install_microstack
467fi
beierlma4a37f72020-06-26 12:55:01 -0400468
beierlm7e54dfc2020-09-24 15:27:53 -0400469
beierlma4a37f72020-06-26 12:55:01 -0400470echo "Your installation is now complete, follow these steps for configuring the osmclient:"
471echo
472echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
473echo
beierlm7e54dfc2020-09-24 15:27:53 -0400474echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
beierlma4a37f72020-06-26 12:55:01 -0400475echo
476echo "2. Add the previous command to your .bashrc for other Shell sessions"
477echo
beierlm7e54dfc2020-09-24 15:27:53 -0400478echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
beierlma4a37f72020-06-26 12:55:01 -0400479echo
480echo "DONE"