diff options
author | Jonathan Bauer | 2013-08-02 17:27:28 +0200 |
---|---|---|
committer | Jonathan Bauer | 2013-08-02 17:27:28 +0200 |
commit | 3ba5a58e5b04b771e6ee99ee6d6f772991c1c236 (patch) | |
tree | 0d91e40266c79ac1f06cf07cef82fe70563f9a34 /remote/modules/vmchooser/data/opt/openslx/scripts | |
parent | [rootfs-stage32] add find and grep to config file (diff) | |
download | tm-scripts-3ba5a58e5b04b771e6ee99ee6d6f772991c1c236.tar.gz tm-scripts-3ba5a58e5b04b771e6ee99ee6d6f772991c1c236.tar.xz tm-scripts-3ba5a58e5b04b771e6ee99ee6d6f772991c1c236.zip |
[vmchooser] moved all vmchooser specific files and scripts to /opt/openslx. Renamed 'var/lib/virt' to 'mnt/vmstore'. Added bwlehrpool theme for vmchooser#
Diffstat (limited to 'remote/modules/vmchooser/data/opt/openslx/scripts')
-rwxr-xr-x | remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store | 6 | ||||
-rwxr-xr-x | remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env | 112 | ||||
-rwxr-xr-x | remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt (renamed from remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh) | 20 | ||||
-rwxr-xr-x | remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter | 64 |
4 files changed, 187 insertions, 15 deletions
diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store index 27a8f55c..75af39fe 100755 --- a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-mount_vm_store @@ -2,7 +2,5 @@ . /opt/openslx/config || exit 1 -export PATH="$PATH:/opt/openslx/bin:/opt/openslx/usr/bin:/opt/openslx/sbin:/opt/openslx/usr/sbin" - -mkdir -p /var/lib/virt -mount -t nfs -o ro,async,nolock,vers=3 "$SLX_VM_NFS" /var/lib/virt +mkdir -p /mnt/vmstore +mount -t nfs -o ro,async,nolock,vers=3 "$SLX_VM_NFS" /mnt/vmstore diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env new file mode 100755 index 00000000..50eace20 --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/systemd-vmchooser_env @@ -0,0 +1,112 @@ +#!/bin/sh + +export PATH=$PATH:/opt/openslx/bin:/opt/openslx/sbin:/opt/openslx/usr/bin:/opt/openslx/usr/sbin + +#source config file with vars (e.g. ipaddr, macaddr, hostname) +. /opt/openslx/config + +#from plugins/vmchooser/40-started-hw-config/run-virt.sh +#TODO: extra systemd-service for hwinfo +hwinfo --cdrom | grep -i "Device File:" | awk {'print $3'} >/etc/openslx/hwinfo.cdrom +hwinfo --floppy | grep -i "Device File:" | awk {'print $3'} >/etc/openslx/hwinfo.floppy + +#from plugins/vmchooser/XX_vmchooser.sh +VMCHOOSER_CONF_DIR=/opt/openslx/etc/vmchooser + +mkdir -p ${VMCHOOSER_CONF_DIR}/loopimg +mkdir -p ${VMCHOOSER_CONF_DIR}/fd-loop -m 1777 + +# mount a clean tempfs (bug in UnionFS prevents loopmount to work) +grep -qE "unionfs |aufs " /proc/mounts && \ +mount -n -o size=1500k -t tmpfs vm-loopimg ${VMCHOOSER_CONF_DIR}/loopimg + +# create an empty floppy image of 1.4MByte size +dd if=/dev/zero of=${VMCHOOSER_CONF_DIR}/loopimg/fd.img count=2880 bs=512 2>/dev/null +chmod 0777 ${VMCHOOSER_CONF_DIR}/loopimg/fd.img + +# use dos formatter copied into stage3 +mkdosfs ${VMCHOOSER_CONF_DIR}/loopimg/fd.img >/dev/null 2>&1 #|| error +mount -n -t msdos -o loop,umask=000 ${VMCHOOSER_CONF_DIR}/loopimg/fd.img \ + ${VMCHOOSER_CONF_DIR}/fd-loop + +#pvs integration +#if [ $vmchooser_pvs -ne 0 ]; then +# sed -i /usr/share/xsessions/default.desktop \ +# -e "s,vmchooser$,vmchooser --pvs," +#fi + +# setup more scratch space for virtual machines, if configured +mkdir -p /tmp/virt +mkdir -p /var/log/samba + +# enable normal users to setup the extended virtual machine redo file space +# and image source via network block device (NBD only at the moment) +# allow to start/stop samba on virtual devices (latter one ignores multiple +# independent daemons) + +#cat >> /mnt/etc/sudoers << EOF +# allow to start and stop the special /tmp redo file space (RAM + NBD/NFS server RAID) +#ALL ALL=NOPASSWD: /sbin/losetup /dev/loop* +#ALL ALL=NOPASSWD: /sbin/mdadm -C /dev/md0 -l linear --raid-devices=2 /dev/loop* /dev/* +#ALL ALL=NOPASSWD: /opt/openslx/rootfs/usr/sbin/nbd-client * * /dev/nbd* +# allow to configure and start/stop samba services +#ALL ALL=NOPASSWD: /opt/openslx/rootfs/bin/sed -i /etc/*/smb.conf -e * +#ALL ALL=NOPASSWD: /usr/sbin/nmbd -s /etc/*/smb.conf +#ALL ALL=NOPASSWD: /usr/sbin/smbd -s /etc/*/smb.conf +#ALL ALL=NOPASSWD: /opt/openslx/rootfs/usr/bin/killall nmbd smbd +#EOF + +#from plugins/vmchooser/80-after-plugins/virtualization.sh + +# change free mem +mem_free=$(grep -i "^memfree:" /proc/meminfo | awk '{print $2}') +mem_cached=$(grep -i "^cached:" /proc/meminfo | awk '{print $2}') +mem_swapcached=$(grep -i "^swapcached:" /proc/meminfo | awk '{print $2}') +[ -z "$mem_free" ] && mem_free="2048000" +[ -z "$mem_cached" ] && mem_cached="0" +[ -z "$mem_swapcached" ] && mem_swapcached="0" +totalmem="$[ ( $mem_free + $mem_cached + $mem_swapcached ) / 1024 ]" +echo "totalmem=${totalmem}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + +# cpu cores +CPU_CORES=$(grep '^processor.*:' /proc/cpuinfo | wc -l) +if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then + echo "cpu_cores=${CPU_CORES}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +else + echo 'cpu_cores=1' >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +fi + +# arch +echo "host_arch=$(uname -m)" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + +# VT enabled cpu? +if grep -q ^flags.*\\\<vmx\\\> /proc/cpuinfo; then + echo "vtflag=1" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + echo 'kvm_module="kvm_intel"' >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + elif grep -q ^flags.*\\\<svm\\\> /proc/cpuinfo; then + echo "vtflag=1" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + echo 'kvm_module="kvm_amd"' >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + else + echo "vtflag=0" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +fi + +# write mac +echo "hostmacaddr=${SLX_PXE_MAC}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +# ip addr +echo "hostip=${SLX_PXE_CLIENT_IP}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf +# hostname +echo "hostname=${SLX_HOSTNAME}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + +# get further hw information +j=0 +for i in $(cat /etc/openslx/hwinfo.cdrom); do + echo "cdrom_$j=$i" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + j=$(expr $j + 1) +done + +j=0 +for i in $(cat /etc/openslx/hwinfo.floppy); do + echo "floppy_$j=$i" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf + j=$(expr $j + 1) +done + diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt index 473dfbc7..874669dd 100755 --- a/remote/modules/vmchooser/data/opt/openslx/scripts/run-virt.sh +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-run_virt @@ -22,14 +22,12 @@ ### Define default dirs / get configs ################################################################################ -PLUGINCONFROOT=/etc/opt/openslx/plugins -PLUGINCONFDIR=/etc/opt/openslx/plugins/vmchooser # include general configuration from vmchooser -[ -f /etc/openslx/vmchooser/vmchooser.conf ] && \ -. /etc/openslx/vmchooser/vmchooser.conf +[ -f /opt/openslx/etc/vmchooser/vmchooser.conf ] && \ +. /opt/openslx/etc/vmchooser/vmchooser.conf # load general virtualization information -[ -f /etc/openslx/vmchooser/virtualization.conf ] && \ -. /etc/openslx/vmchooser/virtualization.conf +[ -f /opt/openslx/etc/vmchooser/virtualization.conf ] && \ +. /opt/openslx/etc/vmchooser/virtualization.conf ################################################################################ ### Functions used throughout the script @@ -356,7 +354,7 @@ fdtest=${floppy_0:+"TRUE"} # if $fdtest not set floppy0="FALSE", else "TRUE" floppy0=${fdtest:-"FALSE"} floppy1="TRUE" -floppy1name="/etc/openslx/vmchooser/loopimg/fd.img" +floppy1name="/opt/openslx/etc/vmchooser/loopimg/fd.img" # if $cdrom_0 from run-virt.include set then cdtest="TRUE" cdtest= cdtest=${cdrom_0:+"TRUE"} @@ -415,14 +413,14 @@ fi # Copy guest configuration (with added information) config.xml to be accessed # via virtual floppy -cp "$xmlfile" "/etc/openslx/vmchooser/fd-loop/config.xml" +cp "$xmlfile" "/opt/openslx/etc/vmchooser/fd-loop/config.xml" # Add another file with resolution information -xrandr | grep -o -E 'current\s*[0-9]+\s*x\s*[0-9]+' | cut -c 8- | sed -r 's/(\s|\t|\n)//g' | head -n 1 > "/etc/openslx/vmchooser/fd-loop/hostres.txt" +xrandr | grep -o -E 'current\s*[0-9]+\s*x\s*[0-9]+' | cut -c 8- | sed -r 's/(\s|\t|\n)//g' | head -n 1 > "/opt/openslx/etc/vmchooser/fd-loop/hostres.txt" # Get all virtual machine specific stuff from the respective include file -if [ -e /etc/openslx/"${xmlvirt}"/run-virt.include ] ; then +if [ -e /opt/openslx/etc/"${xmlvirt}"/run-virt.include ] ; then self="${xmlvirt}" - . /etc/openslx/"${xmlvirt}"/run-virt.include + . /opt/openslx/etc/"${xmlvirt}"/run-virt.include # start a windowmanager for easier handling # (expect problems /w windows opening in background /w vmware without wm) for dm in twm xfwm4 metacity openbox blackbox kwin fvwm2 ; do diff --git a/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter new file mode 100755 index 00000000..67e49d3e --- /dev/null +++ b/remote/modules/vmchooser/data/opt/openslx/scripts/vmchooser-xml_filter @@ -0,0 +1,64 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2007..2009 - RZ Uni FR +# Copyright (c) 2007..2011 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# xmlfilter.sh +# - This script is invoked by the vmchooser tool. It simply filters xml- +# files (taking the path to these files in $1). You might modify it in any +# way to match your needs, e.g. ask some database instead. You can re- +# implement it in any other programming language too. You simply have to +# return a list of proper xml files to be interpreted by the vmchooser +# binary). Please check for vmchooser.sh too ... +# ----------------------------------------------------------------------------- + +# This script . +# +# currently: +# - filter for slxgrp (which comes from /etc/machine-setup) +# + +# include default directories +. /etc/opt/openslx/openslx.conf + +if [ -f ${OPENSLX_DEFAULT_CONFDIR}/plugins/vmchooser/vmchooser.conf ]; then + . ${OPENSLX_DEFAULT_CONFDIR}/plugins/vmchooser/vmchooser.conf +fi + +function handlePersistentVM() { + if [[ "$(grep --extended-regexp \ + "<persistent param=\"(|.+:)$USER(|:.+)\"" "$1")" ]]; then + # If this virtual machine is useable as persistent version for current + # user we provide an additional persistent version. + local persistentConfigVersionFilePath="$(mktemp --directory)/$(basename "${1}-persistent")" + /opt/openslx/plugin-repo/vmchooser/clc.bash "$1" \ + "$persistentConfigVersionFilePath" --create-persistent-config && \ + echo "$persistentConfigVersionFilePath" + fi +} + +for FILE in $(find -L "$1" -iname "*.xml"); do + # filter all xmls which aren't set active + if [ $(grep "<active param=.*true.*" "$FILE" | wc -l) -eq 1 ]; then + if [ -n "${vmchooser_env}" ]; then + # filter all xmls with pool-param not equal to vmchooser::env + if [ $(grep "<pools param=\"${vmchooser_env}\"" "$FILE" | wc -l) -eq 1 ] + then + handlePersistentVM "$FILE" + echo "$FILE" + fi + else + handlePersistentVM "$FILE" + # if there is no pool set, just take all available xmls + echo "$FILE" + fi + fi +done |