-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl
executable file
·65 lines (58 loc) · 1.68 KB
/
repl
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
#!/bin/sh
export HOST=https://192.168.1.10
export OUTPUT_PARAM="--output=/dev/null"
PROG=$(basename "$0")
usage() {
echo "Usage: $PROG --enable-all | --disable-all"
exit 0
}
set_repl() {
ID=$1
REPL_TO=$2
if http --check-status $OUTPUT_PARAM -pHBhb --verify=no --ignore-stdin PUT $HOST/api/v1.0/storage/replication/"$ID"/ repl_enabled="$REPL_TO"
then
echo 'OK!'
else
case $? in
2) echo 'Request timed out!' ;;
3) echo 'Unexpected HTTP 3xx Redirection!' ;;
4) echo 'HTTP 4xx Client Error!' ;;
5) echo 'HTTP 5xx Server Error!' ;;
6) echo 'Exceeded --max-redirects=<n> redirects!' ;;
*) echo 'Other Error!' ;;
esac
fi
}
for arg
do
case "$arg" in
--enable-all)
REPL_FROM=false
REPL_TO=true
REPL_ACTION=enabling
;;
--disable-all)
REPL_FROM=true
REPL_TO=false
REPL_ACTION=disabling
;;
--verbose)
OUTPUT_PARAM=
;;
*)
usage
;;
esac
done
test -n "$REPL_FROM" -a -n "$REPL_TO" || usage
http --verify=no $HOST/api/v1.0/storage/replication/ |
jq "map(select(.repl_enabled==$REPL_FROM)) | .[] | .id,.repl_filesystem" |
paste -d, - - |
while read -r task
do
ID=$(echo "$task" | cut -d, -f1)
export ID
NAME=$(echo "$task" | cut -d, -f2)
echo "$REPL_ACTION" "$NAME"
set_repl "$ID" "$REPL_TO"
done