Update iptables during osm installation only if LXD is installed
[osm/devops.git] / installers / full_install_osm.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 function usage(){
17 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
18 echo -e "usage: $0 [OPTIONS]"
19 echo -e "Install OSM"
20 echo -e " OPTIONS"
21 echo -e " -h / --help: print this help"
22 echo -e " -y: do not prompt for confirmation, assumes yes"
23 echo -e " -r <repo>: use specified repository name for osm packages"
24 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
25 echo -e " -u <repo base>: use specified repository url for osm packages"
26 echo -e " -k <repo key>: use specified repository public key url"
27 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
28 echo -e " -b master (main dev branch)"
29 echo -e " -b v2.0 (v2.0 branch)"
30 echo -e " -b tags/v1.1.0 (a specific tag)"
31 echo -e " ..."
32 echo -e " -a <apt proxy url>: use this apt proxy url when downloading apt packages (air-gapped installation)"
33 echo -e " -s <namespace> namespace when installed using k8s, default is osm"
34 echo -e " -H <VCA host> use specific juju host controller IP"
35 echo -e " -S <VCA secret> use VCA/juju secret key"
36 echo -e " -P <VCA pubkey> use VCA/juju public key file"
37 echo -e " -A <VCA apiproxy> use VCA/juju API proxy"
38 echo -e " --pla: install the PLA module for placement support"
39 echo -e " --old-sa: install old Service Assurance framework (MON, POL); do not install Airflow and Pushgateway"
40 echo -e " --ng-sa: install new Service Assurance framework (Airflow, AlertManager and Pushgateway) (enabled by default)"
41 echo -e " -m <MODULE>: install OSM but only rebuild or pull the specified docker images (NG-UI, NBI, LCM, RO, MON, POL, PLA, KAFKA, MONGO, PROMETHEUS, PROMETHEUS-CADVISOR, KEYSTONE-DB, NONE)"
42 echo -e " -o <ADDON>: ONLY (un)installs one of the addons (k8s_monitor, ng-sa)"
43 echo -e " -O <openrc file path/cloud name>: Install OSM to an OpenStack infrastructure. <openrc file/cloud name> is required. If a <cloud name> is used, the clouds.yaml file should be under ~/.config/openstack/ or /etc/openstack/"
44 echo -e " -N <openstack public network name/ID>: Public network name required to setup OSM to OpenStack"
45 echo -e " -f <path to SSH public key>: Public SSH key to use to deploy OSM to OpenStack"
46 echo -e " -F <path to cloud-init file>: Cloud-Init userdata file to deploy OSM to OpenStack"
47 echo -e " -D <devops path> use local devops installation path"
48 echo -e " -w <work dir> Location to store runtime installation"
49 echo -e " -t <docker tag> specify osm docker tag (default is latest)"
50 echo -e " -l: LXD cloud yaml file"
51 echo -e " -L: LXD credentials yaml file"
52 echo -e " -K: Specifies the name of the controller to use - The controller must be already bootstrapped"
53 echo -e " -d <docker registry URL> use docker registry URL instead of dockerhub"
54 echo -e " -p <docker proxy URL> set docker proxy URL as part of docker CE configuration"
55 echo -e " -T <docker tag> specify docker tag for the modules specified with option -m"
56 echo -e " --debug: debug mode"
57 echo -e " --nocachelxdimages: do not cache local lxd images, do not create cronjob for that cache (will save installation time, might affect instantiation time)"
58 echo -e " --cachelxdimages: cache local lxd images, create cronjob for that cache (will make installation longer)"
59 echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
60 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
61 echo -e " --nojuju: do not juju, assumes already installed"
62 echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)"
63 echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)"
64 echo -e " --nohostclient: do not install the osmclient"
65 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
66 echo -e " --source: install OSM from source code using the latest stable tag"
67 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
68 echo -e " --pullimages: pull/run osm images from docker.io/opensourcemano"
69 echo -e " --k8s_monitor: install the OSM kubernetes monitoring with prometheus and grafana"
70 echo -e " --volume: create a VM volume when installing to OpenStack"
71 echo -e " --showopts: print chosen options and exit (only for debugging)"
72 echo -e " --charmed: Deploy and operate OSM with Charms on k8s"
73 echo -e " [--bundle <bundle path>]: Specify with which bundle to deploy OSM with charms (--charmed option)"
74 echo -e " [--k8s <kubeconfig path>]: Specify with which kubernetes to deploy OSM with charms (--charmed option)"
75 echo -e " [--vca <name>]: Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)"
76 echo -e " [--small-profile]: Do not install and configure LXD which aims to use only K8s Clouds (--charmed option)"
77 echo -e " [--lxd <yaml path>]: Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)"
78 echo -e " [--lxd-cred <yaml path>]: Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
79 echo -e " [--microstack]: Installs microstack as a vim. (--charmed option)"
80 echo -e " [--overlay]: Add an overlay to override some defaults of the default bundle (--charmed option)"
81 echo -e " [--ha]: Installs High Availability bundle. (--charmed option)"
82 echo -e " [--tag]: Docker image tag. (--charmed option)"
83 echo -e " [--registry]: Docker registry with optional credentials as user:pass@hostname:port (--charmed option)"
84 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
85 }
86
87 # takes a juju/accounts.yaml file and returns the password specific
88 # for a controller. I wrote this using only bash tools to minimize
89 # additions of other packages
90 function parse_juju_password {
91 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
92 password_file="${HOME}/.local/share/juju/accounts.yaml"
93 local controller_name=$1
94 local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
95 sed -ne "s|^\($s\):|\1|" \
96 -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
97 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
98 awk -F$fs -v controller=$controller_name '{
99 indent = length($1)/2;
100 vname[indent] = $2;
101 for (i in vname) {if (i > indent) {delete vname[i]}}
102 if (length($3) > 0) {
103 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
104 if (match(vn,controller) && match($2,"password")) {
105 printf("%s",$3);
106 }
107 }
108 }'
109 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
110 }
111
112 function set_vca_variables() {
113 OSM_VCA_CLOUDNAME="lxd-cloud"
114 [ -n "$OSM_VCA_HOST" ] && OSM_VCA_CLOUDNAME="localhost"
115 if [ -z "$OSM_VCA_HOST" ]; then
116 [ -z "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_NAMESPACE"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
117 [ -n "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`juju show-controller $CONTROLLER_NAME |grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
118 [ -z "$OSM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
119 fi
120 if [ -z "$OSM_VCA_SECRET" ]; then
121 [ -z "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $OSM_NAMESPACE)
122 [ -n "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $CONTROLLER_NAME)
123 [ -z "$OSM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
124 fi
125 if [ -z "$OSM_VCA_PUBKEY" ]; then
126 OSM_VCA_PUBKEY=$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)
127 [ -z "$OSM_VCA_PUBKEY" ] && FATAL "Cannot obtain juju public key"
128 fi
129 if [ -z "$OSM_VCA_CACERT" ]; then
130 [ -z "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $OSM_NAMESPACE '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
131 [ -n "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $CONTROLLER_NAME '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
132 [ -z "$OSM_VCA_CACERT" ] && FATAL "Cannot obtain juju CA certificate"
133 fi
134 }
135
136 function generate_secret() {
137 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
138 head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
139 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
140 }
141
142 function check_packages() {
143 NEEDED_PACKAGES="$1"
144 echo -e "Checking required packages: ${NEEDED_PACKAGES}"
145 for PACKAGE in ${NEEDED_PACKAGES} ; do
146 dpkg -L ${PACKAGE}
147 if [ $? -ne 0 ]; then
148 echo -e "Package ${PACKAGE} is not installed."
149 echo -e "Updating apt-cache ..."
150 sudo apt-get update
151 echo -e "Installing ${PACKAGE} ..."
152 sudo apt-get install -y ${PACKAGE} || FATAL "failed to install ${PACKAGE}"
153 fi
154 done
155 echo -e "Required packages are present: ${NEEDED_PACKAGES}"
156 }
157
158 function ask_user(){
159 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
160 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
161 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
162 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
163 read -e -p "$1" USER_CONFIRMATION
164 while true ; do
165 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
166 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
167 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
168 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
169 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
170 done
171 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
172 }
173
174 function install_osmclient(){
175 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
176 CLIENT_RELEASE=${RELEASE#"-R "}
177 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
178 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
179 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
180 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
181 curl $key_location | sudo APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key add -
182 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient IM"
183 sudo apt-get -y update
184 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip
185 sudo -H LC_ALL=C python3 -m pip install -U pip
186 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-osm-im python3-osmclient
187 if [ -f /usr/lib/python3/dist-packages/osm_im/requirements.txt ]; then
188 python3 -m pip install -r /usr/lib/python3/dist-packages/osm_im/requirements.txt
189 fi
190 if [ -f /usr/lib/python3/dist-packages/osmclient/requirements.txt ]; then
191 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libmagic1
192 python3 -m pip install -r /usr/lib/python3/dist-packages/osmclient/requirements.txt
193 fi
194 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
195 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
196 echo -e "\nOSM client installed"
197 if [ -z "$INSTALL_LIGHTWEIGHT" ]; then
198 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
199 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
200 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
201 else
202 echo -e "OSM client assumes that OSM host is running in localhost (127.0.0.1)."
203 echo -e "In case you want to interact with a different OSM host, you will have to configure this env variable in your .bashrc file:"
204 echo " export OSM_HOSTNAME=<OSM_host>"
205 fi
206 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
207 return 0
208 }
209
210 function docker_login() {
211 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
212 echo "Docker login"
213 [ -z "${DEBUG_INSTALL}" ] || DEBUG "Docker registry user: ${DOCKER_REGISTRY_USER}"
214 sg docker -c "docker login -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASSWORD} --password-stdin"
215 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
216 }
217
218 function generate_docker_images() {
219 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
220 echo "Generating docker images"
221 _build_from=$COMMIT_ID
222 [ -z "$_build_from" ] && _build_from="latest"
223 echo "OSM Docker images generated from $_build_from"
224 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
225 trap 'rm -rf "${LWTEMPDIR}"' EXIT
226 for module in MON POL NBI KEYSTONE RO LCM NG-UI PLA; do
227 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q ${module} ; then
228 module_lower=${module,,}
229 if [ $module == "PLA" -a ! -n "$INSTALL_PLA" ]; then
230 continue
231 fi
232 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/$module
233 git -C ${LWTEMPDIR}/${module} checkout ${COMMIT_ID}
234 sg docker -c "docker build ${LWTEMPDIR}/${module} -f ${LWTEMPDIR}/${module}/docker/Dockerfile -t ${DOCKER_USER}/${module_lower} --no-cache" || FATAL "cannot build ${module} docker image"
235 fi
236 done
237 if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q osmclient; then
238 BUILD_ARGS+=(--build-arg REPOSITORY="$REPOSITORY")
239 BUILD_ARGS+=(--build-arg RELEASE="$RELEASE")
240 BUILD_ARGS+=(--build-arg REPOSITORY_KEY="$REPOSITORY_KEY")
241 BUILD_ARGS+=(--build-arg REPOSITORY_BASE="$REPOSITORY_BASE")
242 sg docker -c "docker build -t ${DOCKER_USER}/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ."
243 fi
244 echo "Finished generation of docker images"
245 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
246 }
247
248 function cmp_overwrite() {
249 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
250 file1="$1"
251 file2="$2"
252 if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then
253 if [ -f "${file2}" ]; then
254 ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2}
255 else
256 cp -b ${file1} ${file2}
257 fi
258 fi
259 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
260 }
261
262 #deploys osm pods and services
263 function deploy_osm_services() {
264 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
265 # helm is already installed as part of install_kubeadm_cluster.sh
266
267 # Generate helm values to be passed with -f osm-values.yaml
268 sudo mkdir -p ${OSM_HELM_WORK_DIR}
269 if [ -n "${INSTALL_JUJU}" ]; then
270 sudo bash -c "cat << EOF > ${OSM_HELM_WORK_DIR}/osm-values.yaml
271 vca:
272 pubkey: \"${OSM_VCA_PUBKEY}\"
273 EOF"
274 fi
275
276 # Generate helm values to be passed with --set
277 OSM_HELM_OPTS=""
278 # OSM_HELM_OPTS="${OSM_HELM_OPTS} --set nbi.useOsmSecret=false"
279 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.image.repositoryBase=${DOCKER_REGISTRY_URL}${DOCKER_USER}"
280 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set mysql.dbHostPath=${OSM_NAMESPACE_VOL}"
281 if [ -n "${INSTALL_JUJU}" ]; then
282 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.enabled=true"
283 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.host=${OSM_VCA_HOST}"
284 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.secret=${OSM_VCA_SECRET}"
285 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.cacert=${OSM_VCA_CACERT}"
286 fi
287 [ -n "$OSM_VCA_APIPROXY" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set lcm.config.OSMLCM_VCA_APIPROXY=${OSM_VCA_APIPROXY}"
288 [ ! "$OSM_DOCKER_TAG" == "testing-daily" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.image.tag=${OSM_DOCKER_TAG}"
289 [ -n "${INSTALL_NGSA}" ] || OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.oldServiceAssurance=true"
290 if [ -n "${OSM_BEHIND_PROXY}" ]; then
291 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.behindHttpProxy=true"
292 [ -n "${HTTP_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTP_PROXY=${HTTP_PROXY}"
293 [ -n "${HTTPS_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTPS_PROXY=${HTTPS_PROXY}"
294 [ -n "${NO_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.NO_PROXY=${NO_PROXY}"
295 fi
296
297 if [ -n "${INSTALL_JUJU}" ]; then
298 OSM_HELM_OPTS="-f ${OSM_HELM_WORK_DIR}/osm-values.yaml ${OSM_HELM_OPTS}"
299 fi
300 echo "helm install -n $OSM_NAMESPACE --create-namespace $OSM_NAMESPACE $OSM_DEVOPS/installers/helm/osm ${OSM_HELM_OPTS}"
301 helm install -n $OSM_NAMESPACE --create-namespace $OSM_NAMESPACE $OSM_DEVOPS/installers/helm/osm ${OSM_HELM_OPTS}
302 # Override existing values.yaml with the final values.yaml used to install OSM
303 helm -n $OSM_NAMESPACE get values $OSM_NAMESPACE | sudo tee -a ${OSM_HELM_WORK_DIR}/osm-values.yaml
304 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
305 }
306
307 #deploy charmed services
308 function deploy_charmed_services() {
309 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
310 juju add-model $OSM_NAMESPACE $OSM_VCA_K8S_CLOUDNAME
311 juju deploy ch:mongodb-k8s -m $OSM_NAMESPACE --channel latest/stable
312 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
313 }
314
315 #deploy mongodb
316 function deploy_mongodb() {
317 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
318 MONGO_OPTS="-d ${OSM_HELM_WORK_DIR} -D ${OSM_DEVOPS} -t ${OSM_DOCKER_TAG} -U ${DOCKER_USER} ${DEBUG_INSTALL}"
319 [ -n "${DOCKER_REGISTRY_URL}" ] && MONGO_OPTS="${MONGO_OPTS} -r ${DOCKER_REGISTRY_URL}"
320 $OSM_DEVOPS/installers/install_mongodb.sh ${MONGO_OPTS} || \
321 FATAL_TRACK install_osm_mongodb_service "install_mongodb.sh failed"
322 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
323 }
324
325 function install_osm_ngsa_service() {
326 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
327 NGSA_OPTS="-d ${OSM_HELM_WORK_DIR} -D ${OSM_DEVOPS} -t ${OSM_DOCKER_TAG} -U ${DOCKER_USER} ${DEBUG_INSTALL}"
328 [ -n "${DOCKER_REGISTRY_URL}" ] && NGSA_OPTS="${NGSA_OPTS} -r ${DOCKER_REGISTRY_URL}"
329 $OSM_DEVOPS/installers/install_ngsa.sh ${NGSA_OPTS} || \
330 FATAL_TRACK install_osm_ngsa_service "install_ngsa.sh failed"
331 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
332 }
333
334 function add_local_k8scluster() {
335 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
336 /usr/bin/osm --all-projects vim-create \
337 --name _system-osm-vim \
338 --account_type dummy \
339 --auth_url http://dummy \
340 --user osm --password osm --tenant osm \
341 --description "dummy" \
342 --config '{management_network_name: mgmt}'
343 /usr/bin/osm --all-projects k8scluster-add \
344 --creds ${HOME}/.kube/config \
345 --vim _system-osm-vim \
346 --k8s-nets '{"net1": null}' \
347 --version '1.15' \
348 --description "OSM Internal Cluster" \
349 _system-osm-k8s
350 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
351 }
352
353 function configure_apt_proxy() {
354 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
355 OSM_APT_PROXY=$1
356 OSM_APT_PROXY_FILE="/etc/apt/apt.conf.d/osm-apt"
357 echo "Configuring apt proxy in file ${OSM_APT_PROXY_FILE}"
358 if [ ! -f ${OSM_APT_PROXY_FILE} ]; then
359 sudo bash -c "cat <<EOF > ${OSM_APT_PROXY}
360 Acquire::http { Proxy \"${OSM_APT_PROXY}\"; }
361 EOF"
362 else
363 sudo sed -i "s|Proxy.*|Proxy \"${OSM_APT_PROXY}\"; }|" ${OSM_APT_PROXY_FILE}
364 fi
365 sudo apt-get update || FATAL "Configured apt proxy, but couldn't run 'apt-get update'. Check ${OSM_APT_PROXY_FILE}"
366 track prereq apt_proxy_configured_ok
367 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
368 }
369
370 function ask_proceed() {
371 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
372
373 [ -z "$ASSUME_YES" ] && ! ask_user "The installation will do the following
374 1. Install and configure LXD
375 2. Install juju
376 3. Install docker CE
377 4. Disable swap space
378 5. Install and initialize Kubernetes
379 as pre-requirements.
380 Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
381
382 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
383 }
384
385 function check_osm_behind_proxy() {
386 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
387
388 export OSM_BEHIND_PROXY=""
389 export OSM_PROXY_ENV_VARIABLES=""
390 [ -n "${http_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "http_proxy=${http_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} http_proxy"
391 [ -n "${https_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${https_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} https_proxy"
392 [ -n "${HTTP_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "HTTP_PROXY=${HTTP_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTP_PROXY"
393 [ -n "${HTTPS_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${HTTPS_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTPS_PROXY"
394 [ -n "${no_proxy}" ] && echo "no_proxy=${no_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} no_proxy"
395 [ -n "${NO_PROXY}" ] && echo "NO_PROXY=${NO_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} NO_PROXY"
396
397 echo "OSM_BEHIND_PROXY=${OSM_BEHIND_PROXY}"
398 echo "OSM_PROXY_ENV_VARIABLES=${OSM_PROXY_ENV_VARIABLES}"
399
400 if [ -n "${OSM_BEHIND_PROXY}" ]; then
401 [ -z "$ASSUME_YES" ] && ! ask_user "
402 The following env variables have been found for the current user:
403 ${OSM_PROXY_ENV_VARIABLES}.
404
405 This suggests that this machine is behind a proxy and a special configuration is required.
406 The installer will install Docker CE, LXD and Juju to work behind a proxy using those
407 env variables.
408
409 Take into account that the installer uses apt, curl, wget, docker, lxd, juju and snap.
410 Depending on the program, the env variables to work behind a proxy might be different
411 (e.g. http_proxy vs HTTP_PROXY).
412
413 For that reason, it is strongly recommended that at least http_proxy, https_proxy, HTTP_PROXY
414 and HTTPS_PROXY are defined.
415
416 Finally, some of the programs (apt, snap) those programs are run as sudoer, requiring that
417 those env variables are also set for root user. If you are not sure whether those variables
418 are configured for the root user, you can stop the installation now.
419
420 Do you want to proceed with the installation (Y/n)? " y && echo "Cancelled!" && exit 1
421 else
422 echo "This machine is not behind a proxy"
423 fi
424
425 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
426 }
427
428 function find_devops_folder() {
429 if [ -z "$OSM_DEVOPS" ]; then
430 if [ -n "$TEST_INSTALLER" ]; then
431 echo -e "\nUsing local devops repo for OSM installation"
432 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
433 else
434 echo -e "\nCreating temporary dir for OSM installation"
435 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
436 trap 'rm -rf "$OSM_DEVOPS"' EXIT
437 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
438 fi
439 fi
440 }
441
442 function install_osm() {
443 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
444
445 trap ctrl_c INT
446
447
448 check_osm_behind_proxy
449 check_packages "git wget curl tar snapd"
450 if [ -n "${INSTALL_JUJU}" ]; then
451 sudo snap install jq || FATAL "Could not install jq (snap package). Make sure that snap works"
452 fi
453 find_devops_folder
454
455 track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type $OSM_INSTALLATION_TYPE none none os_info $os_info none none
456
457 track checks checkingroot_ok
458 [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
459 track checks noroot_ok
460 ask_proceed
461 track checks proceed_ok
462
463 echo "Installing OSM"
464
465 [ -n "$DOCKER_REGISTRY_URL" ] && parse_docker_registry_url
466
467 echo "Determining IP address of the interface with the default route"
468 [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}')
469 [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}')
470 [ -z "$OSM_DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
471 OSM_DEFAULT_IP=`ip -o -4 a s ${OSM_DEFAULT_IF} |awk '{split($4,a,"/"); print a[1]; exit}'`
472 [ -z "$OSM_DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
473
474 # configure apt proxy
475 [ -n "$APT_PROXY_URL" ] && configure_apt_proxy $APT_PROXY_URL
476
477 # if lxd is requested, we will install it
478 if [ -n "$INSTALL_LXD" ]; then
479 LXD_INSTALL_OPTS="-D ${OSM_DEVOPS} -i ${OSM_DEFAULT_IF} ${DEBUG_INSTALL}"
480 [ -n "${OSM_BEHIND_PROXY}" ] && LXD_INSTALL_OPTS="${LXD_INSTALL_OPTS} -P"
481 $OSM_DEVOPS/installers/install_lxd.sh ${LXD_INSTALL_OPTS} || FATAL_TRACK lxd "install_lxd.sh failed"
482 fi
483
484 track prereq prereqok_ok
485
486 if [ ! -n "$INSTALL_NODOCKER" ]; then
487 DOCKER_CE_OPTS="-D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
488 [ -n "${DOCKER_PROXY_URL}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -p ${DOCKER_PROXY_URL}"
489 [ -n "${OSM_BEHIND_PROXY}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -P"
490 $OSM_DEVOPS/installers/install_docker_ce.sh ${DOCKER_CE_OPTS} || FATAL_TRACK docker_ce "install_docker_ce.sh failed"
491 fi
492
493 track docker_ce docker_ce_ok
494
495 echo "Creating folders for installation"
496 [ ! -d "$OSM_WORK_DIR" ] && sudo mkdir -p $OSM_WORK_DIR
497 sudo cp -b $OSM_DEVOPS/installers/kubeadm-config.yaml $OSM_WORK_DIR/kubeadm-config.yaml
498
499 $OSM_DEVOPS/installers/install_kubeadm_cluster.sh -i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} || \
500 FATAL_TRACK k8scluster "install_kubeadm_cluster.sh failed"
501 track k8scluster k8scluster_ok
502
503 if [ -n "${INSTALL_JUJU}" ]; then
504 JUJU_OPTS="-D ${OSM_DEVOPS} -s ${OSM_NAMESPACE} -i ${OSM_DEFAULT_IP} ${DEBUG_INSTALL} ${INSTALL_CACHELXDIMAGES}"
505 [ -n "${OSM_VCA_HOST}" ] && JUJU_OPTS="$JUJU_OPTS -H ${OSM_VCA_HOST}"
506 [ -n "${LXD_CLOUD_FILE}" ] && JUJU_OPTS="$JUJU_OPTS -l ${LXD_CLOUD_FILE}"
507 [ -n "${LXD_CRED_FILE}" ] && JUJU_OPTS="$JUJU_OPTS -L ${LXD_CRED_FILE}"
508 [ -n "${CONTROLLER_NAME}" ] && JUJU_OPTS="$JUJU_OPTS -K ${CONTROLLER_NAME}"
509 [ -n "${OSM_BEHIND_PROXY}" ] && JUJU_OPTS="${JUJU_OPTS} -P"
510 $OSM_DEVOPS/installers/install_juju.sh ${JUJU_OPTS} || FATAL_TRACK juju "install_juju.sh failed"
511 set_vca_variables
512 fi
513 track juju juju_ok
514
515 # Deploy OSM services
516 [ -z "$DOCKER_NOBUILD" ] && [ -z "$PULL_IMAGES" ] && generate_docker_images
517 track docker_images docker_images_ok
518
519 deploy_mongodb
520 track deploy_osm deploy_mongodb_ok
521 deploy_osm_services
522 track deploy_osm deploy_osm_services_k8s_ok
523 if [ -n "$INSTALL_K8S_MONITOR" ]; then
524 # install OSM MONITORING
525 install_k8s_monitoring
526 track deploy_osm install_k8s_monitoring_ok
527 fi
528 if [ -n "$INSTALL_NGSA" ]; then
529 # optional NGSA install
530 install_osm_ngsa_service
531 track deploy_osm install_osm_ngsa_ok
532 fi
533
534 [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient
535 track osmclient osmclient_ok
536
537 echo -e "Checking OSM health state..."
538 $OSM_DEVOPS/installers/osm_health.sh -s ${OSM_NAMESPACE} -k || \
539 (echo -e "OSM is not healthy, but will probably converge to a healthy state soon." && \
540 echo -e "Check OSM status with: kubectl -n ${OSM_NAMESPACE} get all" && \
541 track healthchecks osm_unhealthy didnotconverge)
542 track healthchecks after_healthcheck_ok
543
544 add_local_k8scluster
545 track final_ops add_local_k8scluster_ok
546
547 # if lxd is requested, iptables firewall is updated to work with both docker and LXD
548 if [ -n "$INSTALL_LXD" ]; then
549 arrange_docker_default_network_policy
550 fi
551
552 wget -q -O- https://osm-download.etsi.org/ftp/osm-15.0-fifteen/README2.txt &> /dev/null
553 track end
554 sudo find /etc/osm
555 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
556 return 0
557 }
558
559 function install_to_openstack() {
560 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
561
562 if [ -z "$2" ]; then
563 FATAL "OpenStack installer requires a valid external network name"
564 fi
565
566 # Install Pip for Python3
567 sudo apt install -y python3-pip python3-venv
568 sudo -H LC_ALL=C python3 -m pip install -U pip
569
570 # Create a venv to avoid conflicts with the host installation
571 python3 -m venv $OPENSTACK_PYTHON_VENV
572
573 source $OPENSTACK_PYTHON_VENV/bin/activate
574
575 # Install Ansible, OpenStack client and SDK, latest openstack version supported is Train
576 python -m pip install -U wheel
577 python -m pip install -U "python-openstackclient<=4.0.2" "openstacksdk>=0.12.0,<=0.36.2" "ansible>=2.10,<2.11"
578
579 # Install the Openstack cloud module (ansible>=2.10)
580 ansible-galaxy collection install openstack.cloud
581
582 export ANSIBLE_CONFIG="$OSM_DEVOPS/installers/openstack/ansible.cfg"
583
584 OSM_INSTALLER_ARGS="${REPO_ARGS[@]}"
585
586 ANSIBLE_VARS="external_network_name=$2 setup_volume=$3 server_name=$OPENSTACK_VM_NAME"
587
588 if [ -n "$OPENSTACK_SSH_KEY_FILE" ]; then
589 ANSIBLE_VARS+=" key_file=$OPENSTACK_SSH_KEY_FILE"
590 fi
591
592 if [ -n "$OPENSTACK_USERDATA_FILE" ]; then
593 ANSIBLE_VARS+=" userdata_file=$OPENSTACK_USERDATA_FILE"
594 fi
595
596 # Execute the Ansible playbook based on openrc or clouds.yaml
597 if [ -e "$1" ]; then
598 . $1
599 ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \
600 $OSM_DEVOPS/installers/openstack/site.yml
601 else
602 ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \
603 -e cloud_name=$1 $OSM_DEVOPS/installers/openstack/site.yml
604 fi
605
606 # Exit from venv
607 deactivate
608
609 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
610 return 0
611 }
612
613 function arrange_docker_default_network_policy() {
614 echo -e "Fixing firewall so docker and LXD can share the same host without affecting each other."
615 sudo iptables -I DOCKER-USER -j ACCEPT
616 sudo iptables-save | sudo tee /etc/iptables/rules.v4
617 sudo ip6tables-save | sudo tee /etc/iptables/rules.v6
618 }
619
620 function install_k8s_monitoring() {
621 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
622 # install OSM monitoring
623 sudo chmod +x $OSM_DEVOPS/installers/k8s/*.sh
624 sudo $OSM_DEVOPS/installers/k8s/install_osm_k8s_monitoring.sh || FATAL_TRACK install_k8s_monitoring "k8s/install_osm_k8s_monitoring.sh failed"
625 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
626 }
627
628 function dump_vars(){
629 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
630 echo "APT_PROXY_URL=$APT_PROXY_URL"
631 echo "DEVELOP=$DEVELOP"
632 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
633 echo "DOCKER_NOBUILD=$DOCKER_NOBUILD"
634 echo "DOCKER_PROXY_URL=$DOCKER_PROXY_URL"
635 echo "DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL"
636 echo "DOCKER_USER=$DOCKER_USER"
637 echo "INSTALL_CACHELXDIMAGES=$INSTALL_CACHELXDIMAGES"
638 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
639 echo "INSTALL_JUJU=$INSTALL_JUJU"
640 echo "INSTALL_K8S_MONITOR=$INSTALL_K8S_MONITOR"
641 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
642 echo "INSTALL_LXD=$INSTALL_LXD"
643 echo "INSTALL_NGSA=$INSTALL_NGSA"
644 echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
645 echo "INSTALL_ONLY=$INSTALL_ONLY"
646 echo "INSTALL_PLA=$INSTALL_PLA"
647 echo "INSTALL_TO_OPENSTACK=$INSTALL_TO_OPENSTACK"
648 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
649 echo "NO_HOST_PORTS=$NO_HOST_PORTS"
650 echo "OPENSTACK_PUBLIC_NET_NAME=$OPENSTACK_PUBLIC_NET_NAME"
651 echo "OPENSTACK_OPENRC_FILE_OR_CLOUD=$OPENSTACK_OPENRC_FILE_OR_CLOUD"
652 echo "OPENSTACK_ATTACH_VOLUME=$OPENSTACK_ATTACH_VOLUME"
653 echo "OPENSTACK_SSH_KEY_FILE"="$OPENSTACK_SSH_KEY_FILE"
654 echo "OPENSTACK_USERDATA_FILE"="$OPENSTACK_USERDATA_FILE"
655 echo "OPENSTACK_VM_NAME"="$OPENSTACK_VM_NAME"
656 echo "OSM_DEVOPS=$OSM_DEVOPS"
657 echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
658 echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
659 echo "OSM_NAMESPACE=$OSM_NAMESPACE"
660 echo "OSM_VCA_HOST=$OSM_VCA_HOST"
661 echo "OSM_VCA_PUBKEY=$OSM_VCA_PUBKEY"
662 echo "OSM_VCA_SECRET=$OSM_VCA_SECRET"
663 echo "OSM_WORK_DIR=$OSM_WORK_DIR"
664 echo "PULL_IMAGES=$PULL_IMAGES"
665 echo "RECONFIGURE=$RECONFIGURE"
666 echo "RELEASE=$RELEASE"
667 echo "REPOSITORY=$REPOSITORY"
668 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
669 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
670 echo "SHOWOPTS=$SHOWOPTS"
671 echo "TEST_INSTALLER=$TEST_INSTALLER"
672 echo "TO_REBUILD=$TO_REBUILD"
673 echo "UNINSTALL=$UNINSTALL"
674 echo "UPDATE=$UPDATE"
675 echo "Install from specific refspec (-b): $COMMIT_ID"
676 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
677 }
678
679 function parse_docker_registry_url() {
680 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
681 DOCKER_REGISTRY_USER=$(echo "$DOCKER_REGISTRY_URL" | awk '{split($1,a,"@"); split(a[1],b,":"); print b[1]}')
682 DOCKER_REGISTRY_PASSWORD=$(echo "$DOCKER_REGISTRY_URL" | awk '{split($1,a,"@"); split(a[1],b,":"); print b[2]}')
683 DOCKER_REGISTRY_URL=$(echo "$DOCKER_REGISTRY_URL" | awk '{split($1,a,"@"); print a[2]}')
684 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
685 }
686
687 function ctrl_c() {
688 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
689 echo "** Trapped CTRL-C"
690 FATAL "User stopped the installation"
691 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
692 }
693
694 UNINSTALL=""
695 DEVELOP=""
696 UPDATE=""
697 RECONFIGURE=""
698 TEST_INSTALLER=""
699 INSTALL_LXD=""
700 SHOWOPTS=""
701 COMMIT_ID=""
702 ASSUME_YES=""
703 APT_PROXY_URL=""
704 INSTALL_FROM_SOURCE=""
705 DEBUG_INSTALL=""
706 RELEASE="ReleaseTEN"
707 REPOSITORY="stable"
708 INSTALL_K8S_MONITOR=""
709 INSTALL_NGSA="y"
710 INSTALL_PLA=""
711 INSTALL_VIMEMU=""
712 LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
713 LXD_REPOSITORY_PATH=""
714 INSTALL_LIGHTWEIGHT="y"
715 INSTALL_TO_OPENSTACK=""
716 OPENSTACK_OPENRC_FILE_OR_CLOUD=""
717 OPENSTACK_PUBLIC_NET_NAME=""
718 OPENSTACK_ATTACH_VOLUME="false"
719 OPENSTACK_SSH_KEY_FILE=""
720 OPENSTACK_USERDATA_FILE=""
721 OPENSTACK_VM_NAME="server-osm"
722 OPENSTACK_PYTHON_VENV="$HOME/.virtual-envs/osm"
723 INSTALL_ONLY=""
724 TO_REBUILD=""
725 INSTALL_NODOCKER=""
726 INSTALL_JUJU=""
727 INSTALL_NOHOSTCLIENT=""
728 INSTALL_CACHELXDIMAGES=""
729 OSM_DEVOPS=
730 OSM_VCA_HOST=
731 OSM_VCA_SECRET=
732 OSM_VCA_PUBKEY=
733 OSM_VCA_CLOUDNAME="localhost"
734 OSM_VCA_K8S_CLOUDNAME="k8scloud"
735 OSM_NAMESPACE=osm
736 NO_HOST_PORTS=""
737 DOCKER_NOBUILD=""
738 REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
739 REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/debian"
740 OSM_WORK_DIR="/etc/osm"
741 OSM_HELM_WORK_DIR="${OSM_WORK_DIR}/helm"
742 OSM_HOST_VOL="/var/lib/osm"
743 OSM_NAMESPACE_VOL="${OSM_HOST_VOL}/${OSM_NAMESPACE}"
744 OSM_DOCKER_TAG="testing-daily"
745 DOCKER_USER=opensourcemano
746 PULL_IMAGES="y"
747 KAFKA_TAG=2.11-1.0.2
748 KIWIGRID_K8S_SIDECAR_TAG="1.15.6"
749 PROMETHEUS_TAG=v2.28.1
750 GRAFANA_TAG=8.1.1
751 PROMETHEUS_NODE_EXPORTER_TAG=0.18.1
752 PROMETHEUS_CADVISOR_TAG=latest
753 KEYSTONEDB_TAG=10
754 OSM_DATABASE_COMMONKEY=
755 ELASTIC_VERSION=6.4.2
756 ELASTIC_CURATOR_VERSION=5.5.4
757 POD_NETWORK_CIDR=10.244.0.0/16
758 K8S_MANIFEST_DIR="/etc/kubernetes/manifests"
759 RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
760 DOCKER_REGISTRY_URL=
761 DOCKER_PROXY_URL=
762 MODULE_DOCKER_TAG=
763 OSM_INSTALLATION_TYPE="Default"
764
765 while getopts ":a:b:r:n:k:u:R:D:o:O:m:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:-: hy" o; do
766 case "${o}" in
767 a)
768 APT_PROXY_URL=${OPTARG}
769 ;;
770 b)
771 COMMIT_ID=${OPTARG}
772 PULL_IMAGES=""
773 ;;
774 r)
775 REPOSITORY="${OPTARG}"
776 REPO_ARGS+=(-r "$REPOSITORY")
777 ;;
778 k)
779 REPOSITORY_KEY="${OPTARG}"
780 REPO_ARGS+=(-k "$REPOSITORY_KEY")
781 ;;
782 u)
783 REPOSITORY_BASE="${OPTARG}"
784 REPO_ARGS+=(-u "$REPOSITORY_BASE")
785 ;;
786 R)
787 RELEASE="${OPTARG}"
788 REPO_ARGS+=(-R "$RELEASE")
789 ;;
790 D)
791 OSM_DEVOPS="${OPTARG}"
792 ;;
793 o)
794 INSTALL_ONLY="y"
795 [ "${OPTARG}" == "k8s_monitor" ] && INSTALL_K8S_MONITOR="y" && continue
796 [ "${OPTARG}" == "ng-sa" ] && INSTALL_NGSA="y" && continue
797 ;;
798 O)
799 INSTALL_TO_OPENSTACK="y"
800 if [ -n "${OPTARG}" ]; then
801 OPENSTACK_OPENRC_FILE_OR_CLOUD="${OPTARG}"
802 else
803 echo -e "Invalid argument for -O : ' $OPTARG'\n" >&2
804 usage && exit 1
805 fi
806 ;;
807 f)
808 OPENSTACK_SSH_KEY_FILE="${OPTARG}"
809 ;;
810 F)
811 OPENSTACK_USERDATA_FILE="${OPTARG}"
812 ;;
813 N)
814 OPENSTACK_PUBLIC_NET_NAME="${OPTARG}"
815 ;;
816 m)
817 [ "${OPTARG}" == "NG-UI" ] && TO_REBUILD="$TO_REBUILD NG-UI" && continue
818 [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue
819 [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue
820 [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue
821 [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue
822 [ "${OPTARG}" == "POL" ] && TO_REBUILD="$TO_REBUILD POL" && continue
823 [ "${OPTARG}" == "PLA" ] && TO_REBUILD="$TO_REBUILD PLA" && continue
824 [ "${OPTARG}" == "osmclient" ] && TO_REBUILD="$TO_REBUILD osmclient" && continue
825 [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue
826 [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue
827 [ "${OPTARG}" == "PROMETHEUS" ] && TO_REBUILD="$TO_REBUILD PROMETHEUS" && continue
828 [ "${OPTARG}" == "PROMETHEUS-CADVISOR" ] && TO_REBUILD="$TO_REBUILD PROMETHEUS-CADVISOR" && continue
829 [ "${OPTARG}" == "KEYSTONE-DB" ] && TO_REBUILD="$TO_REBUILD KEYSTONE-DB" && continue
830 [ "${OPTARG}" == "GRAFANA" ] && TO_REBUILD="$TO_REBUILD GRAFANA" && continue
831 [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue
832 ;;
833 H)
834 OSM_VCA_HOST="${OPTARG}"
835 ;;
836 S)
837 OSM_VCA_SECRET="${OPTARG}"
838 ;;
839 s)
840 OSM_NAMESPACE="${OPTARG}" && [[ ! "${OPTARG}" =~ $RE_CHECK ]] && echo "Namespace $OPTARG is invalid. Regex used for validation is $RE_CHECK" && exit 0
841 ;;
842 t)
843 OSM_DOCKER_TAG="${OPTARG}"
844 REPO_ARGS+=(-t "$OSM_DOCKER_TAG")
845 ;;
846 U)
847 DOCKER_USER="${OPTARG}"
848 ;;
849 P)
850 OSM_VCA_PUBKEY=$(cat ${OPTARG})
851 ;;
852 A)
853 OSM_VCA_APIPROXY="${OPTARG}"
854 ;;
855 l)
856 LXD_CLOUD_FILE="${OPTARG}"
857 ;;
858 L)
859 LXD_CRED_FILE="${OPTARG}"
860 ;;
861 K)
862 CONTROLLER_NAME="${OPTARG}"
863 ;;
864 d)
865 DOCKER_REGISTRY_URL="${OPTARG}"
866 ;;
867 p)
868 DOCKER_PROXY_URL="${OPTARG}"
869 ;;
870 T)
871 MODULE_DOCKER_TAG="${OPTARG}"
872 ;;
873 -)
874 [ "${OPTARG}" == "help" ] && usage && exit 0
875 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && PULL_IMAGES="" && continue
876 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="--debug" && continue
877 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
878 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
879 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
880 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
881 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
882 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
883 [ "${OPTARG}" == "lxd" ] && INSTALL_LXD="y" && continue
884 [ "${OPTARG}" == "nolxd" ] && INSTALL_LXD="" && continue
885 [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
886 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
887 [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue
888 [ "${OPTARG}" == "juju" ] && INSTALL_JUJU="y" && continue
889 [ "${OPTARG}" == "nojuju" ] && INSTALL_JUJU="" && continue
890 [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue
891 [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue
892 [ "${OPTARG}" == "pullimages" ] && continue
893 [ "${OPTARG}" == "k8s_monitor" ] && INSTALL_K8S_MONITOR="y" && continue
894 [ "${OPTARG}" == "charmed" ] && CHARMED="y" && OSM_INSTALLATION_TYPE="Charmed" && continue
895 [ "${OPTARG}" == "bundle" ] && continue
896 [ "${OPTARG}" == "k8s" ] && continue
897 [ "${OPTARG}" == "lxd-cred" ] && continue
898 [ "${OPTARG}" == "microstack" ] && continue
899 [ "${OPTARG}" == "overlay" ] && continue
900 [ "${OPTARG}" == "only-vca" ] && continue
901 [ "${OPTARG}" == "small-profile" ] && continue
902 [ "${OPTARG}" == "vca" ] && continue
903 [ "${OPTARG}" == "ha" ] && continue
904 [ "${OPTARG}" == "tag" ] && continue
905 [ "${OPTARG}" == "registry" ] && continue
906 [ "${OPTARG}" == "pla" ] && INSTALL_PLA="y" && continue
907 [ "${OPTARG}" == "old-sa" ] && INSTALL_NGSA="" && continue
908 [ "${OPTARG}" == "ng-sa" ] && INSTALL_NGSA="y" && continue
909 [ "${OPTARG}" == "volume" ] && OPENSTACK_ATTACH_VOLUME="true" && continue
910 [ "${OPTARG}" == "nocachelxdimages" ] && continue
911 [ "${OPTARG}" == "cachelxdimages" ] && INSTALL_CACHELXDIMAGES="--cachelxdimages" && continue
912 echo -e "Invalid option: '--$OPTARG'\n" >&2
913 usage && exit 1
914 ;;
915 :)
916 echo "Option -$OPTARG requires an argument" >&2
917 usage && exit 1
918 ;;
919 \?)
920 echo -e "Invalid option: '-$OPTARG'\n" >&2
921 usage && exit 1
922 ;;
923 h)
924 usage && exit 0
925 ;;
926 y)
927 ASSUME_YES="y"
928 ;;
929 *)
930 usage && exit 1
931 ;;
932 esac
933 done
934
935 source $OSM_DEVOPS/common/all_funcs
936
937 [ -z "${DEBUG_INSTALL}" ] || DEBUG Debug is on
938 [ -n "$SHOWOPTS" ] && dump_vars && exit 0
939
940 # Uninstall if "--uninstall"
941 if [ -n "$UNINSTALL" ]; then
942 if [ -n "$CHARMED" ]; then
943 ${OSM_DEVOPS}/installers/charmed_uninstall.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D $OSM_DEVOPS -t $DOCKER_TAG "$@" || \
944 FATAL_TRACK charmed_uninstall "charmed_uninstall.sh failed"
945 else
946 ${OSM_DEVOPS}/installers/uninstall_osm.sh "$@" || \
947 FATAL_TRACK community_uninstall "uninstall_osm.sh failed"
948 fi
949 echo -e "\nDONE"
950 exit 0
951 fi
952
953 # Installation starts here
954
955 # Get README and create OSM_TRACK_INSTALLATION_ID
956 wget -q -O- https://osm-download.etsi.org/ftp/osm-15.0-fifteen/README.txt &> /dev/null
957 export OSM_TRACK_INSTALLATION_ID="$(date +%s)-$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)"
958
959 # Get OS info to be tracked
960 os_distro=$(lsb_release -i 2>/dev/null | awk '{print $3}')
961 echo $os_distro
962 os_release=$(lsb_release -r 2>/dev/null | awk '{print $2}')
963 echo $os_release
964 os_info="${os_distro}_${os_release}"
965 os_info="${os_info// /_}"
966
967 # Charmed installation
968 if [ -n "$CHARMED" ]; then
969 sudo snap install jq || FATAL "Could not install jq (snap package). Make sure that snap works"
970 ${OSM_DEVOPS}/installers/charmed_install.sh --tag $OSM_DOCKER_TAG "$@" || \
971 FATAL_TRACK charmed_install "charmed_install.sh failed"
972 wget -q -O- https://osm-download.etsi.org/ftp/osm-15.0-fifteen/README2.txt &> /dev/null
973 echo -e "\nDONE"
974 exit 0
975 fi
976
977 # Installation to Openstack
978 if [ -n "$INSTALL_TO_OPENSTACK" ]; then
979 install_to_openstack $OPENSTACK_OPENRC_FILE_OR_CLOUD $OPENSTACK_PUBLIC_NET_NAME $OPENSTACK_ATTACH_VOLUME
980 echo -e "\nDONE"
981 exit 0
982 fi
983
984 # Community_installer
985 # Check incompatible options
986 [ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options"
987 [ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" == " PLA" ] && [ -z "$INSTALL_PLA" ] && FATAL "Incompatible option: -m PLA cannot be used without --pla option"
988 # Special cases go first
989 # if develop, we force master
990 [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
991 [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring
992 [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_NGSA" ] && install_osm_ngsa_service
993 [ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
994 # This is where installation starts
995 install_osm
996 echo -e "\nDONE"
997 exit 0