forked from rut31337/order_svc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
stop_svc.sh
executable file
·63 lines (49 loc) · 1.49 KB
/
stop_svc.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
#!/bin/bash
# CloudForms Retire Services - Ahsen Shah <ahshah@redhat.com>
# this script is for automation only, be careful!
# because this script reads stdin, you have to set those environment variables:
# - username
# - password
# - uri
# safety options
set -e -o pipefail
ORIG="$(cd "$(dirname "$0")" || exit; pwd)"
# shellcheck source=common.sh
. "${ORIG}/common.sh"
usage() {
echo "Error: Usage $0 [-u <username> -w <uri> ]"
echo
echo "This script reads the input from STDIN. Each line should be ID NAME of service to retire."
echo "ex: . credentials.rc; ./get_svc.sh | grep 'OCP'| ./stop_svc.sh"
}
while getopts y:hu:w:d: FLAG; do
case $FLAG in
# y) noni=1;;
u) username="$OPTARG"
export username
;;
w) uri="$OPTARG"
export uri
;;
h) usage;exit;;
*) usage;exit;;
esac
done
if ! command -v jq > /dev/null; then
echo >&2 "please install jq"
exit 2
fi
while read -r itemID name; do
# ensure (itemID name) couple makes sense
remoteName=$(cfget "${uri}/api/services/${itemID}?attributes=name&expand=resources" \
| jq -r '.name')
if [ "${name}" != "${remoteName}" ]; then
echo >&2 "name provided with id does not match remote name: ${name} != ${remoteName}"
exit 2
fi
PAYLOAD="{ \"action\": \"StopNV\" }"
cfpost \
-d "${PAYLOAD}" \
"${uri}/api/services/${itemID}" \
| jq -r '(.id|tostring) + " " + .name'
done