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 PATH
=/snap
/bin
:${PATH}
23 function check_arguments
(){
24 while [ $# -gt 0 ] ; do
26 --bundle) BUNDLE
="$2" ;;
27 --k8s) KUBECFG
="$2" ;;
28 --vca) CONTROLLER
="$2" ;;
29 --lxd) LXD_CLOUD
="$2" ;;
30 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
31 --microstack) MICROSTACK
=y
;;
32 --ha) BUNDLE
="cs:osm-ha" ;;
34 --registry) REGISTRY_INFO
="$2" ;;
39 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
42 function install_snaps
(){
43 if [ ! -v KUBECFG
]; then
44 sudo snap
install microk8s
--classic
45 sudo usermod
-a -G microk8s
`whoami`
47 sudo chown
-f -R `whoami` ~
/.kube
49 sg
${KUBEGRP} -c "microk8s status --wait-ready"
52 sudo snap
install kubectl
--classic
53 export KUBECONFIG
=${KUBECFG}
56 sudo snap
install juju
--classic --channel=2.8/stable
59 function bootstrap_k8s_lxd
(){
60 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
61 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
63 if [ -v BOOTSTRAP_NEEDED
]; then
64 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
65 if [ $CONTROLLER_PRESENT -ge 1 ]; then
67 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
68 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
71 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
73 Please retry the installation once this conflict has been resolved.
78 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
79 if [ $CONTROLLER_PRESENT -le 0 ]; then
81 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
82 that exists, or remove the --vca ${CONTROLLER_NAME} option.
84 Please retry the installation with one of the solutions applied.
90 if [ -v KUBECFG
]; then
91 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
92 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
93 --config controller-service-type
=loadbalancer \
96 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
97 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
98 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
100 start_time="$
(date -u +%s
)"
104 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
105 echo "Microk8s storage failed to
enable"
106 sg ${KUBEGRP} -c "microk8s.status
"
109 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
110 if [[ $storage_status == "enabled
" ]]; then
116 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
117 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
118 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=2.8.1" \
119 && K8S_CLOUD_NAME=microk8s
122 if [ -v LXD_CLOUD ]; then
123 if [ ! -v LXD_CREDENTIALS ]; then
124 echo "The installer needs the LXD server certificate
if the LXD is external
"
128 LXDENDPOINT=$DEFAULT_IP
129 LXD_CLOUD=~/.osm/lxd-cloud.yaml
130 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
131 # Apply sysctl production values for optimal performance
132 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
135 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
136 sudo snap install lxd
138 sudo usermod -a -G lxd `whoami`
139 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"
140 sg lxd -c "lxd waitready
"
141 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
142 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
143 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
145 cat << EOF > $LXD_CLOUD
149 auth-types: [certificate]
150 endpoint: "https
://$LXDENDPOINT:8443"
152 ssl-hostname-verification: false
154 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
"
155 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
156 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
157 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
159 cat << EOF > $LXD_CREDENTIALS
163 auth-type: certificate
171 lxc config trust add local: ~/.osm/client.crt
174 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
175 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
176 sg lxd -c "lxd waitready
"
177 juju controller-config features=[k8s-operators]
180 function wait_for_port(){
184 start_time="$
(date -u +%s
)"
188 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
189 echo "Failed to expose external
${SERVICE} interface port
"
193 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
200 function deploy_charmed_osm(){
201 if [ -v REGISTRY_INFO ] ; then
202 registry_parts=(${REGISTRY_INFO//@/ })
203 if [ ${#registry_parts[@]} -eq 1 ] ; then
204 # No credentials supplied
207 REGISTRY_URL=${registry_parts[0]}
209 credentials=${registry_parts[0]}
210 credential_parts=(${credentials//:/ })
211 REGISTRY_USERNAME=${credential_parts[0]}
212 REGISTRY_PASSWORD=${credential_parts[1]}
213 REGISTRY_URL=${registry_parts[1]}
215 # Ensure the URL ends with a /
216 case $REGISTRY_URL in
218 *) REGISTRY_URL=${REGISTRY_URL}/
223 echo "Creating OSM model
"
224 if [ -v KUBECFG ]; then
225 juju add-model osm $K8S_CLOUD_NAME
227 sg ${KUBEGRP} -c "juju add-model osm
$K8S_CLOUD_NAME"
229 echo "Deploying OSM with charms
"
231 if [ -v REGISTRY_URL ]; then
232 [ ! -v TAG ] && TAG='latest'
234 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
236 if [ -v BUNDLE ]; then
237 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
239 juju deploy cs:osm --overlay ~/.osm/vca-overlay.yaml $images_overlay
242 echo "Waiting
for deployment to finish...
"
244 echo "OSM with charms deployed
"
245 if [ ! -v KUBECFG ]; then
246 API_SERVER=${DEFAULT_IP}
248 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
249 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
250 url="$
(echo ${API_SERVER/$proto/})"
251 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
252 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
253 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
256 # Expose OSM services
258 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
259 juju expose grafana-k8s
260 wait_for_port grafana-k8s 0
263 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
265 wait_for_port nbi-k8s 1
268 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
270 wait_for_port ng-ui 2
273 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
274 juju expose prometheus-k8s
275 wait_for_port prometheus-k8s 3
278 juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
280 wait_for_port ui-k8s 4
283 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/backend-protocol
=HTTPS
-n osm
-l juju-app
=nbi-k8s
"
284 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -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
=ng-ui
"
286 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ui-k8s
"
289 function check_osm_deployed() {
291 start_time="$
(date -u +%s
)"
292 total_service_count=15
296 service_count=$(juju status | grep kubernetes | grep active | wc -l)
297 echo "$service_count / $total_service_count services active
"
298 if [ $service_count -eq $total_service_count ]; then
301 if [ $service_count -ne $previous_count ]; then
302 previous_count=$service_count
303 start_time="$
(date -u +%s
)"
306 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
307 echo "Timed out waiting
for OSM services to become ready
"
314 function create_overlay() {
316 sudo apt install python3-pip -y
317 python3 -m pip install yq
318 PATH=$PATH:$HOME/.local/bin # make yq command available
319 local HOME=/home/$USER
320 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
321 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
322 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)
323 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)
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 --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert
"]' --raw-output | 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_password: $vca_password
341 vca_pubkey: $vca_pubkey
342 vca_cacert: $vca_cacert
343 vca_cloud: $vca_cloud
344 vca_k8s_cloud: $K8S_CLOUD_NAME
348 vca_password: $vca_password
350 vca_cacert: $vca_cacert
352 mv /tmp/vca-overlay.yaml ~/.osm/
353 OSM_VCA_HOST=$vca_host
356 function generate_images_overlay(){
357 if [ ! -z "$REGISTRY_USERNAME" ] ; then
358 REGISTRY_CREDENTIALS=$(cat <<EOF
360 image_username: $REGISTRY_USERNAME
361 image_password: $REGISTRY_PASSWORD
366 cat << EOF > /tmp/images-overlay.yaml
370 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
373 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
376 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
379 image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
382 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
385 image: ${REGISTRY_URL}opensourcemano/light-ui:$TAG ${REGISTRY_CREDENTIALS}
388 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
391 image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
394 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
396 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
399 function install_osmclient() {
400 sudo snap install osmclient
401 sudo snap alias osmclient.osm osm
405 function install_microstack() {
406 sudo snap install microstack --classic --beta
407 sudo microstack.init --auto
408 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
409 microstack.openstack image create \
411 --disk-format qcow2 \
412 --container-format bare \
413 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
415 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
416 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
417 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s
".address'`
418 osm vim-create --name microstack-site \
420 --password keystone \
421 --auth_url http://10.20.20.1:5000/v3 \
423 --account_type openstack \
424 --config='{security_groups: default,
427 user_domain_name: default,
428 region_name: microstack,
430 availability_zone: nova,
434 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
435 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
443 if [ -v MICROSTACK ]; then
447 OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
449 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
451 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
453 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
455 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
457 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"