/etc/bash_completion.d/vzctl.sh is in vzctl 4.9.4-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | # OpenVZ vzctl bash completion by Kir Kolyshkin <kir@openvz.org>
# Put this file to /etc/bash_completion.d/
# modified Thorsten Schifferdecker <tsd@debian.systs.org>
_get_ves()
{
local cmd=$1
local rm_empty='sed s/^-[[:space:]]*//'
# Only allow this completion when user has root privileges
[ "$EUID" -ne 0 ] && return 1
case $cmd in
create)
# create a new CTID, by increasing the last one
local veids=`/usr/sbin/vzlist -H -a -octid \
2>/dev/null | tail -1`
[ -n "$veids" ] || veids=100
echo $((veids+1))
;;
start|mount|umount|destroy|delete)
# stopped CTs
/usr/sbin/vzlist -H -S -octid 2>/dev/null
/usr/sbin/vzlist -H -S -oname 2>/dev/null | $rm_empty
;;
stop|restart|enter|exec*|suspend|chkpnt)
# running CTs
/usr/sbin/vzlist -H -octid 2>/dev/null
/usr/sbin/vzlist -H -oname 2>/dev/null | $rm_empty
;;
resume|restore)
# suspended CTs
(/usr/sbin/vzlist -HS -o status,ctid;
/usr/sbin/vzlist -HS -o status,name) 2>/dev/null | \
grep '^suspended ' | \
sed 's/^suspended *//' | $rm_empty
;;
convert)
# stopped CTs on simfs
(/usr/sbin/vzlist -HS -o layout,ctid;
/usr/sbin/vzlist -HS -o layout,name) 2>/dev/null | \
grep '^simfs ' | \
sed 's/^simfs *//' | $rm_empty
;;
compact|snapshot*)
# CTs on ploop
(/usr/sbin/vzlist -H -a -o layout,ctid;
/usr/sbin/vzlist -H -a -o layout,name) 2>/dev/null | \
grep '^ploop ' | \
sed 's/^ploop *//' | $rm_empty
;;
*)
# All CTs
/usr/sbin/vzlist -H -a -octid 2>/dev/null
/usr/sbin/vzlist -H -a -oname 2>/dev/null | $rm_empty
;;
esac
}
_vzctl()
{
#echo "ARGS: $*"
#echo "COMP_WORDS: $COMP_WORDS"
#echo "COMP_CWORD: $COMP_CWORD"
#echo "COMP_WORDS[1]: ${COMP_WORDS[1]}"
COMPREPLY=()
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local vzctl_common_opts="--quiet --verbose --help --version"
local vzctl_cmds="create destroy delete mount umount chkpnt restore \
suspend resume \
set start stop restart status quotaon quotaoff quotainit \
enter exec exec2 runscript console"
local vzctl_create_opts="--ostemplate --config --private --root \
--layout --diskspace --diskinodes --ipadd --hostname \
--name --description"
local vzctl_convert_opts="--layout"
local vzctl_set_opts="--save --onboot --root --private \
--userpasswd --disabled --ipadd --ipdel \
--hostname --nameserver --searchdomain \
--numproc --numtcpsock --numothersock --vmguarpages \
--kmemsize --tcpsndbuf --tcprcvbuf --othersockbuf \
--dgramrcvbuf --oomguarpages --lockedpages --privvmpages \
--shmpages --numfile --numflock --numpty --numsiginfo \
--dcachesize --numiptent --physpages --swappages \
--vm_overcommit --cpuunits --cpulimit --cpus --cpumask --nodemask \
--netfilter --netdev_add --netdev_del --netif_add --netif_del \
--diskquota --mount_opts \
--diskspace --diskinodes --quotatime --quotaugidlimit \
--capability --devnodes --devices --applyconfig \
--name --ioprio --iolimit --iopslimit \
--setmode --meminfo --bootorder --features \
--reset_ub --stop-timeout --offline-resize"
local vzctl_start_opts="--wait --force --skip-fsck --skip-remount"
local vzctl_stop_opts="--fast --skip-umount"
local vzctl_restart_opts="$vzctl_start_opts $vzctl_stop_opts"
local vzctl_snapshot_create_opts="--id --name --description \
--skip-suspend --skip-config"
local vzctl_snapshot_switch_opts="--id --skip-resume --must-resume \
--skip-config"
local vzctl_snapshot_mount_opts="--id --target"
local vzctl_snapshot_list_opts="-H --no-header -o --output --id \
-L --list --help"
local netfilter_names="disabled stateless stateful full"
local cap_names="chown dac_override dac_read_search fowner fsetid kill
setgid setuid setpcap linux_immutable net_bind_service
net_broadcast net_admin net_raw ipc_lock ipc_owner
sys_module sys_rawio sys_chroot sys_ptrace sys_pacct
sys_admin sys_boot sys_nice sys_resource sys_time
sys_tty_config mknod lease setveid ve_admin"
local feature_names="sysfs nfs sit ipip ppp ipgre bridge nfsd"
if test -f /proc/vz/ploop_minor; then
vzctl_cmds+=" convert compact snapshot \
snapshot-mount snapshot-umount \
snapshot-switch snapshot-delete snapshot-list"
fi
case $COMP_CWORD in
1)
# command or global option
COMPREPLY=( $( compgen -W "$vzctl_cmds $vzctl_common_opts" -- $cur ) )
;;
2)
case "$prev" in
--help|--version)
COMPREPLY=()
;;
--*)
# command
COMPREPLY=( $( compgen -W "$vzctl_cmds" -- $cur ) )
;;
*)
# CTID
COMPREPLY=( $( compgen -W "$(_get_ves $prev)" -- $cur ) )
;;
esac
;;
*) # COMP_CWORD >= 3
if [ $COMP_CWORD -eq 3 -a ${COMP_WORDS[1]::2} = "--" ]; then
# Global option was used, need CTID here
COMPREPLY=( $( compgen -W "$(_get_ves $prev)" -- $cur ) )
else
# flag or option
case $prev in
--ostemplate)
COMPREPLY=( $( compgen -W "$(/usr/sbin/vztmpl-dl --list-all)" -- $cur ) )
;;
--onboot|--disabled|--diskquota)
COMPREPLY=( $( compgen -W "yes no" -- $cur ) )
;;
--setmode)
COMPREPLY=( $( compgen -W "restart ignore" -- $cur ) )
;;
--config|--applyconfig)
local configs=$(command ls -1 /etc/vz/conf/*.conf-sample |
cut -d "-" -f 2- | sed -e 's#.conf-sample$##')
COMPREPLY=( $( compgen -W "$configs" -- $cur ) )
;;
--layout)
COMPREPLY=( $( compgen -W "ploop ploop:expanded ploop:plain ploop:raw simfs" -- $cur ) )
;;
--netfilter)
COMPREPLY=( $( compgen -W "$netfilter_names" -- $cur ) )
;;
--netdev*)
local devs=`ip addr show | awk '/^[0-9]/ && /UP/ && !/venet/ && !/lo/ \
{ print $2 }' | sed s/://`
COMPREPLY=( $( compgen -W "$devs" -- $cur ) )
;;
--meminfo)
local meminfo="none privvmpages:1"
COMPREPLY=( $( compgen -W "$meminfo" -- $cur ) )
;;
--ioprio)
# ioprio range: 0 - 7 (default : 4)
local ioprio='0 1 2 3 4 5 6 7'
COMPREPLY=( $( compgen -W "$ioprio" -- $cur ) )
;;
--capability)
# capname:on|off
COMPREPLY=( $( compgen -W "$cap_names" -- $cur ) )
# FIXME: add :on or :off -- doesn't work :(
# if [[ ${#COMPREPLY[@]} -le 1 ]]; then
# if [[ $cur =~ ":" ]]; then
# cap=${cur%%:*}
# else
# cap=${COMPREPLY[0]%%:*}
# fi
# Single match: add :on|:off
# COMPREPLY=( $(compgen -W \
# "${cap}:on ${cap}:off" -- $cur) )
# fi
;;
--features)
# featurename:on|off
COMPREPLY=( $( compgen -W "$feature_names" -- $cur ) )
# FIXME: add :on or :off -- can't make it work
;;
--devnodes)
# FIXME: device:r|w|rw|none
local devs=''
COMPREPLY=( $( compgen -W "$devs" -- $cur ) )
;;
--devices)
# FIXME: b|c:major:minor|all:r|w|rw
local devices=''
COMPREPLY=( $( compgen -W "$devices" -- $cur ) )
;;
--ipdel)
# Only allow this completion
# when user has root privileges
[ "$EUID" -ne 0 ] && return 1
# Get CTID
local cmd=${COMP_WORDS[1]}
local ve=${COMP_WORDS[2]}
if [ ${cmd::2} = "--" ] ; then
# --verbose or --quiet used
ve=${COMP_WORDS[3]}
fi
local ips="`/usr/sbin/vzlist -H -o ip $ve 2>/dev/null | grep -vi -`"
COMPREPLY=( $( compgen -W "$ips all" -- $cur ) )
;;
--netif_del)
local netif
if [ -f /proc/vz/veth ]; then
# Get CTID
local cmd=${COMP_WORDS[1]}
local ve=${COMP_WORDS[2]}
if [ ${cmd::2} = "--" ] ; then
# --verbose or --quiet used
ve=${COMP_WORDS[3]}
fi
# get veth(ernet) device of CT, proc and config
local netif_proc="`awk "/${ve}/ { print \\$4 }" /proc/vz/veth`"
local netif_conf="`grep ^NETIF /etc/vz/conf/${ve}.conf |
sed -e 's/"/\n/g' -e 's/;/\n/g' -e 's/,/\n/g' -e 's/=/ /g' | awk '/^ifname/ {print \$2}'`"
netif="$netif_proc $netif_conf"
fi
COMPREPLY=( $( compgen -W "$netif" -- $cur ) )
;;
--private|--root)
# FIXME
# Dir autocompletion works bad since there is
# a space added. Alternatively, we could use
# -o dirname option to 'complete' -- but it
# makes no sense for other parameters (UBCs
# etc). So no action for now.
;;
--id|--uuid)
# Only allow this completion
# when user has root privileges
[ "$EUID" -ne 0 ] && return 1
# Get command and CTID
local cmd=${COMP_WORDS[1]}
local ve=${COMP_WORDS[2]}
if [ ${cmd::2} = "--" ] ; then
# --verbose or --quiet used
cmd=${COMP_WORDS[2]}
ve=${COMP_WORDS[3]}
fi
local ids
case ${cmd} in
snapshot-umount)
# For umount, only give mounted IDs
ids="`/usr/sbin/vzctl --quiet snapshot-list $ve -H -ouuid,device 2>/dev/null | awk 'NF==2 {print $1}' | tr -d '{}'`"
;;
snapshot-*)
# For other commands, give all IDs
ids="`/usr/sbin/vzctl --quiet snapshot-list $ve -H -ouuid 2>/dev/null | tr -d '{}'`"
;;
*)
# Do not give anything for other cmds
# including 'snapshot' itself
# since it requires a new unused ID
return 0
;;
esac
COMPREPLY=( $( compgen -W "$ids" -- $cur ) )
;;
*)
if [[ "${prev::2}" != "--" || "$prev" = "--save" ]]; then
# List options
local cmd=${COMP_WORDS[1]}
if [ ${cmd::2} = "--" ] ; then
# --verbose or --quiet used
cmd=${COMP_WORDS[2]}
fi
case "$cmd" in
create)
COMPREPLY=( $( compgen -W "$vzctl_create_opts" -- $cur ) )
;;
set)
COMPREPLY=( $( compgen -W "$vzctl_set_opts" -- $cur ) )
;;
convert)
COMPREPLY=( $( compgen -W "$vzctl_convert_opts" -- $cur ) )
;;
suspend|resume|chkpnt|restore)
COMPREPLY=( $( compgen -W "--dumpfile" -- $cur ) )
;;
start)
COMPREPLY=( $( compgen -W "$vzctl_start_opts" -- $cur ) )
;;
stop)
COMPREPLY=( $( compgen -W "$vzctl_stop_opts" -- $cur ) )
;;
restart)
COMPREPLY=( $( compgen -W "$vzctl_restart_opts" -- $cur ) )
;;
snapshot)
COMPREPLY=( $( compgen -W "$vzctl_snapshot_create_opts" -- $cur ) )
;;
snapshot-switch)
COMPREPLY=( $( compgen -W "$vzctl_snapshot_switch_opts" -- $cur ) )
;;
snapshot-delete|snapshot-umount)
COMPREPLY=( $( compgen -W "--id" -- $cur ) )
;;
snapshot-mount)
COMPREPLY=( $( compgen -W "$vzctl_snapshot_mount_opts" -- $cur ) )
;;
snapshot-list)
COMPREPLY=( $( compgen -W "$vzctl_snapshot_list_opts" -- $cur ) )
;;
*)
;;
esac
else
# Option that requires an argument
# which we can't autocomplete
COMPREPLY=( $( compgen -W "" -- $cur ) )
fi
;;
esac
fi
esac
return 0
}
complete -F _vzctl vzctl
# EOF
|