~ubuntu-branches/ubuntu/karmic/vzctl/karmic

« back to all changes in this revision

Viewing changes to etc/bash_completion.d/vzctl.sh.in

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
5
_get_ves()
 
6
{
 
7
        local cmd=$1
 
8
        local rm_empty='sed s/^-[[:space:]]*//'
 
9
        case $cmd in
 
10
                create)
 
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
 
14
                        echo $((veids+1))
 
15
                        ;;
 
16
                start|mount|umount|destroy)
 
17
                        # stopped VEs
 
18
                        @SBINDIR@/vzlist -H -S -oveid
 
19
                        @SBINDIR@/vzlist -H -S -oname | $rm_empty
 
20
                        ;;
 
21
                stop|enter|exec*)
 
22
                        # running VEs
 
23
                        @SBINDIR@/vzlist -H -oveid
 
24
                        @SBINDIR@/vzlist -H -oname | $rm_emtpy
 
25
                        ;;
 
26
                *)
 
27
                        # All VEs
 
28
                        @SBINDIR@/vzlist -H -a -oveid
 
29
                        @SBINDIR@/vzlist -H -a -oname | $rm_empty
 
30
                        ;;
 
31
        esac
 
32
}
 
33
 
 
34
_vzctl()
 
35
{
 
36
        local cur prev cmd vzctl_cmds vzctl_create_opts vzctl_set_opts
 
37
        local iptables_names cap_names
 
38
 
 
39
        #echo "ARGS: $*"
 
40
        #echo "COMP_WORDS: $COMP_WORDS"
 
41
        #echo "COMP_CWORD: $COMP_CWORD"
 
42
        #echo "COMP_WORDS[1]: ${COMP_WORDS[1]}"
 
43
        
 
44
        COMPREPLY=()
 
45
        cur=${COMP_WORDS[COMP_CWORD]}
 
46
        prev=${COMP_WORDS[COMP_CWORD-1]}
 
47
 
 
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 \
 
64
                --ioprio"
 
65
 
 
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"
 
71
 
 
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"
 
78
                
 
79
                                                                          
 
80
 
 
81
        case $COMP_CWORD in
 
82
        1)
 
83
                # command or global option
 
84
                COMPREPLY=( $( compgen -W "$vzctl_cmds $vzctl_common_opts" -- $cur ) )
 
85
                ;;
 
86
 
 
87
        2)
 
88
                case "$prev" in
 
89
                --help|--version)
 
90
                        COMPREPLY=()
 
91
                        ;;
 
92
                --*)
 
93
                        # command
 
94
                        COMPREPLY=( $( compgen -W "$vzctl_cmds" -- $cur ) )
 
95
                        ;;
 
96
                *)
 
97
                        # VEID
 
98
                        COMPREPLY=( $( compgen -W "$(_get_ves $prev)" -- $cur ) )
 
99
                        ;;
 
100
                esac
 
101
                ;;
 
102
 
 
103
        *) # COMP_CWORD >= 3
 
104
                if [[ $COMP_CWORD -eq 3 && ! $prev != '^[1-9][0-9]*$' ]]; then
 
105
                        # VEID
 
106
                        COMPREPLY=( $( compgen -W "$(_get_ves $prev)" -- $cur ) )
 
107
                else
 
108
        
 
109
                        # flag or option
 
110
                        case $prev in
 
111
                        --ostemplate)
 
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 ) )
 
116
 
 
117
                                ;;
 
118
                        --onboot|--disabled|--noatime)
 
119
                                COMPREPLY=( $( compgen -W "yes no" -- $cur ) )
 
120
                                ;;
 
121
                        --config|--applyconfig)
 
122
                                local configs=$(ls -1 @PKGCONFDIR@/conf/*.conf-sample | \
 
123
                                                    cut -d "-" -f 2- | sed -e 's#.conf-sample$##')
 
124
 
 
125
                                configs=${configs/.conf-sample/}
 
126
                                COMPREPLY=( $( compgen -W "$configs" -- $cur ) )
 
127
                                ;;
 
128
                        --iptables)
 
129
                                COMPREPLY=( $( compgen -W "$iptables_names" -- $cur ) )
 
130
                                ;;
 
131
                        --netdev*)
 
132
                                local devs=`ip addr show | awk '/^[0-9]/ && /UP/ && !/venet/ && !/lo/ \
 
133
                                                    { print $2 }' | sed s/://`
 
134
 
 
135
                                COMPREPLY=( $( compgen -W "$devs" -- $cur ) )
 
136
                                ;;
 
137
                        --capability)
 
138
                                # capname:on|off
 
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
 
143
#                                               cap=${cur%%:*}
 
144
#                                       else
 
145
#                                               cap=${COMPREPLY[0]%%:*}
 
146
#                                       fi
 
147
                                        # Single match: add :on|:off
 
148
#                                       COMPREPLY=( $(compgen -W \
 
149
#                                       "${cap}:on ${cap}:off" -- $cur) )
 
150
#                               fi
 
151
                                ;;
 
152
                        --devnodes)
 
153
                                # FIXME: device:r|w|rw|none
 
154
                                local devs=''
 
155
                                COMPREPLY=( $( compgen -W "$devs" -- $cur ) )
 
156
                                ;;
 
157
                        --ipdel)
 
158
                                # Get VEID
 
159
                                local ve=${COMP_WORDS[2]}
 
160
                                if [[ ! ${ve} != '^[1-9][0-9]*$' ]] ; then
 
161
                                        # --verbose or --quiet used
 
162
                                        ve=${COMP_WORDS[3]}
 
163
                                fi
 
164
                                # VENAME or VEID ?
 
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 ) )
 
168
                                ;;
 
169
                        --private|--root)
 
170
                                # FIXME
 
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.
 
176
                                ;;
 
177
                        *)
 
178
                                if [[ "${prev::2}" != "--" || "$prev" = "--save" ]]; then
 
179
                                        # List options
 
180
                                        cmd=${COMP_WORDS[1]}
 
181
                                        if [ ${cmd::2} = "--" ] ; then
 
182
                                                # --verbose or --quiet used
 
183
                                                cmd=${COMP_WORDS[2]}
 
184
                                        fi
 
185
                
 
186
                                        case "$cmd" in
 
187
                                        create)
 
188
                                                COMPREPLY=( $( compgen -W "$vzctl_create_opts" -- $cur ) )
 
189
                                                ;;
 
190
                                        set)
 
191
                                                COMPREPLY=( $( compgen -W "$vzctl_set_opts" -- $cur ) )
 
192
                                                ;;
 
193
                                        chkpnt|restore)
 
194
                                                COMPREPLY=( $( compgen -W "--dumpfile" -- $cur ) )
 
195
                                                ;;
 
196
                                        stop)
 
197
                                                COMPREPLY=( $( compgen -W "--fast" -- $cur ) )
 
198
                                                ;;
 
199
                                        *)
 
200
                                                ;;
 
201
                                        esac
 
202
                                else
 
203
                                        # Option that requires an argument
 
204
                                        # which we can't autocomplete
 
205
                                        COMPREPLY=( $( compgen -W "" -- $cur ) )
 
206
                                fi
 
207
                                ;;
 
208
                        esac
 
209
                fi
 
210
        esac
 
211
 
 
212
        return 0
 
213
}
 
214
 
 
215
complete -F _vzctl vzctl
 
216
 
 
217
# EOF