Revision e2a2a2eb

b/.gitignore
39 39
/doc/rapi-resources.sgml
40 40

  
41 41
# doc/examples
42
/doc/examples/bash_completion
42 43
/doc/examples/ganeti.cron
43 44
/doc/examples/ganeti.initd
44 45

  
b/Makefile.am
228 228

  
229 229

  
230 230
all-local: stamp-directories lib/_autoconf.py devel/upload \
231
	doc/examples/bash_completion \
231 232
	doc/examples/ganeti.initd doc/examples/ganeti.cron
232 233

  
233 234
devel/upload: devel/upload.in stamp-directories $(REPLACE_VARS_SED)
234 235
	sed -f $(REPLACE_VARS_SED) < $< > $@
235 236
	chmod u+x $@
236 237

  
237
doc/examples/ganeti.%: doc/examples/ganeti.%.in stamp-directories \
238
doc/examples/%: doc/examples/%.in stamp-directories \
238 239
		$(REPLACE_VARS_SED)
239 240
	sed -f $(REPLACE_VARS_SED) < $< > $@
240 241

  
b/doc/examples/bash_completion.in
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
      *)
112
        ;;
113
      esac
114
  esac
115

  
116
  return 0
117
}
118

  
119
complete -F _gnt_cluster gnt-cluster
120

  
121
_gnt_debug()
122
{
123
  local cur prev cmds
124
  cur="$2"
125
  prev="$3"
126

  
127
  cmds="allocator delay submit-job"
128

  
129
  # default completion is empty
130
  COMPREPLY=()
131

  
132
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
133
    # cluster not initialized
134
    return 0
135
  fi
136

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

  
159
  return 0
160
}
161

  
162
complete -F _gnt_debug gnt-debug
163

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

  
177
  # default completion is empty
178
  COMPREPLY=()
179

  
180
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
181
    # cluster not initialized
182
    return 0
183
  fi
184

  
185
  ilist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_instance_list")
186
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
187

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

  
280
  return 0
281
}
282

  
283
complete -F _gnt_instance gnt-instance
284

  
285
_gnt_job()
286
{
287
  local cur prev cmds
288
  cur="$2"
289
  prev="$3"
290

  
291
  cmds="archive autoarchive cancel info list"
292

  
293
  # default completion is empty
294
  COMPREPLY=()
295

  
296
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
297
    # cluster not initialized
298
    return 0
299
  fi
300

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

  
320
      esac
321
  esac
322

  
323
  return 0
324
}
325

  
326
complete -F _gnt_job gnt-job
327

  
328
_gnt_os()
329
{
330
  local cur prev cmds
331
  cur="$2"
332
  prev="$3"
333

  
334
  cmds="list diagnose"
335

  
336
  # default completion is empty
337
  COMPREPLY=()
338

  
339
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
340
    # cluster not initialized
341
    return 0
342
  fi
343

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

  
361
  return 0
362
}
363

  
364
complete -F _gnt_os gnt-os
365

  
366
_gnt_node()
367
{
368
  local cur prev cmds base_cmd
369
  cur="$2"
370
  prev="$3"
371

  
372
  cmds="add add-tags evacuate failover info list list-tags migrate modify \
373
          remove remove-tags volumes"
374

  
375
  # default completion is empty
376
  COMPREPLY=()
377

  
378
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
379
    # cluster not initialized
380
    return 0
381
  fi
382

  
383
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
384

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

  
468
  return 0
469
}
470

  
471
complete -F _gnt_node gnt-node
472

  
473
# other tools
474

  
475
_gnt_tool_burnin()
476
{
477
  local cur prev
478
  cur="$2"
479
  prev="$3"
480

  
481
  # default completion is empty
482
  COMPREPLY=()
483

  
484
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
485
    # cluster not initialized
486
    return 0
487
  fi
488

  
489
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
490

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

  
534
  return 0
535
}
536

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

Also available in: Unified diff