diff options
Diffstat (limited to 'kud/hosting_providers/vagrant')
-rw-r--r-- | kud/hosting_providers/vagrant/README.md | 10 | ||||
-rwxr-xr-x | kud/hosting_providers/vagrant/cleanup.sh | 87 |
2 files changed, 95 insertions, 2 deletions
diff --git a/kud/hosting_providers/vagrant/README.md b/kud/hosting_providers/vagrant/README.md index 00f0a70f..f0210149 100644 --- a/kud/hosting_providers/vagrant/README.md +++ b/kud/hosting_providers/vagrant/README.md @@ -4,7 +4,7 @@ This project offers a means for deploying a Kubernetes cluster that satisfies the requirements of [ONAP multicloud/k8s plugin][1]. Its -ansible playbooks allow to provision a deployment on Virtual Machines. +ansible playbooks allow provisioning a deployment on Virtual Machines. ![Diagram](../../../docs/img/diagram.png) @@ -21,16 +21,22 @@ Linux instructions to install dependencies and plugins required for its usage. This script supports two Virtualization technologies (Libvirt and VirtualBox). - $ ./setup.sh -p libvirt + $ sudo ./setup.sh -p libvirt Once Vagrant is installed, it's possible to provision a cluster using the following instructions: $ vagrant up && vagrant up installer +In-depth documentation and use cases of various Vagrant commands [Vagrant commands][3] +is available on the Vagrant site. + ## License Apache-2.0 [1]: https://git.onap.org/multicloud/k8s + [2]: https://www.vagrantup.com/ + +[3]: https://www.vagrantup.com/docs/cli/ diff --git a/kud/hosting_providers/vagrant/cleanup.sh b/kud/hosting_providers/vagrant/cleanup.sh new file mode 100755 index 00000000..75e6de11 --- /dev/null +++ b/kud/hosting_providers/vagrant/cleanup.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# options: +# remove stopped containers and untagged images +# $ ./cleanup +# remove all stopped|running containers and untagged images +# $ ./cleanup --reset +# remove containers|images| matching {repository:tag} +# pattern and untagged images +# $ ./cleanup --purge {image} +# everything +# $ ./cleanup --nuclear + +function _clean_docker { +local matchExp="" +if [ "$1" == "--reset" ]; then + # Remove all containers regardless of state + docker rm -vf $(docker ps -a -q) 2>/dev/null || \ + echo "No more containers to remove." + exit 0 +elif [ "$1" == "--purge" ]; then + if [ -z "$2" ]; then + echo "Cannot purge. Please provide image name to purge." + exit 0 + fi + matchExp=$2 + # Attempt to remove running containers that are using the images we're trying to purge first. + if [[ $(docker ps --filter "name=$matchExp") ]]; then + echo "Removing running containers using the \"$2\" container image" + docker rm -vf $(docker ps -a --format "{{.Image}} {{.Names}}" | \ + awk '$0 ~ matchExp {print $2}') 2>/dev/null + else + echo "No running containers using the \"$2\" container image" + fi + echo "Continue to purge container images..." + # Remove all images matching arg given after "--purge"` + docker images -q --format "{{.Repository}}:{{.Tag}}" | grep "$matchExp" + returnVal=$? + if [ $returnVal -ne 0 ]; then + echo "No \"$2\" container image found." + exit 0 + else + echo "Removing all the \"$2\" container images." + docker images --format "{{.Repository}}:{{.Tag}}" | grep "$matchExp" |\ + awk '$0 ~ matchExp {print $1}' | xargs docker rmi 2>/dev/null + exit 0 + fi +else + # This alternate only removes "stopped" containers + docker rm -vf $(docker ps -a | grep "Exited" | \ + awk '{print $2}') 2>/dev/null || echo "No stopped containers to remove." +fi + +if [ "$1" == "--nuclear" ]; then + docker rm -vf $(docker ps -a -q) 2>/dev/null || \ + echo "No more containers to remove." + docker rmi $(docker images -q) 2>/dev/null || \ + echo "No more images to remove." + echo "Preparing to uninstall docker ....." + dpkg -l | grep Docker | awk '{print $2}' > /tmp/docker-list.txt + while read list; do + sudo apt-get remove $list -y + done </tmp/docker-list.txt + rm /tmp/docker-list.txt + else + # Remove all images which are not used by existing container + docker image prune -a || echo "No untagged images to delete." +fi + +} + +function _clean_ansible { +if [ "$1" == "--nuclear" ]; then +version=$(grep "ansible_version" ${kud_playbooks}/kud-vars.yml | \ +awk -F ': ' '{print $2}') +sudo pip uninstall ansible==$version +fi +} + +#Defining config path +INSTALLER_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")" +kud_folder=${INSTALLER_DIR} +kud_infra_folder=$kud_folder/../../deployment_infra +kud_playbooks=$kud_infra_folder/playbooks + +_clean_docker $@ +_clean_ansible $1 |