forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup-integration
executable file
·73 lines (54 loc) · 2.92 KB
/
cleanup-integration
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
set -e
xargs_func () {
if [[ $(uname) == "Darwin" ]]; then
xargs -n 1 -P 15 $@
else
xargs -n 1 -P 15 -r $@
fi
}
if [[ -z $CF_INT_API ]]; then
echo "\$CF_INT_API is unset! Did you run 'int'?"
fi
CF_API=${CF_INT_API:-"NO-BOSH-LITE-SET"}
export CF_USERNAME=${CF_INT_USERNAME:-"admin"}
export CF_PASSWORD=${CF_INT_PASSWORD:-"admin"}
export CF_CLI_EXPERIMENTAL=true
export CF_DIAL_TIMEOUT=15
if [[ -z $SKIP_SSL_VALIDATION || $SKIP_SSL_VALIDATION == "true" ]]; then
cf api $CF_API --skip-ssl-validation
else
cf api $CF_API
fi
cf auth
# we don't want the pipeline job to fail because there's a high chance of
# failure when running commands in parallel
set +e
cf create-org temp-org
cf target -o temp-org
cf domains | egrep -i ^\(sub.\)?integration- | cut -d " " -f1 | xargs_func cf delete-shared-domain -f
# This is required for older stacks where the delete-security-group API call was not implemented recursively by the CC.
if [[ $1 == "unbind-first" ]]; then
cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i staging | awk '{print $2 " " $3 " " $4}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle staging
cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i staging | awk '{print $1 " " $2 " " $3}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle staging
cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i running | awk '{print $2 " " $3 " " $4}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle running
cf security-groups | grep -i "integration-sec-group" | grep -v \<all\>| grep -i running | awk '{print $1 " " $2 " " $3}' | uniq - | xargs -n 3 -P 15 -r cf unbind-security-group --lifecycle running
fi
cf security-groups | grep -i "integration-sec-group" | sed 's=^#[0-9]*==' | awk '{print $1}' | xargs_func cf delete-security-group -f
cf isolation-segments | grep -i ^integration-isolation-segment | xargs_func cf delete-isolation-segment -f
cf service-brokers | grep -i -e ^integration-service-broker- -e CATS- | awk '{print $1}' | xargs_func cf delete-service-broker -f
cf quotas | grep -i -e ^integration-quota -e CATS- | awk '{print $1}' | xargs_func cf delete-quota -f
cf orgs | grep -i -e ^integration-org -e CATS- | xargs_func cf delete-org -f
cf delete-org -f temp-org
cf buildpacks | awk '/INTEGRATION-BUILDPACK/ { if(NF >= 6) { printf("cf delete-buildpack -f %s -s %s\n", $2, $3); } else { printf("cf delete-buildpack -f %s\n", $2); }}' | bash
for stack in $(cf stacks | awk '/INTEGRATION-STACK/ { print $1 }'); do
echo Deleting $stack
cf curl -X DELETE "/v3/stacks/$(cf stack --guid $stack)"
done
USER_PAGES=$(cf curl /v3/users | jq -r .pagination.total_pages)
for ((i=1; i<=${USER_PAGES}; i++)) ; do
cf curl "/v3/users?&page=${i}" | \
jq -r .resources[].username | \
grep -i -e ^integration-user -e CATS- | \
xargs_func cf delete-user -f || echo
done