<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michael&#039;s World &#187; kvm</title>
	<atom:link href="http://www.michael-kress.de/category/kvm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michael-kress.de</link>
	<description>Mitten aus dem Leben</description>
	<lastBuildDate>Wed, 26 May 2010 05:56:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>kvm-shell</title>
		<link>http://www.michael-kress.de/2009/12/kvm-shell/</link>
		<comments>http://www.michael-kress.de/2009/12/kvm-shell/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 22:49:22 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[kvm]]></category>

		<guid isPermaLink="false">http://www.michael-kress.de/?p=29</guid>
		<description><![CDATA[In lack of a frontend for the kvm users on my server, I wrote that little menu named &#8220;kvm-shell&#8221;. It allows them to administer their own virtual servers. The original idea came from a utility I used once named xen-shell. I hope it&#8217;s any use for you. See the &#8220;INSTALL&#8221; section inside the script to [...]]]></description>
			<content:encoded><![CDATA[<p>In lack of a frontend for the kvm users on my server, I wrote that little menu named &#8220;kvm-shell&#8221;. It allows them to administer their own virtual servers. The original idea came from a utility I used once named xen-shell. I hope it&#8217;s any use for you. See the &#8220;INSTALL&#8221; section  inside the script to get started. Download the file <a href="http://download.michael-kress.de/kvm-shell">here</a>.</p>
<p><span id="more-29"></span></p>
<pre class="prettyprint">#!/bin/sh
#    kvm-shell - a small interface to kvm for regular users
#    v1.0-0
#    Copyright (C) 2009 Michael Kress
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#
# INSTALL:
# 1) create these entries for your users in /etc/sudoers (use visudo) :
#    User_Alias   KVMUSERS = vuser1,vuser2
#    Cmnd_Alias   KVM      = /usr/bin/virsh
#    KVMUSERS     ALL      = NOPASSWD: KVM
# 2) Create /usr/local/etc/kvm-shell-users (see config variable below) :
#    Format:
#
#    Example:
#      vuser1 vm1
#      vuser2 vm1 vm2 vm3
#    Description: List here which users are allowed to control which vms
#
# KNOWN BUGS:
# * To update the status, select another menu item and return to the current one
#
# CHANGELOG:
# v1.0-0 / 2009-12-23 / Initial release

# configuration
USERSFILE=/usr/local/etc/kvm-shell-users
CURRENTUSER=$USER
### test:    CURRENTUSER=vuser1
SUDO=/usr/bin/sudo
VIRSH=/usr/bin/virsh
VNCBASEPORT=5900
# set DEBUG to 1 to see some messages, otherwise leave on 0
DEBUG=0

# change nothing below here
MYEXIT=0

function select_vm {
# PARAMETERS: none
# DESCRIPTION: extract the vms which the current user is allowed to control and display them in a little menu
AVAILABLEVMS=`grep $CURRENTUSER $USERSFILE | sed -e "s/$CURRENTUSER\(.*\)/\1/g"`
MENUITEMS=""
COUNTER=0
NEWAVAILABLEVMS=""
for i in $AVAILABLEVMS
do
        $SUDO $VIRSH domstate $i 2>/dev/null
        if [ "$?" = "0" ]; then
                NEWAVAILABLEVMS="${NEWAVAILABLEVMS} ${i}"
                COUNTER=$((COUNTER+1))
                STATE=`$SUDO $VIRSH domstate $i|grep -v "^$" | sed -e "s/ /_/g"`
                MENUITEMS="$MENUITEMS $i $STATE"
        fi
done
AVAILABLEVMS=$NEWAVAILABLEVMS
[ $DEBUG -eq 1 ] &amp;&amp; echo $MENUITEMS
selectedvm=`dialog --stdout --title "User $CURRENTUSER - please select your VM to manage" --menu "Available VMs:" 15 55 $COUNTER $MENUITEMS`
ret=$?
case $ret in
  0)
        [ $DEBUG -eq 1 ] &amp;&amp; echo "selected: $selectedvm"
        while [ $MYEXIT -ne 2 ];
        do
                select_action
        done
        MYEXIT=0
        ;;
  1)
        [ $DEBUG -eq 1 ] &amp;&amp; echo "You pressed cancel."
        MYEXIT=1;;
  255)
        [ $DEBUG -eq 1 ] &amp;&amp; echo "You hit Esc."
        MYEXIT=1;;
esac
}

function select_action {
# PARAMETERS: none
# DESCRIPTION: display actions and execute them on the selected vm
# REQUIRES: $selectedvm filled with a valid vm
# actions displayed in menu:
#   - dominfo
#   - vncdisplay
#   - start
#   - shutdown
#   - reboot
#   - destroy
### TODO: Check if $selectedvm is really a valid vm (should be ok, but still ...)
STATE=`$SUDO $VIRSH domstate $selectedvm|grep -v "^$" | sed -e "s/ /_/g"`
selectedaction=`dialog --stdout --title "User $CURRENTUSER - please select action for VM $selectedvm" --menu "Available actions for VM $selectedvm ($STATE):" 15 55 5  "dominfo" "" "vncdisplay" "" "start" "" "shutdown" "" "reboot" "" "destroy" ""`
ret=$?
case $ret in
  0)
        echo "$SUDO $VIRSH $selectedaction $selectedvm"
        case $selectedaction in
          dominfo)
                $SUDO $VIRSH $selectedaction $selectedvm
                ;;
          vncdisplay)
                VNCDSP=`$SUDO $VIRSH vncdisplay $selectedvm | grep -v "^$" | sed -e "s/://g"`
                VNCDSP=$((VNCBASEPORT+VNCDSP))
                echo "VNC port: $VNCDSP"
                ;;
          start)
                $SUDO $VIRSH $selectedaction $selectedvm
                ;;
          shutdown)
                $SUDO $VIRSH $selectedaction $selectedvm
                ;;
          reboot)
                $SUDO $VIRSH $selectedaction $selectedvm
                ;;
          destroy)
                $SUDO $VIRSH $selectedaction $selectedvm
                ;;
        esac
        sleep 1
        [ "$selectedaction" != "dominfo" ] &amp;&amp; $SUDO $VIRSH dominfo $selectedvm
        read -p "[Hit Return]" x
        ;;
  1)
        [ $DEBUG -eq 1 ] &amp;&amp; echo "You pressed cancel."
        MYEXIT=2
        ;;
  255)
        [ $DEBUG -eq 1 ] &amp;&amp; echo "You hit Esc."
        MYEXIT=2
        ;;
esac
}

# main loop
while [ $MYEXIT -ne 1 ];
do
        select_vm
done

exit 0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.michael-kress.de/2009/12/kvm-shell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
