-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.sh
executable file
·68 lines (60 loc) · 1.63 KB
/
cli.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
62
63
64
65
66
67
68
#!/bin/bash
function add_cluster() {
[ -z "$1" ] && usage
[ -z "$2" ] && usage
curl -i -XPOST http://127.0.0.1:8000/api/v1/cluster -d "{\"name\": \"$1\", \"prefix\": \"$2\"}"
}
function remove_cluster() {
[ -z "$1" ] && usage
curl -i -XDELETE http://127.0.0.1:8000/api/v1/cluster -d "{\"name\": \"$1\"}"
}
function add_endpoint() {
[ -z "$1" ] && usage
[ -z "$2" ] && usage
[ -z "$3" ] && usage
curl -i -XPOST http://127.0.0.1:8000/api/v1/endpoint -d "{\"cluster\": \"$1\", \"ipaddress\": \"$2\", \"port\": $3}"
}
function remove_endpoint() {
[ -z "$1" ] && usage
[ -z "$2" ] && usage
[ -z "$3" ] && usage
curl -i -XDELETE http://127.0.0.1:8000/api/v1/endpoint -d "{\"cluster\": \"$1\", \"ipaddress\": \"$2\", \"port\": $3}"
}
function commit_changes() {
curl -i -XPOST http://127.0.0.1:8000/api/v1/commit
}
function usage() {
echo "Usage:"
echo "$0 cluster add <name> <url_prefix>"
echo "$0 cluster remove <name>"
echo "$0 endpoint add <cluster_name> <ip_address> <port>"
echo "$0 endpoint remove <cluster_name> <ip_address> <port>"
echo "$0 commit"
exit 1
}
case "$1" in
cluster)
if [ "$2" == "add" ]; then
add_cluster "$3" "$4"
elif [ "$2" == "remove" ]; then
remove_cluster "$3"
else
usage
fi
;;
endpoint)
if [ "$2" == "add" ]; then
add_endpoint "$3" "$4" "$5"
elif [ "$2" == "remove" ]; then
remove_endpoint "$3" "$4" "$5"
else
usage
fi
;;
commit)
commit_changes
;;
*)
usage
;;
esac