blob: 85569a31aabfa67d8ab4fed059d838fd11a5f40d [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
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010027function check_arguments(){
28 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020029 case $1 in
30 --bundle) BUNDLE="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020031 --k8s) KUBECFG="$2" ;;
32 --vca) CONTROLLER="$2" ;;
33 --lxd) LXD_CLOUD="$2" ;;
34 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020035 --microstack) MICROSTACK=y ;;
David Garciacef05e92020-08-20 12:08:31 +020036 --ha) BUNDLE="cs:osm-ha" ;;
David Garcia69388c22020-05-07 12:14:19 +020037 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050038 --registry) REGISTRY_INFO="$2" ;;
David Garcia42375212020-04-27 19:07:49 +020039 esac
40 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010041 done
42
David Garcia42375212020-04-27 19:07:49 +020043 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010044}
beierlma4a37f72020-06-26 12:55:01 -040045
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010046function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040047 if [ ! -v KUBECFG ]; then
beierlm481ae7d2020-12-14 09:59:19 -050048 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
beierlma4a37f72020-06-26 12:55:01 -040049 sudo usermod -a -G microk8s `whoami`
50 mkdir -p ~/.kube
51 sudo chown -f -R `whoami` ~/.kube
52 KUBEGRP="microk8s"
beierlmf2782c52020-11-05 17:04:05 -050053 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlma4a37f72020-06-26 12:55:01 -040054 else
55 KUBECTL="kubectl"
56 sudo snap install kubectl --classic
57 export KUBECONFIG=${KUBECFG}
58 KUBEGRP=$(id -g -n)
59 fi
60 sudo snap install juju --classic --channel=2.8/stable
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010061}
62
63function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +020064 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -040065 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
66
67 if [ -v BOOTSTRAP_NEEDED ]; then
68 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
69 if [ $CONTROLLER_PRESENT -ge 1 ]; then
70 cat << EOF
71Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
72You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
73using this command:
74
75 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
76
77Please retry the installation once this conflict has been resolved.
78EOF
79 exit 1
80 fi
beierlm9afb0ef2020-10-16 12:53:51 -040081 else
82 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
83 if [ $CONTROLLER_PRESENT -le 0 ]; then
84 cat << EOF
85Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
86that exists, or remove the --vca ${CONTROLLER_NAME} option.
87
88Please retry the installation with one of the solutions applied.
89EOF
90 exit 1
91 fi
beierlma4a37f72020-06-26 12:55:01 -040092 fi
David Garcia42375212020-04-27 19:07:49 +020093
94 if [ -v KUBECFG ]; then
95 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -040096 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
97 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +020098 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010099 else
beierlma4a37f72020-06-26 12:55:01 -0400100 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -0400101 sg ${KUBEGRP} -c "microk8s.enable ingress"
beierlma4a37f72020-06-26 12:55:01 -0400102 sg ${KUBEGRP} -c "microk8s.enable storage dns"
103 TIME_TO_WAIT=30
104 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200105 while true
106 do
beierlma4a37f72020-06-26 12:55:01 -0400107 now="$(date -u +%s)"
108 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
109 echo "Microk8s storage failed to enable"
110 sg ${KUBEGRP} -c "microk8s.status"
111 exit 1
112 fi
113 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
114 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200115 break
116 fi
117 sleep 1
118 done
David Garcia42375212020-04-27 19:07:49 +0200119
beierlma4a37f72020-06-26 12:55:01 -0400120 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400121 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200122 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400123 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100124 fi
125
David Garcia42375212020-04-27 19:07:49 +0200126 if [ -v LXD_CLOUD ]; then
127 if [ ! -v LXD_CREDENTIALS ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100128 echo "The installer needs the LXD server certificate if the LXD is external"
129 exit 1
130 fi
131 else
132 LXDENDPOINT=$DEFAULT_IP
David Garcia42375212020-04-27 19:07:49 +0200133 LXD_CLOUD=~/.osm/lxd-cloud.yaml
134 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
135 # Apply sysctl production values for optimal performance
136 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
137 sudo sysctl --system
138 # Install LXD snap
139 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
140 sudo snap install lxd
David Garcia42375212020-04-27 19:07:49 +0200141 # Configure LXD
142 sudo usermod -a -G lxd `whoami`
143 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"
144 sg lxd -c "lxd waitready"
145 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
146 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
David Garciad00e49c2020-06-19 10:33:37 +0200147 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100148
David Garcia42375212020-04-27 19:07:49 +0200149 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100150clouds:
151 lxd-cloud:
152 type: lxd
153 auth-types: [certificate]
154 endpoint: "https://$LXDENDPOINT:8443"
155 config:
156 ssl-hostname-verification: false
157EOF
David Garcia42375212020-04-27 19:07:49 +0200158 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"
159 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
160 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
161 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100162
David Garcia42375212020-04-27 19:07:49 +0200163 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100164credentials:
165 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200166 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100167 auth-type: certificate
168 server-cert: |
169$server_cert
170 client-cert: |
171$client_cert
172 client-key: |
173$client_key
174EOF
David Garcia42375212020-04-27 19:07:49 +0200175 lxc config trust add local: ~/.osm/client.crt
176 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100177
David Garcia42375212020-04-27 19:07:49 +0200178 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
179 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
180 sg lxd -c "lxd waitready"
beierlma4a37f72020-06-26 12:55:01 -0400181 juju controller-config features=[k8s-operators]
182}
183
184function wait_for_port(){
185 SERVICE=$1
186 INDEX=$2
187 TIME_TO_WAIT=30
188 start_time="$(date -u +%s)"
189 while true
190 do
191 now="$(date -u +%s)"
192 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
193 echo "Failed to expose external ${SERVICE} interface port"
194 exit 1
195 fi
196
beierlm9afb0ef2020-10-16 12:53:51 -0400197 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 -0400198 break
199 fi
200 sleep 1
201 done
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100202}
203
204function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500205 if [ -v REGISTRY_INFO ] ; then
206 registry_parts=(${REGISTRY_INFO//@/ })
207 if [ ${#registry_parts[@]} -eq 1 ] ; then
208 # No credentials supplied
209 REGISTRY_USERNAME=""
210 REGISTRY_PASSWORD=""
211 REGISTRY_URL=${registry_parts[0]}
212 else
213 credentials=${registry_parts[0]}
214 credential_parts=(${credentials//:/ })
215 REGISTRY_USERNAME=${credential_parts[0]}
216 REGISTRY_PASSWORD=${credential_parts[1]}
217 REGISTRY_URL=${registry_parts[1]}
218 fi
219 # Ensure the URL ends with a /
220 case $REGISTRY_URL in
221 */) ;;
222 *) REGISTRY_URL=${REGISTRY_URL}/
223 esac
224 fi
225
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100226 create_overlay
227 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200228 if [ -v KUBECFG ]; then
David Garciaef349d92020-12-10 21:16:12 +0100229 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100230 else
David Garciaef349d92020-12-10 21:16:12 +0100231 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100232 fi
233 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400234 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500235 if [ -v REGISTRY_URL ]; then
236 [ ! -v TAG ] && TAG='latest'
237 fi
beierlma4a37f72020-06-26 12:55:01 -0400238 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500239
David Garcia42375212020-04-27 19:07:49 +0200240 if [ -v BUNDLE ]; then
David Garciaef349d92020-12-10 21:16:12 +0100241 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100242 else
David Garciaef349d92020-12-10 21:16:12 +0100243 juju deploy -m $MODEL_NAME cs:osm-53 --overlay ~/.osm/vca-overlay.yaml $images_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100244 fi
beierlma4a37f72020-06-26 12:55:01 -0400245
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100246 echo "Waiting for deployment to finish..."
beierlma4a37f72020-06-26 12:55:01 -0400247 check_osm_deployed
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100248 echo "OSM with charms deployed"
beierlma4a37f72020-06-26 12:55:01 -0400249 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400250 API_SERVER=${DEFAULT_IP}
251 else
252 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
253 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
254 url="$(echo ${API_SERVER/$proto/})"
255 user="$(echo $url | grep @ | cut -d@ -f1)"
256 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
257 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
258 fi
259
David Garciade5fc1d2020-09-02 11:40:12 +0200260 # Expose OSM services
David Garciaef349d92020-12-10 21:16:12 +0100261 # Expose NBI
262 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.xip.io
263 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.xip.io
264
beierlm9afb0ef2020-10-16 12:53:51 -0400265 # Expose Grafana
David Garciaef349d92020-12-10 21:16:12 +0100266 juju config -m $MODEL_NAME grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
267 juju expose -m $MODEL_NAME grafana-k8s
beierlm9afb0ef2020-10-16 12:53:51 -0400268 wait_for_port grafana-k8s 0
269
beierlm9afb0ef2020-10-16 12:53:51 -0400270 # Expose Prometheus
David Garciaef349d92020-12-10 21:16:12 +0100271 juju config -m $MODEL_NAME prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
272 juju expose -m $MODEL_NAME prometheus-k8s
273 wait_for_port prometheus-k8s 1
beierlma4a37f72020-06-26 12:55:01 -0400274
David Garciade5fc1d2020-09-02 11:40:12 +0200275 # Apply annotations
beierlm9afb0ef2020-10-16 12:53:51 -0400276 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 -0400277}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100278
279function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400280 TIME_TO_WAIT=600
281 start_time="$(date -u +%s)"
David Garcia02a5eb92020-11-28 14:41:22 +0100282 total_service_count=14
beierlm7e54dfc2020-09-24 15:27:53 -0400283 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100284 while true
285 do
David Garciaef349d92020-12-10 21:16:12 +0100286 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
beierlma4a37f72020-06-26 12:55:01 -0400287 echo "$service_count / $total_service_count services active"
288 if [ $service_count -eq $total_service_count ]; then
289 break
290 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400291 if [ $service_count -ne $previous_count ]; then
292 previous_count=$service_count
293 start_time="$(date -u +%s)"
294 fi
beierlma4a37f72020-06-26 12:55:01 -0400295 now="$(date -u +%s)"
296 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
297 echo "Timed out waiting for OSM services to become ready"
298 exit 1
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100299 fi
300 sleep 10
301 done
302}
303
304function create_overlay() {
David Garcia42375212020-04-27 19:07:49 +0200305 sudo snap install jq
David Garciac8660ad2020-12-16 13:13:20 +0100306 sudo snap install yq
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100307 local HOME=/home/$USER
David Garciac8660ad2020-12-16 13:13:20 +0100308 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq r - controllers.$CONTROLLER_NAME.user)
309 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq r - controllers.$CONTROLLER_NAME.password)
310 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.api-endpoints[0] | cut -d ":" -f 1)
311 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 +0100312 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
313 local vca_cloud="lxd-cloud"
314 # Get the VCA Certificate
David Garciac8660ad2020-12-16 13:13:20 +0100315 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 +0100316
317 # Calculate the default route of this machine
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200318 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100319
320 # Generate a new overlay.yaml, overriding any existing one
David Garcia42375212020-04-27 19:07:49 +0200321 cat << EOF > /tmp/vca-overlay.yaml
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100322applications:
323 lcm-k8s:
324 options:
325 vca_user: $vca_user
326 vca_password: $vca_password
327 vca_host: $vca_host
328 vca_port: $vca_port
329 vca_pubkey: $vca_pubkey
330 vca_cacert: $vca_cacert
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100331 vca_cloud: $vca_cloud
beierlma4a37f72020-06-26 12:55:01 -0400332 vca_k8s_cloud: $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100333 mon-k8s:
334 options:
335 vca_user: $vca_user
336 vca_password: $vca_password
337 vca_host: $vca_host
338 vca_cacert: $vca_cacert
339EOF
David Garcia42375212020-04-27 19:07:49 +0200340 mv /tmp/vca-overlay.yaml ~/.osm/
341 OSM_VCA_HOST=$vca_host
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100342}
343
David Garcia69388c22020-05-07 12:14:19 +0200344function generate_images_overlay(){
David Garciaef349d92020-12-10 21:16:12 +0100345 cat << EOF > /tmp/nbi_registry.yaml
346registrypath: ${REGISTRY_URL}opensourcemano/nbi:$TAG
347EOF
348 cat << EOF > /tmp/ng_ui_registry.yaml
349registrypath: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG
350EOF
beierlmf2782c52020-11-05 17:04:05 -0500351 if [ ! -z "$REGISTRY_USERNAME" ] ; then
352 REGISTRY_CREDENTIALS=$(cat <<EOF
353
354 image_username: $REGISTRY_USERNAME
355 image_password: $REGISTRY_PASSWORD
356EOF
357 );
David Garciaef349d92020-12-10 21:16:12 +0100358 echo username: $REGISTRY_USERNAME >> /tmp/nbi_registry.yaml
359 echo password: $REGISTRY_PASSWORD >> /tmp/nbi_registry.yaml
360 echo username: $REGISTRY_USERNAME >> /tmp/ng_ui_registry.yaml
361 echo password: $REGISTRY_PASSWORD >> /tmp/ng_ui_registry.yaml
beierlmf2782c52020-11-05 17:04:05 -0500362fi
363
David Garcia69388c22020-05-07 12:14:19 +0200364 cat << EOF > /tmp/images-overlay.yaml
365applications:
366 lcm-k8s:
367 options:
beierlmf2782c52020-11-05 17:04:05 -0500368 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200369 mon-k8s:
370 options:
beierlmf2782c52020-11-05 17:04:05 -0500371 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200372 ro-k8s:
373 options:
beierlmf2782c52020-11-05 17:04:05 -0500374 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
David Garciaef349d92020-12-10 21:16:12 +0100375 nbi:
376 resources:
377 image: /tmp/nbi_registry.yaml
David Garcia69388c22020-05-07 12:14:19 +0200378 pol-k8s:
379 options:
beierlmf2782c52020-11-05 17:04:05 -0500380 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400381 pla:
382 options:
beierlmf2782c52020-11-05 17:04:05 -0500383 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
beierlma4a37f72020-06-26 12:55:01 -0400384 ng-ui:
David Garciaef349d92020-12-10 21:16:12 +0100385 resources:
386 image: /tmp/ng_ui_registry.yaml
David Garcia009a5d62020-08-27 16:53:44 +0200387 keystone:
388 options:
beierlmf2782c52020-11-05 17:04:05 -0500389 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
David Garcia69388c22020-05-07 12:14:19 +0200390EOF
391 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
392}
393
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100394function install_osmclient() {
395 sudo snap install osmclient
396 sudo snap alias osmclient.osm osm
397}
398
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100399
400function install_microstack() {
401 sudo snap install microstack --classic --beta
402 sudo microstack.init --auto
403 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
404 microstack.openstack image create \
David Garcia42375212020-04-27 19:07:49 +0200405 --public \
406 --disk-format qcow2 \
407 --container-format bare \
408 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
409 ubuntu1604
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100410 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
411 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
David Garciaef349d92020-12-10 21:16:12 +0100412 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi".address'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100413 osm vim-create --name microstack-site \
David Garcia42375212020-04-27 19:07:49 +0200414 --user admin \
415 --password keystone \
416 --auth_url http://10.20.20.1:5000/v3 \
417 --tenant admin \
418 --account_type openstack \
419 --config='{security_groups: default,
420 keypair: microstack,
421 project_name: admin,
422 user_domain_name: default,
423 region_name: microstack,
424 insecure: True,
425 availability_zone: nova,
426 version: 3}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100427}
428
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200429DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100430DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
431
432check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200433mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100434install_snaps
435bootstrap_k8s_lxd
436deploy_charmed_osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100437install_osmclient
David Garcia42375212020-04-27 19:07:49 +0200438if [ -v MICROSTACK ]; then
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100439 install_microstack
440fi
beierlma4a37f72020-06-26 12:55:01 -0400441
David Garciaef349d92020-12-10 21:16:12 +0100442OSM_HOSTNAME=$(juju config nbi site_url | sed "s/http.*\?:\/\///"):443
beierlm7e54dfc2020-09-24 15:27:53 -0400443
beierlma4a37f72020-06-26 12:55:01 -0400444echo "Your installation is now complete, follow these steps for configuring the osmclient:"
445echo
446echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
447echo
beierlm7e54dfc2020-09-24 15:27:53 -0400448echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
beierlma4a37f72020-06-26 12:55:01 -0400449echo
450echo "2. Add the previous command to your .bashrc for other Shell sessions"
451echo
beierlm7e54dfc2020-09-24 15:27:53 -0400452echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
beierlma4a37f72020-06-26 12:55:01 -0400453echo
454echo "DONE"