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 JUJU_AGENT_VERSION
=2.8.6
19 K8S_CLOUD_NAME
="k8s-cloud"
20 KUBECTL
="microk8s.kubectl"
21 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
22 PATH
=/snap
/bin
:${PATH}
24 function check_arguments
(){
25 while [ $# -gt 0 ] ; do
27 --bundle) BUNDLE
="$2" ;;
28 --k8s) KUBECFG
="$2" ;;
29 --vca) CONTROLLER
="$2" ;;
30 --lxd) LXD_CLOUD
="$2" ;;
31 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
32 --microstack) MICROSTACK
=y
;;
33 --ha) BUNDLE
="cs:osm-ha" ;;
35 --registry) REGISTRY_INFO
="$2" ;;
40 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
43 function install_snaps
(){
44 if [ ! -v KUBECFG
]; then
45 sudo snap
install microk8s
--classic
46 sudo usermod
-a -G microk8s
`whoami`
48 sudo chown
-f -R `whoami` ~
/.kube
50 sg
${KUBEGRP} -c "microk8s status --wait-ready"
53 sudo snap
install kubectl
--classic
54 export KUBECONFIG
=${KUBECFG}
57 sudo snap
install juju
--classic --channel=2.8/stable
60 function bootstrap_k8s_lxd
(){
61 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
62 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
64 if [ -v BOOTSTRAP_NEEDED
]; then
65 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
66 if [ $CONTROLLER_PRESENT -ge 1 ]; then
68 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
69 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
72 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
74 Please retry the installation once this conflict has been resolved.
79 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
80 if [ $CONTROLLER_PRESENT -le 0 ]; then
82 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
83 that exists, or remove the --vca ${CONTROLLER_NAME} option.
85 Please retry the installation with one of the solutions applied.
91 if [ -v KUBECFG
]; then
92 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
93 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
94 --config controller-service-type
=loadbalancer \
95 --agent-version=$JUJU_AGENT_VERSION
97 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
98 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
99 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
101 start_time="$
(date -u +%s
)"
105 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
106 echo "Microk8s storage failed to
enable"
107 sg ${KUBEGRP} -c "microk8s.status
"
110 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
111 if [[ $storage_status == "enabled
" ]]; then
117 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
118 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
119 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
120 && K8S_CLOUD_NAME=microk8s
123 if [ -v LXD_CLOUD ]; then
124 if [ ! -v LXD_CREDENTIALS ]; then
125 echo "The installer needs the LXD server certificate
if the LXD is external
"
129 LXDENDPOINT=$DEFAULT_IP
130 LXD_CLOUD=~/.osm/lxd-cloud.yaml
131 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
132 # Apply sysctl production values for optimal performance
133 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
136 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
137 sudo snap install lxd
139 sudo usermod -a -G lxd `whoami`
140 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"
141 sg lxd -c "lxd waitready
"
142 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
143 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
144 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
146 cat << EOF > $LXD_CLOUD
150 auth-types: [certificate]
151 endpoint: "https
://$LXDENDPOINT:8443"
153 ssl-hostname-verification: false
155 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
"
156 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
157 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
158 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
160 cat << EOF > $LXD_CREDENTIALS
164 auth-type: certificate
172 lxc config trust add local: ~/.osm/client.crt
175 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
176 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
177 sg lxd -c "lxd waitready
"
178 juju controller-config features=[k8s-operators]
181 function wait_for_port(){
185 start_time="$
(date -u +%s
)"
189 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
190 echo "Failed to expose external
${SERVICE} interface port
"
194 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
201 function deploy_charmed_osm(){
202 if [ -v REGISTRY_INFO ] ; then
203 registry_parts=(${REGISTRY_INFO//@/ })
204 if [ ${#registry_parts[@]} -eq 1 ] ; then
205 # No credentials supplied
208 REGISTRY_URL=${registry_parts[0]}
210 credentials=${registry_parts[0]}
211 credential_parts=(${credentials//:/ })
212 REGISTRY_USERNAME=${credential_parts[0]}
213 REGISTRY_PASSWORD=${credential_parts[1]}
214 REGISTRY_URL=${registry_parts[1]}
216 # Ensure the URL ends with a /
217 case $REGISTRY_URL in
219 *) REGISTRY_URL=${REGISTRY_URL}/
224 echo "Creating OSM model
"
225 if [ -v KUBECFG ]; then
226 juju add-model osm $K8S_CLOUD_NAME
228 sg ${KUBEGRP} -c "juju add-model osm
$K8S_CLOUD_NAME"
230 echo "Deploying OSM with charms
"
232 if [ -v REGISTRY_URL ]; then
233 [ ! -v TAG ] && TAG='latest'
235 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
237 if [ -v BUNDLE ]; then
238 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
240 juju deploy cs:osm --overlay ~/.osm/vca-overlay.yaml $images_overlay
243 echo "Waiting
for deployment to finish...
"
245 echo "OSM with charms deployed
"
246 if [ ! -v KUBECFG ]; then
247 API_SERVER=${DEFAULT_IP}
249 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
250 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
251 url="$
(echo ${API_SERVER/$proto/})"
252 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
253 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
254 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
257 # Expose OSM services
259 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
260 juju expose grafana-k8s
261 wait_for_port grafana-k8s 0
264 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
266 wait_for_port nbi-k8s 1
269 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
271 wait_for_port ng-ui 2
274 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
275 juju expose prometheus-k8s
276 wait_for_port prometheus-k8s 3
279 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
281 wait_for_port ui-k8s 4
284 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/backend-protocol
=HTTPS
-n osm
-l juju-app
=nbi-k8s
"
285 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=nbi-k8s
"
286 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ng-ui
"
287 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ui-k8s
"
290 function check_osm_deployed() {
292 start_time="$
(date -u +%s
)"
293 total_service_count=15
297 service_count=$(juju status | grep kubernetes | grep active | wc -l)
298 echo "$service_count / $total_service_count services active
"
299 if [ $service_count -eq $total_service_count ]; then
302 if [ $service_count -ne $previous_count ]; then
303 previous_count=$service_count
304 start_time="$
(date -u +%s
)"
307 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
308 echo "Timed out waiting
for OSM services to become ready
"
315 function create_overlay() {
317 sudo apt install python3-pip -y
318 python3 -m pip install yq
319 PATH=$PATH:$HOME/.local/bin # make yq command available
320 local HOME=/home/$USER
321 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
322 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
323 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)
324 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)
325 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
326 local vca_cloud="lxd-cloud
"
327 # Get the VCA Certificate
328 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)
330 # Calculate the default route of this machine
331 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
333 # Generate a new overlay.yaml, overriding any existing one
334 cat << EOF > /tmp/vca-overlay.yaml
339 vca_password: $vca_password
342 vca_pubkey: $vca_pubkey
343 vca_cacert: $vca_cacert
344 vca_cloud: $vca_cloud
345 vca_k8s_cloud: $K8S_CLOUD_NAME
349 vca_password: $vca_password
351 vca_cacert: $vca_cacert
353 mv /tmp/vca-overlay.yaml ~/.osm/
354 OSM_VCA_HOST=$vca_host
357 function generate_images_overlay(){
358 if [ ! -z "$REGISTRY_USERNAME" ] ; then
359 REGISTRY_CREDENTIALS=$(cat <<EOF
361 image_username: $REGISTRY_USERNAME
362 image_password: $REGISTRY_PASSWORD
367 cat << EOF > /tmp/images-overlay.yaml
371 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
374 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
377 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
380 image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
383 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
386 image: ${REGISTRY_URL}opensourcemano/light-ui:$TAG ${REGISTRY_CREDENTIALS}
389 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
392 image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
395 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
397 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
400 function install_osmclient() {
401 sudo snap install osmclient
402 sudo snap alias osmclient.osm osm
406 function install_microstack() {
407 sudo snap install microstack --classic --beta
408 sudo microstack.init --auto
409 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
410 microstack.openstack image create \
412 --disk-format qcow2 \
413 --container-format bare \
414 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
416 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
417 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
418 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s
".address'`
419 osm vim-create --name microstack-site \
421 --password keystone \
422 --auth_url http://10.20.20.1:5000/v3 \
424 --account_type openstack \
425 --config='{security_groups: default,
428 user_domain_name: default,
429 region_name: microstack,
431 availability_zone: nova,
435 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
436 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
444 if [ -v MICROSTACK ]; then
448 OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
450 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
452 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
454 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
456 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
458 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"