summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2011-09-17 13:40:26 +0200
committerDominique Martinet <asmadeus@codewreck.org>2011-09-17 13:41:01 +0200
commitf5c65edae223262b4a926979ab3cd34606de86d3 (patch)
tree5f52aac77de89484f07d5c74677c8781a8df3947
parent67b33515f708afd310d124491777d8e7eb41861b (diff)
bash completion update and syntax change (put vm in second position as logic would imply - affects balloon and migrate commands)
-rw-r--r--host_config/bash_completion.d-kvm-wrapper109
-rwxr-xr-xkvm-wrapper.sh18
2 files changed, 71 insertions, 56 deletions
diff --git a/host_config/bash_completion.d-kvm-wrapper b/host_config/bash_completion.d-kvm-wrapper
index 69b9c08..ff9ebcb 100644
--- a/host_config/bash_completion.d-kvm-wrapper
+++ b/host_config/bash_completion.d-kvm-wrapper
@@ -3,62 +3,77 @@
have kvm-wrapper &&
_kvm_wrapper()
{
- local cur prev vms
+ local cur command vms
+ local ROOTDIR=/usr/share/kvm-wrapper
COMPREPLY=()
cur=`_get_cword`
- prev=${COMP_WORDS[COMP_CWORD-1]}
+ command=${COMP_WORDS[1]}
- if [[ "$cur" == -* ]]; then
- COMPREPLY=( $( compgen -W 'start stop list screen create bootstrap remove edit create-disk status' -- "$cur" ) )
+ 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' -- "$cur" ) )
return 0
fi
- case "$prev" in
- list|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
- local ROOTDIR=/usr/share/kvm-wrapper
- . $ROOTDIR/kvm-wrapper.conf >&/dev/null #complains random_mac isn't defined, but doesn't matter to us...
- case "$prev" 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
- ;;
- esac
+ if [[ "$COMP_CWORD" == "2" ]]; then
+ case "$command" in
+ list|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
+ ;;
+ 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
- _expand || return 0
- 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' -- "$cur" ) )
} &&
complete -F _kvm_wrapper $filenames kvm-wrapper
diff --git a/kvm-wrapper.sh b/kvm-wrapper.sh
index a78ad83..befdc9c 100755
--- a/kvm-wrapper.sh
+++ b/kvm-wrapper.sh
@@ -826,12 +826,12 @@ function print_help ()
echo -e "Usage: $SCRIPT_NAME {start|screen|stop} virtual-machine"
echo -e " $SCRIPT_NAME {attach|monitor|serial} virtual-machine"
echo -e " $SCRIPT_NAME {save-state|load-state} virtual-machine"
- echo -e " $SCRIPT_NAME migrate dest-node virtual-machine"
+ echo -e " $SCRIPT_NAME migrate virtual-machine dest-node"
echo -e ""
echo -e " $SCRIPT_NAME status [virtual-machine]"
echo -e " $SCRIPT_NAME list"
echo
- echo -e " $SCRIPT_NAME balloon target_RAM virtual-machine"
+ echo -e " $SCRIPT_NAME balloon virtual-machine target_RAM"
echo -e " $SCRIPT_NAME create [flags] virtual-machine #for flag list, try $SCRIPT_NAME help create"
echo -e " $SCRIPT_NAME create-desc virtual-machine [diskimage [size]]"
echo -e " $SCRIPT_NAME bootstrap virtual-machine"
@@ -910,27 +910,27 @@ case "$1" in
if [[ $# -eq 3 ]]; then
! test_file "$PID_FILE" && fail_exit "Error : $VM_NAME doesn't seem to be running."
! test_socket_rw "$MONITOR_FILE" && fail_exit "Error : could not open monitor socket $MONITOR_FILE."
- desc_update_setting "KVM_CLUSTER_NODE" "$2"
+ desc_update_setting "KVM_CLUSTER_NODE" "$3"
PORT=$((RANDOM%1000+4000))
- "$SCRIPT_PATH" receive-migrate-screen $PORT "$3"
+ "$SCRIPT_PATH" receive-migrate-screen "$2" $PORT
sleep 1
monitor_send_cmd "migrate_set_speed 1024m"
-# monitor_send_cmd "migrate \"exec: ssh `get_cluster_host $2` socat - unix:$RUN_DIR/migrate-$3.sock\""
- monitor_send_cmd "migrate tcp:`get_cluster_host $2`:$PORT"
+# monitor_send_cmd "migrate \"exec: ssh `get_cluster_host $3` socat - unix:$RUN_DIR/migrate-$3.sock\""
+ monitor_send_cmd "migrate tcp:`get_cluster_host $3`:$PORT"
monitor_send_cmd "quit"
else print_help; fi
;;
receive-migrate)
if [[ $# -eq 3 ]]; then
# KVM_ADDITIONNAL_PARAMS+=" -incoming unix:$RUN_DIR/migrate-$VM_NAME.sock"
- KVM_ADDITIONNAL_PARAMS+=" -incoming tcp:`get_cluster_host $(hostname -s)`:$2"
+ KVM_ADDITIONNAL_PARAMS+=" -incoming tcp:`get_cluster_host $(hostname -s)`:$3"
FORCE="yes"
kvm_start_vm "$VM_NAME"
else print_help; fi
;;
receive-migrate-screen)
if [[ $# -eq 3 ]]; then
- $SCREEN_START_DETACHED "$SCREEN_SESSION_NAME" $SCREEN_EXTRA_OPTS "$SCRIPT_PATH" receive-migrate "$2" "$VM_NAME"
+ $SCREEN_START_DETACHED "$SCREEN_SESSION_NAME" $SCREEN_EXTRA_OPTS "$SCRIPT_PATH" receive-migrate "$VM_NAME" "$3"
sleep 1
else print_help; fi
;;
@@ -953,7 +953,7 @@ case "$1" in
;;
balloon)
if [[ $# -eq 3 ]]; then
- kvm_balloon_vm "$2"
+ kvm_balloon_vm "$3"
else print_help; fi
;;
restart)