aboutsummaryrefslogtreecommitdiff
path: root/kvm-manager
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2009-10-08 11:37:42 -0400
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2009-10-08 11:37:42 -0400
commit9f76ba28ae735037d1126f8ee55c7da81f423071 (patch)
tree5b9f8c84dc25aaa384fe27386780e73c797e1340 /kvm-manager
downloadkvm-manager-9f76ba28ae735037d1126f8ee55c7da81f423071.tar.gz
kvm-manager-9f76ba28ae735037d1126f8ee55c7da81f423071.tar.bz2
initial scattered import
Diffstat (limited to 'kvm-manager')
-rwxr-xr-xkvm-manager81
1 files changed, 81 insertions, 0 deletions
diff --git a/kvm-manager b/kvm-manager
new file mode 100755
index 0000000..40972ce
--- /dev/null
+++ b/kvm-manager
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+set -e
+set -x
+
+# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
+# Date: 2009-10-08
+# License: GPL v3+
+
+## expect to pull these values from the environment:
+# VMNAME=snapper
+# OWNER=jrollins
+# TAP=tap0
+# RAM=512
+# MAC=52:54:00:12:34:56
+
+if [ -z "$VMNAME" ] ; then
+ exit 1
+fi
+
+###################
+OWNERGROUP=$(groups "$OWNER" | cut -f1 -d\ )
+OWNERHOME=$(getent passwd "$OWNER" | cut -f6 -d: )
+
+VGNAME=vg_$(hostname)0
+
+up() {
+# bring up the network tap:
+ modprobe -v tun
+ tunctl -u "$OWNER" -t "$TAP"
+ ip link set "$TAP" up
+ brctl addif br0 "$TAP"
+
+# make sure the block device is readable by the owner:
+ chgrp "$OWNERGROUP" "/dev/mapper/${VGNAME}-$VMNAME"
+
+ chpst -u "$OWNER:$OWNERGROUP" mkdir -p "$OWNERHOME/vms/$VMNAME"
+
+ CDISO="$OWNERHOME/vms/$VMNAME/cd.iso"
+ NETBOOT="$OWNERHOME/vms/$VMNAME/netboot"
+ KVMARGS=
+
+ if [ -e "$NETBOOT" ] ; then
+ KVMARGS="-boot n"
+ elif [ -e "$CDISO" ] && [ -e $(readlink -f "$CDISO") ] ; then
+ KVMARGS="-cdrom $CDISO -boot d"
+ fi
+
+ LOGNAME="$OWNERHOME/vms/$VMNAME/console"
+ ln -sfT "$LOGNAME" ./servicelog
+ if [ -e "$LOGNAME" ] ; then
+ chpst -u "$OWNER" mv "$LOGNAME" "$LOGNAME".$(date +%F_%T%z|tr : .)
+ fi
+
+ exec chpst -u "$OWNER:$OWNERGROUP:kvm" /usr/bin/screen -D -m -L -c /etc/screenrc.kvm-manager -S "$VMNAME" -t "$VMNAME" -s /bin/false /usr/bin/kvm $KVMARGS -nographic -name "$VMNAME" -m "$RAM" -net nic,"macaddr=$MAC" -net "tap,hostname=$VMNAME,ifname=$TAP,script=no,downscript=no" -no-reboot -serial stdio "/dev/mapper/${VGNAME}-$VMNAME"
+}
+
+
+down() {
+ brctl delif br0 "$TAP"
+ ip link set "$TAP" down
+ tunctl -d "$TAP"
+# no need to lock up the block device as well, since the owner might
+# prefer to manipulate the disk directly.
+}
+
+log() {
+ LOGDIR="$OWNERHOME/vms/$VMNAME/servicelog"
+ chpst -u "$OWNER" mkdir -p "$LOGDIR"
+ exec chpst -u "$OWNER" svlogd -tt "$LOGDIR"
+}
+
+case "$1" in
+ up|down|log)
+ "$1"
+ ;;
+ *)
+ echo "Usage: $0 [up|down]"
+ exit 1
+ ;;
+esac