summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kvm-wrapper.conf34
-rwxr-xr-xnet/kvm-ifdown12
-rwxr-xr-xnet/kvm-ifup18
-rw-r--r--net/kvm-net.conf5
-rwxr-xr-xstartup/kvm-wrapper-startup.sh80
-rw-r--r--startup/startup-list4
6 files changed, 153 insertions, 0 deletions
diff --git a/kvm-wrapper.conf b/kvm-wrapper.conf
new file mode 100644
index 0000000..b7114e7
--- /dev/null
+++ b/kvm-wrapper.conf
@@ -0,0 +1,34 @@
+#
+# KVM Wrapper Configuration File
+# -- bencoh, 2009/06
+#
+
+KVM_BIN="/usr/bin/kvm"
+KVM_IMG_BIN="/usr/bin/kvm-img"
+
+PID_DIR="/var/run/kvm-wrapper"
+MONITOR_DIR="$PID_DIR/monitor"
+SERIAL_DIR="$PID_DIR/serial"
+VM_DIR="$ROOTDIR/vm"
+
+KVM_IMG_FORMAT="qcow2"
+
+# Some default KVM options
+#xxDEFAULTxx#
+
+KVM_MEM="128M"
+KVM_CPU_NUM="1"
+
+KVM_NETWORK_MODEL="rtl8139"
+KVM_MACADDRESS="`random_mac`"
+#KVM_BRIDGE
+
+KVM_BOOTDEVICE="c"
+#KVM_HDA
+#KVM_CDROM
+
+KVM_KEYMAP="en-us"
+KVM_OUTPUT="-curses"
+
+#KVM_BIN
+
diff --git a/net/kvm-ifdown b/net/kvm-ifdown
new file mode 100755
index 0000000..b1d7c2f
--- /dev/null
+++ b/net/kvm-ifdown
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+. /usr/share/kvm-wrapper/net/kvm-net.conf
+
+echo "$0:"
+
+echo "Removing $1 from bridge $BRIDGE"
+ip link set $1 down
+brctl delif "$BRIDGE" $1
+
+exit 0
+
diff --git a/net/kvm-ifup b/net/kvm-ifup
new file mode 100755
index 0000000..87e105e
--- /dev/null
+++ b/net/kvm-ifup
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# Debian default
+#switch=$(ip route ls | awk '/^default / { for(i=0;i<NF;i++) { if ($(i) == "dev") print $(i+1) }}')
+#/sbin/ifconfig $1 0.0.0.0 up
+#/usr/sbin/brctl addif ${switch} $1
+#exit 0
+
+
+# Configuration with NAT support
+
+. /usr/share/kvm-wrapper/net/kvm-net.conf
+
+echo "$0:"
+echo "Adding $1 to bridge interface $BRIDGE"
+brctl addif "$BRIDGE" "$1"
+ip link set "$1" up
+
diff --git a/net/kvm-net.conf b/net/kvm-net.conf
new file mode 100644
index 0000000..bedcea2
--- /dev/null
+++ b/net/kvm-net.conf
@@ -0,0 +1,5 @@
+BRIDGE=kvmnat
+#NETWORK=192.168.172.0
+#HOST=192.168.172.1
+#MASK=255.255.255.0
+#EXTIF=br0
diff --git a/startup/kvm-wrapper-startup.sh b/startup/kvm-wrapper-startup.sh
new file mode 100755
index 0000000..17d6044
--- /dev/null
+++ b/startup/kvm-wrapper-startup.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+# kvm-wrapper startup init script
+# This scripts starts/stops a list a VMs using the kvm-wrapper script
+# -- bencoh, 2009/08/11
+
+SCRIPTNAME=/etc/init.d/kvm-wrapper
+
+. /lib/lsb/init-functions
+
+KVM_WRAPPER_DIR=/usr/share/kvm-wrapper
+KVM_WRAPPER="$KVM_WRAPPER_DIR"/kvm-wrapper.sh
+KVM_VM_LIST="$KVM_WRAPPER_DIR"/startup/startup-list
+
+start_vm()
+{
+ VM_NAME="$1"
+# SCREEN_SESSION_NAME="kvm-$VM_NAME"
+ log_begin_msg "Starting up VM : $VM_NAME ..."
+# screen -d -m -S "$SCREEN_SESSION_NAME" /bin/sh -c "\"$KVM_WRAPPER\" start \"$VM_NAME\""
+ $KVM_WRAPPER screen "$VM_NAME"
+ EXITNUM="$?"
+ echo $EXITNUM
+ case "$EXITNUM" in
+ 0) log_end_msg 0 ;;
+ *) log_end_msg 1 ;;
+ esac
+ return 0
+}
+
+do_start()
+{
+grep -E -v '^#' "$KVM_VM_LIST" |
+while read line
+do
+ start_vm "$line"
+done
+}
+
+do_stop()
+{
+grep -E -v '^#' "$KVM_VM_LIST" |
+while read line
+do
+ VM_NAME="$line"
+ log_begin_msg "Stopping VM : $VM_NAME ..."
+ "$KVM_WRAPPER" stop "$VM_NAME"
+ log_end_msg 0
+done
+}
+
+case "$1" in
+ start)
+ log_begin_msg "Autostarting VMs (kvm-wrapper) ..."
+ do_start
+ case "$?" in
+ 0|1) log_end_msg 0 ;;
+ 2) log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ log_begin_msg "Shutting down autostarted VMs (kvm-wrapper) ..."
+ do_stop
+ case "$?" in
+ 0|1) log_end_msg 0 ;;
+ 2) log_end_msg 1 ;;
+ esac
+ ;;
+ restart|force-reload)
+ ;;
+ start-vm)
+ start_vm "$2"
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop}" >&2
+ echo " $SCRIPTNAME start-vm xxxxx" >&2
+ exit 3
+ ;;
+esac
+
diff --git a/startup/startup-list b/startup/startup-list
new file mode 100644
index 0000000..5de13bb
--- /dev/null
+++ b/startup/startup-list
@@ -0,0 +1,4 @@
+# kvm-wrapper startup VMs list
+# Add in this file the VMs you want to be launched with the kvm-wrapper
+# init.d script
+# One line per VM