+#deploys osm pods and services
+function deploy_osm_services() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ echo "The following manifests under $OSM_K8S_WORK_DIR will be deployed:"
+ ls $OSM_K8S_WORK_DIR
+ kubectl apply -n $OSM_NAMESPACE -f $OSM_K8S_WORK_DIR
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+#deploy charmed services
+function deploy_charmed_services() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ juju add-model $OSM_NAMESPACE $OSM_VCA_K8S_CLOUDNAME
+ juju deploy ch:mongodb-k8s -m $OSM_NAMESPACE
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function deploy_osm_pla_service() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ # corresponding to deploy_osm_services
+ kubectl apply -n $OSM_NAMESPACE -f $OSM_DOCKER_WORK_DIR/osm_pla
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function install_osm_ngsa_service() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ NGSA_OPTS="-d ${OSM_HELM_WORK_DIR} -D ${OSM_DEVOPS} -t ${OSM_DOCKER_TAG} -U ${DOCKER_USER} ${DEBUG_INSTALL}"
+ [ -n "${DOCKER_REGISTRY_URL}" ] && NGSA_OPTS="${NGSA_OPTS} -r ${DOCKER_REGISTRY_URL}"
+ $OSM_DEVOPS/installers/install_ngsa.sh ${NGSA_OPTS} || \
+ FATAL_TRACK install_osm_ngsa_service "install_ngsa.sh failed"
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function parse_yaml() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ TAG=$1
+ shift
+ services=$@
+ for module in $services; do
+ if [ "$module" == "pla" ]; then
+ if [ -n "$INSTALL_PLA" ]; then
+ echo "Updating K8s manifest file for ${module} from opensourcemano\/pla:.* to ${DOCKER_REGISTRY_URL}${DOCKER_USER}\/pla:${TAG}"
+ sudo sed -i "s#opensourcemano/pla:.*#${DOCKER_REGISTRY_URL}${DOCKER_USER}/pla:${TAG}#g" ${OSM_DOCKER_WORK_DIR}/osm_pla/pla.yaml
+ fi
+ else
+ image=${module}
+ if [ "$module" == "ng-prometheus" ]; then
+ image="prometheus"
+ elif [ "$module" == "ng-mon" ]; then
+ image="mon"
+ fi
+ echo "Updating K8s manifest file for ${module} from opensourcemano\/${image}:.* to ${DOCKER_REGISTRY_URL}${DOCKER_USER}\/${image}:${TAG}"
+ sudo sed -i "s#opensourcemano/${image}:.*#${DOCKER_REGISTRY_URL}${DOCKER_USER}/${image}:${TAG}#g" ${OSM_K8S_WORK_DIR}/${module}.yaml
+ fi
+ done
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function update_manifest_files() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ osm_services="nbi lcm ro pol mon ng-mon ng-ui keystone pla prometheus ng-prometheus"
+ list_of_services=""
+ for module in $osm_services; do
+ module_upper="${module^^}"
+ if ! echo $TO_REBUILD | grep -q $module_upper ; then
+ list_of_services="$list_of_services $module"
+ fi
+ done
+ if [ ! "$OSM_DOCKER_TAG" == "13" ]; then
+ parse_yaml $OSM_DOCKER_TAG $list_of_services
+ fi
+ if [ -n "$MODULE_DOCKER_TAG" ]; then
+ parse_yaml $MODULE_DOCKER_TAG $list_of_services_to_rebuild
+ fi
+ # The manifest for prometheus is prometheus.yaml or ng-prometheus.yaml, depending on the installation option
+ # If NG-SA is installed, it will include ng-mon (only mon-dashboarder), ng-prometheus and webhook translator. It won't include pol, mon and prometheus
+ if [ -n "$INSTALL_NGSA" ]; then
+ sudo rm -f ${OSM_K8S_WORK_DIR}/prometheus.yaml
+ sudo rm -f ${OSM_K8S_WORK_DIR}/mon.yaml
+ sudo rm -f ${OSM_K8S_WORK_DIR}/pol.yaml
+ else
+ sudo rm -f ${OSM_K8S_WORK_DIR}/ng-mon.yaml
+ sudo rm -f ${OSM_K8S_WORK_DIR}/ng-prometheus.yaml
+ sudo rm -f ${OSM_K8S_WORK_DIR}/webhook-translator.yaml
+ fi
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function namespace_vol() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ # List of services with a volume mounted in path /var/lib/osm
+ osm_services="mysql"
+ for osm in $osm_services; do
+ if [ -f "$OSM_K8S_WORK_DIR/$osm.yaml" ] ; then
+ sudo sed -i "s#path: /var/lib/osm#path: $OSM_NAMESPACE_VOL#g" $OSM_K8S_WORK_DIR/$osm.yaml
+ fi
+ done
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function add_local_k8scluster() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ /usr/bin/osm --all-projects vim-create \
+ --name _system-osm-vim \
+ --account_type dummy \
+ --auth_url http://dummy \
+ --user osm --password osm --tenant osm \
+ --description "dummy" \
+ --config '{management_network_name: mgmt}'
+ /usr/bin/osm --all-projects k8scluster-add \
+ --creds ${HOME}/.kube/config \
+ --vim _system-osm-vim \
+ --k8s-nets '{"net1": null}' \
+ --version '1.15' \
+ --description "OSM Internal Cluster" \
+ _system-osm-k8s
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function configure_apt_proxy() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ OSM_APT_PROXY=$1
+ OSM_APT_PROXY_FILE="/etc/apt/apt.conf.d/osm-apt"
+ echo "Configuring apt proxy in file ${OSM_APT_PROXY_FILE}"
+ if [ ! -f ${OSM_APT_PROXY_FILE} ]; then
+ sudo bash -c "cat <<EOF > ${OSM_APT_PROXY}
+Acquire::http { Proxy \"${OSM_APT_PROXY}\"; }
+EOF"
+ else
+ sudo sed -i "s|Proxy.*|Proxy \"${OSM_APT_PROXY}\"; }|" ${OSM_APT_PROXY_FILE}
+ fi
+ sudo apt-get update || FATAL "Configured apt proxy, but couldn't run 'apt-get update'. Check ${OSM_APT_PROXY_FILE}"
+ track prereq apt_proxy_configured_ok
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function ask_proceed() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+
+ [ -z "$ASSUME_YES" ] && ! ask_user "The installation will do the following
+ 1. Install and configure LXD
+ 2. Install juju
+ 3. Install docker CE
+ 4. Disable swap space
+ 5. Install and initialize Kubernetes
+ as pre-requirements.
+ Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
+
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function check_osm_behind_proxy() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+
+ export OSM_BEHIND_PROXY=""
+ export OSM_PROXY_ENV_VARIABLES=""
+ [ -n "${http_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "http_proxy=${http_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} http_proxy"
+ [ -n "${https_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${https_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} https_proxy"
+ [ -n "${HTTP_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "HTTP_PROXY=${HTTP_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTP_PROXY"
+ [ -n "${HTTPS_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${HTTPS_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTPS_PROXY"
+ [ -n "${no_proxy}" ] && echo "no_proxy=${no_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} no_proxy"
+ [ -n "${NO_PROXY}" ] && echo "NO_PROXY=${NO_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} NO_PROXY"
+
+ echo "OSM_BEHIND_PROXY=${OSM_BEHIND_PROXY}"
+ echo "OSM_PROXY_ENV_VARIABLES=${OSM_PROXY_ENV_VARIABLES}"
+
+ if [ -n "${OSM_BEHIND_PROXY}" ]; then
+ [ -z "$ASSUME_YES" ] && ! ask_user "
+The following env variables have been found for the current user:
+${OSM_PROXY_ENV_VARIABLES}.
+
+This suggests that this machine is behind a proxy and a special configuration is required.
+The installer will install Docker CE, LXD and Juju to work behind a proxy using those
+env variables.
+
+Take into account that the installer uses apt, curl, wget, docker, lxd, juju and snap.
+Depending on the program, the env variables to work behind a proxy might be different
+(e.g. http_proxy vs HTTP_PROXY).
+
+For that reason, it is strongly recommended that at least http_proxy, https_proxy, HTTP_PROXY
+and HTTPS_PROXY are defined.
+
+Finally, some of the programs (apt, snap) those programs are run as sudoer, requiring that
+those env variables are also set for root user. If you are not sure whether those variables
+are configured for the root user, you can stop the installation now.
+
+Do you want to proceed with the installation (Y/n)? " y && echo "Cancelled!" && exit 1
+ else
+ echo "This machine is not behind a proxy"
+ fi
+
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function find_devops_folder() {
+ if [ -z "$OSM_DEVOPS" ]; then
+ if [ -n "$TEST_INSTALLER" ]; then
+ echo -e "\nUsing local devops repo for OSM installation"
+ OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
+ else
+ echo -e "\nCreating temporary dir for OSM installation"
+ OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
+ trap 'rm -rf "$OSM_DEVOPS"' EXIT
+ git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
+ fi
+ fi
+}
+
+function install_osm() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+
+ trap ctrl_c INT
+
+ # TODO: move this under start
+ [ -n "$DOCKER_REGISTRY_URL" ] && parse_docker_registry_url
+
+ check_osm_behind_proxy
+ track checks proxy_ok
+
+ check_packages "git wget curl tar snapd"
+
+ sudo snap install jq || FATAL "Could not install jq (snap package). Make sure that snap works"
+
+ find_devops_folder
+
+ track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type $OSM_INSTALLATION_TYPE none none
+
+ track checks checkingroot_ok
+ [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
+ track checks noroot_ok
+
+ ask_proceed
+ track checks proceed_ok
+
+ echo "Installing OSM"
+
+ echo "Determining IP address of the interface with the default route"
+ [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}')
+ [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}')
+ [ -z "$OSM_DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
+ OSM_DEFAULT_IP=`ip -o -4 a s ${OSM_DEFAULT_IF} |awk '{split($4,a,"/"); print a[1]; exit}'`
+ [ -z "$OSM_DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
+
+ # configure apt proxy
+ [ -n "$APT_PROXY_URL" ] && configure_apt_proxy $APT_PROXY_URL
+
+ # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to
+ if [ -z "$OSM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ] && [ -z "$LXD_CLOUD_FILE" ]; then
+ LXD_INSTALL_OPTS="-D ${OSM_DEVOPS} -i ${OSM_DEFAULT_IF} ${DEBUG_INSTALL}"
+ [ -n "${OSM_BEHIND_PROXY}" ] && LXD_INSTALL_OPTS="${LXD_INSTALL_OPTS} -P"
+ $OSM_DEVOPS/installers/install_lxd.sh ${LXD_INSTALL_OPTS} || FATAL_TRACK lxd "install_lxd.sh failed"
+ fi
+
+ track prereq prereqok_ok
+
+ if [ ! -n "$INSTALL_NODOCKER" ]; then
+ DOCKER_CE_OPTS="-D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
+ [ -n "${DOCKER_PROXY_URL}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -p ${DOCKER_PROXY_URL}"
+ [ -n "${OSM_BEHIND_PROXY}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -P"
+ $OSM_DEVOPS/installers/install_docker_ce.sh ${DOCKER_CE_OPTS} || FATAL_TRACK docker_ce "install_docker_ce.sh failed"
+ fi
+
+ track docker_ce docker_ce_ok
+
+ echo "Creating folders for installation"
+ [ ! -d "$OSM_DOCKER_WORK_DIR" ] && sudo mkdir -p $OSM_DOCKER_WORK_DIR
+ [ ! -d "$OSM_DOCKER_WORK_DIR/osm_pla" -a -n "$INSTALL_PLA" ] && sudo mkdir -p $OSM_DOCKER_WORK_DIR/osm_pla
+ sudo cp -b $OSM_DEVOPS/installers/docker/cluster-config.yaml $OSM_DOCKER_WORK_DIR/cluster-config.yaml
+
+ $OSM_DEVOPS/installers/install_kubeadm_cluster.sh -i ${OSM_DEFAULT_IP} -d ${OSM_DOCKER_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} || \
+ FATAL_TRACK k8scluster "install_kubeadm_cluster.sh failed"
+ track k8scluster k8scluster_ok
+
+ JUJU_OPTS="-D ${OSM_DEVOPS} -s ${OSM_NAMESPACE} -i ${OSM_DEFAULT_IP} ${DEBUG_INSTALL} ${INSTALL_NOJUJU} ${INSTALL_CACHELXDIMAGES}"
+ [ -n "${OSM_VCA_HOST}" ] && JUJU_OPTS="$JUJU_OPTS -H ${OSM_VCA_HOST}"
+ [ -n "${LXD_CLOUD_FILE}" ] && JUJU_OPTS="$JUJU_OPTS -l ${LXD_CLOUD_FILE}"
+ [ -n "${LXD_CRED_FILE}" ] && JUJU_OPTS="$JUJU_OPTS -L ${LXD_CRED_FILE}"
+ [ -n "${CONTROLLER_NAME}" ] && JUJU_OPTS="$JUJU_OPTS -K ${CONTROLLER_NAME}"
+ [ -n "${OSM_BEHIND_PROXY}" ] && JUJU_OPTS="${JUJU_OPTS} -P"
+ $OSM_DEVOPS/installers/install_juju.sh ${JUJU_OPTS} || FATAL_TRACK juju "install_juju.sh failed"
+ set_vca_variables
+ track juju juju_ok
+
+ if [ -z "$OSM_DATABASE_COMMONKEY" ]; then
+ OSM_DATABASE_COMMONKEY=$(generate_secret)
+ [ -z "OSM_DATABASE_COMMONKEY" ] && FATAL "Cannot generate common db secret"
+ fi
+
+ # Deploy OSM services
+ [ -z "$DOCKER_NOBUILD" ] && pull_docker_images
+ [ -z "$DOCKER_NOBUILD" ] && [ -z "$PULL_IMAGES" ] && generate_docker_images
+ track docker_images docker_images_ok
+
+ generate_k8s_manifest_files
+ track osm_files manifest_files_ok