summaryrefslogtreecommitdiffstats
path: root/bootstrap/vagrant-onap/lib/oom
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/vagrant-onap/lib/oom')
-rwxr-xr-xbootstrap/vagrant-onap/lib/oom220
1 files changed, 220 insertions, 0 deletions
diff --git a/bootstrap/vagrant-onap/lib/oom b/bootstrap/vagrant-onap/lib/oom
new file mode 100755
index 000000000..ef7e5ede5
--- /dev/null
+++ b/bootstrap/vagrant-onap/lib/oom
@@ -0,0 +1,220 @@
+#!/bin/bash
+
+source /var/onap/functions
+
+RANCHER_PORT=8880
+oom_delay=30
+export RANCHER_URL=http://localhost:$RANCHER_PORT
+export RANCHER_ACCESS_KEY='access_key'
+export RANCHER_SECRET_KEY='secret_key'
+
+# _install_docker() - Function that installs Docker version for Rancher
+function _install_docker {
+ if ! $(docker version &>/dev/null); then
+ curl https://releases.rancher.com/install-docker/1.12.sh | sh
+ _configure_docker_settings 15
+ fi
+}
+
+# _pull_rancher_images() - Function that retrieves Rancher images required for k8s
+function _pull_rancher_images {
+ for image in "net:v0.13.5" "k8s:v1.8.5-rancher3" \
+"lb-service-rancher:v0.7.17" "network-manager:v0.7.18" "metadata:v0.9.5" \
+"kubectld:v0.8.5" "kubernetes-agent:v0.6.6" "dns:v0.15.3" \
+"kubernetes-auth:v0.0.8" "healthcheck:v0.3.3" "etcd:v2.3.7-13" \
+"etc-host-updater:v0.0.3" "net:holder"; do
+ pull_docker_image rancher/$image &
+ done
+}
+
+# _pull_k8s_images() - Function that retrieves Google k8s images
+function _pull_k8s_images {
+ for image in "kubernetes-dashboard-amd64:v1.7.1" \
+"k8s-dns-sidecar-amd64:1.14.5" "k8s-dns-kube-dns-amd64:1.14.5" \
+"k8s-dns-dnsmasq-nanny-amd64:1.14.5" "heapster-influxdb-amd64:v1.3.3" \
+"heapster-grafana-amd64:v4.4.3" "heapster-amd64:v1.4.0" "pause-amd64:3.0"; do
+ pull_docker_image gcr.io/google_containers/$image &
+ done
+}
+
+# _install_rancher() - Function that installs Rancher CLI and container
+function _install_rancher {
+ local rancher_version=v0.6.5
+ local rancher_server_version=v1.6.10
+ local rancher_server=rancher/server:$rancher_server_version
+
+ if [ ! -d /opt/rancher/current ]; then
+ mkdir -p /opt/rancher/current
+ wget https://github.com/rancher/cli/releases/download/$rancher_version/rancher-linux-amd64-$rancher_version.tar.gz
+ tar -xzf rancher-linux-amd64-$rancher_version.tar.gz -C /tmp
+ mv /tmp/rancher-$rancher_version/rancher /opt/rancher/current/
+ fi
+
+ _install_docker
+ pull_docker_image $rancher_server
+ run_docker_image -d --restart=unless-stopped -p $RANCHER_PORT:8080 $rancher_server
+ while true; do
+ if curl --fail -X GET $RANCHER_URL; then
+ break
+ fi
+ echo "waiting for racher"
+ sleep $oom_delay
+ done
+}
+
+# _install_kubernetes() - Function that deploys kubernetes via RancherOS host registration
+function _install_kubernetes {
+ local rancher_agent_version=v1.2.7
+ local rancher_agent=rancher/agent:$rancher_agent_version
+
+ _install_rancher
+
+ _pull_rancher_images
+ _pull_k8s_images
+ pull_docker_image $rancher_agent
+ _wait_docker_pull
+
+ pushd /opt/rancher/current/
+ export RANCHER_ENVIRONMENT=`./rancher env create -t kubernetes onap_on_kubernetes`
+ popd
+
+ install_python_package rancher-agent-registration
+ export no_proxy=$no_proxy,$IP_ADDRESS
+ rancher-agent-registration --host-ip $IP_ADDRESS --url http://$IP_ADDRESS:$RANCHER_PORT --environment $RANCHER_ENVIRONMENT --key $RANCHER_ACCESS_KEY --secret $RANCHER_SECRET_KEY
+}
+
+# _install_kubectl() - Function that installs kubectl as client for kubernetes
+function _install_kubectl {
+ if ! $(kubectl version &>/dev/null); then
+ rm -rf ~/.kube
+ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
+ chmod +x ./kubectl
+ mv ./kubectl /usr/local/bin/kubectl
+ mkdir ~/.kube
+ pushd ~/.kube
+ python /var/onap/files/kubectl_config_generator.py
+ popd
+ fi
+}
+
+# _install_helm() - Function that install Kubernetes Package Manager
+function _install_helm {
+ local helm_version=v2.3.0
+
+ if ! $(helm version &>/dev/null); then
+ wget http://storage.googleapis.com/kubernetes-helm/helm-${helm_version}-linux-amd64.tar.gz
+ tar -zxvf helm-${helm_version}-linux-amd64.tar.gz -C /tmp
+ mv /tmp/linux-amd64/helm /usr/local/bin/helm
+ helm init
+ fi
+}
+
+# _pull_images_from_yaml() - Function that parses a yaml file and pull their images
+function _pull_images_from_yaml_file {
+ local values_file=$1
+ local prefix=$2
+ local s='[[:space:]]*'
+ local w='[a-zA-Z0-9_]*'
+ fs=`echo @|tr @ '\034'`
+
+ for line in $(sed -ne "s|^\($s\):|\1|" \
+-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
+-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $values_file |
+awk -F$fs '{
+indent = length($1)/2;
+vname[indent] = $2;
+for (i in vname) {
+ if (i > indent) {
+ delete vname[i]}
+ }
+ if (length($3) > 0) {
+ vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])(".")}
+ printf("%s%s%s=%s\n", "'$prefix'",vn, $2, $3);
+ }
+}' | grep image); do
+ echo $line
+ if echo $line | grep -q Version ; then
+ pull_docker_image "$image_name:$(echo $line | awk -F "=" '{print $2}')" &
+ else
+ image_name=`echo ${line#*=}`
+ if [[ ${image_name#*${nexus_docker_repo:-nexus3.onap.org:10001}} == *:* ]]; then
+ pull_docker_image $image_name &
+ else
+ pull_docker_image $image_name:latest
+ fi
+ fi
+ done
+}
+
+# _wait_docker_pull() - Function that waits for all docker pull processes
+function _wait_docker_pull {
+ local counter=150
+
+ while [ $(ps -ef | grep "docker pull" | wc -l) -gt 1 ]; do
+ sleep $oom_delay
+ counter=$((counter - 1))
+ if [ "$counter" -eq 0 ]; then
+ break
+ fi
+ done
+}
+
+# get_oom_images() - Function that retrieves ONAP images from official hub
+function get_oom_images {
+ if [[ "$build_image" == "True" ]]; then
+ # TODO(electrocucaracha): Create a function for calling the build docker function of every ONAP project
+ echo "Not Implemented"
+ else
+ if [[ "$clone_repo" != "True" ]]; then
+ clone_repos "oom"
+ fi
+
+ docker_openecomp_login
+ for values_file in `find ${src_folders[oom]}/kubernetes -name values.yaml -type f`; do
+ _pull_images_from_yaml_file $values_file
+ done
+ docker logout
+ _wait_docker_pull
+ fi
+}
+
+# _install_oom() - Function that clones OOM and deploys ONAP
+function install_oom {
+ if [[ "$clone_repo" != "True" ]]; then
+ clone_repos "oom"
+ fi
+ pushd ${src_folders[oom]}/kubernetes/oneclick
+ source setenv.bash
+
+ pushd ${src_folders[oom]}/kubernetes/config
+ cp onap-parameters-sample.yaml onap-parameters.yaml
+ ./createConfig.sh -n onap
+ popd
+
+ for app in consul msb mso message-router sdnc vid robot portal policy appc aai sdc dcaegen2 log cli multicloud clamp vnfsdk uui aaf vfc kube2msb; do
+ ./createAll.bash -n onap -a $app
+ done
+ popd
+}
+
+# init_oom() - Function that deploys ONAP using OOM
+function init_oom {
+ mount_external_partition sda /var/lib/docker/
+ _install_kubernetes
+ _install_kubectl
+ _install_helm
+ if [[ "$clone_repo" == "True" ]]; then
+ clone_repos "oom"
+ fi
+
+ if [[ "$skip_get_images" == "False" ]]; then
+ get_oom_images
+ if [[ "$skip_install" == "False" ]]; then
+ until kubectl cluster-info; do
+ echo "waiting for kubernetes host"
+ sleep $oom_delay
+ done
+ install_oom
+ fi
+ fi
+}