various small fixups and stuff
authorJoerg Jaspert <joerg@debian.org>
Mon, 12 Dec 2011 21:48:56 +0000 (22:48 +0100)
committerJoerg Jaspert <joerg@debian.org>
Mon, 12 Dec 2011 21:48:56 +0000 (22:48 +0100)
Signed-off-by: Joerg Jaspert <joerg@debian.org>
kvm-shell

index 4cd7fbd..2a34b51 100644 (file)
--- a/kvm-shell
+++ b/kvm-shell
@@ -147,27 +147,27 @@ menu options given to you.
 }
 
 ########################################################################
 }
 
 ########################################################################
-# Main functions come here                                             #
-########################################################################
-
 
 # main_menu: Find the VMs for the current user and display a menu to
 #            select from
 # No arguments
 function main_menu {
 
 # main_menu: Find the VMs for the current user and display a menu to
 #            select from
 # No arguments
 function main_menu {
-    local AVAILABLEVMS=$(egrep "^$USER " $USERSFILE)
+    local AVAILABLEVMS=$(egrep "^$USER " "$USERSFILE")
+    # Only end up with the VMs, not the username too
     AVAILABLEVMS=${AVAILABLEVMS#* }
     local MENUITEMS=""
     local COUNTER=0
     for vm in ${AVAILABLEVMS}; do
         set +e
         local STATE=$(${SUDO} ${VIRSH} domstate $vm 2>/dev/null)
     AVAILABLEVMS=${AVAILABLEVMS#* }
     local MENUITEMS=""
     local COUNTER=0
     for vm in ${AVAILABLEVMS}; do
         set +e
         local STATE=$(${SUDO} ${VIRSH} domstate $vm 2>/dev/null)
-        STATE=${STATE:-"unknown"}
-        STATE=${STATE// /-}
         local ret=$?
         set -e
         local ret=$?
         set -e
+        # if virsh got us nothing we replace it with "unknown"
+        STATE=${STATE:-"unknown"}
+        # dialog is picky-picky-annoying, so we want to ensure there isnt a space anywhere in STATE
+        STATE=${STATE// /-}
         if [ "${ret}" = 0 ]; then
         if [ "${ret}" = 0 ]; then
-            COUNTER=$((COUNTER+1))
+            COUNTER=$(( COUNTER+1 ))
             MENUITEMS="${MENUITEMS} ${vm} ${STATE}"
         fi
     done
             MENUITEMS="${MENUITEMS} ${vm} ${STATE}"
         fi
     done
@@ -185,18 +185,22 @@ function main_menu {
     rm -f "${dialogout}"
     case $ret in
         0)
     rm -f "${dialogout}"
     case $ret in
         0)
-            # Clean exit, means selected a VM
+            # Clean exit, means selected a VM, lets call its action menu
             select_action ${selectedvm}
             ;;
         2)
             select_action ${selectedvm}
             ;;
         2)
+            # Hoowah, help? Go away.
             helpbox
             ;;
         *)
             # Anything else means we send em to the shredder...
             exit
             helpbox
             ;;
         *)
             # Anything else means we send em to the shredder...
             exit
+            ;;
     esac
 }
 
     esac
 }
 
+# Deal with a VM directly, do whatever (console, dominfo, ...)
+# Takes on argument, the VM name
 function select_action {
     local selvm=${1:-""}
     if [ -z "${selvm}" ]; then
 function select_action {
     local selvm=${1:-""}
     if [ -z "${selvm}" ]; then
@@ -204,12 +208,12 @@ function select_action {
     fi
     set +e
     STATE=$(${SUDO} ${VIRSH} domstate $selvm 2>/dev/null)
     fi
     set +e
     STATE=$(${SUDO} ${VIRSH} domstate $selvm 2>/dev/null)
-    if [ $? -ne 0 ]; then
+    ret=$?
+    set -e
+    if [ ${ret} -ne 0 ]; then
         dialog --sleep 5 --title "User ${USER} - unknown VM Selected" --infobox "\nHeyho, you selected an unknown VM" 5 40
         dialog --sleep 5 --title "User ${USER} - unknown VM Selected" --infobox "\nHeyho, you selected an unknown VM" 5 40
-        set -e
         return
     fi
         return
     fi
-    set -e
     while :; do
         dialogout=$(mktemp -p "${TMPDIR}" kvmshell.XXXXXXXX)
         TEMPFILES="${TEMPFILES} dialogout"
     while :; do
         dialogout=$(mktemp -p "${TMPDIR}" kvmshell.XXXXXXXX)
         TEMPFILES="${TEMPFILES} dialogout"
@@ -218,8 +222,15 @@ function select_action {
             --title "User $USER - please select action for VM ${selvm} (${STATE})" \
             --cancel-label "Main Menu" --ok-label "Select Action" \
             --help-button --timeout ${TIMEOUTSECS} \
             --title "User $USER - please select action for VM ${selvm} (${STATE})" \
             --cancel-label "Main Menu" --ok-label "Select Action" \
             --help-button --timeout ${TIMEOUTSECS} \
-            --menu "Available actions for VM ${selvm} ($STATE):" 15 65 5 \
-            "dominfo" "" "console" "" "start" "" "shutdown" "" "reboot" "" "destroy" "" "mainmenu" "" 2>${dialogout}
+            --menu "Available actions for VM ${selvm} ($STATE):" 15 65 10 \
+            "dominfo"  "Information about your VM" \
+            "console"  "Serial console access" \
+            "start"    "Boot a stopped VM" \
+            "shutdown" "Stop a running VM" \
+            "reboot"   "Reboot a running VM" \
+            "destroy"  "Kill a VM (as if power cable pulled)" \
+            "rdns"     "Edit reverse DNS of IPs for the VM" \
+            "mainmenu" "Back to main menu" 2>${dialogout}
         ret=$?
         set -e
         local selectedaction=$(cat "${dialogout}")
         ret=$?
         set -e
         local selectedaction=$(cat "${dialogout}")
@@ -235,9 +246,10 @@ function select_action {
                         ${SUDO} ${VIRSH} ${selectedaction} ${selvm}
                         ;;
                     dominfo|start|shutdown|reboot|destroy)
                         ${SUDO} ${VIRSH} ${selectedaction} ${selvm}
                         ;;
                     dominfo|start|shutdown|reboot|destroy)
-                               set +e
+                        set +e
                         ${SUDO} ${VIRSH} ${selectedaction} ${selvm}
                         ${SUDO} ${VIRSH} ${selectedaction} ${selvm}
-                               set -e
+                        set -e
+                        ;;
                     rdns)
                         if [ "${DO_RDNS}" = "yes" ]; then
                             revdns ${selvm}
                     rdns)
                         if [ "${DO_RDNS}" = "yes" ]; then
                             revdns ${selvm}
@@ -250,9 +262,11 @@ function select_action {
                         return
                         ;;
                 esac
                         return
                         ;;
                 esac
-                sleep 1
                 read -p "[Hit Return]" x
                 ;;
                 read -p "[Hit Return]" x
                 ;;
+            2)
+                helpbox
+                ;;
                *)
                 return
                 ;;
                *)
                 return
                 ;;