Feature 10966 Prometheus recording rules for VNF and NS status
[osm/devops.git] / installers / install_lxd.sh
1 #!/bin/bash
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 #
15
16 set +eux
17
18 function usage(){
19 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
20 echo -e "usage: $0 [OPTIONS]"
21 echo -e "Install Juju for OSM"
22 echo -e " OPTIONS"
23 echo -e " -h / --help: print this help"
24 echo -e " -D <devops path> use local devops installation path"
25 echo -e " -H <VCA host> use specific juju host controller IP"
26 echo -e " -S <VCA secret> use VCA/juju secret key"
27 echo -e " -P <VCA pubkey> use VCA/juju public key file"
28 echo -e " -l: LXD cloud yaml file"
29 echo -e " -L: LXD credentials yaml file"
30 echo -e " -K: Specifies the name of the controller to use - The controller must be already bootstrapped"
31 echo -e " --debug: debug mode"
32 echo -e " --cachelxdimages: cache local lxd images, create cronjob for that cache (will make installation longer)"
33 echo -e " --nojuju: do not juju, assumes already installed"
34 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
35 }
36
37 function install_lxd() {
38 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
39 # Apply sysctl production values for optimal performance
40 sudo cp ${OSM_DEVOPS}/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
41 sudo sysctl --system
42
43 # Install LXD snap
44 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
45 snap info lxd | grep installed > /dev/null
46 if [ $? -eq 0 ]; then
47 sudo snap refresh lxd --channel $LXD_VERSION/stable
48 else
49 sudo snap install lxd --channel $LXD_VERSION/stable
50 fi
51
52 # Configure LXD
53 sudo usermod -a -G lxd `whoami`
54 cat ${OSM_DEVOPS}/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$DEFAULT_IP':8443/' | sg lxd -c "lxd init --preseed"
55 sg lxd -c "lxd waitready"
56 DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}')
57 [ -z "$DEFAULT_IF" ] && DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}')
58 [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
59 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
60 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
61 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
62 # sudo systemctl stop lxd-bridge
63 # sudo systemctl --system daemon-reload
64 # sudo systemctl enable lxd-bridge
65 # sudo systemctl start lxd-bridge
66 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
67 }
68
69 DEBUG_INSTALL=""
70 LXD_VERSION=5.0
71 OSM_DEVOPS=
72
73 # main
74 while getopts ":D:d:i:-: h" o; do
75 case "${o}" in
76 i)
77 DEFAULT_IP="${OPTARG}"
78 ;;
79 d)
80 OSM_DOCKER_WORK_DIR="${OPTARG}"
81 ;;
82 D)
83 OSM_DEVOPS="${OPTARG}"
84 ;;
85 -)
86 [ "${OPTARG}" == "help" ] && usage && exit 0
87 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
88 echo -e "Invalid option: '--$OPTARG'\n" >&2
89 exit 1
90 ;;
91 :)
92 echo "Option -$OPTARG requires an argument" >&2
93 exit 1
94 ;;
95 \?)
96 echo -e "Invalid option: '-$OPTARG'\n" >&2
97 exit 1
98 ;;
99 h)
100 usage && exit 0
101 ;;
102 *)
103 exit 1
104 ;;
105 esac
106 done
107
108 source $OSM_DEVOPS/common/logging
109 source $OSM_DEVOPS/common/track
110
111 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
112 echo "DEFAULT_IP=$DEFAULT_IP"
113 echo "OSM_DEVOPS=$OSM_DEVOPS"
114
115 [ -z "$INSTALL_NOJUJU" ] && install_lxd
116 track juju juju_install_ok
117