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/_onap_functions | 6 +- bootstrap/vagrant-onap/lib/config/env-vars | 2 + .../lib/files/kubectl_config_generator.py | 40 ++++ bootstrap/vagrant-onap/lib/functions | 38 +++- bootstrap/vagrant-onap/lib/oom | 220 +++++++++++++++++++++ bootstrap/vagrant-onap/lib/sdc | 20 +- 6 files changed, 298 insertions(+), 28 deletions(-) create mode 100644 bootstrap/vagrant-onap/lib/files/kubectl_config_generator.py create mode 100755 bootstrap/vagrant-onap/lib/oom (limited to 'bootstrap/vagrant-onap/lib') diff --git a/bootstrap/vagrant-onap/lib/_onap_functions b/bootstrap/vagrant-onap/lib/_onap_functions index cedd6f0a3..960b298ef 100755 --- a/bootstrap/vagrant-onap/lib/_onap_functions +++ b/bootstrap/vagrant-onap/lib/_onap_functions @@ -15,7 +15,7 @@ function create_configuration_files { # docker_openecomp_login() - Login to OpenECOMP Docker Hub function docker_openecomp_login { install_docker - docker login -u $nexus_username -p $nexus_password $nexus_docker_repo + docker login -u ${nexus_username:-docker} -p ${nexus_password:-docker} ${nexus_docker_repo:-nexus3.onap.org:10001} } # pull_openecomp_image() - Pull Docker container image from a Docker Registry Hub @@ -23,7 +23,7 @@ function pull_openecomp_image { local image=$1 local tag=$2 docker_openecomp_login - pull_docker_image $nexus_docker_repo/openecomp/${image}:${docker_version-latest} $tag + pull_docker_image ${nexus_docker_repo:-nexus3.onap.org:10001}/openecomp/${image}:${docker_version-latest} $tag docker logout } @@ -32,7 +32,7 @@ function pull_onap_image { local image=$1 local tag=$2 docker_openecomp_login - pull_docker_image $nexus_docker_repo/onap/${image}:${docker_version-latest} $tag + pull_docker_image ${nexus_docker_repo:-nexus3.onap.org:10001}/onap/${image}:${docker_version-latest} $tag docker logout } diff --git a/bootstrap/vagrant-onap/lib/config/env-vars b/bootstrap/vagrant-onap/lib/config/env-vars index 1eddf673e..a55557ae7 100755 --- a/bootstrap/vagrant-onap/lib/config/env-vars +++ b/bootstrap/vagrant-onap/lib/config/env-vars @@ -13,6 +13,7 @@ src_folders=( ["msb"]="$git_src_folder/msb" ["mso"]="$git_src_folder/mso" ["multicloud"]="$git_src_folder/multicloud" +["oom"]="$git_src_folder/oom" ["policy"]="$git_src_folder/policy" ["portal"]="$git_src_folder/portal" ["robot"]="$git_src_folder/testsuite" @@ -50,6 +51,7 @@ dcae/utils/buildtools" ["multicloud"]="multicloud multicloud/framework multicloud/openstack \ multicloud/openstack/vmware multicloud/openstack/windriver \ multicloud/azure" +["oom"]="oom oom/registrator" ["policy"]="policy/api policy/common policy/docker \ policy/drools-applications policy/drools-pdp policy/engine \ policy/gui policy/pap policy/pdp" diff --git a/bootstrap/vagrant-onap/lib/files/kubectl_config_generator.py b/bootstrap/vagrant-onap/lib/files/kubectl_config_generator.py new file mode 100644 index 000000000..6b5a6e9f6 --- /dev/null +++ b/bootstrap/vagrant-onap/lib/files/kubectl_config_generator.py @@ -0,0 +1,40 @@ +import requests +import os +import base64 + +RANCHER_URL = str(os.environ['RANCHER_URL']) +RANCHER_ENVIRONMENT_ID = str(os.environ['RANCHER_ENVIRONMENT']) +data = requests.post(RANCHER_URL + '/v1/projects/' + RANCHER_ENVIRONMENT_ID + '/apikeys', + {"accountId": RANCHER_ENVIRONMENT_ID, + "description": "ONAP on Kubernetes", + "name": "ONAP on Kubernetes", + "publicValue": "string", + "secretValue": "password"}) +json_dct = data.json() +access_key = json_dct['publicValue'] +secret_key = json_dct['secretValue'] +auth_header = 'Basic ' + base64.b64encode(access_key + ':' + secret_key) +token = "\"" + str(base64.b64encode(auth_header)) + "\"" +dct = \ +""" +apiVersion: v1 +kind: Config +clusters: +- cluster: + api-version: v1 + insecure-skip-tls-verify: true + server: "{}/r/projects/{}/kubernetes:6443" + name: "onap_on_kubernetes" +contexts: +- context: + cluster: "onap_on_kubernetes" + user: "onap_on_kubernetes" + name: "onap_on_kubernetes" +current-context: "onap_on_kubernetes" +users: +- name: "onap_on_kubernetes" + user: + token: {} +""".format(RANCHER_URL, RANCHER_ENVIRONMENT_ID, token) +with open("config", "w") as file: + file.write(dct) diff --git a/bootstrap/vagrant-onap/lib/functions b/bootstrap/vagrant-onap/lib/functions index 08c6d916b..9531fc794 100755 --- a/bootstrap/vagrant-onap/lib/functions +++ b/bootstrap/vagrant-onap/lib/functions @@ -139,6 +139,7 @@ function _configure_docker_settings { local docker_conf_backup=/tmp/docker.backup local docker_conf=/etc/default/docker local chameleonsocks_filename=chameleonsocks.sh + local max_concurrent_downloads=${1:-3} cp $docker_conf $docker_conf_backup if [ $http_proxy ]; then @@ -160,7 +161,20 @@ function _configure_docker_settings { fi rm $docker_conf_backup - echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock\"" >> $docker_conf + echo "DOCKER_OPTS=\"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --max-concurrent-downloads $max_concurrent_downloads \"" >> $docker_conf + usermod -aG docker $USER + + source /etc/os-release || source /usr/lib/os-release + case ${ID,,} in + *suse) + ;; + ubuntu|debian) + service docker restart + sleep 10 + ;; + rhel|centos|fedora) + ;; + esac } # install_nodejs() - Download and install NodeJS @@ -208,7 +222,7 @@ function install_python_requirements { # install_docker() - Download and install docker-engine function install_docker { - if is_package_installed docker-ce; then + if $(docker version &>/dev/null); then return fi source /etc/os-release || source /usr/lib/os-release @@ -229,8 +243,6 @@ function install_docker { install_package docker-ce _configure_docker_settings - service docker restart - sleep 10 } # pull_docker_image() - Pull Docker container image from the Public Docker Registry Hub @@ -265,8 +277,8 @@ function _install_ODL { if [ ! -d /opt/opendaylight/current ]; then mkdir -p /opt/opendaylight/ wget "https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/integration/distribution-karaf/"$odl_version"/distribution-karaf-"$odl_version".tar.gz" -P /opt/ - tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /opt/ - mv "/opt/distribution-karaf-"$odl_version /opt/opendaylight/current + tar xvf "/opt/distribution-karaf-"$odl_version".tar.gz" -C /tmp/ + mv "/tmp/distribution-karaf-"$odl_version /opt/opendaylight/current rm -rf "/opt/distribution-karaf-"$odl_version".tar.gz" fi } @@ -356,3 +368,17 @@ function build_docker_image { eval $docker_build popd } + +# mount_external_partition() - Create partition and mount the external volume +function mount_external_partition { + local dev_name="/dev/$1" + local mount_dir=$2 + + sfdisk $dev_name << EOF +; +EOF + mkfs -t ext4 ${dev_name}1 + mkdir -p $mount_dir + mount ${dev_name}1 $mount_dir + echo "${dev_name}1 $mount_dir ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab +} 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 /tmp/sdc_ext_volume_partitions.txt -# partition table of /dev/sdb -unit: sectors - -/dev/sdb1 : start= 2048, size=209713152, Id=83 -/dev/sdb2 : start= 0, size= 0, Id= 0 -/dev/sdb3 : start= 0, size= 0, Id= 0 -/dev/sdb4 : start= 0, size= 0, Id= 0 -EOL - sfdisk --force /dev/sdb < /tmp/sdc_ext_volume_partitions.txt - mkfs -t ext4 /dev/sdb1 - mkdir -p /data - mount /dev/sdb1 /data - echo "/dev/sdb1 /data ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab -} - # _init_data_folders() - Function that initialize the data folders function _init_data_folders { mkdir -p /data/environments @@ -82,7 +64,7 @@ function install_sdc { # init_sdc() - Function that initialize SDC services function init_sdc { - _mount_external_partition + mount_external_partition sdb /data/ if [[ "$clone_repo" == "True" ]]; then clone_repos "sdc" if [[ "$compile_repo" == "True" ]]; then -- cgit 1.2.3-korg