glusterfs

Форк
0
518 строк · 11.8 Кб
1
#!/bin/bash
2

3
GLUSTER_TOP_SUBOPTIONS1="
4
        {nfs},
5
        {brick},
6
        {list-cnt}
7
"
8
GLUSTER_TOP_SUBOPTIONS2="
9
        {bs
10
                {__SIZE
11
                        {count}
12
                }
13
        },
14
        {brick},
15
        {list-cnt}
16
"
17
GLUSTER_TOP_OPTIONS="
18
        {open
19
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
20
        },
21
        {read
22
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
23
        },
24
        {write
25
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
26
        },
27
        {opendir
28
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
29
        },
30
        {readdir
31
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
32
        },
33
        {clear
34
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
35
        },
36
        {read-perf
37
                [ $GLUSTER_TOP_SUBOPTIONS2 ]
38
        },
39
        {write-perf
40
                [ $GLUSTER_TOP_SUBOPTIONS2 ]
41
        }
42
"
43

44
GLUSTER_QUOTA_OPTIONS="
45
        {enable},
46
        {disable},
47
        {list},
48
        {remove},
49
        {default-soft-limit},
50
        {limit-usage},
51
        {alert-time},
52
        {soft-timeout},
53
        {hard-timeout}
54
"
55

56
GLUSTER_PROFILE_OPTIONS="
57
        {start},
58
        {info [
59
                {peek},
60
                {incremental
61
                        {peek}
62
                },
63
                {cumulative},
64
                {clear},
65
              ]
66
        },
67
        {stop}
68
"
69

70
GLUSTER_BARRIER_OPTIONS="
71
        {enable},
72
        {disable}
73
"
74

75
GLUSTER_GEO_REPLICATION_SUBOPTIONS="
76
"
77
GLUSTER_GEO_REPLICATION_OPTIONS="
78
        {status},
79
        {__VOLNAME [
80
                {status},
81
                {__SECONDARYURL [
82
                        {create [
83
                                {push-pem
84
                                        {force}
85
                                },
86
                                {force}
87
                                ]
88
                        },
89
                        {start {force} },
90
                        {status {detail} },
91
                        {config},
92
                        {pause {force} },
93
                        {resume {force} },
94
                        {stop {force} },
95
                        {delete {force} }
96
                            ]
97
                }
98
                   ]
99
        }
100
"
101

102
GLUSTER_VOLUME_OPTIONS="
103
        {volume [
104
                {add-brick
105
                        {__VOLNAME}
106
                },
107
                {barrier
108
                        {__VOLNAME
109
                                [ $GLUSTER_BARRIER_OPTIONS ]
110
                        }
111
                },
112
                {clear-locks
113
                        {__VOLNAME}
114
                },
115
                {create},
116
                {delete
117
                        {__VOLNAME}
118
                },
119
                {geo-replication
120
                        [ $GLUSTER_GEO_REPLICATION_OPTIONS ]
121
                },
122
                {heal
123
                        {__VOLNAME}
124
                },
125
                {help},
126
                {info
127
                        {__VOLNAME}
128
                },
129
                {list},
130
                {log
131
                        {__VOLNAME}
132
                },
133
                {profile
134
                        {__VOLNAME
135
                                [ $GLUSTER_PROFILE_OPTIONS ]
136
                        }
137
                },
138
                {quota
139
                        {__VOLNAME
140
                                [ $GLUSTER_QUOTA_OPTIONS ]
141
                        }
142
                },
143
                {rebalance
144
                        {__VOLNAME}
145
                },
146
                {remove-brick
147
                        {__VOLNAME}
148
                },
149
                {replace-brick
150
                        {__VOLNAME}
151
                },
152
                {reset
153
                        {__VOLNAME
154
                                {__VOLOPTIONS
155
                                },
156
                        }
157
                },
158
                {set
159
                        {__VOLNAME
160
                                {__VOLOPTIONS
161
                                },
162
                        }
163
                },
164
                {start
165
                        {__VOLNAME
166
                                {force}
167
                        }
168
                },
169
                {statedump
170
                        {__VOLNAME}
171
                },
172
                {status
173
                        {__VOLNAME}
174
                },
175
                {stop
176
                        {__VOLNAME
177
                                {force}
178
                        }
179
                },
180
                {sync
181
                        {__HOSTNAME}
182
                },
183
                {top
184
                        {__VOLNAME
185
                                [ $GLUSTER_TOP_OPTIONS ]
186
                        }
187
                }
188
                ]
189
        }
190
"
191

192
GLUSTER_COMMAND_TREE="
193
{gluster [
194
        $GLUSTER_VOLUME_OPTIONS ,
195
        {peer [
196
              {probe
197
                      {__HOSTNAME}
198
              },
199
              {detach
200
                      {__HOSTNAME
201
                                {force}
202
                      }
203
              },
204
              {status}
205
              ]
206
        },
207
        {pool
208
                {list}
209
        },
210
        {help}
211
        ]
212
}"
213

214
func_return=""
215

216
__SIZE ()
217
{
218
        func_return="SIZE"
219
        return 0
220
}
221

222
__SECONDARYURL ()
223
{
224
        func_return="SECONDARYURL"
225
        return 0
226
}
227

228
__HOSTNAME ()
229
{
230
        local zero=0
231
        local ret=0
232
        local cur_word="$2"
233

234
        if [ "$1" == "X" ]; then
235
                return
236

237
        elif [ "$1" == "match" ]; then
238
                return 0
239

240
        elif [ "$1" == "complete" ]; then
241
                func_return=`echo $(compgen -A hostname -- $cur_word)`
242
        fi
243
        return 0
244
}
245

246
__VOLNAME ()
247
{
248
        local zero=0
249
        local ret=0
250
        local cur_word="$2"
251
        local list=""
252

253
        if [ "X$1" == "X" ]; then
254
                return
255

256
        elif [ "$1" == "match" ]; then
257
                return 0
258

259
        elif [ "$1" == "complete" ]; then
260
                if ! pidof glusterd > /dev/null 2>&1; then
261
                        list='';
262

263
                else
264
                        list=`gluster volume list 2> /dev/null`
265
                fi
266

267
        else
268
                return 0
269
        fi
270

271
        func_return=`echo $(compgen -W "$list" -- $cur_word)`
272
        return 0
273
}
274

275
__VOLOPTIONS()
276
{
277
        local zero=0
278
        local ret=0
279
        local cur_word="$2"
280
        local list=""
281

282
        if [ "X$1" == "X" ]; then
283
                return
284

285
        elif [ "$1" == "match" ]; then
286
                return 0
287

288
        elif [ "$1" == "complete" ]; then
289
                if ! pidof glusterd > /dev/null 2>&1; then
290
                        list='';
291
                else
292
                        list=`gluster volume set help 2>/dev/null | grep "^Option:" | cut -d ' ' -f 2`
293
                fi
294
        else
295
                return 0
296
        fi
297

298
        func_return=`echo $(compgen -W "$list" -- $cur_word)`
299

300
        return 0
301
}
302

303
_gluster_throw () {
304
#echo $1 >&2
305
        COMPREPLY=''
306
        exit
307
}
308

309
declare GLUSTER_FINAL_LIST=''
310
declare GLUSTER_LIST=''
311
declare -i GLUSTER_TOP=0
312
_gluster_push () {
313
        GLUSTER_TOP=$((GLUSTER_TOP + 1))
314
        return $GLUSTER_TOP
315
}
316
_gluster_pop () {
317
        GLUSTER_TOP=$((GLUSTER_TOP - 1))
318
        return $GLUSTER_TOP
319
}
320

321
_gluster_goto_end ()
322
{
323
        local prev_top=$1
324
        local top=$1
325
        local token=''
326

327
        while [ $top -ge $prev_top ]; do
328
                read -r token
329
                case $token in
330
                '{' | '[')
331
                        _gluster_push
332
                        top=$?
333
                        ;;
334
                '}' | ']')
335
                        _gluster_pop
336
                        top=$?
337
                        ;;
338
                esac
339
        done
340

341
        return
342
}
343

344
_gluster_form_list ()
345
{
346
        local token=''
347
        local top=0
348
        local comma=''
349
        local cur_word="$1"
350

351
        read -r token
352
        case $token in
353
        ']')
354
                ;;
355
        '{')
356
                _gluster_push
357
                top=$?
358
                read -r key
359
                if [ "X$cur_word" == "X" -o "${cur_word:0:1}" == "${key:0:1}" -o "${key:0:1}" == "_" ]; then
360
                        GLUSTER_LIST="$GLUSTER_LIST $key"
361
                fi
362

363
                _gluster_goto_end $top
364
                read -r comma
365
                if [ "$comma" == "," ]; then
366
                        _gluster_form_list $cur_word
367
                fi
368
                ;;
369
        *)
370
                _gluster_throw "Expected '{' but received $token"
371
                ;;
372
        esac
373

374
        return
375
}
376

377
_gluster_goto_child ()
378
{
379
        local match_string="$1"
380
        local token=''
381
        local top=0
382
        local comma=''
383

384
        read -r token
385
        case $token in
386
        '{')
387
                _gluster_push
388
                top=$?
389
                ;;
390
        *)
391
                _gluster_throw "Expected '{' but received $token"
392
                ;;
393
        esac
394

395
        read -r token
396
        case `echo $token` in
397
        '[' | ']' | '{' | '}')
398
                _gluster_throw "Expected string but received $token"
399
                ;;
400
        _*)
401
                $token "match" $match_string
402
                ret=$?
403
                if [ $ret -eq 0 ]; then
404
                        return
405
                else
406
                        _gluster_goto_end $top
407

408
                        read -r comma
409
                        if [ "$comma" == "," ]; then
410
                                _gluster_goto_child $match_string
411
                        fi
412
                fi
413
                ;;
414

415
        "$match_string")
416
                return
417
                ;;
418
        *)
419
                _gluster_goto_end $top
420

421
                read -r comma
422
                if [ "$comma" == "," ]; then
423
                        _gluster_goto_child $match_string
424
                fi
425
                ;;
426
        esac
427

428
        return
429
}
430

431
_gluster_does_match ()
432
{
433
        local token="$1"
434
        local key="$2"
435

436
        if [ "${token:0:1}" == "_" ]; then
437
                $token $2
438
                return $?
439
        fi
440

441
        [ "$token" == "$key" ] && return 0
442

443
        return 1
444
}
445

446
_gluster_parse ()
447
{
448
        local i=0
449
        local token=''
450
        local tmp_token=''
451
        local word=''
452

453
        while [ $i -lt $COMP_CWORD ]; do
454
                read -r token
455
                case $token in
456
                '[')
457
                        _gluster_push
458
                        _gluster_goto_child ${COMP_WORDS[$i]}
459
                        ;;
460
                '{')
461
                        _gluster_push
462
                        read -r tmp_token
463
                        _gluster_does_match $tmp_token ${COMP_WORDS[$i]}
464
                        if [ $? -ne 0 ]; then
465
                                _gluster_throw "No match"
466
                        fi
467
                        ;;
468
                esac
469
                i=$((i+1))
470
        done
471

472
        read -r token
473
        if [ "$token" == '[' ]; then
474
                _gluster_push
475
                _gluster_form_list ${COMP_WORDS[COMP_CWORD]}
476

477
        elif [ "$token" == '{' ]; then
478
                read -r tmp_token
479
                GLUSTER_LIST="$tmp_token"
480
        fi
481

482
        echo $GLUSTER_LIST
483
}
484

485
_gluster_handle_list ()
486
{
487
        local list="${!1}"
488
        local cur_word=$2
489
        local count=0
490
        local i=0
491
        local res=""
492

493
        for i in `echo $list`; do
494
                if [ "${i:0:1}" == "_" ]; then
495
                        $i "complete" $cur_word
496
                        res="$res $func_return"
497
                else
498
                        res="$res $i"
499
                fi
500
        done
501

502
        COMPREPLY=($(compgen -W "$res" -- $cur_word))
503
        return
504
}
505

506
_gluster_completion ()
507
{
508
        GLUSTER_FINAL_LIST=`echo $GLUSTER_COMMAND_TREE |                      \
509
                egrep -ao --color=never "([A-Za-z0-9_.-]+)|[[:space:]]+|." |  \
510
                        egrep -v --color=never "^[[:space:]]*$" |             \
511
                                _gluster_parse`
512

513
        ARG="GLUSTER_FINAL_LIST"
514
        _gluster_handle_list $ARG ${COMP_WORDS[COMP_CWORD]}
515
        return
516
}
517

518
complete -F _gluster_completion gluster
519

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.