first version
authorSvenne Krap <svenne@krap.dk>
Thu, 19 Sep 2013 19:21:42 +0000 (21:21 +0200)
committerSvenne Krap <svenne@krap.dk>
Thu, 19 Sep 2013 19:31:21 +0000 (21:31 +0200)
19 files changed:
.gitignore [new file with mode: 0644]
README.txt [new file with mode: 0644]
_all_stop.sh [new file with mode: 0755]
_pids/readme.txt [new file with mode: 0644]
_run/common.sh [new file with mode: 0644]
_run/ifup_br0 [new symlink]
_run/ifup_common [new file with mode: 0755]
_run/plain.sh [new file with mode: 0644]
_run/virtio.sh [new file with mode: 0644]
autostart.sh [new file with mode: 0755]
gluster.vm [new file with mode: 0644]
kill.sh [new file with mode: 0755]
list-running.sh [new file with mode: 0755]
newmac [new file with mode: 0755]
plain.vm [new file with mode: 0644]
run.sh [new file with mode: 0755]
stop.sh [new file with mode: 0755]
used-ram.sh [new file with mode: 0755]
virtio.vm [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..d040ffe
--- /dev/null
@@ -0,0 +1 @@
+.*.un~
diff --git a/README.txt b/README.txt
new file mode 100644 (file)
index 0000000..07e5c3b
--- /dev/null
@@ -0,0 +1,4 @@
+Svenne's KVM control scripts
+(c) 2011- Svenne Krap
+
+Released under the 2-clause BSD license
diff --git a/_all_stop.sh b/_all_stop.sh
new file mode 100755 (executable)
index 0000000..7d1c35b
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+cd /virtual-machines
+for x in *.vm ; do ./stop.sh $x ; done
diff --git a/_pids/readme.txt b/_pids/readme.txt
new file mode 100644 (file)
index 0000000..8501eeb
--- /dev/null
@@ -0,0 +1 @@
+Dir for pid-files
diff --git a/_run/common.sh b/_run/common.sh
new file mode 100644 (file)
index 0000000..95f7317
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+IP=0.0.0.0
+MONPORT=$(( 8500+${VMID} ))
+VNCPORT=$(( ${VMID} ))
+SERPORT=$(( 9900+${VMID} ))
+TAP_NAME="kvm${VMID}"
+PWD=$( pwd )
+
+if [ -n "$DRIVE2" ] ; then
+       DRIVE2="-drive file=${DRIVE2},if=virtio,cache=none"
+fi
+
+if [ -n "$CORES" ] ; then
+       CORES="-smp cores=$CORES"
+
+fi
+if [ -n "$TABLET" ] ; then
+       TABLET="-usbdevice tablet"
+fi
+
+if [ -z "$VLAN" ] ; then
+    VLAN=0
+fi
+if [ ! -L _run/ifup_br${VLAN} ] ; then 
+    pushd _run
+    ln -s ifup_common ifup_br${VLAN}
+    popd
+fi
+
+if [ -z "MACADDR" ] ; then 
+    VLANDIGIT=$( echo 'ibase=10;obase=16;'$VLAN | bc)
+    VMDIGIT=$( echo 'ibase=10;obase=16;'$VMID | bc )
+    MACADDR="C0:FF:EE:19:$VLANDIGIT:$VMDIGIT"
+fi
diff --git a/_run/ifup_br0 b/_run/ifup_br0
new file mode 120000 (symlink)
index 0000000..f7890b9
--- /dev/null
@@ -0,0 +1 @@
+ifup_common
\ No newline at end of file
diff --git a/_run/ifup_common b/_run/ifup_common
new file mode 100755 (executable)
index 0000000..ca1e7ba
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+switch=${0:10}
+/bin/ifconfig $1 0.0.0.0 up
+/sbin/brctl addif ${switch} $1
diff --git a/_run/plain.sh b/_run/plain.sh
new file mode 100644 (file)
index 0000000..3a59746
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+. _run/common.sh
+
+echo "$0 $NAME started, vnc at $VNCPORT, monitor at $MONPORT"
+qemu-kvm \
+            -name $NAME \
+            -monitor telnet:${IP}:${MONPORT},server,nowait  \
+        -drive file=${BOOTDRIVE},if=ide,cache=none \
+       -boot order=c \
+       $CORES \
+       $DRIVE2 \
+       $TABLET \
+        -m ${MEMORY} \
+        -k da \
+        -vga std \
+        -vnc :${VNCPORT} \
+        -enable-kvm \
+        -rtc base=utc \
+        -daemonize  \
+        -cpu kvm64 \
+       -net nic,macaddr=${MACADDR}  \
+       -net tap,ifname=${TAP_NAME},script=_run/ifup_br${VLAN} \
+       -pidfile _pids/$NAME \
+        $*
diff --git a/_run/virtio.sh b/_run/virtio.sh
new file mode 100644 (file)
index 0000000..3995a93
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+. _run/common.sh
+
+echo "$0 $NAME started, vnc at $VNCPORT, monitor at $MONPORT"
+qemu-kvm \
+            -name $NAME \
+            -monitor telnet:${IP}:${MONPORT},server,nowait  \
+        -drive file=${BOOTDRIVE},if=virtio,cache=none \
+       -boot order=c \
+       $CORES \
+       $DRIVE2 \
+       $TABLET \
+        -m ${MEMORY} \
+        -k da \
+        -vga std \
+        -vnc :${VNCPORT} \
+        -enable-kvm \
+        -rtc base=utc \
+        -daemonize  \
+        -cpu kvm64 \
+       -net nic,model=virtio,macaddr=${MACADDR}  \
+       -net tap,ifname=${TAP_NAME},script=_run/ifup_br${VLAN} \
+       -pidfile _pids/$NAME \
+        $*
diff --git a/autostart.sh b/autostart.sh
new file mode 100755 (executable)
index 0000000..ca9f030
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+if [ $# -lt 1 ] ; then
+       echo "$0 <machine-conf>"
+       exit
+fi
+if [ ! -f $1 ] ; then
+       echo "<machine conf> does not exists at $1";
+       exit
+fi
+. $1
+if [ ${AUTOSTART} -ne 1 ] ; then
+       echo "$1 not autostarting"
+       exit
+else 
+       echo "$1 autostart"
+fi
+shift
+. _run/${TYPE}.sh
diff --git a/gluster.vm b/gluster.vm
new file mode 100644 (file)
index 0000000..6dbacba
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+TYPE=virtio
+VMID=3
+NAME="gluster"
+BOOTDRIVE="gluster://otherhost/gv0/qcows/docker.qcow2"
+MEMORY=2048
+CORES=2
+VLAN=3
+AUTOSTART=1
diff --git a/kill.sh b/kill.sh
new file mode 100755 (executable)
index 0000000..070d96e
--- /dev/null
+++ b/kill.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+if [ $# -lt 1 ] ; then
+       echo "$0 <machine-conf>"
+       exit
+fi
+if [ ! -f $1 ] ; then
+       echo "<machine conf> does not exists at $1";
+       exit
+fi
+. $1
+if [ ! -f _pids/$NAME ] ; then
+       echo "machine $NAME is not running";
+       exit
+fi
+. _run/common.sh
+kill $( cat _pids/$NAME ) 
+rm _pids/$NAME
diff --git a/list-running.sh b/list-running.sh
new file mode 100755 (executable)
index 0000000..12d383a
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+#ps aux | grep [q]emu | grep -P -o "\-name ([^ ]*) .* -vnc ([^ ]*) " | cut -b 7-
+ps aux | gawk '/qemu/ {match($0,"-name ([^ ]*).*-vnc ([^ ]*)", a) ; print(a[1], "pid " $2, a[2])} ' | grep -v "(\[^"
diff --git a/newmac b/newmac
new file mode 100755 (executable)
index 0000000..911f624
--- /dev/null
+++ b/newmac
@@ -0,0 +1,2 @@
+#!/bin/bash
+echo -n C0:FF:EE ; for i in `seq 1 3` ; do echo -n `echo ":$RANDOM$RANDOM" | cut -n -c -3` ;done; echo 
diff --git a/plain.vm b/plain.vm
new file mode 100644 (file)
index 0000000..a94ccdb
--- /dev/null
+++ b/plain.vm
@@ -0,0 +1,9 @@
+#!/bin/bash
+TYPE=plain
+VMID=2
+NAME="plain"
+BOOTDRIVE="qcows/plain.qcow2"
+MEMORY=2048
+CORES=2
+VLAN=3
+AUTOSTART=1
diff --git a/run.sh b/run.sh
new file mode 100755 (executable)
index 0000000..75d9db3
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+if [ $# -lt 1 ] ; then
+       echo "$0 <machine-conf>"
+       exit
+fi
+if [ ! -f $1 ] ; then
+       echo "<machine conf> does not exists at $1";
+       exit
+fi
+. $1
+shift
+. _run/${TYPE}.sh
diff --git a/stop.sh b/stop.sh
new file mode 100755 (executable)
index 0000000..aa9a344
--- /dev/null
+++ b/stop.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+if [ $# -lt 1 ] ; then
+       echo "$0 <machine-conf>"
+       exit
+fi
+if [ ! -f $1 ] ; then
+       echo "<machine conf> does not exists at $1";
+       exit
+fi
+. $1
+if [ ! -f _pids/$NAME ] ; then
+       echo "machine $NAME is not running";
+       exit
+fi
+echo "system_powerdown" | socat - TCP:localhost:$MONPORT
+rm _pids/$NAME
diff --git a/used-ram.sh b/used-ram.sh
new file mode 100755 (executable)
index 0000000..126dbde
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+grep MEM *.vm | awk 'FS="=" { sum += $2 } END { print sum } '
diff --git a/virtio.vm b/virtio.vm
new file mode 100644 (file)
index 0000000..f0ffed0
--- /dev/null
+++ b/virtio.vm
@@ -0,0 +1,9 @@
+#!/bin/bash
+TYPE=virtio
+VMID=1
+NAME="virtio"
+BOOTDRIVE="/dev/vg0/kvm__virtio"
+MEMORY=2048
+CORES=2
+VLAN=3
+AUTOSTART=1