-
Notifications
You must be signed in to change notification settings - Fork 0
/
motraddr.sh
executable file
·312 lines (277 loc) · 7.05 KB
/
motraddr.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#
# Copyright (c) 2022 Seagate Technology LLC and/or its Affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For any questions about this software or licensing,
# please email opensource@seagate.com or cortx-questions@seagate.com.
#
#!/usr/bin/env bash
#
# prints out a set of motr parameters for a
# single connection.
#
# Ganesan Umanesan <ganesan.umanesan@seagate.com>
# 14/12/2020 - initial script
# 28/12/2020 - MIO yaml format added
# 05/01/2021 - Bash export format added
# 20/02/2021 - hastatus.yaml in /etc/motr
# 26/09/2022 - ceph.config file
#
hastatusetc='/etc/motr/hastatus.yaml'
hastatustmp=$(mktemp --tmpdir hastatus.XXXXXX)
cleanup()
{
rm -f "$hastatustmp"
}
trap cleanup EXIT
c=$HOSTNAME
[[ -f "$hastatusetc" ]] && hastatus="$hastatusetc"
[[ ! -f "$hastatusetc" ]] && hastatus="$hastatustmp"
# exclude cache, read afresh
for a in "$@" ; do
[[ "$a" = "-x" ]] && hastatus="$hastatustmp"
[[ "$a" = "--exclude-cache" ]] && hastatus="$hastatustmp"
done
# use /tmp/hastatus.yaml
if [ "$hastatus" == "$hastatustmp" ]; then
hctl status > "$hastatustmp"
echo "sage-tier9-9" >> "$hastatustmp" #add a dummy node pattern at the end
fi
pools=()
descp=()
pools=($(sed -n "/Data/,/Profile/p" "$hastatus" | sed -n "/0x.*/p" | awk '{print $1}'))
descp=($(sed -n "/Data/,/Profile/p" "$hastatus" | sed -n "/0x.*/p" | awk '{print $2}'))
#printf '%s\n' "${pools[@]}"
#printf '%s\n' "${descp[@]}"
if [ ${#pools[@]} -ne ${#descp[@]} ]; then
echo "pool/description mismatch"
exit
fi
#for (( idx=0; idx<${#pools[@]}; idx++ ))
#do
# echo "${pools[$idx]} ${descp[$idx]}"
#done
profs=()
profs=($(sed -n "/Profile/,/Services/p" "$hastatus" | sed -n "/0x.*/p" | awk '{print $1}'))
#printf '%s\n' "${profs[@]}"
#for (( idx=0; idx<${#profs[@]}; idx++ ))
#do
# echo "${profs[$idx]}"
#done
#regex for sage nodes
spat0+="client-2[1-8]|datawarp-0[1-4]|visnode-0[1-4]|sage-tier[0-9]-[0-9]"
spat0+="|client-tx2-[0-9]|sage-tier[0-9]-[0-9]a"
laddr=()
lproc=()
#echo $c
#sed -nE "/Services/,/$spat0/p" $hastatus | sed '1d;$d' | sed 's/[:@]/ /g' | awk '/hax|m0_client/ {print $0}'
#sed -nE "/Services/,/$spat0/p" $hastatus | sed '1d;$d'
#sed -nE "/Services/,/$spat0/p" $hastatus
#exit
#single-node cluster
if grep -q "localhost" "$hastatus"; then
laddr=($(sed -nE "/Services/,/$spat0/p" "$hastatus" | sed '1d;$d' | awk '/hax|m0_client/ {print $4}'))
lproc=($(sed -nE "/Services/,/$spat0/p" "$hastatus" | sed '1d;$d' | awk '/hax|m0_client/ {print $3}'))
#multi-node sage cluster
else
laddr=($(sed -nE "/$c/,/$spat0/p" "$hastatus" | sed '1d;$d' | awk '{print $4}'))
lproc=($(sed -nE "/$c/,/$spat0/p" "$hastatus" | sed '1d;$d' | awk '{print $3}'))
fi
#printf '%s\n' "${laddr[@]}"
#printf '%s\n' "${lproc[@]}"
if [ ${#laddr[@]} -ne ${#lproc[@]} ]; then
echo "addr/port mismatch"
exit
fi
#for (( idx=0; idx<${#laddr[@]}; idx++ ))
#do
# echo "${laddr[$idx]} ${lproc[$idx]}"
#done
#exit
s=$((${#laddr[@]}-1)) # max local addresses
r=$((0 + RANDOM % s)) # random local address
usage()
{
cat <<USAGE_END
Usage: $(basename "$0") [-h|--help] [options]
-m|--mio print mio configuration parameters
-e|--exp print in shell export format
-h|--help Print this help screen.
USAGE_END
exit 1
}
exp()
{
read -r -d '' BASH <<EOF
# $USER $HOSTNAME
# Bash shell export format
export CLIENT_LADDR="${laddr[1+$r]}"
export CLIENT_HA_ADDR="${laddr[0]}"
export CLIENT_PROFILE="${profs[0]}"
export CLIENT_PROC_FID="${lproc[1+$r]}"
EOF
echo "$BASH"
}
mio()
{
read -r -d '' YAML <<EOF
# $USER $HOSTNAME
# MIO configuration Yaml file.
# MIO_Config_Sections: [MIO_CONFIG, MOTR_CONFIG]
MIO_CONFIG:
MIO_LOG_DIR:
MIO_LOG_LEVEL: MIO_DEBUG
MIO_DRIVER: MOTR
MIO_TELEMETRY_STORE: ADDB
MOTR_CONFIG:
MOTR_USER_GROUP: motr
MOTR_INST_ADDR: ${laddr[1+$r]}
MOTR_HA_ADDR: ${laddr[0]}
MOTR_PROFILE: <${profs[0]}>
MOTR_PROCESS_FID: <${lproc[1+$r]}>
MOTR_DEFAULT_UNIT_SIZE: 1048576
MOTR_IS_OOSTORE: 1
MOTR_IS_READ_VERIFY: 0
MOTR_TM_RECV_QUEUE_MIN_LEN: 64
MOTR_MAX_RPC_MSG_SIZE: 131072
MOTR_POOLS:
# Set SAGE cluster pools, ranking from high performance to low.
# The pool configuration parameters can be queried using hare.
# MOTR_POOL_TYPE currently Only supports HDD, SSD or NVM.
- MOTR_POOL_NAME: Pool1
MOTR_POOL_ID: ${pools[0]}
MOTR_POOL_TYPE: NVM
- MOTR_POOL_NAME: Pool2
MOTR_POOL_ID: ${pools[1]}
MOTR_POOL_TYPE: SSD
- MOTR_POOL_NAME: Pool3
MOTR_POOL_ID: ${pools[2]}
MOTR_POOL_TYPE: HDD
EOF
echo "$YAML"
}
miof()
{
r="$1"
((r--))
mio > "$2"
}
rgw()
{
read -r -d '' CEPH <<EOF
[global]
debug rgw = 20
[client]
rgw backend store = motr
motr profile fid = ${profs[0]}
motr ha endpoint = ${laddr[0]}
motr my endpoint = ${laddr[1]}
motr my fid = ${lproc[1]}
motr admin endpoint = ${laddr[1]}
motr admin fid = ${lproc[1]}
[client.rgw]
rgw frontends = beast port=8000
log file = /var/log/ceph/ceph-client.rgw.log
EOF
echo "$CEPH"
}
#
# MAIN
#
# options
TEMP=$( getopt -o cdxmeh --long create-cache,delete-cache,exclude-cache,mio,exp,help,ceph-config -n "$PROG_NAME" -- "$@" )
[[ $? != 0 ]] && usage
eval set -- "$TEMP"
while true ;
do
case "$1" in
-x|--exclude-cache)
shift
;;
-d|--delete-cache)
set -x
rm -rf "$hastatusetc"
rm -rf /tmp/hastatus.*
set +x
shift
exit
;;
-c|--create-cache)
set -x
hctl status > "$hastatusetc"
echo "dummy-node9-9" >> "$hastatusetc"
tail "$hastatusetc"
set +x
shift
exit
;;
-m|--mio)
# print to stdout
if [ "$#" -eq 2 ]; then
mio
exit 0
fi
# print to files
shift; shift; z="$1"; shift
[[ "$z" -ge 1 ]] || { echo "Invalid number!, must be > 0!!"; exit 1; }
[[ "$#" -eq "$z" ]] || { echo "Illeg number of arguments!"; exit 1; }
for (( i=1; i<="$z"; i++ ))
do
miof "$i" "$1"; shift
done
exit 0
shift
;;
-e|--exp)
exp
exit 0
shift
;;
--ceph-config)
rgw
exit 0
shift
;;
-h|--help)
usage
shift
;;
--)
shift
break
;;
*)
echo 'getopt: internal error...'
exit 1
;;
esac
done
echo "#"
echo "# USER: $USER"
echo "# Application: All"
echo "#"
echo
echo "HA_ENDPOINT_ADDR = ${laddr[0]}"
echo "PROFILE_FID = ${profs[0]}"
echo
for (( idx=0; idx<${#pools[@]}; idx++ ))
do
echo "M0_POOL_TIER$((idx+1)) = ${pools[$((idx))]}"
done
echo
for (( idx=0; idx<${#laddr[@]}-1; idx++ ))
do
echo "LOCAL_ENDPOINT_ADDR$((idx)) = ${laddr[1+(($idx+$r)%$s)]}"
echo "LOCAL_PROC_FID$((idx)) = ${lproc[1+(($idx+$r)%$s)]}"
done