Skip to content

Commit 96f735f

Browse files
committed
refactor: ghe-cluster-each --print, --ip, --uuid flags
1 parent 90304d4 commit 96f735f

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

share/github-backup-utils/ghe-cluster-nodes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ prefix="$2"
2828
role=$(echo "$prefix" | cut -d '-' -f1)
2929

3030
if ghe-ssh "$GHE_HOSTNAME" test -f $GHE_REMOTE_ROOT_DIR/etc/github/cluster; then
31-
node_uuids=$(ghe-ssh "$GHE_HOSTNAME" ghe-cluster-each -r "$role" -u)
31+
node_uuids=$(ghe-ssh "$GHE_HOSTNAME" /usr/local/bin/ghe-cluster-nodes -r "$role" -u | cut -f 2)
3232
hostnames=''
3333
for uuid in $node_uuids; do
3434
hostnames+="$prefix-$uuid "

test/bin/ghe-cluster-each

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
#!/usr/bin/env bash
2-
# Usage: ghe-config
3-
# Emulates the remote GitHub ghe-config command. Tests use this
2+
# Usage: ghe-cluster-each
3+
# Emulates the remote GitHub ghe-cluster-each command. Tests use this
44
# to assert that the command was executed.
55
set -e
66

77
for _ in "$@"; do
88
case "$1" in
9-
-u)
10-
SHOW_UUID=true
11-
shift
12-
;;
13-
-r|--role)
14-
# fake change last save timestamp every 1s
15-
ROLE=$2
16-
shift
17-
shift
18-
;;
199
--)
2010
if [ "$1" = "--" ]; then
2111
shift
@@ -43,22 +33,3 @@ if [ "$COMMAND" == "/usr/local/share/enterprise/ghe-nomad-cleanup" ]; then
4333
echo "nomad cleanup"
4434
exit 0
4535
fi
46-
47-
if $SHOW_UUID; then
48-
CONFIG="$GHE_REMOTE_DATA_USER_DIR/common/cluster.conf"
49-
50-
hosts=$(git config -f $CONFIG --get-regexp cluster.*.hostname | cut -d ' ' -f2)
51-
52-
if [ -z "$hosts" ]; then
53-
# Mimic `ghe-cluster-each $role -u`
54-
echo "fake-uuid
55-
fake-uuid1
56-
fake-uuid2
57-
"
58-
else
59-
for hostname in $hosts; do
60-
[ -n "$ROLE" ] && [ "$(git config -f $CONFIG cluster.$hostname.$ROLE-server)" != "true" ] && continue
61-
echo $hostname
62-
done
63-
fi
64-
fi

test/bin/ghe-cluster-nodes

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# Usage: ghe-cluster-nodes
3+
# Emulates the remote GitHub ghe-cluster-nodes command. Tests use this
4+
# to assert that the command was executed.
5+
set -e
6+
7+
for _ in "$@"; do
8+
case "$1" in
9+
-r|--role)
10+
MATCH_ROLE=$2
11+
shift
12+
;;
13+
-u|--uuid)
14+
PRINT_UUIDS=true
15+
shift
16+
;;
17+
esac
18+
done
19+
20+
CONFIG="$GHE_REMOTE_DATA_USER_DIR/common/cluster.conf"
21+
22+
hosts=$(git config -f $CONFIG --get-regexp cluster.*.hostname | cut -d ' ' -f2)
23+
24+
for hostname in $hosts; do
25+
[ -n "$MATCH_ROLE" ] && [ "$(git config -f $CONFIG cluster.$hostname.$MATCH_ROLE-server)" != "true" ] && continue
26+
27+
print_line="$hostname"
28+
29+
if [ -n "$PRINT_UUIDS" ]; then
30+
uuid="$(ghe-config cluster.$hostname.uuid || true)"
31+
print_line="$print_line\t$uuid"
32+
fi
33+
34+
echo -e "${print_line#\\t}"
35+
done

0 commit comments

Comments
 (0)