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"
22 OSMCLIENT_VERSION
=10.0
23 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
24 PATH
=/snap
/bin
:${PATH}
29 OSM_HA_BUNDLE
=cs
:osm-ha-51
32 function check_arguments
(){
33 while [ $# -gt 0 ] ; do
35 --bundle) BUNDLE
="$2" ;;
36 --overlay) OVERLAY
="$2" ;;
37 --k8s) KUBECFG
="$2" ;;
38 --vca) CONTROLLER
="$2" ;;
39 --lxd) LXD_CLOUD
="$2" ;;
40 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
41 --microstack) MICROSTACK
=y
;;
42 --ha) BUNDLE
=$OSM_HA_BUNDLE ;;
44 --registry) REGISTRY_INFO
="$2" ;;
45 --only-vca) ONLY_VCA
=y
;;
50 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
53 function install_snaps
(){
54 if [ ! -v KUBECFG
]; then
55 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
56 sudo
cat /var
/snap
/microk8s
/current
/args
/kube-apiserver |
grep advertise-address ||
(
57 echo "--advertise-address $DEFAULT_IP" | sudo
tee -a /var
/snap
/microk8s
/current
/args
/kube-apiserver
61 sudo usermod
-a -G microk8s
`whoami`
63 sudo chown
-f -R `whoami` ~
/.kube
65 sg
${KUBEGRP} -c "microk8s status --wait-ready"
66 KUBECONFIG
=~
/.osm
/microk8s-config.yaml
67 sg
${KUBEGRP} -c "microk8s config" |
tee ${KUBECONFIG}
70 sudo snap
install kubectl
--classic
71 export KUBECONFIG
=${KUBECFG}
74 sudo snap
install juju
--classic --channel=2.8/stable
77 function bootstrap_k8s_lxd
(){
78 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
79 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
81 if [ -v BOOTSTRAP_NEEDED
]; then
82 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
83 if [ $CONTROLLER_PRESENT -ge 1 ]; then
85 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
86 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
89 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
91 Please retry the installation once this conflict has been resolved.
96 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
97 if [ $CONTROLLER_PRESENT -le 0 ]; then
99 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
100 that exists, or remove the --vca ${CONTROLLER_NAME} option.
102 Please retry the installation with one of the solutions applied.
108 if [ -v KUBECFG
]; then
109 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
110 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
111 --config controller-service-type
=loadbalancer \
112 --agent-version=$JUJU_AGENT_VERSION
114 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
115 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
116 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
118 start_time="$
(date -u +%s
)"
122 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
123 echo "Microk8s storage failed to
enable"
124 sg ${KUBEGRP} -c "microk8s.status
"
127 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
128 if [[ $storage_status == "enabled
" ]]; then
134 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
135 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
136 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
137 && K8S_CLOUD_NAME=microk8s
140 if [ -v LXD_CLOUD ]; then
141 if [ ! -v LXD_CREDENTIALS ]; then
142 echo "The installer needs the LXD server certificate
if the LXD is external
"
146 LXDENDPOINT=$DEFAULT_IP
147 LXD_CLOUD=~/.osm/lxd-cloud.yaml
148 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
149 # Apply sysctl production values for optimal performance
150 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
153 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
154 sudo snap install lxd
156 sudo usermod -a -G lxd `whoami`
157 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"
158 sg lxd -c "lxd waitready
"
159 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
160 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
161 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
163 cat << EOF > $LXD_CLOUD
167 auth-types: [certificate]
168 endpoint: "https
://$LXDENDPOINT:8443"
170 ssl-hostname-verification: false
172 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
"
173 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
174 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
175 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
177 cat << EOF > $LXD_CREDENTIALS
181 auth-type: certificate
189 lxc config trust add local: ~/.osm/client.crt
192 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
193 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
194 sg lxd -c "lxd waitready
"
195 juju controller-config features=[k8s-operators]
198 function wait_for_port(){
202 start_time="$
(date -u +%s
)"
206 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
207 echo "Failed to expose external
${SERVICE} interface port
"
211 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
218 function deploy_charmed_osm(){
219 if [ -v REGISTRY_INFO ] ; then
220 registry_parts=(${REGISTRY_INFO//@/ })
221 if [ ${#registry_parts[@]} -eq 1 ] ; then
222 # No credentials supplied
225 REGISTRY_URL=${registry_parts[0]}
227 credentials=${registry_parts[0]}
228 credential_parts=(${credentials//:/ })
229 REGISTRY_USERNAME=${credential_parts[0]}
230 REGISTRY_PASSWORD=${credential_parts[1]}
231 REGISTRY_URL=${registry_parts[1]}
233 # Ensure the URL ends with a /
234 case $REGISTRY_URL in
236 *) REGISTRY_URL=${REGISTRY_URL}/
240 echo "Creating OSM model
"
241 if [ -v KUBECFG ]; then
242 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
244 sg ${KUBEGRP} -c "juju add-model
$MODEL_NAME $K8S_CLOUD_NAME"
246 echo "Deploying OSM with charms
"
248 if [ -v REGISTRY_URL ]; then
249 [ ! -v TAG ] && TAG='latest'
251 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
253 if [ -v OVERLAY ]; then
254 extra_overlay="--overlay $OVERLAY"
257 if [ -v BUNDLE ]; then
258 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
260 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
263 if [ ! -v KUBECFG ]; then
264 API_SERVER=${DEFAULT_IP}
266 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
267 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
268 url="$
(echo ${API_SERVER/$proto/})"
269 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
270 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
271 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
273 # Expose OSM services
274 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
275 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
276 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
277 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
279 echo "Waiting
for deployment to finish...
"
281 echo "OSM with charms deployed
"
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 e .controllers.$CONTROLLER_NAME.user - )
314 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
315 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
316 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .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 e .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_secret: $vca_secret
334 vca_pubkey: $vca_pubkey
335 vca_cacert: $vca_cacert
336 vca_cloud: $vca_cloud
337 vca_k8s_cloud: $K8S_CLOUD_NAME
341 vca_secret: $vca_secret
343 vca_cacert: $vca_cacert
345 mv /tmp/vca-overlay.yaml ~/.osm/
346 OSM_VCA_HOST=$vca_host
349 function generate_images_overlay(){
350 echo "applications
:" > /tmp/images-overlay.yaml
352 charms_with_resources="nbi lcm mon pol ng-ui ro pla keystone
"
353 for charm in $charms_with_resources; do
354 cat << EOF > /tmp/${charm}_registry.yaml
355 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
357 if [ ! -z "$REGISTRY_USERNAME" ] ; then
358 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
359 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
362 cat << EOF >> /tmp/images-overlay.yaml
365 image: /tmp/${charm}_registry.yaml
370 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
373 function refresh_osmclient_snap() {
374 osmclient_snap_install_refresh refresh
377 function install_osm_client_snap() {
378 osmclient_snap_install_refresh install
381 function osmclient_snap_install_refresh() {
382 channel_preference="stable candidate beta edge
"
383 for channel in $channel_preference; do
384 echo "Trying to
install osmclient from channel
$OSMCLIENT_VERSION/$channel"
385 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
388 function install_osmclient() {
389 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
392 function add_local_k8scluster() {
393 osm --all-projects vim-create \
394 --name _system-osm-vim \
395 --account_type dummy \
396 --auth_url http://dummy \
397 --user osm --password osm --tenant osm \
398 --description "dummy
" \
399 --config '{management_network_name: mgmt}'
400 tmpfile=$(mktemp --tmpdir=${HOME})
401 cp ${KUBECONFIG} ${tmpfile}
402 osm --all-projects k8scluster-add \
404 --vim _system-osm-vim \
405 --k8s-nets '{"net1
": null}' \
407 --description "OSM Internal Cluster
" \
412 function install_microstack() {
413 sudo snap install microstack --classic --beta
414 sudo microstack.init --auto
415 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
416 microstack.openstack image create \
418 --disk-format qcow2 \
419 --container-format bare \
420 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
422 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
423 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
424 export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi
".address'`
425 osm vim-create --name microstack-site \
427 --password keystone \
428 --auth_url http://10.20.20.1:5000/v3 \
430 --account_type openstack \
431 --config='{security_groups: default,
434 user_domain_name: default,
435 region_name: microstack,
437 availability_zone: nova,
441 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
442 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
449 if [ -v ONLY_VCA ]; then
451 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
452 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
453 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
454 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
455 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
456 vca_cloud="lxd-cloud
"
457 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
458 hostname=`cat /etc/hostname`
460 echo "Use the following
command to register the installed VCA to your OSM
:"
461 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"
465 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s
/http.
*\?:\
/\
///"):443
468 if [ -v MICROSTACK ]; then
472 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
474 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
476 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
478 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
480 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"