}
########################################################################
-# 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 {
- 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)
- STATE=${STATE:-"unknown"}
- STATE=${STATE// /-}
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
- COUNTER=$((COUNTER+1))
+ COUNTER=$(( COUNTER+1 ))
MENUITEMS="${MENUITEMS} ${vm} ${STATE}"
fi
done
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)
+ # Hoowah, help? Go away.
helpbox
;;
*)
# Anything else means we send em to the shredder...
exit
+ ;;
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
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
- set -e
return
fi
- set -e
while :; do
dialogout=$(mktemp -p "${TMPDIR}" kvmshell.XXXXXXXX)
TEMPFILES="${TEMPFILES} dialogout"
--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}")
${SUDO} ${VIRSH} ${selectedaction} ${selvm}
;;
dominfo|start|shutdown|reboot|destroy)
- set +e
+ set +e
${SUDO} ${VIRSH} ${selectedaction} ${selvm}
- set -e
+ set -e
+ ;;
rdns)
if [ "${DO_RDNS}" = "yes" ]; then
revdns ${selvm}
return
;;
esac
- sleep 1
read -p "[Hit Return]" x
;;
+ 2)
+ helpbox
+ ;;
*)
return
;;