1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/bin/bash
# completion for vgt
_vgt() {
local cur prev cmd_name
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmd_name="${COMP_WORDS[1]}"
opts="validate-compute validate-cleanup"
case "${cmd_name}" in
"validate-compute")
case ${COMP_CWORD} in
2|4|6|8|10|12|14|16|18|20)
COMPREPLY=( $(compgen -W "--host --flavor-name --network-name --image-name --ssh-username" -- "${cur}") )
return 0
;;
*)
case "${prev}" in
"--image-name")
local image_list
mapfile -t image_list < <(
openstack image list --public --format value -c Name
)
local escaped=()
for img in "${image_list[@]}"; do
escaped+=( "$(printf '%q' "$img")" )
done
COMPREPLY=( $(compgen -W "${escaped[*]}" -- "$cur") )
return 0
;;
"--network-name")
local network_list
mapfile -t network_list < <(
openstack network list --share --format value -c Name
)
local escaped=()
for net in "${network_list[@]}"; do
escaped+=( "$(printf '%q' "$net")" )
done
COMPREPLY=( $(compgen -W "${escaped[*]}" -- "$cur") )
return 0
;;
"--flavor-name")
local flavor_list
mapfile -t flavor_list < <(
openstack flavor list --format value -c Name
)
local escaped=()
for fla in "${flavor_list[@]}"; do
escaped+=( "$(printf '%q' "$fla")" )
done
COMPREPLY=( $(compgen -W "${escaped[*]}" -- "$cur") )
return 0
;;
"--host")
local host_list
mapfile -t host_list < <(
openstack compute service list --format csv | q -H -d, "SELECT Host from - WHERE Binary='nova-compute' AND Status='disabled'"
)
local escaped=()
for comp in "${host_list[@]}"; do
escaped+=( "$(printf '%q' "$comp")" )
done
COMPREPLY=( $(compgen -W "${escaped[*]}" -- "$cur") )
return 0
;;
*)
;;
esac
;;
esac
;;
"validate-cleanup")
return 0
;;
*)
;;
esac
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
}
complete -F _vgt vgt
|