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.
20 JUJU_AGENT_VERSION
=2.8.9
21 K8S_CLOUD_NAME
="k8s-cloud"
22 KUBECTL
="microk8s.kubectl"
24 OSMCLIENT_VERSION
=10.0
25 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
26 PATH
=/snap
/bin
:${PATH}
31 OSM_HA_BUNDLE
=cs
:osm-ha-51
34 function check_arguments
(){
35 while [ $# -gt 0 ] ; do
37 --bundle) BUNDLE
="$2" ;;
38 --overlay) OVERLAY
="$2" ;;
39 --k8s) KUBECFG
="$2" ;;
40 --vca) CONTROLLER
="$2" ;;
41 --lxd) LXD_CLOUD
="$2" ;;
42 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
43 --microstack) MICROSTACK
=y
;;
44 --ha) BUNDLE
=$OSM_HA_BUNDLE ;;
46 --registry) REGISTRY_INFO
="$2" ;;
47 --only-vca) ONLY_VCA
=y
;;
52 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
55 function install_snaps
(){
56 if [ ! -v KUBECFG
]; then
57 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
58 sudo
cat /var
/snap
/microk8s
/current
/args
/kube-apiserver |
grep advertise-address ||
(
59 echo "--advertise-address $DEFAULT_IP" | sudo
tee -a /var
/snap
/microk8s
/current
/args
/kube-apiserver
63 sudo usermod
-a -G microk8s
`whoami`
65 sudo chown
-f -R `whoami` ~
/.kube
67 sg
${KUBEGRP} -c "microk8s status --wait-ready"
68 KUBECONFIG
=~
/.osm
/microk8s-config.yaml
69 sg
${KUBEGRP} -c "microk8s config" |
tee ${KUBECONFIG}
72 sudo snap
install kubectl
--classic
73 export KUBECONFIG
=${KUBECFG}
76 sudo snap
install juju
--classic --channel=$JUJU_VERSION/stable
79 function bootstrap_k8s_lxd
(){
80 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
81 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
83 if [ -v BOOTSTRAP_NEEDED
]; then
84 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
85 if [ $CONTROLLER_PRESENT -ge 1 ]; then
87 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
88 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
91 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
93 Please retry the installation once this conflict has been resolved.
98 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
99 if [ $CONTROLLER_PRESENT -le 0 ]; then
101 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
102 that exists, or remove the --vca ${CONTROLLER_NAME} option.
104 Please retry the installation with one of the solutions applied.
110 if [ -v KUBECFG
]; then
111 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
112 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
113 --config controller-service-type
=loadbalancer \
114 --agent-version=$JUJU_AGENT_VERSION
116 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
117 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
118 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
120 start_time="$
(date -u +%s
)"
124 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
125 echo "Microk8s storage failed to
enable"
126 sg ${KUBEGRP} -c "microk8s.status
"
129 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
130 if [[ $storage_status == "enabled
" ]]; then
136 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
137 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
138 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
139 && K8S_CLOUD_NAME=microk8s
142 if [ -v LXD_CLOUD ]; then
143 if [ ! -v LXD_CREDENTIALS ]; then
144 echo "The installer needs the LXD server certificate
if the LXD is external
"
148 LXDENDPOINT=$DEFAULT_IP
149 LXD_CLOUD=~/.osm/lxd-cloud.yaml
150 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
151 # Apply sysctl production values for optimal performance
152 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
155 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
156 sudo snap install lxd --channel $LXD_VERSION/stable
158 sudo usermod -a -G lxd `whoami`
159 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"
160 sg lxd -c "lxd waitready
"
161 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
162 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
163 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
165 cat << EOF > $LXD_CLOUD
169 auth-types: [certificate]
170 endpoint: "https
://$LXDENDPOINT:8443"
172 ssl-hostname-verification: false
174 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
"
175 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
176 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
177 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
179 cat << EOF > $LXD_CREDENTIALS
183 auth-type: certificate
191 lxc config trust add local: ~/.osm/client.crt
194 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
195 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
196 sg lxd -c "lxd waitready
"
197 juju controller-config features=[k8s-operators]
200 function wait_for_port(){
204 start_time="$
(date -u +%s
)"
208 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
209 echo "Failed to expose external
${SERVICE} interface port
"
213 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
220 function deploy_charmed_osm(){
221 if [ -v REGISTRY_INFO ] ; then
222 registry_parts=(${REGISTRY_INFO//@/ })
223 if [ ${#registry_parts[@]} -eq 1 ] ; then
224 # No credentials supplied
227 REGISTRY_URL=${registry_parts[0]}
229 credentials=${registry_parts[0]}
230 credential_parts=(${credentials//:/ })
231 REGISTRY_USERNAME=${credential_parts[0]}
232 REGISTRY_PASSWORD=${credential_parts[1]}
233 REGISTRY_URL=${registry_parts[1]}
235 # Ensure the URL ends with a /
236 case $REGISTRY_URL in
238 *) REGISTRY_URL=${REGISTRY_URL}/
242 echo "Creating OSM model
"
243 if [ -v KUBECFG ]; then
244 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
246 sg ${KUBEGRP} -c "juju add-model
$MODEL_NAME $K8S_CLOUD_NAME"
248 echo "Deploying OSM with charms
"
250 if [ -v REGISTRY_URL ]; then
251 [ ! -v TAG ] && TAG='latest'
253 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
255 if [ -v OVERLAY ]; then
256 extra_overlay="--overlay $OVERLAY"
259 if [ -v BUNDLE ]; then
260 juju deploy -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
262 juju deploy -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay
265 if [ ! -v KUBECFG ]; then
266 API_SERVER=${DEFAULT_IP}
268 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
269 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
270 url="$
(echo ${API_SERVER/$proto/})"
271 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
272 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
273 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
275 # Expose OSM services
276 juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io
277 juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io
278 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
279 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
281 echo "Waiting
for deployment to finish...
"
283 echo "OSM with charms deployed
"
286 function check_osm_deployed() {
288 start_time="$
(date -u +%s
)"
289 total_service_count=14
293 service_count=$(juju status -m $MODEL_NAME | grep kubernetes | grep active | wc -l)
294 echo "$service_count / $total_service_count services active
"
295 if [ $service_count -eq $total_service_count ]; then
298 if [ $service_count -ne $previous_count ]; then
299 previous_count=$service_count
300 start_time="$
(date -u +%s
)"
303 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
304 echo "Timed out waiting
for OSM services to become ready
"
311 function create_overlay() {
314 local HOME=/home/$USER
315 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
316 local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
317 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
318 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
319 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
320 local vca_cloud="lxd-cloud
"
321 # Get the VCA Certificate
322 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
324 # Calculate the default route of this machine
325 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
327 # Generate a new overlay.yaml, overriding any existing one
328 cat << EOF > /tmp/vca-overlay.yaml
333 vca_secret: $vca_secret
336 vca_pubkey: $vca_pubkey
337 vca_cacert: $vca_cacert
338 vca_cloud: $vca_cloud
339 vca_k8s_cloud: $K8S_CLOUD_NAME
343 vca_secret: $vca_secret
345 vca_cacert: $vca_cacert
347 mv /tmp/vca-overlay.yaml ~/.osm/
348 OSM_VCA_HOST=$vca_host
351 function generate_images_overlay(){
352 echo "applications
:" > /tmp/images-overlay.yaml
354 charms_with_resources="nbi lcm mon pol ng-ui ro pla keystone
"
355 for charm in $charms_with_resources; do
356 cat << EOF > /tmp/${charm}_registry.yaml
357 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
359 if [ ! -z "$REGISTRY_USERNAME" ] ; then
360 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
361 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
364 cat << EOF >> /tmp/images-overlay.yaml
367 image: /tmp/${charm}_registry.yaml
372 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
375 function refresh_osmclient_snap() {
376 osmclient_snap_install_refresh refresh
379 function install_osm_client_snap() {
380 osmclient_snap_install_refresh install
383 function osmclient_snap_install_refresh() {
384 channel_preference="stable candidate beta edge
"
385 for channel in $channel_preference; do
386 echo "Trying to
install osmclient from channel
$OSMCLIENT_VERSION/$channel"
387 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
390 function install_osmclient() {
391 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
394 function add_local_k8scluster() {
395 osm --all-projects vim-create \
396 --name _system-osm-vim \
397 --account_type dummy \
398 --auth_url http://dummy \
399 --user osm --password osm --tenant osm \
400 --description "dummy
" \
401 --config '{management_network_name: mgmt}'
402 tmpfile=$(mktemp --tmpdir=${HOME})
403 cp ${KUBECONFIG} ${tmpfile}
404 osm --all-projects k8scluster-add \
406 --vim _system-osm-vim \
407 --k8s-nets '{"net1
": null}' \
409 --description "OSM Internal Cluster
" \
414 function install_microstack() {
415 sudo snap install microstack --classic --beta
416 sudo microstack.init --auto
417 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
418 microstack.openstack image create \
420 --disk-format qcow2 \
421 --container-format bare \
422 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
424 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
425 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
426 export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi
".address'`
427 osm vim-create --name microstack-site \
429 --password keystone \
430 --auth_url http://10.20.20.1:5000/v3 \
432 --account_type openstack \
433 --config='{security_groups: default,
436 user_domain_name: default,
437 region_name: microstack,
439 availability_zone: nova,
443 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
444 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
451 if [ -v ONLY_VCA ]; then
453 vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - )
454 vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - )
455 vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1)
456 vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2)
457 vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
458 vca_cloud="lxd-cloud
"
459 vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n)
460 hostname=`cat /etc/hostname`
462 echo "Use the following
command to register the installed VCA to your OSM
:"
463 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"
467 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s
/http.
*\?:\
/\
///"):443
470 if [ -v MICROSTACK ]; then
474 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
476 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
478 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
480 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
482 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"