blob: f9ae450fdc30b43c83c8b45ee904ef57b27932da (
plain)
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
|
# kvm-wrapper completion
# Copyright (C) 2011 Dominique Martinet <asmadeus@codewreck.org>
# Published under the WTFPLv2 (see LICENSE)
have kvm-wrapper &&
_kvm_wrapper()
{
local cur command vms
local ROOTDIR=/usr/share/kvm-wrapper
COMPREPLY=()
cur=`_get_cword`
command=${COMP_WORDS[1]}
if [[ "$COMP_CWORD" == "1" ]]; then
COMPREPLY=( $( compgen -W 'help attach create-desc start stop list screen create bootstrap remove edit create-disk status mount-disk umount-disk migrate receive-migrate save-state load-state balloon monitor serial conf top' -- "$cur" ) )
return 0
fi
if [[ "$COMP_CWORD" == "2" ]]; then
case "$command" in
create-desc)
return 0
;;
help)
COMPREPLY=( $( compgen -W "create" -- "$cur" ) )
return 0
;;
create)
# COMPREPLY=( $( compgen -W '-m --mem -s --size -e --edit -c --cpu' -- "$cur" ) )
return 0
;;
esac
. $ROOTDIR/kvm-wrapper.conf >&/dev/null #complains random_mac isn't defined, but doesn't matter to us...
case "$command" in
start|screen|bootstrap|create-disk|remove|mount-disk|load-state)
if [[ -n "`\ls -1 $PID_DIR/*-vm.pid 2>/dev/null`" ]]; then
vms=`\ls -1 $ROOTDIR/vm/*-vm|sed -e "s:$ROOTDIR/vm/::g" -e 's/-vm//g'|grep -v -x -F "$(\ls -1 $PID_DIR/*-vm.pid|sed -e "s@$PID_DIR/.*:@@g" -e 's/-vm.pid//g')"`
else
vms=`\ls -1 $ROOTDIR/vm/*-vm|sed -e "s:$ROOTDIR/vm/::g" -e 's/-vm//g'`
fi
COMPREPLY=( $( compgen -W "$vms" -- "$cur" ) )
return 0
;;
stop|status|attach|migrate|save-state|balloon|monitor|serial)
vms=`\ls -1 $PID_DIR/*-vm.pid 2>/dev/null |sed -e "s@$PID_DIR/.*:@@g" -e 's/-vm.pid//g'`
COMPREPLY=( $( compgen -W "$vms" -- "$cur" ) )
return 0
;;
edit)
vms=`\ls -1 $ROOTDIR/vm/*-vm|sed -e "s:$ROOTDIR/vm/::g" -e 's/-vm//g'`
COMPREPLY=( $( compgen -W "$vms" -- "$cur" ) )
return 0
;;
umount-disk)
vms=`\ls -1 /mnt|sed -e 's:/mnt/::'`
COMPREPLY=( $( compgen -W "$vms" -- "$cur" ) )
return 0
;;
list)
local nodes=`grep -e '^set_cluster_host' $ROOTDIR/kvm-cluster.conf | cut -d' ' -f2`
COMPREPLY=( $( compgen -W "$nodes" -- "$cur" ) )
return 0
;;
esac
fi
if [[ "$COMP_CWORD" == "3" ]]; then
case "$command" in
migrate)
vms="${COMP_WORDS[2]}"
. "$ROOTDIR/vm/$vms-vm"
# echo $KVM_CLUSTER_NODE -- $vms
local nodes=`grep -e '^set_cluster_host' $ROOTDIR/kvm-cluster.conf | cut -d' ' -f2 |grep -v $KVM_CLUSTER_NODE`
COMPREPLY=( $( compgen -W "$nodes" -- "$cur" ) )
return 0
;;
esac
fi
_expand || return 0
} &&
complete -F _kvm_wrapper $filenames kvm-wrapper
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
|