-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhf.cluster.statuses.table.sh
More file actions
executable file
·62 lines (58 loc) · 1.95 KB
/
hf.cluster.statuses.table.sh
File metadata and controls
executable file
·62 lines (58 loc) · 1.95 KB
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
#!/bin/bash
# Show cluster adapter statuses in table format (Available and Finalized only)
# Usage: hf.cluster.statuses.table.sh [cluster_id]
source "$(dirname "$(realpath "$0")")/hf.lib.sh"
hf_require_config api-url api-version cluster-id
hf_require_jq
CLUSTER_ID=$(hf_cluster_id "${1:-}")
URL="${HF_API_URL}/api/hyperfleet/${HF_API_VERSION}/clusters/${CLUSTER_ID}/statuses"
hf_info "Getting statuses table for cluster: $CLUSTER_ID"
GREEN=$(printf '\033[32m')
RED=$(printf '\033[31m')
YELLOW=$(printf '\033[33m')
RESET=$(printf '\033[0m')
curl -s "$URL" | jq -r '
def cond(t):
map(select(.type == t)) | .[0].status // "-" |
if . == "True" then ""
elif . == "False" then ""
elif . == "Unknown" then ""
else . end;
(["ADAPTER", "GEN", "Available", "Finalized"] | @tsv),
(["---", "---", "---", "---"] | @tsv),
(.items[] | [
.adapter,
(.observed_generation // 0 | tostring),
(.conditions | cond("Available")),
(.conditions | cond("Finalized"))
] | @tsv)
' | awk -v green="$GREEN" -v red="$RED" -v yellow="$YELLOW" -v reset="$RESET" '
BEGIN { FS = "\t" }
{
row[NR] = $0
n = split($0, f, "\t")
if (n > ncols) ncols = n
for (i = 1; i <= n; i++) {
cell = f[i]
if (cell == "\001") dw = 4
else if (cell == "\002") dw = 5
else if (cell == "\003") dw = 7
else dw = length(cell)
if (dw > cw[i]) cw[i] = dw
}
}
END {
for (r = 1; r <= NR; r++) {
n = split(row[r], f, "\t")
for (i = 1; i <= ncols; i++) {
cell = (i <= n) ? f[i] : ""
if (cell == "\001") { display = green "True" reset; dw = 4 }
else if (cell == "\002") { display = red "False" reset; dw = 5 }
else if (cell == "\003") { display = yellow "Unknown" reset; dw = 7 }
else { display = cell; dw = length(cell) }
pad = cw[i] - dw
if (i < ncols) printf "%s%*s ", display, pad, ""
else printf "%s\n", display
}
}
}'