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.9
19 K8S_CLOUD_NAME
="k8s-cloud"
20 KUBECTL
="microk8s.kubectl"
23 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
24 PATH
=/snap
/bin
:${PATH}
29 OSM_HA_BUNDLE
=cs
:osm-ha-46
32 function check_arguments
(){
33 while [ $# -gt 0 ] ; do
35 --bundle) BUNDLE
="$2" ;;
36 --k8s) KUBECFG
="$2" ;;
37 --vca) CONTROLLER
="$2" ;;
38 --lxd) LXD_CLOUD
="$2" ;;
39 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
40 --microstack) MICROSTACK
=y
;;
41 --ha) BUNDLE
=$OSM_HA_BUNDLE ;;
43 --registry) REGISTRY_INFO
="$2" ;;
44 --only-vca) ONLY_VCA
=y
;;
49 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
52 function install_snaps
(){
53 if [ ! -v KUBECFG
]; then
54 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
55 sudo
cat /var
/snap
/microk8s
/current
/args
/kube-apiserver |
grep advertise-address ||
(
56 echo "--advertise-address $DEFAULT_IP" | sudo
tee -a /var
/snap
/microk8s
/current
/args
/kube-apiserver
60 sudo usermod
-a -G microk8s
`whoami`
62 sudo chown
-f -R `whoami` ~
/.kube
64 sg
${KUBEGRP} -c "microk8s status --wait-ready"
65 KUBECONFIG
=~
/.osm
/microk8s-config.yaml
66 sg
${KUBEGRP} -c "microk8s config" |
tee ${KUBECONFIG}
69 sudo snap
install kubectl
--classic
70 export KUBECONFIG
=${KUBECFG}
73 sudo snap
install juju
--classic --channel=2.8/stable
76 function bootstrap_k8s_lxd
(){
77 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
78 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
80 if [ -v BOOTSTRAP_NEEDED
]; then
81 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
82 if [ $CONTROLLER_PRESENT -ge 1 ]; then
84 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
85 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
88 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
90 Please retry the installation once this conflict has been resolved.
95 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
96 if [ $CONTROLLER_PRESENT -le 0 ]; then
98 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
99 that exists, or remove the --vca ${CONTROLLER_NAME} option.
101 Please retry the installation with one of the solutions applied.
107 if [ -v KUBECFG
]; then
108 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
109 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
110 --config controller-service-type
=loadbalancer \
111 --agent-version=$JUJU_AGENT_VERSION
113 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
114 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
115 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
117 start_time="$
(date -u +%s
)"
121 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
122 echo "Microk8s storage failed to
enable"
123 sg ${KUBEGRP} -c "microk8s.status
"
126 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
127 if [[ $storage_status == "enabled
" ]]; then
133 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
134 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
135 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
136 && K8S_CLOUD_NAME=microk8s
139 if [ -v LXD_CLOUD ]; then
140 if [ ! -v LXD_CREDENTIALS ]; then
141 echo "The installer needs the LXD server certificate
if the LXD is external
"
145 LXDENDPOINT=$DEFAULT_IP
146 LXD_CLOUD=~/.osm/lxd-cloud.yaml
147 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
148 # Apply sysctl production values for optimal performance
149 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
152 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
153 sudo snap install lxd
155 sudo usermod -a -G lxd `whoami`
156 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"
157 sg lxd -c "lxd waitready
"
158 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
159 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
160 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
162 cat << EOF > $LXD_CLOUD
166 auth-types: [certificate]
167 endpoint: "https
://$LXDENDPOINT:8443"
169 ssl-hostname-verification: false
171 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
"
172 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
173 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
174 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
176 cat << EOF > $LXD_CREDENTIALS
180 auth-type: certificate
188 lxc config trust add local: ~/.osm/client.crt
191 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
192 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
193 sg lxd -c "lxd waitready
"
194 juju controller-config features=[k8s-operators]
197 function wait_for_port(){
201 start_time="$
(date -u +%s
)"
205 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
206 echo "Failed to expose external
${SERVICE} interface port
"
210 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
217 function deploy_charmed_osm(){
218 if [ -v REGISTRY_INFO ] ; then
219 registry_parts=(${REGISTRY_INFO//@/ })
220 if [ ${#registry_parts[@]} -eq 1 ] ; then
221 # No credentials supplied
224 REGISTRY_URL=${registry_parts[0]}
226 credentials=${registry_parts[0]}
227 credential_parts=(${credentials//:/ })
228 REGISTRY_USERNAME=${credential_parts[0]}
229 REGISTRY_PASSWORD=${credential_parts[1]}
230 REGISTRY_URL=${registry_parts[1]}
232 # Ensure the URL ends with a /
233 case $REGISTRY_URL in
235 *) REGISTRY_URL=${REGISTRY_URL}/
239 echo "Creating OSM model
"
240 if [ -v KUBECFG ]; then
241 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
243 sg ${KUBEGRP} -c "juju add-model
$MODEL_NAME $K8S_CLOUD_NAME"
245 echo "Deploying OSM with charms
"
247 if [ -v REGISTRY_URL ]; then
248 [ ! -v TAG ] && TAG='latest'
250 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
252 if [ -v BUNDLE ]; then
253 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
255 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
258 if [ ! -v KUBECFG ]; then
259 API_SERVER=${DEFAULT_IP}
261 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
262 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
263 url="$
(echo ${API_SERVER/$proto/})"
264 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
265 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
266 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
268 # Expose OSM services
269 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
270 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
271 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
272 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
274 echo "Waiting
for deployment to finish...
"
276 echo "OSM with charms deployed
"
279 function check_osm_deployed() {
281 start_time="$
(date -u +%s
)"
282 total_service_count=14
286 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
287 echo "$service_count / $total_service_count services active
"
288 if [ $service_count -eq $total_service_count ]; then
291 if [ $service_count -ne $previous_count ]; then
292 previous_count=$service_count
293 start_time="$
(date -u +%s
)"
296 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
297 echo "Timed out waiting
for OSM services to become ready
"
304 function create_overlay() {
307 local HOME=/home/$USER
308 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
309 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
310 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
311 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
312 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
313 local vca_cloud="lxd-cloud
"
314 # Get the VCA Certificate
315 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
317 # Calculate the default route of this machine
318 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
320 # Generate a new overlay.yaml, overriding any existing one
321 cat << EOF > /tmp/vca-overlay.yaml
326 vca_secret: $vca_secret
329 vca_pubkey: $vca_pubkey
330 vca_cacert: $vca_cacert
331 vca_cloud: $vca_cloud
332 vca_k8s_cloud: $K8S_CLOUD_NAME
336 vca_secret: $vca_secret
338 vca_cacert: $vca_cacert
340 mv /tmp/vca-overlay.yaml ~/.osm/
341 OSM_VCA_HOST=$vca_host
344 function generate_images_overlay(){
345 echo "applications
:" > /tmp/images-overlay.yaml
347 charms_with_resources="nbi lcm mon pol ng-ui ro pla keystone
"
348 for charm in $charms_with_resources; do
349 cat << EOF > /tmp/${charm}_registry.yaml
350 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
352 if [ ! -z "$REGISTRY_USERNAME" ] ; then
353 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
354 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
357 cat << EOF >> /tmp/images-overlay.yaml
360 image: /tmp/${charm}_registry.yaml
365 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
368 function refresh_osmclient_snap() {
369 osmclient_snap_install_refresh refresh
372 function install_osm_client_snap() {
373 osmclient_snap_install_refresh install
376 function osmclient_snap_install_refresh() {
377 channel_preference="stable candidate beta edge
"
378 for channel in $channel_preference; do
379 echo "Trying to
install osmclient from channel
$OSMCLIENT_VERSION/$channel"
380 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
383 function install_osmclient() {
384 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
387 function add_local_k8scluster() {
388 osm --all-projects vim-create \
389 --name _system-osm-vim \
390 --account_type dummy \
391 --auth_url http://dummy \
392 --user osm --password osm --tenant osm \
393 --description "dummy
" \
394 --config '{management_network_name: mgmt}'
395 tmpfile=$(mktemp --tmpdir=${HOME})
396 cp ${KUBECONFIG} ${tmpfile}
397 osm --all-projects k8scluster-add \
399 --vim _system-osm-vim \
400 --k8s-nets '{"net1
": null}' \
402 --description "OSM Internal Cluster
" \
407 function install_microstack() {
408 sudo snap install microstack --classic --beta
409 sudo microstack.init --auto
410 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
411 microstack.openstack image create \
413 --disk-format qcow2 \
414 --container-format bare \
415 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
417 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
418 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
419 export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi
".address'`
420 osm vim-create --name microstack-site \
422 --password keystone \
423 --auth_url http://10.20.20.1:5000/v3 \
425 --account_type openstack \
426 --config='{security_groups: default,
429 user_domain_name: default,
430 region_name: microstack,
432 availability_zone: nova,
436 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
437 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
444 if [ -v ONLY_VCA ]; then
446 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
447 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
448 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
449 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
450 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
451 vca_cloud="lxd-cloud
"
452 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
453 hostname=`cat /etc/hostname`
455 echo "Use the following
command to register the installed VCA to your OSM
:"
456 echo -e " osm vca-add
--endpoints $vca_host:$vca_port \
\n --user $vca_user \
\n --secret $vca_secret \
\n --cacert $vca_cacert \
\n --lxd-cloud lxd-cloud \
\n --lxd-credentials lxd-cloud \
\n --k8s-cloud microk8s \
\n --k8s-credentials microk8s\
\n $hostname-vca"
460 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s
/http.
*\?:\
/\
///"):443
463 if [ -v MICROSTACK ]; then
467 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
469 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
471 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
473 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
475 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"