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"
22 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
23 PATH
=/snap
/bin
:${PATH}
28 OSM_HA_BUNDLE
=cs
:osm-ha-40
30 function check_arguments
(){
31 while [ $# -gt 0 ] ; do
33 --bundle) BUNDLE
="$2" ;;
34 --k8s) KUBECFG
="$2" ;;
35 --vca) CONTROLLER
="$2" ;;
36 --lxd) LXD_CLOUD
="$2" ;;
37 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
38 --microstack) MICROSTACK
=y
;;
39 --ha) BUNDLE
=$OSM_HA_BUNDLE ;;
41 --registry) REGISTRY_INFO
="$2" ;;
46 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
49 function install_snaps
(){
50 if [ ! -v KUBECFG
]; then
51 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
52 sudo usermod
-a -G microk8s
`whoami`
54 sudo chown
-f -R `whoami` ~
/.kube
56 sg
${KUBEGRP} -c "microk8s status --wait-ready"
57 KUBECONFIG
=~
/.osm
/microk8s-config.yaml
58 sg
${KUBEGRP} -c "microk8s config" > ${KUBECONFIG}
61 sudo snap
install kubectl
--classic
62 export KUBECONFIG
=${KUBECFG}
65 sudo snap
install juju
--classic --channel=2.8/stable
68 function bootstrap_k8s_lxd
(){
69 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
70 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
72 if [ -v BOOTSTRAP_NEEDED
]; then
73 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
74 if [ $CONTROLLER_PRESENT -ge 1 ]; then
76 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
77 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
80 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
82 Please retry the installation once this conflict has been resolved.
87 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
88 if [ $CONTROLLER_PRESENT -le 0 ]; then
90 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
91 that exists, or remove the --vca ${CONTROLLER_NAME} option.
93 Please retry the installation with one of the solutions applied.
99 if [ -v KUBECFG
]; then
100 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
101 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
102 --config controller-service-type
=loadbalancer \
103 --agent-version=$JUJU_AGENT_VERSION
105 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
106 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
107 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
109 start_time="$
(date -u +%s
)"
113 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
114 echo "Microk8s storage failed to
enable"
115 sg ${KUBEGRP} -c "microk8s.status
"
118 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
119 if [[ $storage_status == "enabled
" ]]; then
125 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
126 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
127 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
128 && K8S_CLOUD_NAME=microk8s
131 if [ -v LXD_CLOUD ]; then
132 if [ ! -v LXD_CREDENTIALS ]; then
133 echo "The installer needs the LXD server certificate
if the LXD is external
"
137 LXDENDPOINT=$DEFAULT_IP
138 LXD_CLOUD=~/.osm/lxd-cloud.yaml
139 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
140 # Apply sysctl production values for optimal performance
141 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
144 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
145 sudo snap install lxd
147 sudo usermod -a -G lxd `whoami`
148 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"
149 sg lxd -c "lxd waitready
"
150 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
151 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
152 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
154 cat << EOF > $LXD_CLOUD
158 auth-types: [certificate]
159 endpoint: "https
://$LXDENDPOINT:8443"
161 ssl-hostname-verification: false
163 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
"
164 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
165 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
166 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
168 cat << EOF > $LXD_CREDENTIALS
172 auth-type: certificate
180 lxc config trust add local: ~/.osm/client.crt
183 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
184 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
185 sg lxd -c "lxd waitready
"
186 juju controller-config features=[k8s-operators]
189 function wait_for_port(){
193 start_time="$
(date -u +%s
)"
197 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
198 echo "Failed to expose external
${SERVICE} interface port
"
202 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
209 function deploy_charmed_osm(){
210 if [ -v REGISTRY_INFO ] ; then
211 registry_parts=(${REGISTRY_INFO//@/ })
212 if [ ${#registry_parts[@]} -eq 1 ] ; then
213 # No credentials supplied
216 REGISTRY_URL=${registry_parts[0]}
218 credentials=${registry_parts[0]}
219 credential_parts=(${credentials//:/ })
220 REGISTRY_USERNAME=${credential_parts[0]}
221 REGISTRY_PASSWORD=${credential_parts[1]}
222 REGISTRY_URL=${registry_parts[1]}
224 # Ensure the URL ends with a /
225 case $REGISTRY_URL in
227 *) REGISTRY_URL=${REGISTRY_URL}/
232 echo "Creating OSM model
"
233 if [ -v KUBECFG ]; then
234 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
236 sg ${KUBEGRP} -c "juju add-model
$MODEL_NAME $K8S_CLOUD_NAME"
238 echo "Deploying OSM with charms
"
240 if [ -v REGISTRY_URL ]; then
241 [ ! -v TAG ] && TAG='latest'
243 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
245 if [ -v BUNDLE ]; then
246 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
248 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
251 echo "Waiting
for deployment to finish...
"
253 echo "OSM with charms deployed
"
254 if [ ! -v KUBECFG ]; then
255 API_SERVER=${DEFAULT_IP}
257 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
258 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
259 url="$
(echo ${API_SERVER/$proto/})"
260 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
261 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
262 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
265 # Expose OSM services
267 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.xip.io
268 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.xip.io
271 juju config -m $MODEL_NAME grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
272 juju expose -m $MODEL_NAME grafana-k8s
273 wait_for_port grafana-k8s 0
276 juju config -m $MODEL_NAME prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
277 juju expose -m $MODEL_NAME prometheus-k8s
278 wait_for_port prometheus-k8s 1
281 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ng-ui
"
284 function check_osm_deployed() {
286 start_time="$
(date -u +%s
)"
287 total_service_count=14
291 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
292 echo "$service_count / $total_service_count services active
"
293 if [ $service_count -eq $total_service_count ]; then
296 if [ $service_count -ne $previous_count ]; then
297 previous_count=$service_count
298 start_time="$
(date -u +%s
)"
301 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
302 echo "Timed out waiting
for OSM services to become ready
"
309 function create_overlay() {
312 local HOME=/home/$USER
313 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq r - controllers.$CONTROLLER_NAME.user)
314 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq r - controllers.$CONTROLLER_NAME.password)
315 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.api-endpoints[0] | cut -d ":" -f 1)
316 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.api-endpoints[0] | cut -d ":" -f 2)
317 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
318 local vca_cloud="lxd-cloud
"
319 # Get the VCA Certificate
320 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq r - controllers.$CONTROLLER_NAME.ca-cert | base64 | tr -d \\n)
322 # Calculate the default route of this machine
323 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
325 # Generate a new overlay.yaml, overriding any existing one
326 cat << EOF > /tmp/vca-overlay.yaml
331 vca_password: $vca_password
334 vca_pubkey: $vca_pubkey
335 vca_cacert: $vca_cacert
336 vca_cloud: $vca_cloud
337 vca_k8s_cloud: $K8S_CLOUD_NAME
341 vca_password: $vca_password
343 vca_cacert: $vca_cacert
345 mv /tmp/vca-overlay.yaml ~/.osm/
346 OSM_VCA_HOST=$vca_host
349 function generate_images_overlay(){
350 cat << EOF > /tmp/nbi_registry.yaml
351 registrypath: ${REGISTRY_URL}opensourcemano/nbi:$TAG
353 cat << EOF > /tmp/ng_ui_registry.yaml
354 registrypath: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG
356 if [ ! -z "$REGISTRY_USERNAME" ] ; then
357 REGISTRY_CREDENTIALS=$(cat <<EOF
359 image_username: $REGISTRY_USERNAME
360 image_password: $REGISTRY_PASSWORD
363 echo username: $REGISTRY_USERNAME >> /tmp/nbi_registry.yaml
364 echo password: $REGISTRY_PASSWORD >> /tmp/nbi_registry.yaml
365 echo username: $REGISTRY_USERNAME >> /tmp/ng_ui_registry.yaml
366 echo password: $REGISTRY_PASSWORD >> /tmp/ng_ui_registry.yaml
369 cat << EOF > /tmp/images-overlay.yaml
373 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
376 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
379 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
382 image: /tmp/nbi_registry.yaml
385 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
388 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
391 image: /tmp/ng_ui_registry.yaml
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
404 function add_local_k8scluster() {
405 osm --all-projects vim-create \
406 --name _system-osm-vim \
407 --account_type dummy \
408 --auth_url http://dummy \
409 --user osm --password osm --tenant osm \
410 --description "dummy
" \
411 --config '{management_network_name: mgmt}'
412 tmpfile=$(mktemp --tmpdir=${HOME})
413 cp ${KUBECONFIG} ${tmpfile}
414 osm --all-projects k8scluster-add \
416 --vim _system-osm-vim \
417 --k8s-nets '{"net1
": null}' \
419 --description "OSM Internal Cluster
" \
424 function install_microstack() {
425 sudo snap install microstack --classic --beta
426 sudo microstack.init --auto
427 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
428 microstack.openstack image create \
430 --disk-format qcow2 \
431 --container-format bare \
432 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
434 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
435 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
436 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi
".address'`
437 osm vim-create --name microstack-site \
439 --password keystone \
440 --auth_url http://10.20.20.1:5000/v3 \
442 --account_type openstack \
443 --config='{security_groups: default,
446 user_domain_name: default,
447 region_name: microstack,
449 availability_zone: nova,
453 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
454 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
462 OSM_HOSTNAME=$(juju config nbi site_url | sed "s
/http.
*\?:\
/\
///"):443
465 if [ -v MICROSTACK ]; then
470 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
472 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
474 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
476 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
478 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"