summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Janczyk2010-03-30 20:11:25 +0200
committerMichael Janczyk2010-03-30 20:11:25 +0200
commit9a95c0c2d4a6382683725d5be0ab9171f9aed828 (patch)
tree1d6c8857351ea897ffbcf5b2a76997a0e26dac0f
parentvmgrid graphical mode ;) (diff)
downloadcore-9a95c0c2d4a6382683725d5be0ab9171f9aed828.tar.gz
core-9a95c0c2d4a6382683725d5be0ab9171f9aed828.tar.xz
core-9a95c0c2d4a6382683725d5be0ab9171f9aed828.zip
diskless boot + minor modifications, virtualization.conf /w freemem
-rw-r--r--os-plugins/plugins/virtualbox/files/machine.include2
-rw-r--r--os-plugins/plugins/virtualbox/files/run-virt.include61
-rw-r--r--os-plugins/plugins/vmgrid/XX_vmgrid.sh23
-rw-r--r--os-plugins/plugins/vmgrid/files/run-vmgrid.sh78
-rw-r--r--os-plugins/plugins/vmgrid/files/vmgrid8
5 files changed, 100 insertions, 72 deletions
diff --git a/os-plugins/plugins/virtualbox/files/machine.include b/os-plugins/plugins/virtualbox/files/machine.include
index 125e45cd..78c4bee8 100644
--- a/os-plugins/plugins/virtualbox/files/machine.include
+++ b/os-plugins/plugins/virtualbox/files/machine.include
@@ -111,7 +111,7 @@ cat << EOF > "${machconfig}"
<StorageController name="IDE-Controller" type="PIIX4" PortCount="2">
<AttachedDevice type="HardDisk" port="0" device="0">
<Image uuid="{${imageuuid}}"/>
- </AttachedDevice>
+ </AttachedDevice> <!-- PLEASE DO NOT REMOVE THIS COMMENT!!! -->
<!--
<AttachedDevice passthrough="false" type="DVD" port="0" device="0">
<Image uuid="{dcd1e32a-729f-4faa-b319-67adca15e4a4}"/>
diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include
index 8543e376..f904b5f2 100644
--- a/os-plugins/plugins/virtualbox/files/run-virt.include
+++ b/os-plugins/plugins/virtualbox/files/run-virt.include
@@ -61,12 +61,12 @@ fi
# link to image
diskfile="${diskfolder}/${imgname}"
-ln -sf ${vmpath} ${diskfile}
+[ ${diskless} -eq 0 ] && ln -sf ${vmpath} ${diskfile}
# check the file type
-if echo ${imgname} | grep -iE "vdi|vmdk|vhd" >/dev/null 2>&1; then
+if echo ${imgname} | grep -iE "vdi|vmdk|vhd" && [ ${diskless} -eq 0 ]; then
imgfmt=$(echo ${imgname##*.} | tr [a-z] [A-Z])
-else
+elif [ ${diskless} -eq 0 ]; then
writelog "${imgname} is not a valid image format (vdi|vmdk|vhd), exiting!"
exit 1
fi
@@ -92,7 +92,7 @@ writelog "Directories:"
writelog "\tConfig dir:\t\t$confdir"
writelog "\tMachines dir:\t\t$machfolder"
writelog "\tMachine config:\t\t$machconfig"
-writelog "\tHardDisks dir:\t\t$diskfolder"
+[ ${diskless} -eq 0 ] && writelog "\tHardDisks dir:\t\t$diskfolder"
################################################################################
### Hardware checks
@@ -105,9 +105,9 @@ macaddr=$(echo ${macaddr} | sed 's/://g')
machineuuid="00000000-0000-0000-0000-${macaddr}"
# cosmetical, since UUID in lower case
machineuuid=$(echo ${machineuuid} | tr [A-Z] [a-z])
-# get UUID of VBox image
-diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID \
- | awk '{print $2}')
+# get UUID of VBox image, if not diskless
+[ ${diskless} -eq 0 ] && diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} \
+ | grep UUID | awk '{print $2}')
# make disk immutable
imgtype="Immutable"
# snapshot UUID is static
@@ -136,7 +136,7 @@ if echo "${imgmode}" | grep -q rw; then
imgtype="Normal"
# replace image uuid in machine config
imageuuid=${diskuuid}
-else
+elif [ ${diskless} -eq 0 ]; then
# use temp disk as snapshot
cat ${PLUGINDIRVIRTUALBOX}/empty-diff.vdi.gz \
| gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi"
@@ -257,15 +257,14 @@ else
boot="HardDisk"
fi
-writelog "\tSnapshots dir:\t\t$snapshotdir"
+[ ${diskless} -eq 0 ] && writelog "\tSnapshots dir:\t\t$snapshotdir"
writelog "Diskimage:"
-writelog "\tDisk file:\t\t$diskfile"
-writelog "\tDisk format:\t\t$imgfmt"
-writelog "\tDisk type:\t\t$imgtype"
-writelog "\tVMostype:\t\t$vmostype"
-writelog "\tMachine UUID:\t\t$machineuuid"
-writelog "\tDisk UUID:\t\t$diskuuid"
-writelog "\tSnapshot UUID:\t\t$snapshotuuid"
+[ ${diskless} -eq 0 ] && writelog "\tDisk file:\t\t$diskfile"
+[ ${diskless} -eq 0 ] && writelog "\tDisk format:\t\t$imgfmt"
+[ ${diskless} -eq 0 ] && writelog "\tDisk type:\t\t$imgtype"
+ writelog "\tVMostype:\t\t$vmostype"
+ writelog "\tMachine UUID:\t\t$machineuuid"
+[ ${diskless} -eq 0 ] && writelog "\tDisk UUID:\t\t$diskuuid"
writelog "Virtual Hardware:"
writelog "\tGuest RAM:\t\t${mem} MB"
# echo nur wenn memhost gesetzt
@@ -273,7 +272,9 @@ writelog "\tGuest RAM:\t\t${mem} MB"
writelog "\tMAC address:\t\t$macaddr"
writelog "\tNetwork card:\t\t${vb_network_card}"
writelog "\tNetwork kind:\t\t${network_kind}"
-writelog "\tBooting from:\t\t${boot}"
+writelog "\tBooting from:\t\t${boot}\c"
+[ ${diskless} -eq 0 ] && writelog ""
+[ ${diskless} -eq 1 ] && writelog " 'diskless'"
# TODO: server start activate via xml, etc...
#writelog "\tGuest VRDP port:\t${vrdpport}"
#writelog "\tCD-ROM1:\t${cdrom0}"
@@ -301,6 +302,14 @@ fi
# create machine.xml
. ${PLUGINCONFVIRTUALBOX}/machine.include
+# if diskless remove all disks
+if [ ${diskless} -eq 1 ]; then
+ sed -i "/<HardDisk/d;/<\/HardDisk/d" "${confdir}/VirtualBox.xml"
+ sed -i "/${imageuuid}/d" ${machconfig}
+ sed -i '/AttachedDevice type="HardDisk"/d' ${machconfig}
+ sed -i "/<!-- PLEASE DO NOT REMOVE THIS COMMENT!!! -->/d" ${machconfig}
+fi
+
# add ssh port if linux and NAT
if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then
vmsshport="220${VM_ID}"
@@ -322,33 +331,17 @@ fi
# wait for a certain command to settle
# get the PID of the right process
-# TODO: not very good! But seems to work
-# TODO: not needed? KILL!!!
+# kill PID, seems to work
VBMANPID=$(pstree -p | grep VBoxXPCOMIPCD | grep -ivE "VirtualBox|VBoxHeadless"\
| sed -e "s/.*VBoxXPCOMIPCD(\(.*\)).*/\1/")
for i in $(echo ${VBMANPID}); do
kill -9 ${VBMANPID} >/dev/null 2>&1
done
-# TODO: OLD Version, NOW: KILL process
-#VBMANPID=$(pstree -p | grep VBoxXPCOMIPCD | grep -ivE "VirtualBox|VBoxHeadless"\
-# | sed -e "s/.*VBoxXPCOMIPCD(\(.*\)).*/\1/" | tail -n 1)
-#for i in {0..999}; do
-# ps aux | grep -v grep | grep VBoxXPCOMIPCD | grep -q " ${VBMANPID} " || break
-# if [ $i -eq 999 ]; then
-# kill -9 ${VBMANPID} >/dev/null 2>&1
-# writelog "Process ID ${VBMANPID} did not finish, killing!"
-# fi
-#done
# set the variables appropriately (several interfaces with different names)
VIRTCMD=$(which VirtualBox 2>/dev/null)
VIRTCMDOPTS="--startvm ${machineuuid} --start-running"
-# SDL tests
-#VIRTCMDSDL=$(which VBoxSDL 2>/dev/null)
-#VIRTCMDOPTSSDL="--startvm ${machineuuid} --fullscreen --hwvirtex --memory 1024 \
-# --fixedmode 1680 1050 24 --hostkey 302 0"
-
# set headless mode
VIRTCMDHL=$(which VBoxHeadless 2>/dev/null)
VIRTCMDOPTSHL="-s ${machineuuid}"
diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh
index 3cac7c12..d9e35dfb 100644
--- a/os-plugins/plugins/vmgrid/XX_vmgrid.sh
+++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh
@@ -39,8 +39,6 @@ if [ -f $CONFFILE ]; then
. /etc/functions
testmkd ${PLUGINCONFDIR}
- # create folder for virtual virtualization plugin
- testmkd ${VIRTUALIZATIONPLUGIN}
testmkd ${VIRTDIR}
cp $CONFFILE ${PLUGINCONFDIR}/vmgrid.conf
# create link to binpath
@@ -98,7 +96,26 @@ if [ -f $CONFFILE ]; then
chmod 1777 ${RWSHARE}
echo "vmgrid_rwmnt=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf
- # TODO: virtual virtualization plugin
+ # 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 ..."
diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh
index 21d7cbf8..e1b2ffe6 100644
--- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh
+++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh
@@ -52,6 +52,7 @@ writelog () {
################################################################################
# check if forcemem or graphical mode set
+headless=1
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
@@ -109,7 +110,7 @@ if [ $runningvms -le 0 ]; then
exit 1
fi
# check if vmchooser plugin installed
-if [ ${vmchooser_active} -eq 1 2>/dev/null ] && [ ${runningvms} -gt 1 ]; then
+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!"
@@ -151,8 +152,7 @@ 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${vmgrid_xmlpath}"
-writelog "\tVM Image dir:\t\t${vmgrid_imgpath}"
+writelog "\tVM XML dir:\t\t$(dirname ${xmlfile})"
if ! grep '<?xml' "${xmlfile}" >/dev/null 2>&1; then
writelog \
@@ -167,45 +167,66 @@ writelog "VM config:"
imgname=$(grep -io '<image_name param=.*"' ${xmlfile} | \
sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')
-# 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 ${imgname}
-vm_name=${vm_name:-"${imgname%.*}"}
-# define vm_shortname since vm_name can be very long
-vm_shortname=$(echo ${imgname%.*} | sed -e "s, ,-,g")
-# vm_name = displayname, define for old scripts
-displayname=${vm_name}
-
# 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 support the users /w an ampty rw imgae?
- imgname="{special rw image}"
+ # maybe you want to use an empty rw imgae?
# define only for writelog, will be set in the plugin include again!
- vmpath=${imgname}
- vm_shortname=$(echo ${vm_name} | awk '{print $1" "$2" "$3}' \
- | sed -e "s, ,-,g")
+ vmpath="{special rw image}"
# add new path for rwimg
imgpath=${vmgrid_rwmnt}/specialrwimages
+ unset $imgname
mkdir -m 1777 -p ${imgpath}
-elif echo ${imgname} 2>/dev/null | grep '/' >/dev/null 2>&1; then
+# 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" ]; then
+if ! [ -e "${vmpath}" ] && [ "${imgmode}" != "rwimg" ] && [ ${diskless} -eq 0 ];
+then
writelog "\tVirtual 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}')
+
+# define vm_shortname since vm_name can be very long
+if [ -n "${imgname}" ]; then
+ # if ${vm_name} not defined use ${imgname}
+ vm_name=${vm_name:-"${imgname%.*}"}
+ vm_shortname=$(basename ${imgname%.*} | sed -e "s, ,-,g")
+elif [ -n "${vm_name}" ]; then
+ vm_shortname=$(echo ${vm_name} | awk '{print $1" "$2" "$3}' \
+ | sed -e "s, ,-,g;s,-$,,;s,-$,,")
+else
+ vm_name=$(date | md5sum | awk '{print $1}')
+ vm_shortname=${vm_name}
+fi
+# 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?
@@ -253,7 +274,7 @@ elif [ -z "${xmlvirt}" ]; then
writelog "result:\t${xmlvirt}"
fi
-# TODO: confs von openvz lesen?
+# check for virt
if [ "${vmgrid_virt}" != "${xmlvirt}" ]; then
writelog "\tThe virtual machine specified in ${xmlfile}"
writelog "\tdoes not match the virtualization used here (${vmgrid_virt})"
@@ -269,9 +290,6 @@ network_kind=$(grep -io 'network param=.*"' ${xmlfile} | \
network_card=$(grep -io 'netcard param=.*"' ${xmlfile} | \
awk -F '"' '{ print $2 }')
-# get boot attr
-boot=$(grep -io 'boot 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"
@@ -342,24 +360,24 @@ else
fi
# start graphical mode
-if [ ${headless} -eq 0 2>/dev/null ]; then
+if [ ${headless} -eq 0 ]; then
if [ -z "${VIRTCMD}" ]; then
- writelog "Grapical mode not available, exiting"
+ writelog "Grapical mode not available, exiting!"
exit 1
fi
writelog "Starting ${vmgrid_virt} in graphical mode..."
- ${VIRTCMD} ${VIRTCMDOPTS}
+ ${VIRTCMD} ${VIRTCMDOPTS} 2>/dev/null
# start headless
elif [ -n "${VIRTCMDHL}" ]; then
writelog "Starting ${vmgrid_virt} in headless mode..."
- ${VIRTCMDHL} ${VIRTCMDOPTSHL}
+ ${VIRTCMDHL} ${VIRTCMDOPTSHL} 2>/dev/null
else
writelog "${vmgrid_virt}: No headless mode defined, exiting!"
exit 1
fi
-if echo "${RMDIRS}" 2>/dev/null | grep ${vmgrid_virt} >/dev/null 2>&1; then
- writelog "${vmgrid_virt} exited. Cleanning up...\c"
+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
diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid
index d93f4fbd..b75b5341 100644
--- a/os-plugins/plugins/vmgrid/files/vmgrid
+++ b/os-plugins/plugins/vmgrid/files/vmgrid
@@ -29,7 +29,7 @@ if [ -n "$1" ]; then
exit 0
else
echo "Starting run-vmgrid.sh with options '$@'"
- run-vmgrid.sh $@
+ run-vmgrid.sh $@ 2>/dev/null
exit
fi
fi
@@ -90,7 +90,7 @@ if [ ${hostmem} -lt 256 2>/dev/null ]; then
fi
# get other vm mem
-if [ ${vmchooser_active} -eq 1 ]; then
+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
@@ -156,10 +156,10 @@ for i in {1..4}; do
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]} &
+ 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 5
+ sleep 10
fi
fi
done