Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
192 - 1
#!/bin/bash
2
 
3
if pidof glusterd > /dev/null 2>&1; then
4
        GLUSTER_SET_OPTIONS="
5
        $(for token in `gluster volume set help 2>/dev/null | grep "^Option:" | cut -d ' ' -f 2`
6
        do
7
                echo "{$token},"
8
        done)
9
        "
10
        GLUSTER_RESET_OPTIONS="$GLUSTER_SET_OPTIONS"
11
fi
12
 
13
GLUSTER_TOP_SUBOPTIONS1="
14
        {nfs},
15
        {brick},
16
        {list-cnt}
17
"
18
GLUSTER_TOP_SUBOPTIONS2="
19
        {bs
20
                {__SIZE
21
                        {count}
22
                }
23
        },
24
        {brick},
25
        {list-cnt}
26
"
27
GLUSTER_TOP_OPTIONS="
28
        {open
29
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
30
        },
31
        {read
32
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
33
        },
34
        {write
35
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
36
        },
37
        {opendir
38
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
39
        },
40
        {readdir
41
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
42
        },
43
        {clear
44
                [ $GLUSTER_TOP_SUBOPTIONS1 ]
45
        },
46
        {read-perf
47
                [ $GLUSTER_TOP_SUBOPTIONS2 ]
48
        },
49
        {write-perf
50
                [ $GLUSTER_TOP_SUBOPTIONS2 ]
51
        }
52
"
53
 
54
GLUSTER_QUOTA_OPTIONS="
55
        {enable},
56
        {disable},
57
        {list},
58
        {remove},
59
        {default-soft-limit},
60
        {limit-usage},
61
        {alert-time},
62
        {soft-timeout},
63
        {hard-timeout}
64
"
65
 
66
GLUSTER_PROFILE_OPTIONS="
67
        {start},
68
        {info [
69
                {peek},
70
                {incremental
71
                        {peek}
72
                },
73
                {cumulative},
74
                {clear},
75
              ]
76
        },
77
        {stop}
78
"
79
 
80
GLUSTER_BARRIER_OPTIONS="
81
        {enable},
82
        {disable}
83
"
84
 
85
GLUSTER_GEO_REPLICATION_SUBOPTIONS="
86
"
87
GLUSTER_GEO_REPLICATION_OPTIONS="
88
        {__VOLNAME [
89
                {__SLAVEURL [
90
                        {create [
91
                                {push-pem
92
                                        {force}
93
                                },
94
                                {force}
95
                                ]
96
                        },
97
                        {start {force} },
98
                        {status {detail} },
99
                        {config},
100
                        {pause {force} },
101
                        {resume {force} },
102
                        {stop {force} },
103
                        {delete {force} }
104
                            ]
105
                },
106
                {status}
107
                   ]
108
        },
109
        {status}
110
"
111
 
112
GLUSTER_VOLUME_OPTIONS="
113
        {volume [
114
                {add-brick
115
                        {__VOLNAME}
116
                },
117
                {barrier
118
                        {__VOLNAME
119
                                [ $GLUSTER_BARRIER_OPTIONS ]
120
                        }
121
                },
122
                {clear-locks
123
                        {__VOLNAME}
124
                },
125
                {create},
126
                {delete
127
                        {__VOLNAME}
128
                },
129
                {geo-replication
130
                        [ $GLUSTER_GEO_REPLICATION_OPTIONS ]
131
                },
132
                {heal
133
                        {__VOLNAME}
134
                },
135
                {help},
136
                {info
137
                        {__VOLNAME}
138
                },
139
                {list},
140
                {log
141
                        {__VOLNAME}
142
                },
143
                {profile
144
                        {__VOLNAME
145
                                [ $GLUSTER_PROFILE_OPTIONS ]
146
                        }
147
                },
148
                {quota
149
                        {__VOLNAME
150
                                [ $GLUSTER_QUOTA_OPTIONS ]
151
                        }
152
                },
153
                {rebalance
154
                        {__VOLNAME}
155
                },
156
                {remove-brick
157
                        {__VOLNAME}
158
                },
159
                {replace-brick
160
                        {__VOLNAME}
161
                },
162
                {reset
163
                        {__VOLNAME
164
                                [ $GLUSTER_RESET_OPTIONS ]
165
                        }
166
                },
167
                {set
168
                        {__VOLNAME
169
                                [ $GLUSTER_SET_OPTIONS ]
170
                        }
171
                },
172
                {start
173
                        {__VOLNAME
174
                                {force}
175
                        }
176
                },
177
                {statedump
178
                        {__VOLNAME}
179
                },
180
                {status
181
                        {__VOLNAME}
182
                },
183
                {stop
184
                        {__VOLNAME
185
                                {force}
186
                        }
187
                },
188
                {sync
189
                        {__HOSTNAME}
190
                },
191
                {top
192
                        {__VOLNAME
193
                                [ $GLUSTER_TOP_OPTIONS ]
194
                        }
195
                }
196
                ]
197
        }
198
"
199
 
200
GLUSTER_COMMAND_TREE="
201
{gluster [
202
        $GLUSTER_VOLUME_OPTIONS ,
203
        {peer [
204
              {probe
205
                      {__HOSTNAME}
206
              },
207
              {detach
208
                      {__HOSTNAME
209
                                {force}
210
                      }
211
              },
212
              {status}
213
              ]
214
        },
215
        {pool
216
                {list}
217
        },
218
        {help}
219
        ]
220
}"
221
 
222
__SIZE ()
223
{
224
        return 0
225
}
226
 
227
__SLAVEURL ()
228
{
229
        return 0
230
}
231
 
232
__HOSTNAME ()
233
{
234
        local zero=0
235
        local ret=0
236
        local cur_word="$2"
237
 
238
        if [ "$1" == "X" ]; then
239
                return
240
 
241
        elif [ "$1" == "match" ]; then
242
                return 0
243
 
244
        elif [ "$1" == "complete" ]; then
245
                COMPREPLY=($(compgen -A hostname -- $cur_word))
246
        fi
247
        return 0
248
}
249
 
250
__VOLNAME ()
251
{
252
        local zero=0
253
        local ret=0
254
        local cur_word="$2"
255
        local list=""
256
 
257
        if [ "X$1" == "X" ]; then
258
                return
259
 
260
        elif [ "$1" == "match" ]; then
261
                return 0
262
 
263
        elif [ "$1" == "complete" ]; then
264
                if ! pidof glusterd > /dev/null 2>&1; then
265
                        list='';
266
 
267
                else
268
                        list=`gluster volume list 2> /dev/null`
269
                fi
270
 
271
        else
272
                return 0
273
        fi
274
 
275
        COMPREPLY=($(compgen -W "$list" -- $cur_word))
276
        return 0
277
}
278
 
279
_gluster_throw () {
280
#echo $1 >&2
281
        COMPREPLY=''
282
        exit
283
}
284
 
285
declare GLUSTER_FINAL_LIST=''
286
declare GLUSTER_LIST=''
287
declare -i GLUSTER_TOP=0
288
_gluster_push () {
289
        GLUSTER_TOP=$((GLUSTER_TOP + 1))
290
        return $GLUSTER_TOP
291
}
292
_gluster_pop () {
293
        GLUSTER_TOP=$((GLUSTER_TOP - 1))
294
        return $GLUSTER_TOP
295
}
296
 
297
_gluster_goto_end ()
298
{
299
        local prev_top=$1
300
        local top=$1
301
        local token=''
302
 
303
        while [ $top -ge $prev_top ]; do
304
                read -r token
305
                case $token in
306
                '{' | '[')
307
                        _gluster_push
308
                        top=$?
309
                        ;;
310
                '}' | ']')
311
                        _gluster_pop
312
                        top=$?
313
                        ;;
314
                esac
315
        done
316
 
317
        return
318
}
319
 
320
_gluster_form_list ()
321
{
322
        local token=''
323
        local top=0
324
        local comma=''
325
        local cur_word="$1"
326
 
327
        read -r token
328
        case $token in
329
        ']')
330
                ;;
331
        '{')
332
                _gluster_push
333
                top=$?
334
                read -r key
335
                if [ "X$cur_word" == "X" -o "${cur_word:0:1}" == "${key:0:1}" -o "${key:0:1}" == "_" ]; then
336
                        GLUSTER_LIST="$GLUSTER_LIST $key"
337
                fi
338
 
339
                _gluster_goto_end $top
340
                read -r comma
341
                if [ "$comma" == "," ]; then
342
                        _gluster_form_list $cur_word
343
                fi
344
                ;;
345
        *)
346
                _gluster_throw "Expected '{' but received $token"
347
                ;;
348
        esac
349
 
350
        return
351
}
352
 
353
_gluster_goto_child ()
354
{
355
        local match_string="$1"
356
        local token=''
357
        local top=0
358
        local comma=''
359
 
360
        read -r token
361
        case $token in
362
        '{')
363
                _gluster_push
364
                top=$?
365
                ;;
366
        *)
367
                _gluster_throw "Expected '{' but received $token"
368
                ;;
369
        esac
370
 
371
        read -r token
372
        case `echo $token` in
373
        '[' | ']' | '{' | '}')
374
                _gluster_throw "Expected string but received $token"
375
                ;;
376
        _*)
377
                $token "match" $match_string
378
                ret=$?
379
                if [ $ret -eq 0 ]; then
380
                        return
381
                else
382
                        _gluster_goto_end $top
383
 
384
                        read -r comma
385
                        if [ "$comma" == "," ]; then
386
                                _gluster_goto_child $match_string
387
                        fi
388
                fi
389
                ;;
390
 
391
        "$match_string")
392
                return
393
                ;;
394
        *)
395
                _gluster_goto_end $top
396
 
397
                read -r comma
398
                if [ "$comma" == "," ]; then
399
                        _gluster_goto_child $match_string
400
                fi
401
                ;;
402
        esac
403
 
404
        return
405
}
406
 
407
_gluster_does_match ()
408
{
409
        local token="$1"
410
        local key="$2"
411
 
412
        if [ "${token:0:1}" == "_" ]; then
413
                $token $2
414
                return $?
415
        fi
416
 
417
        [ "$token" == "$key" ] && return 0
418
 
419
        return 1
420
}
421
 
422
_gluster_parse ()
423
{
424
        local i=0
425
        local token=''
426
        local tmp_token=''
427
        local word=''
428
 
429
        while [ $i -lt $COMP_CWORD ]; do
430
                read -r token
431
                case $token in
432
                '[')
433
                        _gluster_push
434
                        _gluster_goto_child ${COMP_WORDS[$i]}
435
                        ;;
436
                '{')
437
                        _gluster_push
438
                        read -r tmp_token
439
                        _gluster_does_match $tmp_token ${COMP_WORDS[$i]}
440
                        if [ $? -ne 0 ]; then
441
                                _gluster_throw "No match"
442
                        fi
443
                        ;;
444
                esac
445
                i=$((i+1))
446
        done
447
 
448
        read -r token
449
        if [ "$token" == '[' ]; then
450
                _gluster_push
451
                _gluster_form_list ${COMP_WORDS[COMP_CWORD]}
452
 
453
        elif [ "$token" == '{' ]; then
454
                read -r tmp_token
455
                GLUSTER_LIST="$tmp_token"
456
        fi
457
 
458
        echo $GLUSTER_LIST
459
}
460
 
461
_gluster_handle_list ()
462
{
463
        local list="${!1}"
464
        local cur_word=$2
465
        local count=0
466
        local i=0
467
 
468
        for i in `echo $list`; do
469
                count=$((count + 1))
470
        done
471
 
472
        if [ $count -eq 1 ] && [ "${i:0:1}" == "_" ]; then
473
                $i "complete" $cur_word
474
        else
475
                COMPREPLY=($(compgen -W "$list" -- $cur_word))
476
        fi
477
        return
478
}
479
 
480
_gluster_completion ()
481
{
482
        GLUSTER_FINAL_LIST=`echo $GLUSTER_COMMAND_TREE |                      \
483
                egrep -ao --color=never "([A-Za-z0-9_.-]+)|[[:space:]]+|." |  \
484
                        egrep -v --color=never "^[[:space:]]*$" |             \
485
                                _gluster_parse`
486
 
487
        ARG="GLUSTER_FINAL_LIST"
488
        _gluster_handle_list $ARG ${COMP_WORDS[COMP_CWORD]}
489
        return
490
}
491
 
492
complete -F _gluster_completion gluster