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.
20 JUJU_AGENT_VERSION
=2.8.11
21 K8S_CLOUD_NAME
="k8s-cloud"
22 KUBECTL
="microk8s.kubectl"
25 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
26 PATH
=/snap
/bin
:${PATH}
31 OSM_HA_BUNDLE
=cs
:osm-ha-40
34 function check_arguments
(){
35 while [ $# -gt 0 ] ; do
37 --bundle) BUNDLE
="$2" ;;
38 --k8s) KUBECFG
="$2" ;;
39 --vca) CONTROLLER
="$2" ;;
40 --lxd) LXD_CLOUD
="$2" ;;
41 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
42 --microstack) MICROSTACK
=y
;;
43 --ha) BUNDLE
=$OSM_HA_BUNDLE ;;
45 --registry) REGISTRY_INFO
="$2" ;;
50 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
53 function install_snaps
(){
54 if [ ! -v KUBECFG
]; then
55 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
56 sudo
cat /var
/snap
/microk8s
/current
/args
/kube-apiserver |
grep advertise-address ||
(
57 echo "--advertise-address $DEFAULT_IP" | sudo
tee -a /var
/snap
/microk8s
/current
/args
/kube-apiserver
61 sudo usermod
-a -G microk8s
`whoami`
63 sudo chown
-f -R `whoami` ~
/.kube
65 sg
${KUBEGRP} -c "microk8s status --wait-ready"
66 KUBECONFIG
=~
/.osm
/microk8s-config.yaml
67 sg
${KUBEGRP} -c "microk8s config" |
tee ${KUBECONFIG}
70 sudo snap
install kubectl
--classic
71 export KUBECONFIG
=${KUBECFG}
74 sudo snap
install juju
--classic --channel=$JUJU_VERSION/stable
77 function bootstrap_k8s_lxd
(){
78 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
79 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
81 if [ -v BOOTSTRAP_NEEDED
]; then
82 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
83 if [ $CONTROLLER_PRESENT -ge 1 ]; then
85 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
86 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
89 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
91 Please retry the installation once this conflict has been resolved.
96 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
97 if [ $CONTROLLER_PRESENT -le 0 ]; then
99 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
100 that exists, or remove the --vca ${CONTROLLER_NAME} option.
102 Please retry the installation with one of the solutions applied.
108 if [ -v KUBECFG
]; then
109 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
110 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
111 --config controller-service-type
=loadbalancer \
112 --agent-version=$JUJU_AGENT_VERSION
114 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
115 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
116 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
118 start_time="$
(date -u +%s
)"
122 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
123 echo "Microk8s storage failed to
enable"
124 sg ${KUBEGRP} -c "microk8s.status
"
127 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
128 if [[ $storage_status == "enabled
" ]]; then
134 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
135 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
136 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
137 && K8S_CLOUD_NAME=microk8s
140 if [ -v LXD_CLOUD ]; then
141 if [ ! -v LXD_CREDENTIALS ]; then
142 echo "The installer needs the LXD server certificate
if the LXD is external
"
146 LXDENDPOINT=$DEFAULT_IP
147 LXD_CLOUD=~/.osm/lxd-cloud.yaml
148 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
149 # Apply sysctl production values for optimal performance
150 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
153 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
154 sudo snap install lxd --channel $LXD_VERSION/stable
156 sudo usermod -a -G lxd `whoami`
157 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"
158 sg lxd -c "lxd waitready
"
159 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
160 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
161 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
163 cat << EOF > $LXD_CLOUD
167 auth-types: [certificate]
168 endpoint: "https
://$LXDENDPOINT:8443"
170 ssl-hostname-verification: false
172 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
"
173 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
174 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
175 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
177 cat << EOF > $LXD_CREDENTIALS
181 auth-type: certificate
189 lxc config trust add local: ~/.osm/client.crt
192 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
193 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
194 sg lxd -c "lxd waitready
"
195 juju controller-config features=[k8s-operators]
198 function wait_for_port(){
202 start_time="$
(date -u +%s
)"
206 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
207 echo "Failed to expose external
${SERVICE} interface port
"
211 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
218 function deploy_charmed_osm(){
219 if [ -v REGISTRY_INFO ] ; then
220 registry_parts=(${REGISTRY_INFO//@/ })
221 if [ ${#registry_parts[@]} -eq 1 ] ; then
222 # No credentials supplied
225 REGISTRY_URL=${registry_parts[0]}
227 credentials=${registry_parts[0]}
228 credential_parts=(${credentials//:/ })
229 REGISTRY_USERNAME=${credential_parts[0]}
230 REGISTRY_PASSWORD=${credential_parts[1]}
231 REGISTRY_URL=${registry_parts[1]}
233 # Ensure the URL ends with a /
234 case $REGISTRY_URL in
236 *) REGISTRY_URL=${REGISTRY_URL}/
241 echo "Creating OSM model
"
242 if [ -v KUBECFG ]; then
243 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
245 sg ${KUBEGRP} -c "juju add-model
$MODEL_NAME $K8S_CLOUD_NAME"
247 echo "Deploying OSM with charms
"
249 if [ -v REGISTRY_URL ]; then
250 [ ! -v TAG ] && TAG='latest'
252 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
254 if [ -v BUNDLE ]; then
255 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
257 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
260 echo "Waiting
for deployment to finish...
"
262 echo "OSM with charms deployed
"
263 if [ ! -v KUBECFG ]; then
264 API_SERVER=${DEFAULT_IP}
266 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
267 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
268 url="$
(echo ${API_SERVER/$proto/})"
269 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
270 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
271 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
274 # Expose OSM services
276 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
277 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
280 juju config -m $MODEL_NAME grafana-k8s juju-external-hostname=grafana.${API_SERVER}.nip.io
281 juju expose -m $MODEL_NAME grafana-k8s
282 wait_for_port grafana-k8s 0
285 juju config -m $MODEL_NAME prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.nip.io
286 juju expose -m $MODEL_NAME prometheus-k8s
287 wait_for_port prometheus-k8s 1
290 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ng-ui
"
293 function check_osm_deployed() {
295 start_time="$
(date -u +%s
)"
296 total_service_count=14
300 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
301 echo "$service_count / $total_service_count services active
"
302 if [ $service_count -eq $total_service_count ]; then
305 if [ $service_count -ne $previous_count ]; then
306 previous_count=$service_count
307 start_time="$
(date -u +%s
)"
310 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
311 echo "Timed out waiting
for OSM services to become ready
"
318 function create_overlay() {
321 local HOME=/home/$USER
322 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
323 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
324 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
325 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
326 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
327 local vca_cloud="lxd-cloud
"
328 # Get the VCA Certificate
329 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
331 # Calculate the default route of this machine
332 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
334 # Generate a new overlay.yaml, overriding any existing one
335 cat << EOF > /tmp/vca-overlay.yaml
340 vca_password: $vca_password
343 vca_pubkey: $vca_pubkey
344 vca_cacert: $vca_cacert
345 vca_cloud: $vca_cloud
346 vca_k8s_cloud: $K8S_CLOUD_NAME
350 vca_password: $vca_password
352 vca_cacert: $vca_cacert
354 mv /tmp/vca-overlay.yaml ~/.osm/
355 OSM_VCA_HOST=$vca_host
358 function generate_images_overlay(){
359 cat << EOF > /tmp/nbi_registry.yaml
360 registrypath: ${REGISTRY_URL}opensourcemano/nbi:$TAG
362 cat << EOF > /tmp/ng_ui_registry.yaml
363 registrypath: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG
365 if [ ! -z "$REGISTRY_USERNAME" ] ; then
366 REGISTRY_CREDENTIALS=$(cat <<EOF
368 image_username: $REGISTRY_USERNAME
369 image_password: $REGISTRY_PASSWORD
372 echo username: $REGISTRY_USERNAME >> /tmp/nbi_registry.yaml
373 echo password: $REGISTRY_PASSWORD >> /tmp/nbi_registry.yaml
374 echo username: $REGISTRY_USERNAME >> /tmp/ng_ui_registry.yaml
375 echo password: $REGISTRY_PASSWORD >> /tmp/ng_ui_registry.yaml
378 cat << EOF > /tmp/images-overlay.yaml
382 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
385 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
388 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
391 image: /tmp/nbi_registry.yaml
394 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
397 image: ${REGISTRY_URL}opensourcemano/pla:8 ${REGISTRY_CREDENTIALS}
400 image: /tmp/ng_ui_registry.yaml
403 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
405 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
408 function refresh_osmclient_snap() {
409 osmclient_snap_install_refresh refresh
412 function install_osm_client_snap() {
413 osmclient_snap_install_refresh install
416 function osmclient_snap_install_refresh() {
417 channel_preference="stable candidate beta edge
"
418 for channel in $channel_preference; do
419 echo "Trying to
install osmclient from channel
$OSMCLIENT_VERSION/$channel"
420 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
423 function install_osmclient() {
424 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
427 function add_local_k8scluster() {
428 osm --all-projects vim-create \
429 --name _system-osm-vim \
430 --account_type dummy \
431 --auth_url http://dummy \
432 --user osm --password osm --tenant osm \
433 --description "dummy
" \
434 --config '{management_network_name: mgmt}'
435 tmpfile=$(mktemp --tmpdir=${HOME})
436 cp ${KUBECONFIG} ${tmpfile}
437 osm --all-projects k8scluster-add \
439 --vim _system-osm-vim \
440 --k8s-nets '{"net1
": null}' \
442 --description "OSM Internal Cluster
" \
447 function install_microstack() {
448 # Install and init microstack
449 sudo snap install microstack --channel beta --devmode
450 sudo snap set microstack config.network.ports.dashboard=8080
451 sudo microstack.init --auto --control
453 # Basic configuration
454 microstack.openstack network create --enable --no-share osm-ext
455 microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 --subnet-range 172.16.0.0/24
456 microstack.openstack router create external-router
457 microstack.openstack router add subnet external-router osm-ext-subnet
458 microstack.openstack router set --external-gateway external external-router
459 for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do
460 microstack.openstack security group rule create $i --protocol icmp --remote-ip 0.0.0.0/0
461 microstack.openstack security group rule create $i --protocol tcp --remote-ip 0.0.0.0/0
463 KEYPAIR_PATH=~/.ssh/microstack
464 if ! test -f $KEYPAIR_PATH; then
465 echo "Generating
ssh keypair
for microstack
"
466 ssh-keygen -t rsa -N "" -f $KEYPAIR_PATH
468 microstack.openstack keypair create --public-key $KEYPAIR_PATH.pub microstack
470 # Add xenial, bionic, and focal images to microstack
471 echo "curl https
://cloud-images.ubuntu.com
/xenial
/current
/xenial-server-cloudimg-amd64-disk1.img | microstack.openstack image create
--public --container-format=bare
--disk-format=qcow2 ubuntu16.04
"
472 echo "curl https
://cloud-images.ubuntu.com
/bionic
/current
/bionic-server-cloudimg-amd64.img | microstack.openstack image create
--public --container-format=bare
--disk-format=qcow2 ubuntu18.04
"
473 echo "curl https
://cloud-images.ubuntu.com
/focal
/current
/focal-server-cloudimg-amd64.img | microstack.openstack image create
--public --container-format=bare
--disk-format=qcow2 ubuntu20.04
"
476 . /var/snap/microstack/common/etc/microstack.rc
477 osm vim-create --name microstack \
478 --user "$OS_USERNAME" \
479 --password "$OS_PASSWORD" \
480 --auth_url "$OS_AUTH_URL/v3
" \
481 --tenant "$OS_USERNAME" \
482 --account_type openstack \
484 use_floating_ip: True,
485 management_network_name: osm-ext,
488 user_domain_name: default,
489 region_name: microstack,
491 availability_zone: nova,
496 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
497 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
505 export OSM_HOSTNAME=$(juju config nbi site_url | sed "s
/http.
*\?:\
/\
///"):443
508 if [ -v MICROSTACK ]; then
513 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
515 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
517 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
519 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
521 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"