-
Notifications
You must be signed in to change notification settings - Fork 37
/
send.sh
executable file
·103 lines (88 loc) · 1.99 KB
/
send.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
host=localhost
port=9090
service="microvm.services.api.v1alpha1.MicroVM"
method="ListMicroVMs"
namespace="ns1"
uid=""
if ! which grpcurl >/dev/null 2>/dev/null; then
echo "!!! grpcurl is not installed. Please install this awesome tool." >&2
echo "" >&2
echo " go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest" >&2
exit 1
fi
function help() {
cat <<EOH
${0} [flags] -s service -m method>
-H/--host HOST hostname; default: ${host}
-p/--port PORT port; default: ${port}
-s/--service service name of the service; default: ${service}
-m/--method method name of the method on the service; default: ${method}
--uid uid uuid of the microvm
--namespace namespace namespace to query; default: ${namespace}
-h/--help help
Special:
* DeleteMicroVM uses --uid
* ListMicroVMs uses --namespace
Examples:
${0} -m ListMicroVMs --namespace ns1
${0} -m DeleteMicroVM --uid "microvmuid"
EOH
exit 0
}
while [[ "$#" -gt 0 ]]; do
case "${1}" in
-H|--host)
host=${2}
shift; shift
;;
-p|--port)
port=${2}
shift; shift
;;
-s|--service)
service=${2}
shift; shift
;;
-m|--method)
method=${2}
shift; shift
;;
-h|--help)
help
exit 0
;;
--namespace)
namespace=${2}
shift; shift;
;;
--uid)
uid=${2}
shift; shift;
;;
*)
echo "Unknown flag: ${1}" >&2
help
exit 1
esac
done
pushd "$(dirname "${0}")" > /dev/null
case "${method}" in
"DeleteMicroVM")
grpcurl -d "{\"uid\": \"${uid}\"}" \
-plaintext "${host}:${port}" \
"${service}/${method}"
;;
"ListMicroVMs")
grpcurl -d "{\"namespace\": \"${namespace}\"}" \
-plaintext "${host}:${port}" \
"${service}/${method}"
;;
*)
grpcurl -d @ \
-plaintext "${host}:${port}" \
"${service}/${method}" \
< "payload/${method}.json"
;;
esac
popd > /dev/null