summaryrefslogtreecommitdiffstats
path: root/src/os-plugins/plugins/xen/files/run-virt.include
diff options
context:
space:
mode:
Diffstat (limited to 'src/os-plugins/plugins/xen/files/run-virt.include')
-rw-r--r--src/os-plugins/plugins/xen/files/run-virt.include157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/os-plugins/plugins/xen/files/run-virt.include b/src/os-plugins/plugins/xen/files/run-virt.include
new file mode 100644
index 00000000..36a1d1f4
--- /dev/null
+++ b/src/os-plugins/plugins/xen/files/run-virt.include
@@ -0,0 +1,157 @@
+# run-virt.include
+# -----------------------------------------------------------------------------
+# Copyright (c) 2010 - RZ Uni Freiburg
+# Copyright (c) 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}"