From fa9eb9c5c50ca147504cb97226007b82f6909b8a Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Mon, 18 Dec 2017 09:56:13 -0800 Subject: Add OOM provisioning script The instructions to provision a ONAP Operations Manager environment was included into the vagrant-onap tool. This script requires a specific docker version besides some tasks that wait for certain services. Change-Id: I39f0b7947e7c87d8aa44ffa93cdb414d700379bd Signed-off-by: Victor Morales Co-Authored-By: Shashank Kumar Shankar Issue-ID: INT-370 --- bootstrap/vagrant-onap/lib/oom | 220 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100755 bootstrap/vagrant-onap/lib/oom (limited to 'bootstrap/vagrant-onap/lib/oom') 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