1
# OpenVZ vzctl bash completion by Kir Kolyshkin <kir@openvz.org>
2
# Put this file to /etc/bash_completion.d/
3
# modified Thorsten Schifferdecker <tsd@debian.systs.org>
8
local rm_empty='sed s/^-[[:space:]]*//'
11
# create a new VEID, by increasing the last one
12
local veids=`@SBINDIR@/vzlist -H -a -oveid | tail -1`
13
[ -n "$veids" ] || veids=100
16
start|mount|umount|destroy)
18
@SBINDIR@/vzlist -H -S -oveid
19
@SBINDIR@/vzlist -H -S -oname | $rm_empty
23
@SBINDIR@/vzlist -H -oveid
24
@SBINDIR@/vzlist -H -oname | $rm_emtpy
28
@SBINDIR@/vzlist -H -a -oveid
29
@SBINDIR@/vzlist -H -a -oname | $rm_empty
36
local cur prev cmd vzctl_cmds vzctl_create_opts vzctl_set_opts
37
local iptables_names cap_names
40
#echo "COMP_WORDS: $COMP_WORDS"
41
#echo "COMP_CWORD: $COMP_CWORD"
42
#echo "COMP_WORDS[1]: ${COMP_WORDS[1]}"
45
cur=${COMP_WORDS[COMP_CWORD]}
46
prev=${COMP_WORDS[COMP_CWORD-1]}
48
vzctl_common_opts="--quiet --verbose --help --version"
49
vzctl_cmds="create destroy mount umount chkpnt restore \
50
set start stop restart status enter exec exec2 runscript"
51
vzctl_create_opts="--ostemplate --config --private --root \
52
--ipadd --hostname FIXME"
53
vzctl_set_opts="--save --onboot --root --private \
54
--userpasswd --disabled --ipadd --ipdel \
55
--hostname --nameserver --searchdomain \
56
--numproc --numtcpsock --numothersock --vmguarpages \
57
--kmemsize --tcpsndbuf --tcprcvbuf --othersockbuf \
58
--dgramrcvbuf --oomguarpages --lockedpages --privvmpages \
59
--shmpages --numfile --numflock --numpty --numsiginfo \
60
--dcachesize --numiptent --physpages --cpuunits --cpulimit \
61
--iptables --netdev_add --netdev_del --veth_add --veth_del \
62
--diskspace --diskinodes --quotatime --quotaugidlimit \
63
--noatime --capability --devnodes --applyconfig --name \
66
iptables_names="iptable_filter iptable_mangle ipt_limit
67
ipt_multiport ipt_tos ipt_TOS ipt_REJECT ipt_TCPMSS
68
ipt_tcpmss ipt_ttl ipt_LOG ipt_length ip_conntrack
69
ip_conntrack_ftp ip_conntrack_irc ipt_conntrack ipt_state
70
ipt_helper iptable_nat ip_nat_ftp ip_nat_irc ipt_REDIRECT"
72
cap_names="chown dac_override dac_read_search fowner fsetid kill
73
setgid setuid setpcap linux_immutable net_bind_service
74
net_broadcast net_admin net_raw ipc_lock ipc_owner
75
sys_module sys_rawio sys_chroot sys_ptrace sys_pacct
76
sys_admin sys_boot sys_nice sys_resource sys_time
77
sys_tty_config mknod lease setveid ve_admin"
83
# command or global option
84
COMPREPLY=( $( compgen -W "$vzctl_cmds $vzctl_common_opts" -- $cur ) )
94
COMPREPLY=( $( compgen -W "$vzctl_cmds" -- $cur ) )
98
COMPREPLY=( $( compgen -W "$(_get_ves $prev)" -- $cur ) )
104
if [[ $COMP_CWORD -eq 3 && ! $prev != '^[1-9][0-9]*$' ]]; then
106
COMPREPLY=( $( compgen -W "$(_get_ves $prev)" -- $cur ) )
112
# get the template path from the vz.conf
113
local vztmpl=`grep ^TEMPLATE @PKGCONFDIR@/vz.conf | cut -d "=" -f 2`
114
COMPREPLY=( $( compgen -W "$(ls -1 $vztmpl/cache/*.tar.gz | \
115
sed -e "s#^$vztmpl/cache/##" -e 's#.tar.gz$##')" -- $cur ) )
118
--onboot|--disabled|--noatime)
119
COMPREPLY=( $( compgen -W "yes no" -- $cur ) )
121
--config|--applyconfig)
122
local configs=$(ls -1 @PKGCONFDIR@/conf/*.conf-sample | \
123
cut -d "-" -f 2- | sed -e 's#.conf-sample$##')
125
configs=${configs/.conf-sample/}
126
COMPREPLY=( $( compgen -W "$configs" -- $cur ) )
129
COMPREPLY=( $( compgen -W "$iptables_names" -- $cur ) )
132
local devs=`ip addr show | awk '/^[0-9]/ && /UP/ && !/venet/ && !/lo/ \
133
{ print $2 }' | sed s/://`
135
COMPREPLY=( $( compgen -W "$devs" -- $cur ) )
139
COMPREPLY=( $( compgen -W "$cap_names" -- $cur ) )
140
# FIXME: add :on or :off -- doesn't work :(
141
# if [[ ${#COMPREPLY[@]} -le 1 ]]; then
142
# if [[ $cur =~ ":" ]]; then
145
# cap=${COMPREPLY[0]%%:*}
147
# Single match: add :on|:off
148
# COMPREPLY=( $(compgen -W \
149
# "${cap}:on ${cap}:off" -- $cur) )
153
# FIXME: device:r|w|rw|none
155
COMPREPLY=( $( compgen -W "$devs" -- $cur ) )
159
local ve=${COMP_WORDS[2]}
160
if [[ ! ${ve} != '^[1-9][0-9]*$' ]] ; then
161
# --verbose or --quiet used
165
LIST_OPT=`echo $ve | awk '/[a-zA-Z]/ {print "-N"}'`
166
local ips="`@SBINDIR@/vzlist -H -o ip $LIST_OPT $ve | grep -vi -`"
167
COMPREPLY=( $( compgen -W "$ips all" -- $cur ) )
171
# Dir autocompletion works bad since there is
172
# a space added. Alternatively, we could use
173
# -o dirname option to 'complete' -- but it
174
# makes no sense for other parameters (UBCs
175
# etc). So no action for now.
178
if [[ "${prev::2}" != "--" || "$prev" = "--save" ]]; then
181
if [ ${cmd::2} = "--" ] ; then
182
# --verbose or --quiet used
188
COMPREPLY=( $( compgen -W "$vzctl_create_opts" -- $cur ) )
191
COMPREPLY=( $( compgen -W "$vzctl_set_opts" -- $cur ) )
194
COMPREPLY=( $( compgen -W "--dumpfile" -- $cur ) )
197
COMPREPLY=( $( compgen -W "--fast" -- $cur ) )
203
# Option that requires an argument
204
# which we can't autocomplete
205
COMPREPLY=( $( compgen -W "" -- $cur ) )
215
complete -F _vzctl vzctl