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.
18 K8S_CLOUD_NAME
="k8s-cloud"
19 KUBECTL
="microk8s.kubectl"
20 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
21 function check_arguments
(){
22 while [ $# -gt 0 ] ; do
24 --bundle) BUNDLE
="$2" ;;
25 --k8s) KUBECFG
="$2" ;;
26 --vca) CONTROLLER
="$2" ;;
27 --lxd) LXD_CLOUD
="$2" ;;
28 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
29 --microstack) MICROSTACK
=y
;;
30 --ha) BUNDLE
="osm-ha" ;;
36 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
39 function install_snaps
(){
40 if [ ! -v KUBECFG
]; then
41 sudo snap
install microk8s
--classic
42 sudo usermod
-a -G microk8s
`whoami`
44 sudo chown
-f -R `whoami` ~
/.kube
48 sudo snap
install kubectl
--classic
49 export KUBECONFIG
=${KUBECFG}
52 sudo snap
install juju
--classic --channel=2.8/stable
55 function bootstrap_k8s_lxd
(){
56 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
57 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
59 if [ -v BOOTSTRAP_NEEDED
]; then
60 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
61 if [ $CONTROLLER_PRESENT -ge 1 ]; then
63 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
64 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
67 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
69 Please retry the installation once this conflict has been resolved.
75 if [ -v KUBECFG
]; then
76 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
77 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
78 --config controller-service-type
=loadbalancer \
81 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
82 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
84 start_time="$
(date -u +%s
)"
88 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
89 echo "Microk8s storage failed to
enable"
90 sg ${KUBEGRP} -c "microk8s.status
"
93 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
94 if [[ $storage_status == "enabled
" ]]; then
100 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
101 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
102 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=2.8.1" \
103 && K8S_CLOUD_NAME=microk8s
106 if [ -v LXD_CLOUD ]; then
107 if [ ! -v LXD_CREDENTIALS ]; then
108 echo "The installer needs the LXD server certificate
if the LXD is external
"
112 LXDENDPOINT=$DEFAULT_IP
113 LXD_CLOUD=~/.osm/lxd-cloud.yaml
114 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
115 # Apply sysctl production values for optimal performance
116 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
119 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
120 sudo snap install lxd
121 sudo apt-get install zfsutils-linux -y
123 sudo usermod -a -G lxd `whoami`
124 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"
125 sg lxd -c "lxd waitready
"
126 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
127 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
128 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
130 cat << EOF > $LXD_CLOUD
134 auth-types: [certificate]
135 endpoint: "https
://$LXDENDPOINT:8443"
137 ssl-hostname-verification: false
139 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
"
140 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
141 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
142 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
144 cat << EOF > $LXD_CREDENTIALS
148 auth-type: certificate
156 lxc config trust add local: ~/.osm/client.crt
159 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
160 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
161 sg lxd -c "lxd waitready
"
162 #juju add-model test lxd-cloud || true
163 juju controller-config features=[k8s-operators]
166 function wait_for_port(){
170 start_time="$
(date -u +%s
)"
174 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
175 echo "Failed to expose external
${SERVICE} interface port
"
179 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
186 function deploy_charmed_osm(){
188 echo "Creating OSM model
"
189 if [ -v KUBECFG ]; then
190 juju add-model osm $K8S_CLOUD_NAME
192 sg ${KUBEGRP} -c "juju add-model osm
$K8S_CLOUD_NAME"
194 echo "Deploying OSM with charms
"
196 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
197 if [ -v BUNDLE ]; then
198 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
200 juju deploy osm --overlay ~/.osm/vca-overlay.yaml $images_overlay
203 echo "Waiting
for deployment to finish...
"
205 echo "OSM with charms deployed
"
206 if [ ! -v KUBECFG ]; then
207 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
208 API_SERVER=${DEFAULT_IP}
210 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
211 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
212 url="$
(echo ${API_SERVER/$proto/})"
213 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
214 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
215 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
218 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
221 wait_for_port nbi-k8s 0
222 sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[0].metadata.annotations += {\"nginx.ingress.kubernetes.io/backend-protocol\": \"HTTPS\"}' | ${KUBECTL} --validate=false replace -f -"
223 sg
${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[0].metadata.annotations += {\"nginx.ingress.kubernetes.io/proxy-body-size\": \"0\"}' | ${KUBECTL} replace -f -"
225 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
228 wait_for_port ng-ui 1
229 sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[2].metadata.annotations += {\"nginx.ingress.kubernetes.io/proxy-body-size\": \"0\"}' |
${KUBECTL} --validate=false replace
-f -"
231 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
234 wait_for_port ui-k8s 2
235 sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq '.items[1].metadata.annotations += {\"nginx.ingress.kubernetes.io/proxy-body-size\": \"0\"}' | ${KUBECTL} --validate=false replace -f -"
238 function check_osm_deployed
() {
240 start_time
="$(date -u +%s)"
241 total_service_count
=14
244 service_count
=$
(juju status |
grep kubernetes |
grep active |
wc -l)
245 echo "$service_count / $total_service_count services active"
246 if [ $service_count -eq $total_service_count ]; then
250 if [[ $
(( now
- start_time
)) -gt $TIME_TO_WAIT ]];then
251 echo "Timed out waiting for OSM services to become ready"
258 function create_overlay
() {
260 sudo apt
install python3-pip
-y
261 python3
-m pip
install yq
262 PATH
=$PATH:$HOME/.local
/bin
# make yq command available
263 local HOME
=/home
/$USER
264 local vca_user
=$
(cat $HOME/.local
/share
/juju
/accounts.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
265 local vca_password
=$
(cat $HOME/.local
/share
/juju
/accounts.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
266 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)
267 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)
268 local vca_pubkey
=\"$
(cat $HOME/.local
/share
/juju
/ssh
/juju_id_rsa.pub
)\"
269 local vca_cloud
="lxd-cloud"
270 # Get the VCA Certificate
271 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
)
273 # Calculate the default route of this machine
274 local DEFAULT_IF
=`ip route list match 0.0.0.0 | awk '{print $5}'`
276 # Generate a new overlay.yaml, overriding any existing one
277 cat << EOF > /tmp/vca-overlay.yaml
282 vca_password: $vca_password
285 vca_pubkey: $vca_pubkey
286 vca_cacert: $vca_cacert
287 vca_cloud: $vca_cloud
288 vca_k8s_cloud: $K8S_CLOUD_NAME
292 vca_password: $vca_password
294 vca_cacert: $vca_cacert
296 mv /tmp
/vca-overlay.yaml ~
/.osm
/
297 OSM_VCA_HOST
=$vca_host
300 function generate_images_overlay
(){
301 cat << EOF > /tmp/images-overlay.yaml
305 image: opensourcemano/lcm:$TAG
308 image: opensourcemano/mon:$TAG
311 image: opensourcemano/ro:$TAG
314 image: opensourcemano/nbi:$TAG
317 image: opensourcemano/pol:$TAG
320 image: opensourcemano/light-ui:$TAG
323 image: opensourcemano/pla:$TAG
326 image: opensourcemano/ng-ui:$TAG
329 mv /tmp
/images-overlay.yaml
$IMAGES_OVERLAY_FILE
332 function install_osmclient
() {
333 sudo snap
install osmclient
334 sudo snap
alias osmclient.osm osm
338 function install_microstack
() {
339 sudo snap
install microstack
--classic --beta
340 sudo microstack.init
--auto
341 wget https
://cloud-images.ubuntu.com
/releases
/16.04/release
/ubuntu-16.04
-server-cloudimg-amd64-disk1.img
-P ~
/.osm
/
342 microstack.openstack image create \
344 --disk-format qcow2 \
345 --container-format bare \
346 --file ~
/.osm
/ubuntu-16.04
-server-cloudimg-amd64-disk1.img \
348 ssh-keygen
-t rsa
-N "" -f ~
/.ssh
/microstack
349 microstack.openstack keypair create
--public-key ~
/.ssh
/microstack.pub microstack
350 export OSM_HOSTNAME
=`juju status --format json | jq -rc '.applications."nbi-k8s".address'`
351 osm vim-create
--name microstack-site \
353 --password keystone \
354 --auth_url http
://10.20.20.1:5000/v3 \
356 --account_type openstack \
357 --config='{security_groups: default,
360 user_domain_name: default,
361 region_name: microstack,
363 availability_zone: nova,
367 DEFAULT_IF
=`ip route list match 0.0.0.0 | awk '{print $5}'`
368 DEFAULT_IP
=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
376 if [ -v MICROSTACK
]; then
380 echo "Your installation is now complete, follow these steps for configuring the osmclient:"
382 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
384 echo "export OSM_HOSTNAME=nbi.$API_SERVER.xip.io:443"
386 echo "2. Add the previous command to your .bashrc for other Shell sessions"
388 echo "echo \"export OSM_HOSTNAME=nbi.$API_SERVER.xip.io:443\" >> ~/.bashrc"