Statistics
| Branch: | Tag: | Revision:

root / doc / examples / bash_completion.in @ 75615bd3

History | View | Annotate | Download (14.3 kB)

1
_gnt_backup()
2
{
3
  local cur prev base_cmd cmds ilist nlist
4
  COMPREPLY=()
5
  cur="$2"
6
  prev="$3"
7
  #
8
  #  The basic options we'll complete.
9
  #
10
  cmds="export import list remove"
11

    
12
  # default completion is empty
13
  COMPREPLY=()
14

    
15
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
16
    # cluster not initialized
17
    return 0
18
  fi
19

    
20
  ilist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_instance_list")
21
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
22

    
23
  case "$COMP_CWORD" in
24
    1)
25
      # complete the command name
26
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
27
      ;;
28
    *)
29
      # we're doing options to commands
30
      base_cmd="${COMP_WORDS[1]}"
31
      case "${base_cmd}" in
32
        export)
33
          case "$COMP_CWORD" in
34
            2)
35
              # options or instances
36
              COMPREPLY=( $(compgen -W "--no-shutdown -n $ilist" -- ${cur}) )
37
              ;;
38
            3)
39
              # if previous was option, we allow instance
40
              case "$prev" in
41
                -*)
42
                  COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
43
                  ;;
44
              esac
45
          esac
46
          ;;
47
        import)
48
          case "$prev" in
49
            -t)
50
              COMPREPLY=( $(compgen -W "diskless file plain drbd" -- ${cur}) )
51
              ;;
52
            --src-node)
53
              COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
54
              ;;
55
            --file-driver)
56
              COMPREPLY=( $(compgen -W "loop blktap" -- ${cur}) )
57
              ;;
58
            -*)
59
              # arguments to other options, we don't have completion yet
60
              ;;
61
            *)
62
              COMPREPLY=( $(compgen -W "-t -n -B -H -s --disks --net \
63
                              --no-nics --no-start --no-ip-check -I \
64
                              --src-node --src-dir --file-driver \
65
                              --file-storage-dir" -- ${cur}) )
66
              ;;
67
          esac
68
          ;;
69
        remove)
70
          if [[ "$COMP_CWORD" -eq 2 ]]; then
71
            COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
72
          fi
73
          ;;
74
      esac
75
  esac
76

    
77
  return 0
78
}
79

    
80
complete -F _gnt_backup gnt-backup
81

    
82
_gnt_cluster()
83
{
84
  local cur prev cmds
85
  cur="$2"
86
  prev="$3"
87
  #
88
  #  The basic options we'll complete.
89
  #
90
  if [[ -e "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
91
    cmds="add-tags command copyfile destroy getmaster info list-tags \
92
          masterfailover modify queue redist-conf remove-tags rename \
93
          search-tags verify verify-disks version"
94
  else
95
    cmds="init"
96
  fi
97

    
98
  # default completion is empty
99
  COMPREPLY=()
100
  case "$COMP_CWORD" in
101
    1)
102
      # complete the command name
103
      COMPREPLY=($(compgen -W "$cmds" -- ${cur}))
104
      ;;
105
    2)
106
      # complete arguments to the command
107
      case "$prev" in
108
        "queue")
109
          COMPREPLY=( $(compgen -W "drain undrain info" -- ${cur}) )
110
          ;;
111
        "copyfile")
112
          COMPREPLY=( $(compgen -f -- ${cur}) )
113
          ;;
114
        "command")
115
          COMPREPLY=( $(compgen -c -- ${cur}) )
116
          ;;
117
	*)
118
          ;;
119
      esac
120
  esac
121

    
122
  return 0
123
}
124

    
125
complete -F _gnt_cluster gnt-cluster
126

    
127
_gnt_debug()
128
{
129
  local cur prev cmds
130
  cur="$2"
131
  prev="$3"
132

    
133
  cmds="allocator delay submit-job"
134

    
135
  # default completion is empty
136
  COMPREPLY=()
137

    
138
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
139
    # cluster not initialized
140
    return 0
141
  fi
142

    
143
  case "$COMP_CWORD" in
144
    1)
145
      # complete the command name
146
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
147
      ;;
148
    *)
149
      # we're doing options to commands
150
      base_cmd="${COMP_WORDS[1]}"
151
      case "${base_cmd}" in
152
        delay)
153
          if [[ "$prev" != -* ]]; then
154
            COMPREPLY=( $(compgen -W "--no-master -n" -- ${cur}) )
155
          fi
156
          ;;
157
        submit-job)
158
          if [[ "$COMP_CWORD" -eq 2 ]]; then
159
            COMPREPLY=( $(compgen -f -- ${cur}) )
160
          fi
161
          ;;
162
      esac
163
  esac
164

    
165
  return 0
166
}
167

    
168
complete -F _gnt_debug gnt-debug
169

    
170
_gnt_instance()
171
{
172
  local cur prev base_cmd cmds ilist nlist
173
  COMPREPLY=()
174
  cur="$2"
175
  prev="$3"
176
  #
177
  #  The basic options we'll complete.
178
  #
179
  cmds="activate-disks add add-tags batch-create console deactivate-disks \
180
        failover grow-disk info list list-tags migrate modify reboot \
181
        reinstall remove remove-tags rename replace-disks shutdown startup"
182

    
183
  # default completion is empty
184
  COMPREPLY=()
185

    
186
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
187
    # cluster not initialized
188
    return 0
189
  fi
190

    
191
  ilist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_instance_list")
192
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
193

    
194
  case "$COMP_CWORD" in
195
    1)
196
      # complete the command name
197
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
198
      ;;
199
    *)
200
      # we're doing options to commands
201
      base_cmd="${COMP_WORDS[1]}"
202
      case "${base_cmd}" in
203
        # first, rules for multiple commands
204
        activate-disks|console|deactivate-disks|list-tags|rename|remove)
205
          # commands with only one instance argument, nothing else
206
          if [[ "$COMP_CWORD" -eq 2 ]]; then
207
            COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
208
          fi
209
          ;;
210
        info)
211
          # commands with more than one instance
212
          COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
213
          ;;
214
        add-tags|grow-disk|reinstall|remove-tags|replace-disks)
215
          # not very well handled
216
          COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
217
          ;;
218
        startup|start|shutdown|stop|reboot)
219
          COMPREPLY=( $(compgen -W "--force-multiple --node --primary \
220
                          --secondary --all --submit $ilist" -- ${cur}) )
221
          ;;
222
        # individual commands
223
        add)
224
          case "$prev" in
225
            -t)
226
              COMPREPLY=( $(compgen -W "diskless file plain drbd" -- ${cur}) )
227
              ;;
228
            --file-driver)
229
              COMPREPLY=( $(compgen -W "loop blktap" -- ${cur}) )
230
              ;;
231
            -*)
232
              # arguments to other options, we don't have completion yet
233
              ;;
234
            *)
235
              COMPREPLY=( $(compgen -W "-t -n -o -B -H -s --disks --net \
236
                            --no-nics --no-start --no-ip-check -I \
237
                            --file-driver --file-storage-dir --submit" \
238
                -- ${cur}) )
239
              ;;
240
          esac
241
          ;;
242
        batch-create)
243
          # this only takes one file name
244
          COMPREPLY=( $(compgen -A file -- ${cur}) )
245
          ;;
246
        failover)
247
          case "$COMP_CWORD" in
248
            2)
249
              # options or instances
250
              COMPREPLY=( $(compgen -W "--ignore-failures $ilist" -- ${cur}) )
251
              ;;
252
            3)
253
              # if previous was option, we allow instance
254
              case "$prev" in
255
                -*)
256
                  COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
257
                  ;;
258
              esac
259
          esac
260
          ;;
261
        list)
262
          COMPREPLY=( $(compgen -W "--no-headers --separator --units -o \
263
                          --sync $ilist" -- ${cur}) )
264
          ;;
265
        modify)
266
          COMPREPLY=( $(compgen -W "-H -B --disk --net $ilist" -- ${cur}) )
267
          ;;
268
        migrate)
269
          case "$COMP_CWORD" in
270
            2)
271
              # options or instances
272
              COMPREPLY=( $(compgen -W "--non-live --cleanup $ilist" -- \
273
                ${cur}) )
274
              ;;
275
            3)
276
              # if previous was option, we allow instance
277
              case "$prev" in
278
                -*)
279
                  COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
280
                  ;;
281
              esac
282
          esac
283
      esac
284
  esac
285

    
286
  return 0
287
}
288

    
289
complete -F _gnt_instance gnt-instance
290

    
291
_gnt_job()
292
{
293
  local cur prev cmds
294
  cur="$2"
295
  prev="$3"
296

    
297
  cmds="archive autoarchive cancel info list"
298

    
299
  # default completion is empty
300
  COMPREPLY=()
301

    
302
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
303
    # cluster not initialized
304
    return 0
305
  fi
306

    
307
  case "$COMP_CWORD" in
308
    1)
309
      # complete the command name
310
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
311
      ;;
312
    *)
313
      # we're doing options to commands
314
      base_cmd="${COMP_WORDS[1]}"
315
      case "${base_cmd}" in
316
        archive|cancel|info)
317
          # FIXME: this is really going into the internals of the job queue
318
          jlist=$( cd @LOCALSTATEDIR@/lib/ganeti/queue; echo job-*)
319
          jlist=${jlist//job-/}
320
          COMPREPLY=( $(compgen -W "$jlist" -- ${cur}) )
321
          ;;
322
        list)
323
          COMPREPLY=( $(compgen -W "--no-headers --separator -o" -- ${cur}) )
324
          ;;
325

    
326
      esac
327
  esac
328

    
329
  return 0
330
}
331

    
332
complete -F _gnt_job gnt-job
333

    
334
_gnt_os()
335
{
336
  local cur prev cmds
337
  cur="$2"
338
  prev="$3"
339

    
340
  cmds="list diagnose"
341

    
342
  # default completion is empty
343
  COMPREPLY=()
344

    
345
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
346
    # cluster not initialized
347
    return 0
348
  fi
349

    
350
  case "$COMP_CWORD" in
351
    1)
352
      # complete the command name
353
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
354
      ;;
355
    *)
356
      # we're doing options to commands
357
      base_cmd="${COMP_WORDS[1]}"
358
      case "${base_cmd}" in
359
        list)
360
          if [[ "$COMP_CWORD" -eq 2 ]]; then
361
            COMPREPLY=( $(compgen -W "--no-headers" -- ${cur}) )
362
          fi
363
          ;;
364
      esac
365
  esac
366

    
367
  return 0
368
}
369

    
370
complete -F _gnt_os gnt-os
371

    
372
_gnt_node()
373
{
374
  local cur prev cmds base_cmd
375
  cur="$2"
376
  prev="$3"
377

    
378
  cmds="add add-tags evacuate failover info list list-tags migrate modify \
379
          remove remove-tags volumes"
380

    
381
  # default completion is empty
382
  COMPREPLY=()
383

    
384
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
385
    # cluster not initialized
386
    return 0
387
  fi
388

    
389
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
390

    
391
  case "$COMP_CWORD" in
392
    1)
393
      # complete the command name
394
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
395
      ;;
396
    *)
397
      # we're doing options to commands
398
      base_cmd="${COMP_WORDS[1]}"
399
      case "${base_cmd}" in
400
        # first rules for multiple commands
401
        list-tags|remove)
402
          # commands with only one instance argument, nothing else
403
          if [[ "$COMP_CWORD" -eq 2 ]]; then
404
            COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
405
          fi
406
          ;;
407
        add-tags|info|remove-tags|volumes)
408
          COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
409
          ;;
410
        # individual commands
411
        add)
412
          # options or instances
413
          COMPREPLY=( $(compgen -W "-s --readd --no-ssh-key-check" -- ${cur}) )
414
          ;;
415
        evacuate)
416
          case "$COMP_CWORD" in
417
            2)
418
              # options or instances
419
              COMPREPLY=( $(compgen -W "-n -I $nlist" -- ${cur}) )
420
              ;;
421
            3)
422
              # if previous was option, we allow node
423
              case "$prev" in
424
                -*)
425
                  COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
426
                  ;;
427
              esac
428
          esac
429
          ;;
430
        failover)
431
          case "$COMP_CWORD" in
432
            2)
433
              # options or instances
434
              COMPREPLY=( $(compgen -W "--ignore-failures $nlist" -- ${cur}) )
435
              ;;
436
            3)
437
              # if previous was option, we allow node
438
              case "$prev" in
439
                -*)
440
                  COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
441
                  ;;
442
              esac
443
          esac
444
          ;;
445
        list)
446
          COMPREPLY=( $(compgen -W "--no-headers --separator --units -o \
447
                          --sync $nlist" -- ${cur}) )
448
          ;;
449
        modify)
450
          # TODO: after a non-option, don't allow options
451
          if [[ "$COMP_CWORD" -eq 2 || "$prev" != -* ]]; then
452
            COMPREPLY=( $(compgen -W "-C -O -D $nlist" -- ${cur}) )
453
          elif [[ "$prev" == -* ]]; then
454
            COMPREPLY=( $(compgen -W "yes no" -- ${cur}) )
455
          fi
456
          ;;
457
        migrate)
458
          case "$COMP_CWORD" in
459
            2)
460
              # options or nodes
461
              COMPREPLY=( $(compgen -W "--non-live $nlist" -- ${cur}) )
462
              ;;
463
            3)
464
              # if previous was option, we allow node
465
              case "$prev" in
466
                -*)
467
                  COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
468
                  ;;
469
              esac
470
          esac
471
      esac
472
  esac
473

    
474
  return 0
475
}
476

    
477
complete -F _gnt_node gnt-node
478

    
479
# other tools
480

    
481
_gnt_tool_burnin()
482
{
483
  local cur prev
484
  cur="$2"
485
  prev="$3"
486

    
487
  # default completion is empty
488
  COMPREPLY=()
489

    
490
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
491
    # cluster not initialized
492
    return 0
493
  fi
494

    
495
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
496

    
497
  case "$prev" in
498
    -t)
499
      COMPREPLY=( $(compgen -W "diskless file plain drbd" -- ${cur}) )
500
      ;;
501
    --rename)
502
      # this needs an unused host name, so we don't complete it
503
      ;;
504
    -n|--nodes)
505
      # nodes from the cluster, comma separated
506
      # FIXME: make completion work for comma-separated values
507
      COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
508
      ;;
509
    -o|--os)
510
      # the os list
511
      COMPREPLY=( $(compgen -W "$(gnt-os list --no-headers)" -- ${cur}) )
512
      ;;
513
    --disk-size|--disk-growth)
514
      # these take a number or unit, we can't really autocomplete, but
515
      # we show a couple of examples
516
      COMPREPLY=( $(compgen -W "128M 512M 1G 4G 1G,256M 4G,1G,1G 10G" -- \
517
        ${cur}) )
518
      ;;
519
    --mem-size)
520
      # this takes a number or unit, we can't really autocomplete, but
521
      # we show a couple of examples
522
      COMPREPLY=( $(compgen -W "128M 256M 512M 1G 4G 8G 12G 16G" -- ${cur}) )
523
      ;;
524
    --net-timeout)
525
      # this takes a number in seconds; again, we can't really complete
526
      COMPREPLY=( $(compgen -W "15 60 300 900" -- ${cur}) )
527
      ;;
528
    *)
529
      # all other, we just list the whole options
530
      COMPREPLY=( $(compgen -W "-o --disk-size --disk-growth --mem-size \
531
                      -v --verbose --no-replace1 --no-replace2 --no-failover \
532
                      --no-migrate --no-importexport --no-startstop \
533
                      --no-reinstall --no-reboot --no-activate-disks \
534
                      --no-add-disks --no-add-nics --no-nics \
535
                      --rename -t -n --nodes -I --iallocator -p --parallel \
536
                      --net-timeout -C --http-check -K --keep-instances" \
537
        -- ${cur}) )
538
  esac
539

    
540
  return 0
541
}
542

    
543
complete -F _gnt_tool_burnin @PREFIX@/lib/ganeti/tools/burnin