forked from jenkinsci/elasticbox-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·46 lines (38 loc) · 1.6 KB
/
cleanup.sh
File metadata and controls
executable file
·46 lines (38 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
if [[ $# -lt 1 ]]
then
echo "Usage: cleanup.sh EBX_ADDRESS EBX_WORKSPACE TAG"
exit 1
fi
ELASTICBOX_RELEASE="4.0"
EBX_ADDRESS=${1}
EBX_WORKSPACE=${2}
TAG=${3}
function delete_boxes() {
BOX_NAME_PART=${1}
BOX_IDS=$(eb boxes list --token ${EBX_TOKEN} --address ${EBX_ADDRESS} --no-keychain -i ${EBX_WORKSPACE} -t ${TAG} | awk '{ print $1 }')
for BOX_ID in ${BOX_IDS}
do
BOX_URL=${EBX_ADDRESS}/services/boxes/${BOX_ID}
echo Deleting box ${BOX_URL}
curl -k# -X DELETE -H "ElasticBox-Token: ${EBX_TOKEN}" -H "ElasticBox-Release: ${ELASTICBOX_RELEASE}" ${BOX_URL}
done
}
sudo pip install ebcli --upgrade
cd $(dirname $0)
REPOSITORY_FOLDER=$(pwd)
source ${REPOSITORY_FOLDER}/common.sh
EBX_TOKEN=$(ebx_token test_admin@elasticbox.com elasticbox)
PROVIDER_IDS=$(curl -k# -H "ElasticBox-Token: ${EBX_TOKEN}" -H "ElasticBox-Release: ${ELASTICBOX_RELEASE}" ${EBX_ADDRESS}/services/workspaces/${EBX_WORKSPACE}/providers | python -m json.tool | grep /services/providers | sed -e 's|/services/providers/||g' -e 's/"//g' | awk '{ print $2 }')
for PROVIDER_ID in ${PROVIDER_IDS}
do
PROVIDER_URL=${EBX_ADDRESS}/services/providers/${PROVIDER_ID}
PROVIDER_NAME=$(curl -k# -H "ElasticBox-Token: ${EBX_TOKEN}" -H "ElasticBox-Release: ${ELASTICBOX_RELEASE}" ${PROVIDER_URL} | python -m json.tool | grep '^ "name":' | sed -e 's/[ ",]//g' -e 's/name://')
if [ -z $(echo ${EXCLUDED_PROVIDERS} | grep ${PROVIDER_NAME}) ]
then
echo Deleting provider ${PROVIDER_URL}
curl -k# -X DELETE -H "ElasticBox-Token: ${EBX_TOKEN}" -H "ElasticBox-Release: ${ELASTICBOX_RELEASE}" "${PROVIDER_URL}"
echo
fi
done
delete_boxes