diff options
author | Nicolas Vigier <boklm@mageia.org> | 2010-11-21 20:54:45 +0000 |
---|---|---|
committer | Nicolas Vigier <boklm@mageia.org> | 2010-11-21 20:54:45 +0000 |
commit | 3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187 (patch) | |
tree | 1e0644dc5869d39a46207b299ddbc4f9ec19f31f | |
parent | 03579d93ac2c05e28d44b419257b9257c99b6b9f (diff) | |
download | puppet-3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187.tar puppet-3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187.tar.gz puppet-3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187.tar.bz2 puppet-3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187.tar.xz puppet-3fc4b80bfb8eb5af732b23aa34e41d71c5bf1187.zip |
add testvm module, used to run test VMs
-rw-r--r-- | modules/testvm/files/_vm | 53 | ||||
-rwxr-xr-x | modules/testvm/files/vm-jonund | 5 | ||||
-rw-r--r-- | modules/testvm/manifests/init.pp | 33 |
3 files changed, 91 insertions, 0 deletions
diff --git a/modules/testvm/files/_vm b/modules/testvm/files/_vm new file mode 100644 index 00000000..a3482596 --- /dev/null +++ b/modules/testvm/files/_vm @@ -0,0 +1,53 @@ +#!/bin/sh + +test -z $vmname && exit 1 + +vmdir="$HOME/VMs" +piddir="$HOME/PIDs" +logdir="$HOME/log" +vmfile="$vmdir/$vmname" +pidfile="$piddir/$vmname" +logfile="$logdir/$vmname" +qemucmd="qemu-kvm -nographic -pidfile $pidfile -hda $vmfile -net nic,vlan=0 -net user,vlan=0,hostfwd=tcp::$sshport-:22 $QEMUOPT" + +function running() +{ + test -f $pidfile || return 1 + pid=`cat $pidfile` + test -d "/proc/$pid" +} + +function stop() +{ + test -f $pidfile || return 1 + pid=`cat $pidfile` + kill "$pid" && rm -f "$pidfile" +} + +function start() +{ + running && echo "VM is already running" && return 1 + nohup $qemucmd > $logfile 2>&1 & +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + start + stop + ;; + status) + running + vmrunning=$? + test $vmrunning -eq 0 && echo "VM $vmname is running" + test $vmrunning -eq 0 || echo "VM $vmname is stopped" + ;; + ssh) + running && ssh -p $sshport localhost + ;; +esac diff --git a/modules/testvm/files/vm-jonund b/modules/testvm/files/vm-jonund new file mode 100755 index 00000000..eeb429e9 --- /dev/null +++ b/modules/testvm/files/vm-jonund @@ -0,0 +1,5 @@ +#!/bin/sh +vmname=jonund +sshport=5051 +SCRIPTSDIR=$(dirname $0) +. "$SCRIPTSDIR/_vm" diff --git a/modules/testvm/manifests/init.pp b/modules/testvm/manifests/init.pp new file mode 100644 index 00000000..93376e45 --- /dev/null +++ b/modules/testvm/manifests/init.pp @@ -0,0 +1,33 @@ +class testvm +{ + $testvm_login = "testvm" + $testvmdir = "/home/testvm" + + group {"$testvm_login": + ensure => present, + } + + user {"$testvm_login": + ensure => present, + comment => "System user used to run test VMs", + managehome => true, + gid => $vmtest_login, + shell => "/bin/bash", + } + + file { "$testvmdir/bin/_vm": + ensure => present, + owner => root, + group => root, + mode => 644, + source => "puppet:///modules/testvm/_vm", + } + + file { "$testvmdir/bin/vm-jonund": + ensure => present, + owner => root, + group => $testvm_login, + mode => 750, + source => "puppet:///modules/testvm/vm-jonund", + } +} |