forked from trento-project/trento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_scenario_from_k8s.sh
executable file
·85 lines (68 loc) · 1.87 KB
/
dump_scenario_from_k8s.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -e
readonly ARGS=("$@")
usage() {
cat <<-EOF
usage: dump_scenario_from_k8s.sh options
Dump the current scenario from a running trento-server installation on the k8s cluster
OPTIONS:
-n, --name The name to use for the scenario. Defaults to "current".
-p, --path The path where the scenario should be saved. Defaults to the current directory.
-h, --help Print this help.
Example:
dump_scenario_from_k8s.sh --name failover --path /tmp
EOF
}
cmdline() {
local arg=
for arg; do
local delim=""
case "$arg" in
--name) args="${args}-n " ;;
--path) args="${args}-p " ;;
--help) args="${args}-h " ;;
# pass through anything else
*)
[[ "${arg:0:1}" == "-" ]] || delim="\""
args="${args}${delim}${arg}${delim} "
;;
esac
done
eval set -- "$args"
while getopts "n:p:h" OPTION; do
case $OPTION in
h)
usage
exit 0
;;
n)
readonly NAME=$OPTARG
;;
p)
readonly EXPORT_PATH=$OPTARG
;;
*)
usage
exit 0
;;
esac
done
return 0
}
dump-scenario() {
local name=${NAME:-current}
local path="${EXPORT_PATH:-$PWD}"
if [[ -d "$path/scenarios/$name" ]]; then
echo "The scenario $name already exists in $path/scenarios/$name"
echo "Please choose a different name."
exit 1
fi
kubectl exec -ti deploy/trento-server-web -- /app/trento ctl dump-scenario --name="$name" --path /scenarios
kubectl exec deploy/trento-server-web -- tar cf - scenarios | tar xf - -C "$path"
kubectl exec deploy/trento-server-web -- rm -rf /scenarios
}
main() {
cmdline "${ARGS[@]}"
dump-scenario
}
main