Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (14.3 kB)

1 e2a2a2eb Iustin Pop
_gnt_backup()
2 e2a2a2eb Iustin Pop
{
3 e2a2a2eb Iustin Pop
  local cur prev base_cmd cmds ilist nlist
4 e2a2a2eb Iustin Pop
  COMPREPLY=()
5 e2a2a2eb Iustin Pop
  cur="$2"
6 e2a2a2eb Iustin Pop
  prev="$3"
7 e2a2a2eb Iustin Pop
  #
8 e2a2a2eb Iustin Pop
  #  The basic options we'll complete.
9 e2a2a2eb Iustin Pop
  #
10 e2a2a2eb Iustin Pop
  cmds="export import list remove"
11 e2a2a2eb Iustin Pop
12 e2a2a2eb Iustin Pop
  # default completion is empty
13 e2a2a2eb Iustin Pop
  COMPREPLY=()
14 e2a2a2eb Iustin Pop
15 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
16 e2a2a2eb Iustin Pop
    # cluster not initialized
17 e2a2a2eb Iustin Pop
    return 0
18 e2a2a2eb Iustin Pop
  fi
19 e2a2a2eb Iustin Pop
20 e2a2a2eb Iustin Pop
  ilist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_instance_list")
21 e2a2a2eb Iustin Pop
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
22 e2a2a2eb Iustin Pop
23 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
24 e2a2a2eb Iustin Pop
    1)
25 e2a2a2eb Iustin Pop
      # complete the command name
26 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
27 e2a2a2eb Iustin Pop
      ;;
28 e2a2a2eb Iustin Pop
    *)
29 e2a2a2eb Iustin Pop
      # we're doing options to commands
30 e2a2a2eb Iustin Pop
      base_cmd="${COMP_WORDS[1]}"
31 e2a2a2eb Iustin Pop
      case "${base_cmd}" in
32 e2a2a2eb Iustin Pop
        export)
33 e2a2a2eb Iustin Pop
          case "$COMP_CWORD" in
34 e2a2a2eb Iustin Pop
            2)
35 e2a2a2eb Iustin Pop
              # options or instances
36 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "--no-shutdown -n $ilist" -- ${cur}) )
37 e2a2a2eb Iustin Pop
              ;;
38 e2a2a2eb Iustin Pop
            3)
39 e2a2a2eb Iustin Pop
              # if previous was option, we allow instance
40 e2a2a2eb Iustin Pop
              case "$prev" in
41 e2a2a2eb Iustin Pop
                -*)
42 e2a2a2eb Iustin Pop
                  COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
43 e2a2a2eb Iustin Pop
                  ;;
44 e2a2a2eb Iustin Pop
              esac
45 e2a2a2eb Iustin Pop
          esac
46 e2a2a2eb Iustin Pop
          ;;
47 e2a2a2eb Iustin Pop
        import)
48 e2a2a2eb Iustin Pop
          case "$prev" in
49 e2a2a2eb Iustin Pop
            -t)
50 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "diskless file plain drbd" -- ${cur}) )
51 e2a2a2eb Iustin Pop
              ;;
52 e2a2a2eb Iustin Pop
            --src-node)
53 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
54 e2a2a2eb Iustin Pop
              ;;
55 e2a2a2eb Iustin Pop
            --file-driver)
56 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "loop blktap" -- ${cur}) )
57 e2a2a2eb Iustin Pop
              ;;
58 e2a2a2eb Iustin Pop
            -*)
59 e2a2a2eb Iustin Pop
              # arguments to other options, we don't have completion yet
60 e2a2a2eb Iustin Pop
              ;;
61 e2a2a2eb Iustin Pop
            *)
62 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "-t -n -B -H -s --disks --net \
63 e2a2a2eb Iustin Pop
                              --no-nics --no-start --no-ip-check -I \
64 e2a2a2eb Iustin Pop
                              --src-node --src-dir --file-driver \
65 e2a2a2eb Iustin Pop
                              --file-storage-dir" -- ${cur}) )
66 e2a2a2eb Iustin Pop
              ;;
67 e2a2a2eb Iustin Pop
          esac
68 e2a2a2eb Iustin Pop
          ;;
69 e2a2a2eb Iustin Pop
        remove)
70 e2a2a2eb Iustin Pop
          if [[ "$COMP_CWORD" -eq 2 ]]; then
71 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
72 e2a2a2eb Iustin Pop
          fi
73 e2a2a2eb Iustin Pop
          ;;
74 e2a2a2eb Iustin Pop
      esac
75 e2a2a2eb Iustin Pop
  esac
76 e2a2a2eb Iustin Pop
77 e2a2a2eb Iustin Pop
  return 0
78 e2a2a2eb Iustin Pop
}
79 e2a2a2eb Iustin Pop
80 e2a2a2eb Iustin Pop
complete -F _gnt_backup gnt-backup
81 e2a2a2eb Iustin Pop
82 e2a2a2eb Iustin Pop
_gnt_cluster()
83 e2a2a2eb Iustin Pop
{
84 e2a2a2eb Iustin Pop
  local cur prev cmds
85 e2a2a2eb Iustin Pop
  cur="$2"
86 e2a2a2eb Iustin Pop
  prev="$3"
87 e2a2a2eb Iustin Pop
  #
88 e2a2a2eb Iustin Pop
  #  The basic options we'll complete.
89 e2a2a2eb Iustin Pop
  #
90 e2a2a2eb Iustin Pop
  if [[ -e "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
91 e2a2a2eb Iustin Pop
    cmds="add-tags command copyfile destroy getmaster info list-tags \
92 e2a2a2eb Iustin Pop
          masterfailover modify queue redist-conf remove-tags rename \
93 e2a2a2eb Iustin Pop
          search-tags verify verify-disks version"
94 e2a2a2eb Iustin Pop
  else
95 e2a2a2eb Iustin Pop
    cmds="init"
96 e2a2a2eb Iustin Pop
  fi
97 e2a2a2eb Iustin Pop
98 e2a2a2eb Iustin Pop
  # default completion is empty
99 e2a2a2eb Iustin Pop
  COMPREPLY=()
100 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
101 e2a2a2eb Iustin Pop
    1)
102 e2a2a2eb Iustin Pop
      # complete the command name
103 e2a2a2eb Iustin Pop
      COMPREPLY=($(compgen -W "$cmds" -- ${cur}))
104 e2a2a2eb Iustin Pop
      ;;
105 e2a2a2eb Iustin Pop
    2)
106 e2a2a2eb Iustin Pop
      # complete arguments to the command
107 e2a2a2eb Iustin Pop
      case "$prev" in
108 e2a2a2eb Iustin Pop
        "queue")
109 b806661b Iustin Pop
          COMPREPLY=( $(compgen -W "drain undrain info" -- ${cur}) )
110 b806661b Iustin Pop
          ;;
111 75615bd3 Iustin Pop
        "copyfile")
112 75615bd3 Iustin Pop
          COMPREPLY=( $(compgen -f -- ${cur}) )
113 75615bd3 Iustin Pop
          ;;
114 75615bd3 Iustin Pop
        "command")
115 75615bd3 Iustin Pop
          COMPREPLY=( $(compgen -c -- ${cur}) )
116 75615bd3 Iustin Pop
          ;;
117 b806661b Iustin Pop
	*)
118 b806661b Iustin Pop
          ;;
119 e2a2a2eb Iustin Pop
      esac
120 e2a2a2eb Iustin Pop
  esac
121 e2a2a2eb Iustin Pop
122 e2a2a2eb Iustin Pop
  return 0
123 e2a2a2eb Iustin Pop
}
124 e2a2a2eb Iustin Pop
125 e2a2a2eb Iustin Pop
complete -F _gnt_cluster gnt-cluster
126 e2a2a2eb Iustin Pop
127 e2a2a2eb Iustin Pop
_gnt_debug()
128 e2a2a2eb Iustin Pop
{
129 e2a2a2eb Iustin Pop
  local cur prev cmds
130 e2a2a2eb Iustin Pop
  cur="$2"
131 e2a2a2eb Iustin Pop
  prev="$3"
132 e2a2a2eb Iustin Pop
133 e2a2a2eb Iustin Pop
  cmds="allocator delay submit-job"
134 e2a2a2eb Iustin Pop
135 e2a2a2eb Iustin Pop
  # default completion is empty
136 e2a2a2eb Iustin Pop
  COMPREPLY=()
137 e2a2a2eb Iustin Pop
138 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
139 e2a2a2eb Iustin Pop
    # cluster not initialized
140 e2a2a2eb Iustin Pop
    return 0
141 e2a2a2eb Iustin Pop
  fi
142 e2a2a2eb Iustin Pop
143 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
144 e2a2a2eb Iustin Pop
    1)
145 e2a2a2eb Iustin Pop
      # complete the command name
146 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
147 e2a2a2eb Iustin Pop
      ;;
148 e2a2a2eb Iustin Pop
    *)
149 e2a2a2eb Iustin Pop
      # we're doing options to commands
150 e2a2a2eb Iustin Pop
      base_cmd="${COMP_WORDS[1]}"
151 e2a2a2eb Iustin Pop
      case "${base_cmd}" in
152 e2a2a2eb Iustin Pop
        delay)
153 e2a2a2eb Iustin Pop
          if [[ "$prev" != -* ]]; then
154 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "--no-master -n" -- ${cur}) )
155 e2a2a2eb Iustin Pop
          fi
156 e2a2a2eb Iustin Pop
          ;;
157 e2a2a2eb Iustin Pop
        submit-job)
158 e2a2a2eb Iustin Pop
          if [[ "$COMP_CWORD" -eq 2 ]]; then
159 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -f -- ${cur}) )
160 e2a2a2eb Iustin Pop
          fi
161 e2a2a2eb Iustin Pop
          ;;
162 e2a2a2eb Iustin Pop
      esac
163 e2a2a2eb Iustin Pop
  esac
164 e2a2a2eb Iustin Pop
165 e2a2a2eb Iustin Pop
  return 0
166 e2a2a2eb Iustin Pop
}
167 e2a2a2eb Iustin Pop
168 e2a2a2eb Iustin Pop
complete -F _gnt_debug gnt-debug
169 e2a2a2eb Iustin Pop
170 e2a2a2eb Iustin Pop
_gnt_instance()
171 e2a2a2eb Iustin Pop
{
172 e2a2a2eb Iustin Pop
  local cur prev base_cmd cmds ilist nlist
173 e2a2a2eb Iustin Pop
  COMPREPLY=()
174 e2a2a2eb Iustin Pop
  cur="$2"
175 e2a2a2eb Iustin Pop
  prev="$3"
176 e2a2a2eb Iustin Pop
  #
177 e2a2a2eb Iustin Pop
  #  The basic options we'll complete.
178 e2a2a2eb Iustin Pop
  #
179 e2a2a2eb Iustin Pop
  cmds="activate-disks add add-tags batch-create console deactivate-disks \
180 e2a2a2eb Iustin Pop
        failover grow-disk info list list-tags migrate modify reboot \
181 e2a2a2eb Iustin Pop
        reinstall remove remove-tags rename replace-disks shutdown startup"
182 e2a2a2eb Iustin Pop
183 e2a2a2eb Iustin Pop
  # default completion is empty
184 e2a2a2eb Iustin Pop
  COMPREPLY=()
185 e2a2a2eb Iustin Pop
186 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
187 e2a2a2eb Iustin Pop
    # cluster not initialized
188 e2a2a2eb Iustin Pop
    return 0
189 e2a2a2eb Iustin Pop
  fi
190 e2a2a2eb Iustin Pop
191 e2a2a2eb Iustin Pop
  ilist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_instance_list")
192 e2a2a2eb Iustin Pop
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
193 e2a2a2eb Iustin Pop
194 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
195 e2a2a2eb Iustin Pop
    1)
196 e2a2a2eb Iustin Pop
      # complete the command name
197 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
198 e2a2a2eb Iustin Pop
      ;;
199 e2a2a2eb Iustin Pop
    *)
200 e2a2a2eb Iustin Pop
      # we're doing options to commands
201 e2a2a2eb Iustin Pop
      base_cmd="${COMP_WORDS[1]}"
202 e2a2a2eb Iustin Pop
      case "${base_cmd}" in
203 e2a2a2eb Iustin Pop
        # first, rules for multiple commands
204 e2a2a2eb Iustin Pop
        activate-disks|console|deactivate-disks|list-tags|rename|remove)
205 e2a2a2eb Iustin Pop
          # commands with only one instance argument, nothing else
206 e2a2a2eb Iustin Pop
          if [[ "$COMP_CWORD" -eq 2 ]]; then
207 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
208 e2a2a2eb Iustin Pop
          fi
209 e2a2a2eb Iustin Pop
          ;;
210 e2a2a2eb Iustin Pop
        info)
211 e2a2a2eb Iustin Pop
          # commands with more than one instance
212 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
213 e2a2a2eb Iustin Pop
          ;;
214 e2a2a2eb Iustin Pop
        add-tags|grow-disk|reinstall|remove-tags|replace-disks)
215 e2a2a2eb Iustin Pop
          # not very well handled
216 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
217 e2a2a2eb Iustin Pop
          ;;
218 e2a2a2eb Iustin Pop
        startup|start|shutdown|stop|reboot)
219 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "--force-multiple --node --primary \
220 e2a2a2eb Iustin Pop
                          --secondary --all --submit $ilist" -- ${cur}) )
221 e2a2a2eb Iustin Pop
          ;;
222 e2a2a2eb Iustin Pop
        # individual commands
223 e2a2a2eb Iustin Pop
        add)
224 e2a2a2eb Iustin Pop
          case "$prev" in
225 e2a2a2eb Iustin Pop
            -t)
226 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "diskless file plain drbd" -- ${cur}) )
227 e2a2a2eb Iustin Pop
              ;;
228 e2a2a2eb Iustin Pop
            --file-driver)
229 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "loop blktap" -- ${cur}) )
230 e2a2a2eb Iustin Pop
              ;;
231 e2a2a2eb Iustin Pop
            -*)
232 e2a2a2eb Iustin Pop
              # arguments to other options, we don't have completion yet
233 e2a2a2eb Iustin Pop
              ;;
234 e2a2a2eb Iustin Pop
            *)
235 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "-t -n -o -B -H -s --disks --net \
236 e2a2a2eb Iustin Pop
                            --no-nics --no-start --no-ip-check -I \
237 e2a2a2eb Iustin Pop
                            --file-driver --file-storage-dir --submit" \
238 e2a2a2eb Iustin Pop
                -- ${cur}) )
239 e2a2a2eb Iustin Pop
              ;;
240 e2a2a2eb Iustin Pop
          esac
241 e2a2a2eb Iustin Pop
          ;;
242 e2a2a2eb Iustin Pop
        batch-create)
243 e2a2a2eb Iustin Pop
          # this only takes one file name
244 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -A file -- ${cur}) )
245 e2a2a2eb Iustin Pop
          ;;
246 e2a2a2eb Iustin Pop
        failover)
247 e2a2a2eb Iustin Pop
          case "$COMP_CWORD" in
248 e2a2a2eb Iustin Pop
            2)
249 e2a2a2eb Iustin Pop
              # options or instances
250 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "--ignore-failures $ilist" -- ${cur}) )
251 e2a2a2eb Iustin Pop
              ;;
252 e2a2a2eb Iustin Pop
            3)
253 e2a2a2eb Iustin Pop
              # if previous was option, we allow instance
254 e2a2a2eb Iustin Pop
              case "$prev" in
255 e2a2a2eb Iustin Pop
                -*)
256 e2a2a2eb Iustin Pop
                  COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
257 e2a2a2eb Iustin Pop
                  ;;
258 e2a2a2eb Iustin Pop
              esac
259 e2a2a2eb Iustin Pop
          esac
260 e2a2a2eb Iustin Pop
          ;;
261 e2a2a2eb Iustin Pop
        list)
262 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "--no-headers --separator --units -o \
263 e2a2a2eb Iustin Pop
                          --sync $ilist" -- ${cur}) )
264 e2a2a2eb Iustin Pop
          ;;
265 e2a2a2eb Iustin Pop
        modify)
266 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "-H -B --disk --net $ilist" -- ${cur}) )
267 e2a2a2eb Iustin Pop
          ;;
268 e2a2a2eb Iustin Pop
        migrate)
269 e2a2a2eb Iustin Pop
          case "$COMP_CWORD" in
270 e2a2a2eb Iustin Pop
            2)
271 e2a2a2eb Iustin Pop
              # options or instances
272 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "--non-live --cleanup $ilist" -- \
273 e2a2a2eb Iustin Pop
                ${cur}) )
274 e2a2a2eb Iustin Pop
              ;;
275 e2a2a2eb Iustin Pop
            3)
276 e2a2a2eb Iustin Pop
              # if previous was option, we allow instance
277 e2a2a2eb Iustin Pop
              case "$prev" in
278 e2a2a2eb Iustin Pop
                -*)
279 e2a2a2eb Iustin Pop
                  COMPREPLY=( $(compgen -W "$ilist" -- ${cur}) )
280 e2a2a2eb Iustin Pop
                  ;;
281 e2a2a2eb Iustin Pop
              esac
282 e2a2a2eb Iustin Pop
          esac
283 e2a2a2eb Iustin Pop
      esac
284 e2a2a2eb Iustin Pop
  esac
285 e2a2a2eb Iustin Pop
286 e2a2a2eb Iustin Pop
  return 0
287 e2a2a2eb Iustin Pop
}
288 e2a2a2eb Iustin Pop
289 e2a2a2eb Iustin Pop
complete -F _gnt_instance gnt-instance
290 e2a2a2eb Iustin Pop
291 e2a2a2eb Iustin Pop
_gnt_job()
292 e2a2a2eb Iustin Pop
{
293 e2a2a2eb Iustin Pop
  local cur prev cmds
294 e2a2a2eb Iustin Pop
  cur="$2"
295 e2a2a2eb Iustin Pop
  prev="$3"
296 e2a2a2eb Iustin Pop
297 e2a2a2eb Iustin Pop
  cmds="archive autoarchive cancel info list"
298 e2a2a2eb Iustin Pop
299 e2a2a2eb Iustin Pop
  # default completion is empty
300 e2a2a2eb Iustin Pop
  COMPREPLY=()
301 e2a2a2eb Iustin Pop
302 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
303 e2a2a2eb Iustin Pop
    # cluster not initialized
304 e2a2a2eb Iustin Pop
    return 0
305 e2a2a2eb Iustin Pop
  fi
306 e2a2a2eb Iustin Pop
307 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
308 e2a2a2eb Iustin Pop
    1)
309 e2a2a2eb Iustin Pop
      # complete the command name
310 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
311 e2a2a2eb Iustin Pop
      ;;
312 e2a2a2eb Iustin Pop
    *)
313 e2a2a2eb Iustin Pop
      # we're doing options to commands
314 e2a2a2eb Iustin Pop
      base_cmd="${COMP_WORDS[1]}"
315 e2a2a2eb Iustin Pop
      case "${base_cmd}" in
316 e2a2a2eb Iustin Pop
        archive|cancel|info)
317 e2a2a2eb Iustin Pop
          # FIXME: this is really going into the internals of the job queue
318 e2a2a2eb Iustin Pop
          jlist=$( cd @LOCALSTATEDIR@/lib/ganeti/queue; echo job-*)
319 e2a2a2eb Iustin Pop
          jlist=${jlist//job-/}
320 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "$jlist" -- ${cur}) )
321 e2a2a2eb Iustin Pop
          ;;
322 e2a2a2eb Iustin Pop
        list)
323 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "--no-headers --separator -o" -- ${cur}) )
324 e2a2a2eb Iustin Pop
          ;;
325 e2a2a2eb Iustin Pop
326 e2a2a2eb Iustin Pop
      esac
327 e2a2a2eb Iustin Pop
  esac
328 e2a2a2eb Iustin Pop
329 e2a2a2eb Iustin Pop
  return 0
330 e2a2a2eb Iustin Pop
}
331 e2a2a2eb Iustin Pop
332 e2a2a2eb Iustin Pop
complete -F _gnt_job gnt-job
333 e2a2a2eb Iustin Pop
334 e2a2a2eb Iustin Pop
_gnt_os()
335 e2a2a2eb Iustin Pop
{
336 e2a2a2eb Iustin Pop
  local cur prev cmds
337 e2a2a2eb Iustin Pop
  cur="$2"
338 e2a2a2eb Iustin Pop
  prev="$3"
339 e2a2a2eb Iustin Pop
340 e2a2a2eb Iustin Pop
  cmds="list diagnose"
341 e2a2a2eb Iustin Pop
342 e2a2a2eb Iustin Pop
  # default completion is empty
343 e2a2a2eb Iustin Pop
  COMPREPLY=()
344 e2a2a2eb Iustin Pop
345 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
346 e2a2a2eb Iustin Pop
    # cluster not initialized
347 e2a2a2eb Iustin Pop
    return 0
348 e2a2a2eb Iustin Pop
  fi
349 e2a2a2eb Iustin Pop
350 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
351 e2a2a2eb Iustin Pop
    1)
352 e2a2a2eb Iustin Pop
      # complete the command name
353 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
354 e2a2a2eb Iustin Pop
      ;;
355 e2a2a2eb Iustin Pop
    *)
356 e2a2a2eb Iustin Pop
      # we're doing options to commands
357 e2a2a2eb Iustin Pop
      base_cmd="${COMP_WORDS[1]}"
358 e2a2a2eb Iustin Pop
      case "${base_cmd}" in
359 e2a2a2eb Iustin Pop
        list)
360 e2a2a2eb Iustin Pop
          if [[ "$COMP_CWORD" -eq 2 ]]; then
361 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "--no-headers" -- ${cur}) )
362 e2a2a2eb Iustin Pop
          fi
363 e2a2a2eb Iustin Pop
          ;;
364 e2a2a2eb Iustin Pop
      esac
365 e2a2a2eb Iustin Pop
  esac
366 e2a2a2eb Iustin Pop
367 e2a2a2eb Iustin Pop
  return 0
368 e2a2a2eb Iustin Pop
}
369 e2a2a2eb Iustin Pop
370 e2a2a2eb Iustin Pop
complete -F _gnt_os gnt-os
371 e2a2a2eb Iustin Pop
372 e2a2a2eb Iustin Pop
_gnt_node()
373 e2a2a2eb Iustin Pop
{
374 e2a2a2eb Iustin Pop
  local cur prev cmds base_cmd
375 e2a2a2eb Iustin Pop
  cur="$2"
376 e2a2a2eb Iustin Pop
  prev="$3"
377 e2a2a2eb Iustin Pop
378 e2a2a2eb Iustin Pop
  cmds="add add-tags evacuate failover info list list-tags migrate modify \
379 e2a2a2eb Iustin Pop
          remove remove-tags volumes"
380 e2a2a2eb Iustin Pop
381 e2a2a2eb Iustin Pop
  # default completion is empty
382 e2a2a2eb Iustin Pop
  COMPREPLY=()
383 e2a2a2eb Iustin Pop
384 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
385 e2a2a2eb Iustin Pop
    # cluster not initialized
386 e2a2a2eb Iustin Pop
    return 0
387 e2a2a2eb Iustin Pop
  fi
388 e2a2a2eb Iustin Pop
389 e2a2a2eb Iustin Pop
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
390 e2a2a2eb Iustin Pop
391 e2a2a2eb Iustin Pop
  case "$COMP_CWORD" in
392 e2a2a2eb Iustin Pop
    1)
393 e2a2a2eb Iustin Pop
      # complete the command name
394 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
395 e2a2a2eb Iustin Pop
      ;;
396 e2a2a2eb Iustin Pop
    *)
397 e2a2a2eb Iustin Pop
      # we're doing options to commands
398 e2a2a2eb Iustin Pop
      base_cmd="${COMP_WORDS[1]}"
399 e2a2a2eb Iustin Pop
      case "${base_cmd}" in
400 e2a2a2eb Iustin Pop
        # first rules for multiple commands
401 e2a2a2eb Iustin Pop
        list-tags|remove)
402 e2a2a2eb Iustin Pop
          # commands with only one instance argument, nothing else
403 e2a2a2eb Iustin Pop
          if [[ "$COMP_CWORD" -eq 2 ]]; then
404 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
405 e2a2a2eb Iustin Pop
          fi
406 e2a2a2eb Iustin Pop
          ;;
407 e2a2a2eb Iustin Pop
        add-tags|info|remove-tags|volumes)
408 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
409 e2a2a2eb Iustin Pop
          ;;
410 e2a2a2eb Iustin Pop
        # individual commands
411 e2a2a2eb Iustin Pop
        add)
412 e2a2a2eb Iustin Pop
          # options or instances
413 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "-s --readd --no-ssh-key-check" -- ${cur}) )
414 e2a2a2eb Iustin Pop
          ;;
415 e2a2a2eb Iustin Pop
        evacuate)
416 e2a2a2eb Iustin Pop
          case "$COMP_CWORD" in
417 e2a2a2eb Iustin Pop
            2)
418 e2a2a2eb Iustin Pop
              # options or instances
419 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "-n -I $nlist" -- ${cur}) )
420 e2a2a2eb Iustin Pop
              ;;
421 e2a2a2eb Iustin Pop
            3)
422 e2a2a2eb Iustin Pop
              # if previous was option, we allow node
423 e2a2a2eb Iustin Pop
              case "$prev" in
424 e2a2a2eb Iustin Pop
                -*)
425 e2a2a2eb Iustin Pop
                  COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
426 e2a2a2eb Iustin Pop
                  ;;
427 e2a2a2eb Iustin Pop
              esac
428 e2a2a2eb Iustin Pop
          esac
429 e2a2a2eb Iustin Pop
          ;;
430 e2a2a2eb Iustin Pop
        failover)
431 e2a2a2eb Iustin Pop
          case "$COMP_CWORD" in
432 e2a2a2eb Iustin Pop
            2)
433 e2a2a2eb Iustin Pop
              # options or instances
434 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "--ignore-failures $nlist" -- ${cur}) )
435 e2a2a2eb Iustin Pop
              ;;
436 e2a2a2eb Iustin Pop
            3)
437 e2a2a2eb Iustin Pop
              # if previous was option, we allow node
438 e2a2a2eb Iustin Pop
              case "$prev" in
439 e2a2a2eb Iustin Pop
                -*)
440 e2a2a2eb Iustin Pop
                  COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
441 e2a2a2eb Iustin Pop
                  ;;
442 e2a2a2eb Iustin Pop
              esac
443 e2a2a2eb Iustin Pop
          esac
444 e2a2a2eb Iustin Pop
          ;;
445 e2a2a2eb Iustin Pop
        list)
446 e2a2a2eb Iustin Pop
          COMPREPLY=( $(compgen -W "--no-headers --separator --units -o \
447 e2a2a2eb Iustin Pop
                          --sync $nlist" -- ${cur}) )
448 e2a2a2eb Iustin Pop
          ;;
449 e2a2a2eb Iustin Pop
        modify)
450 e2a2a2eb Iustin Pop
          # TODO: after a non-option, don't allow options
451 e2a2a2eb Iustin Pop
          if [[ "$COMP_CWORD" -eq 2 || "$prev" != -* ]]; then
452 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "-C -O -D $nlist" -- ${cur}) )
453 e2a2a2eb Iustin Pop
          elif [[ "$prev" == -* ]]; then
454 e2a2a2eb Iustin Pop
            COMPREPLY=( $(compgen -W "yes no" -- ${cur}) )
455 e2a2a2eb Iustin Pop
          fi
456 e2a2a2eb Iustin Pop
          ;;
457 e2a2a2eb Iustin Pop
        migrate)
458 e2a2a2eb Iustin Pop
          case "$COMP_CWORD" in
459 e2a2a2eb Iustin Pop
            2)
460 e2a2a2eb Iustin Pop
              # options or nodes
461 e2a2a2eb Iustin Pop
              COMPREPLY=( $(compgen -W "--non-live $nlist" -- ${cur}) )
462 e2a2a2eb Iustin Pop
              ;;
463 e2a2a2eb Iustin Pop
            3)
464 e2a2a2eb Iustin Pop
              # if previous was option, we allow node
465 e2a2a2eb Iustin Pop
              case "$prev" in
466 e2a2a2eb Iustin Pop
                -*)
467 e2a2a2eb Iustin Pop
                  COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
468 e2a2a2eb Iustin Pop
                  ;;
469 e2a2a2eb Iustin Pop
              esac
470 e2a2a2eb Iustin Pop
          esac
471 e2a2a2eb Iustin Pop
      esac
472 e2a2a2eb Iustin Pop
  esac
473 e2a2a2eb Iustin Pop
474 e2a2a2eb Iustin Pop
  return 0
475 e2a2a2eb Iustin Pop
}
476 e2a2a2eb Iustin Pop
477 e2a2a2eb Iustin Pop
complete -F _gnt_node gnt-node
478 e2a2a2eb Iustin Pop
479 e2a2a2eb Iustin Pop
# other tools
480 e2a2a2eb Iustin Pop
481 e2a2a2eb Iustin Pop
_gnt_tool_burnin()
482 e2a2a2eb Iustin Pop
{
483 e2a2a2eb Iustin Pop
  local cur prev
484 e2a2a2eb Iustin Pop
  cur="$2"
485 e2a2a2eb Iustin Pop
  prev="$3"
486 e2a2a2eb Iustin Pop
487 e2a2a2eb Iustin Pop
  # default completion is empty
488 e2a2a2eb Iustin Pop
  COMPREPLY=()
489 e2a2a2eb Iustin Pop
490 e2a2a2eb Iustin Pop
  if [[ ! -f "@LOCALSTATEDIR@/lib/ganeti/ssconf_cluster_name" ]]; then
491 e2a2a2eb Iustin Pop
    # cluster not initialized
492 e2a2a2eb Iustin Pop
    return 0
493 e2a2a2eb Iustin Pop
  fi
494 e2a2a2eb Iustin Pop
495 e2a2a2eb Iustin Pop
  nlist=$(< "@LOCALSTATEDIR@/lib/ganeti/ssconf_node_list")
496 e2a2a2eb Iustin Pop
497 e2a2a2eb Iustin Pop
  case "$prev" in
498 e2a2a2eb Iustin Pop
    -t)
499 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "diskless file plain drbd" -- ${cur}) )
500 e2a2a2eb Iustin Pop
      ;;
501 e2a2a2eb Iustin Pop
    --rename)
502 e2a2a2eb Iustin Pop
      # this needs an unused host name, so we don't complete it
503 e2a2a2eb Iustin Pop
      ;;
504 e2a2a2eb Iustin Pop
    -n|--nodes)
505 e2a2a2eb Iustin Pop
      # nodes from the cluster, comma separated
506 e2a2a2eb Iustin Pop
      # FIXME: make completion work for comma-separated values
507 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$nlist" -- ${cur}) )
508 e2a2a2eb Iustin Pop
      ;;
509 e2a2a2eb Iustin Pop
    -o|--os)
510 e2a2a2eb Iustin Pop
      # the os list
511 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "$(gnt-os list --no-headers)" -- ${cur}) )
512 e2a2a2eb Iustin Pop
      ;;
513 e2a2a2eb Iustin Pop
    --disk-size|--disk-growth)
514 e2a2a2eb Iustin Pop
      # these take a number or unit, we can't really autocomplete, but
515 e2a2a2eb Iustin Pop
      # we show a couple of examples
516 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "128M 512M 1G 4G 1G,256M 4G,1G,1G 10G" -- \
517 e2a2a2eb Iustin Pop
        ${cur}) )
518 e2a2a2eb Iustin Pop
      ;;
519 e2a2a2eb Iustin Pop
    --mem-size)
520 e2a2a2eb Iustin Pop
      # this takes a number or unit, we can't really autocomplete, but
521 e2a2a2eb Iustin Pop
      # we show a couple of examples
522 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "128M 256M 512M 1G 4G 8G 12G 16G" -- ${cur}) )
523 e2a2a2eb Iustin Pop
      ;;
524 e2a2a2eb Iustin Pop
    --net-timeout)
525 e2a2a2eb Iustin Pop
      # this takes a number in seconds; again, we can't really complete
526 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "15 60 300 900" -- ${cur}) )
527 e2a2a2eb Iustin Pop
      ;;
528 e2a2a2eb Iustin Pop
    *)
529 e2a2a2eb Iustin Pop
      # all other, we just list the whole options
530 e2a2a2eb Iustin Pop
      COMPREPLY=( $(compgen -W "-o --disk-size --disk-growth --mem-size \
531 e2a2a2eb Iustin Pop
                      -v --verbose --no-replace1 --no-replace2 --no-failover \
532 e2a2a2eb Iustin Pop
                      --no-migrate --no-importexport --no-startstop \
533 e2a2a2eb Iustin Pop
                      --no-reinstall --no-reboot --no-activate-disks \
534 e2a2a2eb Iustin Pop
                      --no-add-disks --no-add-nics --no-nics \
535 e2a2a2eb Iustin Pop
                      --rename -t -n --nodes -I --iallocator -p --parallel \
536 e2a2a2eb Iustin Pop
                      --net-timeout -C --http-check -K --keep-instances" \
537 e2a2a2eb Iustin Pop
        -- ${cur}) )
538 e2a2a2eb Iustin Pop
  esac
539 e2a2a2eb Iustin Pop
540 e2a2a2eb Iustin Pop
  return 0
541 e2a2a2eb Iustin Pop
}
542 e2a2a2eb Iustin Pop
543 e2a2a2eb Iustin Pop
complete -F _gnt_tool_burnin @PREFIX@/lib/ganeti/tools/burnin