-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlist_svcs.sh
executable file
·62 lines (49 loc) · 1.67 KB
/
list_svcs.sh
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
#!/bin/bash
# CloudForms Get Services - Patrick Rutledge [email protected]
# Defaults
uri="https://cf.example.com"
# Dont touch from here on
usage() {
echo "Error: Usage $0 -u <username> -c <catalogName> [ -P <password> -w <uri> -N ]"
}
while getopts Nu:c:w:P: FLAG; do
case $FLAG in
u) username="$OPTARG";;
c) catalogName="$OPTARG";;
P) password="$OPTARG";;
N) insecure=1;;
w) uri="$OPTARG";;
*) usage;exit;;
esac
done
if [ -z "$catalogName" ]
then
usage
exit 1
fi
if [ -z "$username" ]
then
echo -n "Enter CF Username: ";read username
fi
if [ -z "$password" ]
then
echo -n "Enter CF Password: "
stty -echo
read password
stty echo
echo
fi
if [ "$insecure" == 1 ]
then
ssl="-k"
else
ssl=""
fi
tok=`curl -s $ssl --user $username:$password -X GET -H "Accept: application/json" $uri/api/auth|python -m json.tool|grep auth_token|cut -f4 -d\"`
catalogName=`echo $catalogName|sed "s/ /+/g"`
catalogID=`curl -s $ssl -H "X-Auth-Token: $tok" -H "Content-Type: application/json" -X GET "$uri/api/service_catalogs?attributes=name,id&expand=resources&filter%5B%5D=name='$catalogName'" | python -m json.tool |grep '"id"' | cut -f2 -d:|sed "s/[ ,\"]//g"`
stIDs=`curl -s $ssl -H "X-Auth-Token: $tok" -H "Content-Type: application/json" -X GET "$uri/api/services?attributes=service_template_id&expand=resources" | python -m json.tool | grep '"service_template_id"'|cut -f2 -d:|sed -e "s/[ \"]//g"`
for sti in $stIDs
do
curl -s $ssl -H "X-Auth-Token: $tok" -H "Content-Type: application/json" -X GET "$uri/api/service_catalogs/$catalogID/service_templates/$sti?attributes=name" | python -m json.tool | grep '"name"'|cut -f2 -d:|sed -e "s/[ \"]//g"
done