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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 JUJU_AGENT_VERSION
=2.9.9
20 K8S_CLOUD_NAME
="k8s-cloud"
21 KUBECTL
="microk8s.kubectl"
23 OSMCLIENT_VERSION
=10.0
24 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
25 PATH
=/snap
/bin
:${PATH}
29 # Latest bundles using old mongodb-k8s
30 # OSM_BUNDLE=cs:osm-68
31 # OSM_HA_BUNDLE=cs:osm-ha-54
32 # The charm store does not support referencing charms from CharmHub,
33 # therefore we will point to the local bundles until we migrate all
35 OSM_BUNDLE
=/usr
/share
/osm-devops
/installers
/charm
/bundles
/osm
/bundle.yaml
36 OSM_HA_BUNDLE
=/usr
/share
/osm-devops
/installers
/charm
/bundles
/osm-ha
/bundle.yaml
39 function check_arguments
(){
40 while [ $# -gt 0 ] ; do
42 --bundle) BUNDLE
="$2" ;;
43 --overlay) OVERLAY
="$2" ;;
44 --k8s) KUBECFG
="$2" ;;
45 --vca) CONTROLLER
="$2" ;;
46 --lxd) LXD_CLOUD
="$2" ;;
47 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
48 --microstack) MICROSTACK
=y
;;
49 --ha) BUNDLE
=$OSM_HA_BUNDLE ;;
51 --registry) REGISTRY_INFO
="$2" ;;
52 --only-vca) ONLY_VCA
=y
;;
57 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
60 function install_snaps
(){
61 if [ ! -v KUBECFG
]; then
62 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
63 sudo
cat /var
/snap
/microk8s
/current
/args
/kube-apiserver |
grep advertise-address ||
(
64 echo "--advertise-address $DEFAULT_IP" | sudo
tee -a /var
/snap
/microk8s
/current
/args
/kube-apiserver
68 sudo usermod
-a -G microk8s
`whoami`
70 sudo chown
-f -R `whoami` ~
/.kube
72 sg
${KUBEGRP} -c "microk8s status --wait-ready"
73 KUBECONFIG
=~
/.osm
/microk8s-config.yaml
74 sg
${KUBEGRP} -c "microk8s config" |
tee ${KUBECONFIG}
77 sudo snap
install kubectl
--classic
78 export KUBECONFIG
=${KUBECFG}
81 sudo snap
install juju
--classic --channel=$JUJU_VERSION/stable
84 function bootstrap_k8s_lxd
(){
85 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
86 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
88 if [ -v BOOTSTRAP_NEEDED
]; then
89 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
90 if [ $CONTROLLER_PRESENT -ge 1 ]; then
92 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
93 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
96 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
98 Please retry the installation once this conflict has been resolved.
103 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
104 if [ $CONTROLLER_PRESENT -le 0 ]; then
106 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
107 that exists, or remove the --vca ${CONTROLLER_NAME} option.
109 Please retry the installation with one of the solutions applied.
115 if [ -v KUBECFG
]; then
116 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
117 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
118 --config controller-service-type
=loadbalancer \
119 --agent-version=$JUJU_AGENT_VERSION
121 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
122 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
123 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
125 start_time="$
(date -u +%s
)"
129 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
130 echo "Microk8s storage failed to
enable"
131 sg ${KUBEGRP} -c "microk8s.status
"
134 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
135 if [[ $storage_status == "enabled
" ]]; then
141 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
142 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
143 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
144 && K8S_CLOUD_NAME=microk8s
147 if [ -v LXD_CLOUD ]; then
148 if [ ! -v LXD_CREDENTIALS ]; then
149 echo "The installer needs the LXD server certificate
if the LXD is external
"
153 LXDENDPOINT=$DEFAULT_IP
154 LXD_CLOUD=~/.osm/lxd-cloud.yaml
155 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
156 # Apply sysctl production values for optimal performance
157 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
160 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
161 sudo snap install lxd
163 sudo usermod -a -G lxd `whoami`
164 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"
165 sg lxd -c "lxd waitready
"
166 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
167 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
168 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
170 cat << EOF > $LXD_CLOUD
174 auth-types: [certificate]
175 endpoint: "https
://$LXDENDPOINT:8443"
177 ssl-hostname-verification: false
179 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
"
180 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
181 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
182 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
184 cat << EOF > $LXD_CREDENTIALS
188 auth-type: certificate
196 lxc config trust add local: ~/.osm/client.crt
199 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
200 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
201 sg lxd -c "lxd waitready
"
202 juju controller-config features=[k8s-operators]
205 function wait_for_port(){
209 start_time="$
(date -u +%s
)"
213 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
214 echo "Failed to expose external
${SERVICE} interface port
"
218 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
225 function deploy_charmed_osm(){
226 if [ -v REGISTRY_INFO ] ; then
227 registry_parts=(${REGISTRY_INFO//@/ })
228 if [ ${#registry_parts[@]} -eq 1 ] ; then
229 # No credentials supplied
232 REGISTRY_URL=${registry_parts[0]}
234 credentials=${registry_parts[0]}
235 credential_parts=(${credentials//:/ })
236 REGISTRY_USERNAME=${credential_parts[0]}
237 REGISTRY_PASSWORD=${credential_parts[1]}
238 REGISTRY_URL=${registry_parts[1]}
240 # Ensure the URL ends with a /
241 case $REGISTRY_URL in
243 *) REGISTRY_URL=${REGISTRY_URL}/
247 echo "Creating OSM model
"
248 if [ -v KUBECFG ]; then
249 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
251 sg ${KUBEGRP} -c "juju add-model
$MODEL_NAME $K8S_CLOUD_NAME"
253 echo "Deploying OSM with charms
"
255 if [ -v REGISTRY_URL ]; then
256 [ ! -v TAG ] && TAG='latest'
258 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
260 if [ -v OVERLAY ]; then
261 extra_overlay="--overlay $OVERLAY"
264 if [ -v BUNDLE ]; then
265 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
267 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
270 if [ ! -v KUBECFG ]; then
271 API_SERVER=${DEFAULT_IP}
273 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
274 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
275 url="$
(echo ${API_SERVER/$proto/})"
276 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
277 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
278 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
280 # Expose OSM services
281 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
282 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
283 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
284 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
286 echo "Waiting
for deployment to finish...
"
288 echo "OSM with charms deployed
"
291 function check_osm_deployed() {
293 start_time="$
(date -u +%s
)"
294 total_service_count=14
298 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
299 echo "$service_count / $total_service_count services active
"
300 if [ $service_count -eq $total_service_count ]; then
303 if [ $service_count -ne $previous_count ]; then
304 previous_count=$service_count
305 start_time="$
(date -u +%s
)"
308 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
309 echo "Timed out waiting
for OSM services to become ready
"
316 function create_overlay() {
319 local HOME=/home/$USER
320 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
321 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
322 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
323 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
324 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
325 local vca_cloud="lxd-cloud
"
326 # Get the VCA Certificate
327 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
329 # Calculate the default route of this machine
330 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
332 # Generate a new overlay.yaml, overriding any existing one
333 cat << EOF > /tmp/vca-overlay.yaml
338 vca_secret: $vca_secret
341 vca_pubkey: $vca_pubkey
342 vca_cacert: $vca_cacert
343 vca_cloud: $vca_cloud
344 vca_k8s_cloud: $K8S_CLOUD_NAME
348 vca_secret: $vca_secret
350 vca_cacert: $vca_cacert
352 mv /tmp/vca-overlay.yaml ~/.osm/
353 OSM_VCA_HOST=$vca_host
356 function generate_images_overlay(){
357 echo "applications
:" > /tmp/images-overlay.yaml
359 charms_with_resources="nbi lcm mon pol ng-ui ro pla keystone
"
360 for charm in $charms_with_resources; do
361 cat << EOF > /tmp/${charm}_registry.yaml
362 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
364 if [ ! -z "$REGISTRY_USERNAME" ] ; then
365 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
366 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
369 cat << EOF >> /tmp/images-overlay.yaml
372 image: /tmp/${charm}_registry.yaml
377 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
380 function refresh_osmclient_snap() {
381 osmclient_snap_install_refresh refresh
384 function install_osm_client_snap() {
385 osmclient_snap_install_refresh install
388 function osmclient_snap_install_refresh() {
389 channel_preference="stable candidate beta edge
"
390 for channel in $channel_preference; do
391 echo "Trying to
install osmclient from channel
$OSMCLIENT_VERSION/$channel"
392 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
395 function install_osmclient() {
396 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
399 function add_local_k8scluster() {
400 osm --all-projects vim-create \
401 --name _system-osm-vim \
402 --account_type dummy \
403 --auth_url http://dummy \
404 --user osm --password osm --tenant osm \
405 --description "dummy
" \
406 --config '{management_network_name: mgmt}'
407 tmpfile=$(mktemp --tmpdir=${HOME})
408 cp ${KUBECONFIG} ${tmpfile}
409 osm --all-projects k8scluster-add \
411 --vim _system-osm-vim \
412 --k8s-nets '{"net1
": null}' \
414 --description "OSM Internal Cluster
" \
419 function install_microstack() {
420 sudo snap install microstack --classic --beta
421 sudo microstack.init --auto
422 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
423 microstack.openstack image create \
425 --disk-format qcow2 \
426 --container-format bare \
427 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
429 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
430 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
431 export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi
".address'`
432 osm vim-create --name microstack-site \
434 --password keystone \
435 --auth_url http://10.20.20.1:5000/v3 \
437 --account_type openstack \
438 --config='{security_groups: default,
441 user_domain_name: default,
442 region_name: microstack,
444 availability_zone: nova,
448 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
449 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
456 if [ -v ONLY_VCA ]; then
458 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
459 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
460 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
461 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
462 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
463 vca_cloud="lxd-cloud
"
464 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
465 hostname=`cat /etc/hostname`
467 echo "Use the following
command to register the installed VCA to your OSM
:"
468 echo -e " osm vca-add
--endpoints $vca_host:$vca_port \\\n --user $vca_user \\\n --secret $vca_secret \\\n --cacert $vca_cacert \\\n --lxd-cloud lxd-cloud
\\\n --lxd-credentials lxd-cloud
\\\n --k8s-cloud microk8s
\\\n --k8s-credentials microk8s
\\\n $hostname-vca"
472 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s
/http.
*\?:\
/\
///"):443
475 if [ -v MICROSTACK ]; then
479 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
481 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
483 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
485 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
487 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"