diff options
author | Michael Janczyk | 2010-04-06 20:03:28 +0200 |
---|---|---|
committer | Michael Janczyk | 2010-04-06 20:03:28 +0200 |
commit | 4661a054dca2bf0844c8bd283829b68328c7fed3 (patch) | |
tree | c9fb9c71fd5033f5b666b1deee432ea5d5f36126 /os-plugins | |
parent | cumulative commit of local branch, many changes regarding virtualization (diff) | |
download | core-4661a054dca2bf0844c8bd283829b68328c7fed3.tar.gz core-4661a054dca2bf0844c8bd283829b68328c7fed3.tar.xz core-4661a054dca2bf0844c8bd283829b68328c7fed3.zip |
cumulative commit of local branch, xen modifications and vmgrid plugin
Diffstat (limited to 'os-plugins')
-rw-r--r-- | os-plugins/plugins/qemukvm/files/ifdown | 31 | ||||
-rw-r--r-- | os-plugins/plugins/qemukvm/files/ifup | 75 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm | 322 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/XX_vmgrid.sh | 124 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 386 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/vmgrid | 208 | ||||
-rw-r--r-- | os-plugins/plugins/xen/files/hvm.include | 209 | ||||
-rw-r--r-- | os-plugins/plugins/xen/files/machine.include | 167 | ||||
-rw-r--r-- | os-plugins/plugins/xen/files/run-virt.include | 157 | ||||
-rw-r--r-- | os-plugins/plugins/xen/init-hooks/10-have-nw-modules/xennet.sh | 4 | ||||
-rwxr-xr-x | os-plugins/plugins/xen/init-hooks/20-nw-bridge-config/bridge.sh | 30 |
11 files changed, 1713 insertions, 0 deletions
diff --git a/os-plugins/plugins/qemukvm/files/ifdown b/os-plugins/plugins/qemukvm/files/ifdown new file mode 100644 index 00000000..be6ec913 --- /dev/null +++ b/os-plugins/plugins/qemukvm/files/ifdown @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright (c) 2009 - 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/ +# ----------------------------------------------------------------------------- +# ifdown +# - Script used for network cleanup of qemukvm in stage4 +# ----------------------------------------------------------------------------- + +# Clean up script + +case "$1" in + tap1) + # Bringing down the dhcp server + killall udhcpd 2>/dev/null + #iptables -t nat -D POSTROUTING -o br0 -j MASQUERADE 2>/dev/null + ;; + tap2) + # Bringing down the dhcp server + killall udhcpd 2>/dev/null + ;; +esac + +# Produce a clean exit status +exit 0 diff --git a/os-plugins/plugins/qemukvm/files/ifup b/os-plugins/plugins/qemukvm/files/ifup new file mode 100644 index 00000000..43956b31 --- /dev/null +++ b/os-plugins/plugins/qemukvm/files/ifup @@ -0,0 +1,75 @@ +#!/bin/sh +# Copyright (c) 2009..2010 - 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/ +# ----------------------------------------------------------------------------- +# ifup +# - Script used for network setup of qemukvm in stage4 +# ----------------------------------------------------------------------------- + +. /etc/opt/openslx/openslx.conf + +PLUGINCONFDIR=${OPENSLX_DEFAULT_CONFDIR}/plugins/qemukvm + +# get VM_ID through tap name +VM_ID=$(echo $1 | grep -oE "0[0-4]$") +QKTMPDIR=/tmp/qemukvm/${USER}/${VM_ID} + +# Use the udhcpcd as DHCP server and brctl as provided by default in OpenSLX +# environments via uclibc-wrapper. +. ${PLUGINCONFDIR}/network.conf + +# Just decide by the virtual network device used which kind of connection +# should be set up (passed in $1): tap0 = bridge, tap1 = nat, tap2 = hostonly. +case "$1" in + tapbridge0*) + # Adding the tap0 interface to the existing bridge configured in stage3 + #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1 + sudo ip link set dev $1 up + #sudo /opt/openslx/uclib-rootfs/usr/sbin/brctl addif br0 $1 + echo "1" >/proc/sys/net/ipv4/conf/br0/forwarding + echo "1" >/proc/sys/net/ipv4/conf/$1/forwarding + ;; + tapnat0*) + # Configuring DHCP on host tap1 interface and enable IP masquerading + #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1 + sudo ip addr add ${nataddress} dev $1 + # not necessary since already done by run-virt.include + #[ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR} + # cut the last .NNN/MM from nataddress ${natnetwork%.*} + # TODO: we use here atatic address, maybe change later + sed -e "s,NWIF,$1,;s,CNETWORK,192.168.1${VM_ID}.254," \ + -e "s,PIDFILE,${QKTMPDIR}/udhcpd.pid," \ + -e "s,LEASEFILE,${QKTMPDIR}/udhcpd.leases," \ + ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf \ + >${QKTMPDIR}/udhcpd.conf + touch ${QKTMPDIR}/udhcpd.leases + # ip link set $1 up + # ip addr add 192.168.101.254/24 dev $1 + sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \ + -S ${QKTMPDIR}/udhcpd.conf + # iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE + ;; + taphost0*) + # Configuring DHCP on host tap2 interface + #sudo /opt/openslx/uclib-rootfs/sbin/tunctl -t $1 >/dev/null 2>&1 + sudo ip addr add ${hoaddress} dev $1 + #[ -d ${QKTMPDIR} ] || mkdir -p ${QKTMPDIR} + sed "s,NWIF,$1,;s,USER,${USER},;s,CNETWORK,192.168.1${VM_ID}.254," \ + ${OPENSLX_DEFAULT_CONFDIR}/udhcpd.conf >${QKTMPDIR}/udhcpd.conf + touch ${QKTMPDIR}/udhcpd.leases + # ip link set $1 up + # ip addr add 192.168.102.254/24 dev $1 + sudo /opt/openslx/uclib-rootfs/usr/sbin/udhcpd \ + -S ${QKTMPDIR}/udhcpd.conf + ;; +esac + +# Produce a clean exit status +exit 0 diff --git a/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm b/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm new file mode 100644 index 00000000..d73e0720 --- /dev/null +++ b/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm @@ -0,0 +1,322 @@ +# Copyright (c) 2008, 2009 - 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/ +# ----------------------------------------------------------------------------- +# vmgrid.pm +# - ... +# ----------------------------------------------------------------------------- +package OpenSLX::OSPlugin::vmgrid; + +use strict; +use warnings; + +use base qw(OpenSLX::OSPlugin::Base); + +use OpenSLX::Basics; +use OpenSLX::Utils; +use OpenSLX::DistroUtils; + +sub new +{ + my $class = shift; + + my $self = { + name => 'vmgrid', + }; + + return bless $self, $class; +} + +# TODO: desc +sub getInfo +{ + my $self = shift; + + return { + description => unshiftHereDoc(<<' End-of-Here'), + ... + End-of-Here + precedence => 80, + #required => [ qr{^(vmware|virtualbox|qemukvm|xen)$} ], + #openvz|vserver + # TODO: virtaul plugin (requires, provides?) + #required => [ qw( virtualization ) ], + #provided => [ qw( virtualization ) ], + }; +} + +sub getAttrInfo +{ + my $self = shift; + + return { + 'vmgrid::active' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + should the 'vmgrid'-plugin be executed during boot? + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '1 means active - 0 means inactive', + default => '1', + }, + 'vmgrid::virt' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + which virtualization technique schould be used? + End-of-Here + content_regex => qr{^(vmware|virtualbox|qemukvm|xen)$}, + #openvz|vserver + content_descr => 'vmware, virtualbox, qemukvm, xen', + #openvz, vserver + default => undef, + }, + 'vmgrid::roshare' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + do you want to mount external resources? + e.g. NFS share /w virt images ... + will be mounted to /var/lib/virt/vmgrid + End-of-Here + content_regex => qr{^nfs://}, + content_descr => 'NFS share as URI (nfs://...)', + default => undef, + }, + 'vmgrid::rwshare' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + do you want a persistent storage device? + use local hard drive (ID45) or NFS share. + will be mounted to /var/opt/openslx/plugins/vmgrid/share + End-of-Here + content_regex => qr{^(id45|nfs://)}, + content_descr => 'NFS share as URI (nfs://...) or "id45"', + default => undef, + }, + 'vmgrid::imgpath' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + location of virtual images + for starts /wo full path + End-of-Here + content_descr => 'absolute path to vm image files', + default => '/var/lib/virt/vmgrid/images', + }, + 'vmgrid::xmlpath' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + location of XML configuration for virtual images + for starts /wo full path + End-of-Here + content_descr => 'absolute path to vm xml files', + default => '/var/lib/virt/vmgrid/xml', + }, + 'vmgrid::startvms' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + which virtaul machines should be started per default + comma separated list. first will be started first, + second second, and so on, max. 4 VMs + End-of-Here + content_descr => 'name of xml file e.g. scilin-5.4-wn(.xml)', + default => undef, + }, + 'vmgrid::hvm' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + use hardware virtualization, if applicable + override the settings of the corresponding virt plugin + (only if supported by plugin) + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '"0", "1" or "-" (for unset)', + default => undef, + }, + 'vmgrid::maxvcpus' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + use this number of vcpus as maximum for one vm + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|4|8|16)$}, + content_descr => '1, 2, 4, 8, 16', + default => undef, + }, + 'vmgrid::minvcpus' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + use this number of vcpus as minimum for one vm + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|4|8|16)$}, + content_descr => '1, 2, 4, 8, 16', + default => undef, + }, + 'vmgrid::memratio' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + define memory ratio in nn% + order: grid client 1, 2, 3, 4, other VMs, host + if desktop virtualization defined the free memory will be + distributed between the remaining grid clients, + according to their ratio + if less than 4 VMs defined in startvms the memory is being + reserved for a later manual start + set to 0 if you don't intend to start them manually + (only if supported by plugin) + End-of-Here + content_regex => qr{^(\d\d??,\d\d??,\d\d??,\d\d??,\d\d??,\d\d??)$}, + content_descr => '\d\d??,\d\d??,\d\d??,\d\d??,\d\d??,\d\d??', + default => '40,0,0,0,40,20', + }, + 'vmgrid::maxram' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + maximum of RAM used for ALL vms + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|3|4|5|6|7|8|9)}, + content_descr => 'absolute or relative e.g. 512 or 50%', + default => undef, + }, + 'vmgrid::minram' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + minimum of RAM used for ALL vms + will be used only if applicable + (only if supported by plugin) + End-of-Here + content_regex => qr{^(1|2|3|4|5|6|7|8|9)}, + content_descr => 'absolute or relative e.g. 512 or 50%', + default => undef, + }, + }; +} + +sub installationPhase +{ + my $self = shift; + my $info = shift; + + my $pluginRepoPath = $info->{'plugin-repo-path'}; + my $openslxBasePath = $info->{'openslx-base-path'}; + + $self->_writeRunlevelScript(); + + # copy all needed files now: + my $pluginName = $self->{'name'}; + my $pluginBasePath = "$openslxBasePath/lib/plugins/$pluginName/files"; + foreach my $file ( qw( vmgrid run-vmgrid.sh ) ) { + copyFile("$pluginBasePath/$file", "$pluginRepoPath/"); + chmod 0755, "$pluginRepoPath/$file"; + } + + return; +} + +sub removalPhase +{ + my $self = shift; + my $info = shift; + + return; +} + +# Write the runlevelscript +sub _writeRunlevelScript +{ + my $self = shift; + my $initfile = newInitFile(); + + $initfile->setName("vmgrid-slx"); + $initfile->setDesc("Setup environment for vmgrid. Part of OpenSLX vmgrid plugin."); + + # todo: Function need to be formated proper... not important right now + #$initfile->addFunction( + # 'running', + # 'lsmod | grep -q "$1[^_-]"' + #); + + # Is a VM running? + my $runningvms = unshiftHereDoc(<<' End-of-Here'); + if [ -e /tmp/vmgrid/vmgrid.pids ]; then + for pid in $(cat /tmp/vmgrid/vmgrid.pids); do + if ps aux | grep " ${pid} " | grep vmgrid; then + echo "Running: ${pid}" + fi + done + fi + End-of-Here + + # Kill all VMS! + my $killvms = unshiftHereDoc(<<' End-of-Here'); + if [ -e /tmp/vmgrid/vmgrid.pids ]; then + for pid in $(cat /tmp/vmgrid/vmgrid.pids); do + if ps aux | grep " ${pid} " | grep vmgrid; then + kill ${pid} + fi + done + fi + End-of-Here + + # FORCE: Kill all VMS! + my $fkillvms = unshiftHereDoc(<<' End-of-Here'); + if [ -e /tmp/vmgrid/vmgrid.pids ]; then + for pid in $(cat /tmp/vmgrid/vmgrid.pids); do + if ps aux | grep " ${pid} " | grep vmgrid; then + kill -9 ${pid} + fi + done + fi + End-of-Here + + $initfile->addFunction( + 'start', + ' vmgrid', + ); + $initfile->addToCase( + 'kill', + 'killvms' + ); + $initfile->addToCase( + 'force-kill', + 'fkillvms' + ); + $initfile->addToCase( + 'status', + 'runningvms' + ); + $initfile->addToCase( + 'restart', + 'stop && start' + ); + + # get distro version +# my $distro = (split('-',$self->{'os-plugin-engine'}->distroName()))[0]; +# my $runlevelscript = getInitFileForDistro($initfile, $distro); +# +# spitFile("$self->{'pluginRepositoryPath'}/vmgrid-slx", $runlevelscript); +} + +1; diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh new file mode 100644 index 00000000..d9e35dfb --- /dev/null +++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh @@ -0,0 +1,124 @@ +# Copyright (c) 2008..2010 - RZ Uni Freiburg +# Copyright (c) 2008..2010 - OpenSLX GmbH +# +# This program/file 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 feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# script is included from init via the "." load function - thus it has all +# variables and functions available + +# include default directories +. /etc/openslx.conf + +CONFFILE="/initramfs/plugin-conf/vmgrid.conf" +PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/vmgrid +VIRTUALIZATIONPLUGIN=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization +#RWSHARE=/mnt/${OPENSLX_DEFAULT_VARDIR}/plugins/vmgrid/share +RWSHARE=/mnt/var/opt/openslx/plugins/vmgrid/share +RWSHAREMNT=/mnt/var/opt/openslx/mnt/vmgrid +BINDIR=/mnt/${OPENSLX_DEFAULT_BINDIR} +PLUGINDIR=${OPENSLX_DEFAULT_DIR}/plugin-repo/vmgrid +VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR}/vmgrid + +if [ -f $CONFFILE ]; then + + # load needed variables + . $CONFFILE + + if [ $vmgrid_active -ne 0 ] ; then + [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..." + + # load general configuration + . /etc/initramfs-setup + # include functions + . /etc/functions + + testmkd ${PLUGINCONFDIR} + testmkd ${VIRTDIR} + cp $CONFFILE ${PLUGINCONFDIR}/vmgrid.conf + # create link to binpath + ln -fs ${PLUGINDIR}/vmgrid ${BINDIR}/vmgrid + ln -fs ${PLUGINDIR}/run-vmgrid.sh ${BINDIR}/run-vmgrid.sh + + # mount nfs virt ro share + if strinstr "nfs://" "${vmgrid_roshare}"; then + virtsrcprot=$(uri_token ${vmgrid_roshare} prot) + virtsrcserv=$(uri_token ${vmgrid_roshare} server) + virtsrcpath="$(uri_token ${vmgrid_roshare} path)" + if [ -n "${virtsrcprot}" -a -n "${virtsrcserv}" -a -n "${virtsrcpath}" ]; + then + virtsrctarget=${VIRTDIR} + # mount the vmgrid source ro + fsmount ${virtsrcprot} ${virtsrcserv} ${virtsrcpath} ${virtsrctarget} \ + ro + fi + fi + + # create rw share + testmkd ${RWSHARE} + # bind mount id 45 to ${RWSHARE} + if strinstr "id45" "${vmgrid_rwshare}" ; then + id45part=$(grep " 45 " /etc/disk.partition | awk '{print $1}' | \ + cut -f 3,3 -d /) + if [ -n "${id45part}" ]; then + testmkd /mnt/media/${id45part}/vmgrid + mount --bind -n /mnt/media/${id45part}/vmgrid ${RWSHARE} \ + >>/tmp/vmgrid.log 2>&1 + fi + # mount nfs rw share + elif strinstr "nfs://" "${vmgrid_rwshare}" ; then + rwshareprot=$(uri_token ${vmgrid_rwshare} prot) + rwshareserv=$(uri_token ${vmgrid_rwshare} server) + rwsharepath="$(uri_token ${vmgrid_rwshare} path)" + if [ -n "${rwshareprot}" -a -n "${rwshareserv}" -a -n "${rwsharepath}" ]; + then + # mount to a dir fist to create spec host dir, then bind mount + testmkd ${RWSHAREMNT} + rwtarget=${RWSHAREMNT} + # mount the vmgrid source rw + fsmount ${rwshareprot} ${rwshareserv} ${rwsharepath} ${rwtarget} rw + # hostname? + host_name=${host_name:=$clientip} + testmkd ${RWSHAREMNT}/${host_name} + mount --bind ${RWSHAREMNT}/${host_name} ${RWSHARE} \ + >>/tmp/vmgrid.log 2>&1 + fi + else + testmkd /mnt/tmp/vmgrid + mount --bind -n /mnt/tmp/vmgrid ${RWSHARE} >>/tmp/vmgrid.log 2>&1 + fi + # chmod so that everybody can write + chmod 1777 ${RWSHARE} + echo "vmgrid_rwmnt=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf + + # virtual virtualization plugin + testmkd ${VIRTUALIZATIONPLUGIN} + totalmemtest=$(expr $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" + "$2" + "$3" + "$4" + "$5" + "$6}')) + totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \ + | awk '{print $2}') / 1024) + if [ ${totalmemtest} -le 100 2>/dev/null ]; then + # get hostmem + freememper=$(expr 100 - $(echo ${vmgrid_memratio} \ + | awk -F ',' '{print $1" - "$2" - "$3" - "$4}')) + freemem=$(expr ${totalmem} \* ${freememper} / 100) + echo "virt_freemem=${freemem}" \ + >> ${VIRTUALIZATIONPLUGIN}/virtualization.conf + else + # more than 100% memory assigned stupid! + # vmgrid will get this as well and exit! + # so we have theoretically 100% free + echo "virt_freemem=${totalmem}" \ + >> ${VIRTUALIZATIONPLUGIN}/virtualization.conf + fi + + # finished ... + [ $DEBUGLEVEL -gt 0 ] && echo "done with 'vmgrid' os-plugin ..." + fi +[ $DEBUGLEVEL -gt 0 ] && echo " * configuration of 'vmgrid' os-plugin failed" +fi diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh new file mode 100644 index 00000000..626dfcca --- /dev/null +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -0,0 +1,386 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2007..2010 - RZ Uni FR +# Copyright (c) 2007..2010 - 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/ +# ----------------------------------------------------------------------------- +# vmgrid +# - This is the generic wrapper for the several virtualization solutions... +################################################################################ + +. /etc/opt/openslx/openslx.conf + +################################################################################ +### Define default dirs / get configs +################################################################################ + +PLUGINCONFROOT=${OPENSLX_DEFAULT_CONFDIR}/plugins +PLUGINCONFVMGRID=${PLUGINCONFROOT}/vmgrid +RWSHARE=/var/opt/openslx/plugins/vmgrid/share +# include general configuration from vmgrid +[ -f ${PLUGINCONFVMGRID}/vmgrid.conf ] && \ + . ${PLUGINCONFVMGRID}/vmgrid.conf +#[ -f ${PLUGINCONFVMGRID}/vmgrid.include ] && \ +# . ${PLUGINCONFVMGRID}/vmgrid.include +# get the vmchooser_active var +[ -f ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ] && \ + . ${PLUGINCONFROOT}/vmchooser/vmchooser.conf + +################################################################################ +### Functions used throughout the script +################################################################################ + +# function to write to stdout and logfile +writelog () { + # write to stdout + echo -e "$1" + # log into file + echo -e "$1" >> ${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log + # log into share dir, so that log is available in vm as well + echo -e "$1" >> ${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log +} + +################################################################################ +### Get XML file and dir +################################################################################ + +# check if forcemem or graphical mode set +headless=1 +while [ $# -gt 0 ]; do + case "$1" in + -h|--help) + echo -e "Usage: run-vmgrid.sh [-g] [--forcemem <memorysize in MB>] \c" + echo -e "[/path/]filename[.xml]" + exit + ;; + -g) + headless=0 + ;; + --forcemem) + forcemem=$2 + shift + ;; + *) + xmlfile=$@ + break + ;; + esac + shift +done + +# absolute or relative path? +if ls ${xmlfile} 2>/dev/null | grep '/' >/dev/null 2>&1; then + xmlpath=$(dirname ${xmlfile}) + xmlfile=$(basename ${xmlfile}) +else + xmlpath=${vmgrid_xmlpath} +fi +# full path +xmlfile="${xmlpath}/${xmlfile%.xml}.xml" + +################################################################################ +### Sanity checks +################################################################################ + +# test if the xml file is valid +if ! [ -r "${xmlfile}" ]; then + writelog "${xmlfile} not a readable XML file!" + run-vmgrid.sh -h & + exit 1 +fi + +# start to log, create shrare log dir +mkdir -m 1777 -p ${vmgrid_rwmnt}/logs +echo "Starting to log at $(date)" \ + >${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log + +# test how many instances running +runningvms=$(ps aux | grep "run-vmgrid.sh " | grep -v grep | wc -l) +# 2 steps, /w only one is seems not to work +runningvms=$(expr ${runningvms} - 1) +# if Xen use different method +if [ "${vmgrid_virt}" = "xen" ]; then + runningvms=$(xm list 2>/dev/null | grep -vE "Domain-0|Name.*ID" | wc -l) + runningvms=$(expr ${runningvms} + 1) +fi +# check value +if [ $runningvms -le 0 ]; then + writelog "Error in value: Running VMs: ${runningvms}. Exit!" + exit 1 +fi +# check if vmchooser plugin installed +if [ -n "${vmchooser_active}" ] && [ ${runningvms} -gt 1 ]; then + # only allow one instance of vmgrid + writelog "Already 1 VMs running and vmchooser plugin is active." + writelog "Can't start ${xmlfile}, exiting!" + exit 1 +# else allow max. 4 instances +elif [ ${runningvms} -gt 4 ]; then + writelog "Already 4 VMs running, exiting!" + exit 1 +fi +VM_ID="0${runningvms}" + +# test if XML file +if ! grep '<?xml' "${xmlfile}" >/dev/null 2>&1; then + writelog \ + "Submitted configuration file ${xmlfile} seems to have wrong XML format" + exit 1 +fi + +################################################################################ +### Logo for console +################################################################################ + +cat <<EOL + __ __ + .----.--.--.-----.___.--.--.--------.-----.----.|__|.--| | + | _| | | |___| | | | _ | _|| || _ | + |__| |_____|__|__| \___/|__|__|__|___ |__| |__||_____| + |_____| + OpenSLX virtual machine environment preparation script ... + +EOL + +################################################################################ +### Read needed variables from XML file +################################################################################ + +writelog "Starting configuration..." +writelog "\tVM-ID:\t\t\t${VM_ID}" +writelog "\tLogfile:\t\t${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log" +writelog "\t/tmp info:\t\t$(df -h | grep " /tmp$" | awk '{print $2}') \c" +writelog "$(grep "/tmp " /proc/mounts | awk '{print $1" "$2" "$3" "$4}')" +writelog "\tVM XML dir:\t\t$(dirname ${xmlfile})" + +if ! grep '<?xml' "${xmlfile}" >/dev/null 2>&1; then + writelog \ + "Submitted configuration file ${xmlfile} seems to have wrong XML format" + exit 1 +fi + +writelog "\tXML file:\t\t$xmlfile" +writelog "VM config:" + +# name of the virt image or dir +imgname=$(grep -io '<image_name param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') + +# image mode +imgmode=$(grep -io '<image_mode param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }') + +# get boot attr +boot=$(grep -io 'boot param=.*"' ${xmlfile} | awk -F '"' '{ print $2 }') +diskless=0 + +# special rw image +if [ "${imgmode}" = "rwimg" ]; then + # maybe you want to use an empty rw imgae? + # define only for writelog, will be set in the plugin include again! + vmpath="{special rw image}" + # add new path for rwimg + imgpath=${vmgrid_rwmnt}/specialrwimages + unset $imgname + mkdir -m 1777 -p ${imgpath} +# diskless boot +elif [ "${boot}" = "n" ] && [ -z "${imgname}" ]; then + diskless=1 + vmpath="{diskless boot}" +# imagename /w full path +elif echo ${imgname} 2>/dev/null | grep -q '^/' >/dev/null 2>&1; then + imgpath=$(dirname ${imgname}) + imgname=$(basename ${imgname}) + vmpath=${imgpath}/${imgname} +# get path from var +else + imgpath=${vmgrid_imgpath} + vmpath=${imgpath}/${imgname} +fi + +# check if virtual machine container file exists, only if not rwimg +if ! [ -e "${vmpath}" ] && [ "${imgmode}" != "rwimg" ] && [ ${diskless} -eq 0 ]; +then + writelog "Virtual machine image or directory ${vmpath} not found!" + exit 1 +fi + +# name of the virt machine, sed because of Windows formatting +vm_name=$(grep -o 'short_description param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') +# if ${vm_name} not defined use ${xmlfile} +vm_name=${vm_name:-${xmlfile%.xml}} + +# define vm_shortname since vm_name can be very long +vm_shortname=$(basename ${xmlfile%.xml} | sed -e "s, ,-,g") + +# vm_name = displayname, define for old scripts +displayname=${vm_name} + +[ "${imgmode}" != "rwimg" ] && [ ${diskless} -eq 0 ] \ + && writelog "\tVM Image dir:\t\t${imgpath}" +writelog "\tVM file/dir:\t\t$vmpath" + +# is there an additional configuration provided? +additional_config=$(grep -o 'additional_config param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') + +# image is for the following virtual machine +xmlvirt=$(grep -o 'virtualmachine param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') + +# make a guess from the filename extension if ${xmlvirt} is empty +# (not set within the XML file) +if [ -z "${xmlvirt}" ] && [ -n "${additional_config}" ]; then + writelog "No virtual machine parameter defined in ${xmlfile}" + writelog "Trying to guess VM...\c" + case "$(cat ${additional_config} | tr [A-Z] [a-z])" in + *config.version*|*virtualhw.version*|*independent-nonpersistent*|*vmdk*) + xmlvirt="vmware" + ;; + *innotek*|*virtualbox*) + xmlvirt="virtualbox" + ;; + *qemu*|*kvm*) + xmlvirt="qemukvm" + ;; + *) + xmlvirt="none" + ;; + esac +elif [ -z "${xmlvirt}" ]; then + case "$(echo ${imgname##*.} | tr [A-Z] [a-z])" in + vmdk) + xmlvirt="vmware" + ;; + vbox) + xmlvirt="virtualbox" + ;; + img|qcow*) + xmlvirt="qemukvm" + ;; + *) + xmlvirt="none" + ;; + esac + writelog "result:\t${xmlvirt}" +fi + +# check for virt +if [ "${vmgrid_virt}" != "${xmlvirt}" ]; then + writelog "The virtual machine specified in ${xmlfile}" + writelog "does not match the virtualization used here (${vmgrid_virt})" + exit 1 +fi + +# definition of the client system +vmostype=$(grep -io '<os param=.*"' ${xmlfile} | awk -F '"' '{ print $2 }') + +# definition of the networking the client system is connected to +network_kind=$(grep -io 'network param=.*"' ${xmlfile} \ + | awk -F '"' '{ print $2 }') +network_card=$(grep -io 'netcard param=.*"' ${xmlfile} \ + | awk -F '"' '{ print $2 }') + +writelog "\tVirtualization:\t\t$xmlvirt" +writelog "\tVM name:\t\t$vm_name" +writelog "\tVM short name:\t\t$vm_shortname" + +############################################################################### +### Declaration of default variables +############################################################################### + +# TODO: cpu cores +#vmgrid::maxvcpus +#vmgrid::minvcpus +#cpu_cores="${cpu_cores}" + +# check for CPU virtualization flags +#vmgrid::hvm + +# get total amount of memory installed in your machine +totalmem=$(expr $(grep -i "memtotal" /proc/meminfo | awk '{print $2}') / 1024) +permem=60 +mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4) +#vmgrid::maxram +#vmgrid::minram + +# configuring ethernet mac address: first 3 bytes are fixed (00:50:56) +# 4th byte is the VM-ID +# last two bytes are taken from the bridge of the host +# define one MAC per guest +macguestpart="00:50:56:${VM_ID}" +machostpart=$($(which ifconfig) br0 | grep br0 | sed -e "s/ //g" \ + | awk -F ":" '{print $(NF-1)":"$NF}') +macaddr=$(echo "${macguestpart}:${machostpart}" | tr [a-z] [A-Z]) + +# ide is expected default, test for the virtual disk image type should +# be done while creating the runscripts ... +# TODO: cdrom / floppy? +ide="TRUE" +scsi="FALSE" +hddrv="ide" + +# add rw share +sharepath="${vmgrid_rwmnt}/folders/${vm_shortname}" +mkdir -p ${sharepath} +chmod -f 1777 "${vmgrid_rwmnt}/folders" +sharename="share" + +# set hostname: using original hostname and adding string +hostname="vmgrid${VM_ID}-$(hostname)" + +writelog "\tVM Hostname:\t\t$hostname" + +################################################################################ +### Setup the rest of the environment and run the configured vm +################################################################################ + +# Copy guest configuration (with added information) config.xml to be accessed +# via virtual floppy +# TODO: virt-floppy needed? + +# Get all virtual machine specific stuff from the respective include file +# TODO: rename to run-vuirt.include +if [ -e ${PLUGINCONFROOT}/${vmgrid_virt}/run-virt.include ] ; then + writelog "Strating ${vmgrid_virt} specific part ..." + self=${vmgrid_virt} + . ${PLUGINCONFROOT}/${vmgrid_virt}/run-virt.include +else + writelog "Failed because of missing ${vmgrid_virt} plugin" + exit 1 +fi + +# start graphical mode +if [ ${headless} -eq 0 ]; then + if [ -z "${VIRTCMD}" ]; then + writelog "Grapical mode not available, exiting!" + exit 1 + fi + writelog "Starting ${vmgrid_virt} in graphical mode..." + ${VIRTCMD} ${VIRTCMDOPTS} 2>/dev/null +# start headless +elif [ -n "${VIRTCMDHL}" ]; then + writelog "Starting ${vmgrid_virt} in headless mode..." + ${VIRTCMDHL} ${VIRTCMDOPTSHL} 2>/dev/null +else + writelog "${vmgrid_virt}: No headless mode defined, exiting!" + exit 1 +fi + +# remove config dirs when finished +if echo "${RMDIRS}" 2>/dev/null | grep -q ${vmgrid_virt}; then + writelog "${vmgrid_virt} exited. Cleanning up... \c" + rm -rf ${RMDIRS} >/dev/null 2>&1 + writelog "done" +fi + +echo -e "Bye." +exit 0 diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid new file mode 100644 index 00000000..b75b5341 --- /dev/null +++ b/os-plugins/plugins/vmgrid/files/vmgrid @@ -0,0 +1,208 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Copyright (c) 2007..2010 - RZ Uni FR +# Copyright (c) 2007..2010 - 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/ +# ----------------------------------------------------------------------------- +# vmgrid +# - Script for autostarts defined in vmgrid::startvms +################################################################################ + +# include default directories +. /etc/opt/openslx/openslx.conf + +################################################################################ +### Manual Start +################################################################################ + +if [ -n "$1" ]; then + if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo -e "Usage: vmgrid [[-g] [--forcemem <memorysize in MB>] \c" + echo -e "[/path/]filename[.xml]]" + exit 0 + else + echo "Starting run-vmgrid.sh with options '$@'" + run-vmgrid.sh $@ 2>/dev/null + exit + fi +fi + +################################################################################ +### Define default dirs / get configs +################################################################################ + +PLUGINCONFROOT=${OPENSLX_DEFAULT_CONFDIR}/plugins +PLUGINCONFDIR=${PLUGINCONFROOT}/vmgrid +RWSHARE=/var/opt/openslx/plugins/vmgrid/share +# include general configuration from vmgrid +[ -f ${PLUGINCONFDIR}/vmgrid.conf ] && \ + . ${PLUGINCONFDIR}/vmgrid.conf +# get the vmchooser_active var +[ -f ${PLUGINCONFROOT}/vmchooser/vmchooser.conf ] && \ + . ${PLUGINCONFROOT}/vmchooser/vmchooser.conf + +################################################################################ +### Functions used throughout the script +################################################################################ + +# function to write to stdout and logfile +writelog () { + # write to stdout + echo -e "$1" + # log into file + echo -e "$1" >> ${OPENSLX_DEFAULT_LOGDIR}/run-vmgrid.${USER}.$$.log + # log into share dir, so that log is available in vm as well + echo -e "$1" >> ${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log +} + +################################################################################ +### Configure VMs for autostart and set RAM +################################################################################ + +# start to log, create shrare log dir +mkdir -m 1777 -p ${vmgrid_rwmnt}/logs +mkdir -m 1777 -p /tmp/vmgrid +mkdir -p /tmp/vmgrid/${USER} +echo "Starting to log at $(date)" \ + >${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log + +# remove blanks +vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s, *,,g") +vmgrid_startvms=$(echo ${vmgrid_startvms} | sed -e "s, *,,g") + +# get total amount of memory installed in your machine +# TODO: stage 3? virtaulization plugin +totalmem=$(expr $(grep -i "memtotal" /proc/meminfo | awk '{print $2}') / 1024) + +# get hostmem +hostratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $6}') +hostmem=$(expr ${totalmem} \* ${hostratio} / 100 2>/dev/null) +if [ ${hostmem} -lt 256 2>/dev/null ]; then + hostmem=256 + writelog "${hostmem} MB RAM reserved for host" +fi + +# get other vm mem +if [ -n "${vmchooser_active}" ]; then + othervmratio=$(echo ${vmgrid_memratio} | awk -F ',' '{print $5}') + othervmmem=$(expr ${totalmem} \* ${othervmratio} / 100 2>/dev/null) + if [ ${othervmmem} -lt 512 2>/dev/null ]; then + othervmmem=512 + writelog "${othervmmem} MB RAM reserved for other virtualization solutions" + fi +else + othervmratio=0 + othervmmem=0 +fi + +# calculate freemem +freemem=$(expr ${totalmem} - ${hostmem} - ${othervmmem} 2>/dev/null) +if [ ${freemem} -lt 512 2>/dev/null ]; then + writelog "Not enough free RAM for this plugin, free: ${freemem} MB" + exit 1 +fi + +# ratio minus other vms and host +restratio=$(expr 100 - ${hostratio} - ${othervmratio}) + +# get clients mem ratio +vmsumratios=0 +for i in {1..4}; do + vm[$i]=$(echo ${vmgrid_startvms} | awk -F ',' '{print $1}') + # remove ${vm[$i]} from list because of '{print $1}' + vmgrid_startvms=$(echo ${vmgrid_startvms} | sed -e "s,${vm[$i]}\,*,,") + vmratio[$i]=$(echo ${vmgrid_memratio} | awk -F ',' '{print $1}') + # remove ${vmratio[$i]} from list because of '{print $1}' + vmgrid_memratio=$(echo ${vmgrid_memratio} | sed -e "s/${vmratio[$i]},*//") + vmsumratios=$(expr ${vmsumratios} + ${vmratio[$i]} 2>/dev/null) +done + +# ratio test: 100 - host - other vm + grid ratios +ratiotest=$(expr 100 - ${restratio} + ${vmsumratios} 2>/dev/null) +if [ ${ratiotest} -gt 100 ]; then + #writelog "you managed to get over 100% in ratio Einstein: ${ratiotest}%" + exit 1 +fi + +for i in {1..4}; do + # calculate vms mem: mem = $freemem * $vmratio/100 * 100/$restratio + # multiple of 4 + vmmem[$i]=$(expr ${freemem} \* ${vmratio[$i]} / ${restratio} / 4 \* 4 \ + 2>/dev/null) + if [ -n "${vm[$i]}" ] && [ ${vmmem[$i]} -lt 512 2>/dev/null ]; then + writelog "Not enough free RAM for ${vm[$i]} (min. 512 MB), \c" + writelog "free: ${vmmem[$i]} MB" + unset vm[$i] + fi +done + +################################################################################ +### Start the VMs +################################################################################ + +# start vms +for i in {1..4}; do + if [ -n "${vm[$i]}" ]; then + alreadyrunning=$(ps aux | grep run-vmgrid.sh | grep -v grep | \ + grep "${vm[$i]}" | wc -l) + if [ ${alreadyrunning} -gt 0 2>/dev/null ]; then + writelog "${vm[$i]} already running, skipping!" + else + writelog "Starting ${vm[$i]} via run-vmgrid.sh with ${vmmem[$i]} MB RAM" + run-vmgrid.sh --forcemem ${vmmem[$i]} ${vm[$i]} 2>/dev/null & + echo $! > /tmp/vmgrid/${USER}/vmgrid.pids + # wait 5 secs for the next vm to start + sleep 10 + fi + fi +done + +exit 0 + +################################################################################ +### old stuff with xml files +################################################################################ +# +#filter_autostart=$(grep -i "active param" ${vmgrid_xmlpath}/*.xml | \ +# grep -E "true|1" | awk -F ":" '{print $1}') +# +## wozu mehrere starten -> siehe cherkasova +# +#filter_virt= +#for i in ${filter_autostart}; do +# filter_temp= +# filter_temp=$(cat $i | grep -i "virtualmachine param.*${vmgrid_virt}" | \ +# wc -l) +# if [ ${filter_temp} -eq 1 ]; then +# filter_virt="${filter_virt} $i" +# fi +#done +# +## remove already started ${vmgrid_startvm} +#filter_virt=$(echo $filter_virt | \ +# sed -e "s,${vmgrid_xmlpath}/${vmgrid_startvm%.xml}.xml,,g") +# +#sort_virt=$(grep 'priority param' ${vmgrid_xmlpath}/*.xml | sort -n | \ +# awk -F ":" '{print $1}') +# +#for i in ${sort_virt}; do +# j=$(echo $filter_virt | grep $i | wc -l) +# if [ $j -eq 1 ]; then +# filter_virt=$(echo $filter_virt | sed -e "s,$i,,g") +# vmgrid ${i#${vmgrid_xmlpath}/} +# fi +#done +# +## start vms /wo priority +#for i in ${filter_virt}; do +# vmgrid ${i#${vmgrid_xmlpath}/} +#done +# +#exit 0 diff --git a/os-plugins/plugins/xen/files/hvm.include b/os-plugins/plugins/xen/files/hvm.include new file mode 100644 index 00000000..beb9315a --- /dev/null +++ b/os-plugins/plugins/xen/files/hvm.include @@ -0,0 +1,209 @@ +# This is an machine template for run-virt.include of the Xen plugin. +# This template was taken from an example in openSUSE 11.2 +# HVM template + +cat <<EOF +# -*- mode: python; -*- +#============================================================================ +# Python configuration setup for 'xm create'. +# This configuration was created through $0 on $(date) +#============================================================================ + +import os, re + +arch_libdir = 'lib' +arch = os.uname()[4] +if os.uname()[0] == 'Linux' and re.search('64', arch): + arch_libdir = 'lib64' + +#---------------------------------------------------------------------------- +# Kernel image file. +kernel = "/usr/lib/xen/boot/hvmloader" + +# The domain build function. HVM domain uses 'hvm'. +builder='hvm' + +# Initial memory allocation (in megabytes) for the new domain. +memory = ${mem} + +# Shadow pagetable memory for the domain, in MB. +# If not explicictly set, xend will pick an appropriate value. +# Should be at least 2KB per MB of domain memory, plus a few MB per vcpu. +#shadow_memory = 8 + +# A name for your domain. All domains must have different names. +name = "${vm_name}" + +#----------------------------------------------------------------------------- +# The number of cpus guest platform has, default=1 +#vcpus=1 + +# Enable/disable HVM guest PAE, default=1 (enabled) +#pae=1 + +# Enable/disable HVM guest ACPI, default=1 (enabled) +#acpi=1 + +# Enable/disable HVM APIC mode, default=1 (enabled) +# Note that this option is ignored if vcpus > 1 +#apic=1 + +# Enable/disable extended power management support within HVM guest, i.e., beyond +# S3, S4, S5 within guest like exposing battery meter. +# 0 (default option, extended power management support disabled) +# 1 (pass-through mode; uses pass-through as needed; efficient but limited in scope) +# 2 (non pass-through mode; extended scope, likely to work on all applicable environment +# but comparitively less efficient than pass-through mode) +# xen_extended_power_mgmt=0 + +# List of which CPUS this domain is allowed to use, default Xen picks +#cpus = "" # leave to Xen to pick +#cpus = "0" # all vcpus run on CPU0 +#cpus = "0-3,5,^1" # all vcpus run on cpus 0,2,3,5 +#cpus = ["2", "3"] # VCPU0 runs on CPU2, VCPU1 runs on CPU3 + +#---------------------------------------------------------------------------- +# Optionally define mac and/or bridge for the network interfaces. +# Random MACs are assigned if not given. +#vif = [ 'type=ioemu, mac=00:16:3e:00:00:11, bridge=xenbr0, model=ne2k_pci' ] +# type=ioemu specify the NIC is an ioemu device not netfront +#vif = [ 'type=ioemu, bridge=xenbr0' ] +vif = [ '${xen_vif}' ] + +#---------------------------------------------------------------------------- +# Define the disk devices you want the domain to have access to, and +# what you want them accessible as. +# Each disk entry is of the form phy:UNAME,DEV,MODE +# where UNAME is the device, DEV is the device name the domain will see, +# and MODE is r for read-only, w for read-write. +#disk = [ 'phy:hda1,hda1,r' ] +#disk = [ 'file:/var/lib/xen/images/disk.img,ioemu:hda,w', ',hdc:cdrom,r' ] +disk = [ '${xen_disk}' ] + +#---------------------------------------------------------------------------- +# Configure the behaviour when a domain exits. There are three 'reasons' +# for a domain to stop: poweroff, reboot, and crash. For each of these you +# may specify: +# "destroy", meaning that the domain is cleaned up as normal; +# "restart", meaning that a new domain is started in place of the old +# one; +# "preserve", meaning that no clean-up is done until the domain is +# manually destroyed (using xm destroy, for example); or +# "rename-restart", meaning that the old domain is not cleaned up, but is +# renamed and a new domain started in its place. +# In the event a domain stops due to a crash, you have the additional options: +# "coredump-destroy", meaning dump the crashed domain's core and then destroy; +# "coredump-restart', meaning dump the crashed domain's core and the restart. +# The default is +# on_poweroff = 'destroy' +# on_reboot = 'restart' +# on_crash = 'restart' +#on_poweroff = 'destroy' +#on_reboot = 'restart' +#on_crash = 'restart' + +#============================================================================ +# HVM specific +#============================================================================ +# Device Model to be used +device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm' + +#----------------------------------------------------------------------------- +# boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d) +# default: hard disk, cd-rom, floppy +#boot="cda" + +#----------------------------------------------------------------------------- +# write to temporary files instead of disk image files +#snapshot=1 + +#---------------------------------------------------------------------------- +# enable SDL library for graphics, default = 0 +sdl=0 + +#---------------------------------------------------------------------------- +# enable OpenGL for texture rendering inside the SDL window, default = 1 +# valid only if sdl is enabled. +opengl=1 + +#---------------------------------------------------------------------------- +# enable VNC library for graphics, default = 1 +vnc=1 + +#---------------------------------------------------------------------------- +# address that should be listened on for the VNC server if vnc is set. +# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp +#vnclisten="127.0.0.1" + +#---------------------------------------------------------------------------- +# set VNC display number, default = domid +#vncdisplay=1 + +#---------------------------------------------------------------------------- +# try to find an unused port for the VNC server, default = 1 +#vncunused=1 + +#---------------------------------------------------------------------------- +# set password for domain's VNC console +# default is depents on vncpasswd in xend-config.sxp +vncpasswd='' + +#---------------------------------------------------------------------------- +# no graphics, use serial port +#nographic=0 + +#---------------------------------------------------------------------------- +# enable stdvga, default = 0 (use cirrus logic device model) +stdvga=0 + +#----------------------------------------------------------------------------- +# serial port re-direct to pty deivce, /dev/pts/n +# then xm console or minicom can connect +serial='pty' + + +#----------------------------------------------------------------------------- +# Qemu Monitor, default is disable +# Use ctrl-alt-2 to connect +#monitor=1 + + +#----------------------------------------------------------------------------- +# enable sound card support, [sb16|es1370|all|..,..], default none +#soundhw='sb16' + + +#----------------------------------------------------------------------------- +# set the real time clock to local time [default=0 i.e. set to utc] +#localtime=1 + + +#----------------------------------------------------------------------------- +# set the real time clock offset in seconds [default=0 i.e. same as dom0] +#rtc_timeoffset=3600 + +#----------------------------------------------------------------------------- +# start in full screen +#full-screen=1 + + +#----------------------------------------------------------------------------- +# Enable USB support (specific devices specified at runtime through the +# monitor window) +#usb=1 +# Enable USB mouse support (only enable one of the following, `mouse' for +# PS/2 protocol relative mouse, `tablet' for +# absolute mouse) +#usbdevice='mouse' +#usbdevice='tablet' + +#----------------------------------------------------------------------------- +# Set keyboard layout, default is en-us keyboard. +#keymap='de' + +#----------------------------------------------------------------------------- +# Enable/disable xen platform PCI device, default=1 (enabled) +#xen_platform_pci=1 + +#============================================================================ +EOF diff --git a/os-plugins/plugins/xen/files/machine.include b/os-plugins/plugins/xen/files/machine.include new file mode 100644 index 00000000..06848949 --- /dev/null +++ b/os-plugins/plugins/xen/files/machine.include @@ -0,0 +1,167 @@ +# This is an machine template for run-virt.include of the Xen plugin. +# This template was taken from an example in openSUSE 11.2 + +cat <<EOF +# -*- mode: python; -*- +#============================================================================ +# Python configuration setup for 'xm create'. +# This configuration was created through $0 on $(date) +#============================================================================ + +#---------------------------------------------------------------------------- +# Kernel image file and (optional) ramdisk (initrd). +kernel = "${xen_kernel}" +ramdisk = "${xen_ramdisk}" + +# Or use domUloader instead of kernel/ramdisk to get kernel from domU FS +#bootloader = "/usr/lib/xen/boot/domUloader.py" +#bootentry = "hda1:/${xen_kernel},/${xen_ramdisk}" +# TODO: check these: +#bootargs="--entry=xvda2:/boot/vmlinuz-xen,/boot/initrd-xen" + +localtime=0 + +# The domain build function. Default is 'linux', HVM domain uses 'hvm'. +builder = 'linux' + +# Initial memory allocation (in megabytes) for the new domain. +memory = ${mem} + +# A name for your domain. All domains must have different names. +name = "${vm_name}" + +# List of which CPUS this domain is allowed to use, default Xen picks +#cpus = "" # leave to Xen to pick +#cpus = "0" # all vcpus run on CPU0 +#cpus = "0-3,5,^1" # run on cpus 0,2,3,5 +#cpus = "${xen_cpus}" + +# Number of Virtual CPUS to use, default is 1 +#vcpus = ${xen_vcpus} + +#---------------------------------------------------------------------------- +# Define network interfaces. + +# By default, no network interfaces are configured. You may have one created +# with sensible defaults using an empty vif clause: +# vif = [ '' ] +# or optionally override backend, bridge, ip, mac, script, type, or vifname: +# vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ] +# or more than one interface may be configured: +# vif = [ '', 'bridge=xenbr1' ] +vif = [ '${xen_vif}' ] + +#---------------------------------------------------------------------------- +# Define the disk devices you want the domain to have access to, and +# what you want them accessible as. +# Each disk entry is of the form phy:UNAME,DEV,MODE +# where UNAME is the device, DEV is the device name the domain will see, +# and MODE is r for read-only, w for read-write. +# disk = [ 'phy:hda1,hda1,w' ] +${xen_disk} + +#---------------------------------------------------------------------------- +# Define frame buffer device. +# By default, no frame buffer device is configured. +# To create one using the SDL backend and sensible defaults: +# vfb = [ 'type=sdl' ] +# This uses environment variables XAUTHORITY and DISPLAY. You +# can override that: +# vfb = [ 'type=sdl,xauthority=/home/bozo/.Xauthority,display=:1' ] +# To create one using the VNC backend and sensible defaults: +# vfb = [ 'type=vnc' ] +# The backend listens on 127.0.0.1 port 5900+N by default, where N is +# the domain ID. You can override both address and N: +# vfb = [ 'type=vnc,vnclisten=127.0.0.1,vncdisplay=1' ] +# Or you can bind the first unused port above 5900: +# vfb = [ 'type=vnc,vnclisten=0.0.0.0,vnunused=1' ] +# You can override the password: +# vfb = [ 'type=vnc,vncpasswd=MYPASSWD' ] +# Empty password disables authentication. Defaults to the vncpasswd +# configured in xend-config.sxp. + +#---------------------------------------------------------------------------- +# Define to which TPM instance the user domain should communicate. +# The vtpm entry is of the form 'instance=INSTANCE,backend=DOM' +# where INSTANCE indicates the instance number of the TPM the VM +# should be talking to and DOM provides the domain where the backend +# is located. +# Note that no two virtual machines should try to connect to the same +# TPM instance. The handling of all TPM instances does require +# some management effort in so far that VM configration files (and thus +# a VM) should be associated with a TPM instance throughout the lifetime +# of the VM / VM configuration file. The instance number must be +# greater or equal to 1. +#vtpm = [ 'instance=1,backend=0' ] + +#---------------------------------------------------------------------------- +# Set the kernel command line for the new domain. +# You only need to define the IP parameters and hostname if the domain's +# IP config doesn't, e.g. in ifcfg-eth0 or via DHCP. +# You can use 'extra' to set the runlevel and custom environment +# variables used by custom rc scripts (e.g. VMID=, usr= ). + +# Set if you want dhcp to allocate the IP address. +dhcp="${xen_dhcp}" +# Set netmask. +#netmask= +# Set default gateway. +#gateway= +# Set the hostname. +hostname= "${hostname}" + +# Set root device (eg. /dev/hda1). +root = "${xen_root}" + +# Root device for nfs. +#root = "/dev/nfs" +# The nfs server. +#nfs_server = '169.254.1.0' +# Root directory on the nfs server. +#nfs_root = '/full/path/to/root/directory' + +# Extra arguments to pass to the kernel. +# Eg: set runlevel +extra = "${xen_extra}" + +#---------------------------------------------------------------------------- +# Configure the behaviour when a domain exits. There are three 'reasons' +# for a domain to stop: poweroff, reboot, and crash. For each of these you +# may specify: +# "destroy", meaning that the domain is cleaned up as normal; +# "restart", meaning that a new domain is started in place of the old +# one; +# "preserve", meaning that no clean-up is done until the domain is +# manually destroyed (using xm destroy, for example); or +# "rename-restart", meaning that the old domain is not cleaned up, but is +# renamed and a new domain started in its place. +# In the event a domain stops due to a crash, you have the additional options: +# "coredump-destroy", meaning dump the crashed domain's core and then destroy; +# "coredump-restart', meaning dump the crashed domain's core and the restart. +# The default is +# on_poweroff = 'destroy' +# on_reboot = 'restart' +# on_crash = 'restart' +#on_poweroff = 'destroy' +#on_reboot = 'restart' +#on_crash = 'restart' + +#----------------------------------------------------------------------------- +# Configure PVSCSI devices: +# PDEV gives physical SCSI device to be attached to specified guest +# domain by one of the following identifier format. +# - XX:XX:XX:XX (4-tuples with decimal notation which shows +# "host:channel:target:lun") +# - /dev/sdxx or sdx +# - /dev/stxx or stx +# - /dev/sgxx or sgx +# - result of 'scsi_id -gu -s'. +# ex. # scsi_id -gu -s /block/sdb +# 36000b5d0006a0000006a0257004c0000 +# VDEV gives virtual SCSI device by 4-tuples (XX:XX:XX:XX) as +# which the specified guest domain recognize. +#vscsi = [ 'PDEV, VDEV' ] +#vscsi = [ '/dev/sdx, 0:0:0:0' ] + +#============================================================================ +EOF diff --git a/os-plugins/plugins/xen/files/run-virt.include b/os-plugins/plugins/xen/files/run-virt.include new file mode 100644 index 00000000..43213e34 --- /dev/null +++ b/os-plugins/plugins/xen/files/run-virt.include @@ -0,0 +1,157 @@ +# run-virt.include +# ----------------------------------------------------------------------------- +# Copyright (c) 2009..2010 - RZ Uni Freiburg +# Copyright (c) 2009..2010 - OpenSLX GmbH +# +# This program/file 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 feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# ----------------------------------------------------------------------------- +# run-virt.include +# - Include script for running Xen on an OpenSLX client via the run-virt.sh +# or run-vmgrid.sh +################################################################################ + +################################################################################ +### Include general configuration +################################################################################ +if [ -f ${OPENSLX_DEFAULT_CONFDIR}/plugins/${self}/${self}.conf ]; then + . ${OPENSLX_DEFAULT_CONFDIR}/plugins/${self}/${self}.conf +else + writelog "Problems reading config file of ${self} plugin" + exit 1 +fi + +################################################################################ +### Declaration of default variables +################################################################################ + +PLUGINCONFXEN="${PLUGINCONFROOT}/${self}" +# create TMPDIR for all users +mkdir -m 1777 /tmp/${self} 2>/dev/null +# dir for configs +confdir="/tmp/${self}/${USER}/${VM_ID}" +# use vm_shortname for VM name since vm_name can be very long +# add id so we can start more tahn one of the same image +vm_name="${vm_shortname}-${VM_ID}" +conffile=${confdir}/${vm_name} +# define dirs and files which can be removed after exit, be carefull! +rm -rf ${confdir} 2>/dev/null +mkdir -p ${confdir} 2>/dev/null + +xen_kernel=${kernel:-"/boot/vmlinuz-xen"} +xen_ramdisk=${initramfs:-"/boot/initrd-xen"} +xen_extra="xencons=tty 3" +[ -n "${imgname}" ] && xen_disk="disk = [ 'file:${vmpath},hda1,r' ]" + +writelog "Directories:" +writelog "\tConfig dir:\t\t$confdir" + +################################################################################ +### Hardware checks +################################################################################ + +# memory part equal to vmware plugin +# percentage of memory to use for virtualbox in standard case +if [ -n "${forcemem}" ]; then + mem="${forcemem}" +else + permem=30 + if [ "${totalmem}" -ge "1600" ]; then + permem=40 + fi + # check if /tmp is on harddisk + if grep -qe "/dev/.* /tmp " /proc/mounts ; then + permem=60 + id44="1" + # Hack, if more than 2,5G RAM use 40% of Ram and write vmem into Ram as well + # (40% vmware | 40% confdir(vmem...) | 20% host + # VMplayer 2+ issue + # TODO: makes this sense for vbox? + #if [ "${totalmem}" -ge "2500" ]; then + #permem=40 + #rmdir ${snapshotdir} + #snapshotdirold=${snapshotdir} + #snapshotdir=/dev/shm/${self}/${USER}/${VM_ID} + #mkdir -p ${snapshotdir} + #ln -sf ${snapshotdir} ${snapshotdirold} + #fi + fi + mem=$(expr ${totalmem} / 100 \* ${permem}) + if [ "${id44}" = "1" ]; then + memhost=$(expr ${totalmem} - ${mem}) + else + memhost=$(expr ${totalmem} - ${mem} - ${mem}) + fi + #permem=40 + #mem=$(expr ${totalmem} * ${permem}) + if [ "${mem}" -lt "256" ] || [ "${memhost}" -lt "256" ]; then + writelog "Memory out of range: ${mem} MB (guest) / ${memhost} MB (host)!" + writelog "Min. 256 MB for host and guest!" + exit 1 + fi +fi + +# translate network kinds (nat, bridged, host-only) +case "${network_kind}" in + bridge*) + xen_vif="mac=$macaddr, bridge=br0" + ;; + *) + xen_vif="mac=$macaddr" +esac +xen_dhcp="dhcp" # off + +# translate boot, use if set else set to disk +xen_root=/dev/hda1 +case ${boot} in + n*|tftp) + pxe_label=$(grep -o 'pxe_label param=.*"' ${xmlfile} \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') + pxe_label=$(grep -A 3 "^LABEL *${pxe_label}" \ + ${xen_tftpdir}/pxelinux.cfg/default 2>/dev/null \ + | grep "^ *KERNEL ") + if [ -n "${pxe_label}" ] && [ -n "${xen_tftpdir}" ]; then + xen_root=/dev/nfs + xen_kernel="${xen_tftpdir}/$(echo ${pxe_label} \ + | awk -F " --- " '{print $2}' | awk '{print $1}')" + xen_ramdisk="${xen_tftpdir}/$(echo ${pxe_label} \ + | awk -F " --- " '{print $3}')" + fi + ;; + # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM + *) + xen_root=/dev/hda1 + ;; +esac + +[ ${diskless} -eq 0 ] && writelog "Diskimage:" +[ ${diskless} -eq 0 ] && writelog "\tMachine diskfile:\t$vmpath" +writelog "Virtual Hardware:" +writelog "\tGuest RAM:\t\t${mem} MB" +# echo nur wenn memhost gesetzt +[ -n "${memhost}" ] && writelog "\tHost RAM:\t\t${memhost} MB" +writelog "\tMAC address:\t\t$macaddr" + +################################################################################ +### Pepare and configure virtual machine and disk image +################################################################################ + +. ${PLUGINCONFXEN}/machine.include > ${conffile} + +################################################################################ +### finally set env for run-virt.sh +################################################################################ + +# set the variables appropriately (several interfaces with different names) +VIRTCMD=$(which xm 2>/dev/null) +# '-c' for console, no graphical output available, later vnc possible +VIRTCMDOPTS="create -c ${conffile}" + +# set headless mode +VIRTCMDHL=$(which xm 2>/dev/null) +VIRTCMDOPTSHL="create ${conffile}" diff --git a/os-plugins/plugins/xen/init-hooks/10-have-nw-modules/xennet.sh b/os-plugins/plugins/xen/init-hooks/10-have-nw-modules/xennet.sh new file mode 100644 index 00000000..d514b68d --- /dev/null +++ b/os-plugins/plugins/xen/init-hooks/10-have-nw-modules/xennet.sh @@ -0,0 +1,4 @@ +# load xennet if necessary, usualy within a NFS VM +if grep -q "Xen Virtual Ethernet Card" /etc/hwinfo.netcard-usbctrl; then + modprobe xennet >/tmp/xennet.log 2>&1 +fi diff --git a/os-plugins/plugins/xen/init-hooks/20-nw-bridge-config/bridge.sh b/os-plugins/plugins/xen/init-hooks/20-nw-bridge-config/bridge.sh new file mode 100755 index 00000000..6aabe8ad --- /dev/null +++ b/os-plugins/plugins/xen/init-hooks/20-nw-bridge-config/bridge.sh @@ -0,0 +1,30 @@ +#!/bin/ash +# Copyright (c) 2009 - 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 feedback to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org +# +# Init hook to create a bridge on the active network interface +# (should be kept identical to the files of virtualbox and qemukvm plugins) +############################################################################# + +local bridge=br0 +local brnwif=${nwif} +local nwifmac=${macaddr} + +# bridge 0 already defined or some other problem +brctl addbr ${bridge} || exit 0 +brctl stp ${bridge} 0 +brctl setfd ${bridge} 0.000000000001 +ip link set addr ${nwifmac} ${bridge} +ip link set dev ${nwif} up +brctl addif ${bridge} ${nwif} + +# fixme: sending back the variable to init does not work properly at the +# moment +nwif=${bridge} |