diff options
author | Michael Janczyk | 2010-03-26 22:09:31 +0100 |
---|---|---|
committer | Michael Janczyk | 2010-03-26 22:09:31 +0100 |
commit | 3e8723555bb0a1be3e27330275c4d6b2da9945df (patch) | |
tree | bd85d3e02dda631f32f2c69ff3fae27836c13a71 | |
parent | added support for rw disks and netboot (diff) | |
download | core-3e8723555bb0a1be3e27330275c4d6b2da9945df.tar.gz core-3e8723555bb0a1be3e27330275c4d6b2da9945df.tar.xz core-3e8723555bb0a1be3e27330275c4d6b2da9945df.zip |
NAT TFTP boot with VBox.
rwimg support added
-rw-r--r-- | os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm | 52 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/XX_virtualbox.sh | 5 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/VirtualBox.xml | 41 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/machine.include | 4 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/run-virt.include | 98 | ||||
-rw-r--r-- | os-plugins/plugins/virtualbox/files/virtualbox.include | 4 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm | 14 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/XX_vmgrid.sh | 29 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/run-vmgrid.sh | 54 | ||||
-rw-r--r-- | os-plugins/plugins/vmgrid/files/vmgrid | 10 |
10 files changed, 170 insertions, 141 deletions
diff --git a/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm b/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm index be7f2cb5..900d08a9 100644 --- a/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm +++ b/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm @@ -45,7 +45,8 @@ sub getInfo stateless client. End-of-Here precedence => 70, - required => [ qw( desktop ) ], + # headless mode does not require a desktop! + #required => [ qw( desktop ) ], }; } @@ -67,7 +68,7 @@ sub getAttrInfo should the 'virtualbox'-plugin be executed during boot? End-of-Here content_regex => qr{^(0|1)$}, - content_descr => '1 means active - 0 means inactive', + content_descr => '1 for active, 0 for inactive', default => '1', }, # attribute 'imagesrc' defines where we can find virtualbox images @@ -77,10 +78,9 @@ sub getAttrInfo description => unshiftHereDoc(<<' End-of-Here'), Where do we store our virtualbox images? NFS? Filesystem? End-of-Here - #TODO: check if the input is valid - #content_regex => qr{^(0|1)$}, - content_descr => 'Allowed values: local path or URI', - default => '', + content_regex => qr{^(/|nfs://)}, + content_descr => 'local path or URI or "-" (unset)', + default => undef, }, # attribute 'bridge' defines if bridged network mode should be # switched on @@ -92,10 +92,46 @@ sub getAttrInfo to the ethernet the host is connected to) be enabled End-of-Here content_regex => qr{^(0|1)$}, - content_descr => 'Allowed values: 0 or 1', + content_descr => '0 or 1', default => '1', }, - + # attribute 'mem' defines if memory should be forced + 'virtualbox::mem' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Do you want to force a ralative amount of RAM? + (Not implemented right now!) + End-of-Here + content_regex => qr{^(\d\d??)$}, + content_descr => 'Between 0 - 99', + default => undef, + }, + # attribute 'kvm' defines if KVM modules should be forced + 'virtualbox::kvm' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Do you want to force the usage of KVM modules where applicable? + (Not implemented right now!) + End-of-Here + content_regex => qr{^(0|1)$}, + content_descr => '0 or 1', + default => undef, + }, + # attribute 'tftpdir' defines TFTP dir for network boots /w NAT + 'virtualbox::tftpdir' => { + applies_to_systems => 1, + applies_to_clients => 1, + description => unshiftHereDoc(<<' End-of-Here'), + Do you want to define a stage 4 TFTP dir for netwoork boots when + using NAT? + Hint: Mount your TFTP ro via NFS to a local dir + End-of-Here + content_regex => qr{^(/)}, + content_descr => 'local path or "-" (unset)', + default => undef, + }, }; } diff --git a/os-plugins/plugins/virtualbox/XX_virtualbox.sh b/os-plugins/plugins/virtualbox/XX_virtualbox.sh index 4599b197..07e58428 100644 --- a/os-plugins/plugins/virtualbox/XX_virtualbox.sh +++ b/os-plugins/plugins/virtualbox/XX_virtualbox.sh @@ -30,8 +30,9 @@ if [ -e ${CONFFILE} ]; then if [ $virtualbox_active -ne 0 2>/dev/null ]; then [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'virtualbox' os-plugin ..."; + # load general configuration - . /initramfs/machine-setup + . /etc/initramfs-setup # get source of virtualbox image server (get type, server and path) if strinstr "/" "${virtualbox_imagesrc}" ; then @@ -55,7 +56,7 @@ if [ -e ${CONFFILE} ]; then cp ${PLUGINDIR}/*.include ${PLUGINCONFDIR} # copy ${CONFFILE} to ${PLUGINCONFDIR} just in case cp ${CONFFILE} ${PLUGINCONFDIR} - + # # TODO: create rawdisk if requested # # create raw disk # for part in $(grep -qE " 44 | 45 " /etc/disk.partition); do diff --git a/os-plugins/plugins/virtualbox/files/VirtualBox.xml b/os-plugins/plugins/virtualbox/files/VirtualBox.xml deleted file mode 100644 index d9a36795..00000000 --- a/os-plugins/plugins/virtualbox/files/VirtualBox.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0"?> -<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.9-linux"> - <Global> - <ExtraData> - <ExtraDataItem name="GUI/Input/AutoCapture" value="true"/> - <ExtraDataItem name="GUI/Input/HostKey" value="65300"/> - <ExtraDataItem name="GUI/LastVMSelected" value="00000000-0000-0000-0000-00505601fe23"/> - <ExtraDataItem name="GUI/LastWindowPostion" value="455,235,770,550"/> - <ExtraDataItem name="GUI/LicenseAgreed" value="7"/> - <ExtraDataItem name="GUI/MaxGuestResolution" value="any"/> - <ExtraDataItem name="GUI/SUNOnlineData" value="triesLeft=0"/> - <ExtraDataItem name="GUI/SuppressMessages" value=",remindAboutAutoCapture,confirmInputCapture,remindAboutWrongColorDepth,confirmGoingFullscreen,remindAboutMouseIntegrationOn,remindAboutMouseIntegrationOff,showRuntimeError.warning.DevATA_DISKFULL,remindAboutPausedVMInput,confirmVMReset"/> - <ExtraDataItem name="GUI/TrayIcon/Enabled" value="false"/> - <ExtraDataItem name="GUI/UpdateCheckCount" value="2"/> - <ExtraDataItem name="GUI/UpdateDate" value="never"/> - </ExtraData> - <MachineRegistry> - <MachineEntry uuid="{00000000-0000-0000-0000-00505601fe23}" src="Machines/WinXP-Standard-01/WinXP-Standard-01.xml"/> - </MachineRegistry> - <MediaRegistry> - <HardDisks> - <HardDisk uuid="{9cc859b2-955c-4047-9c34-8e3cb164f50e}" location="/tmp/virtualbox/np4/HardDisks/WinXP-Standard-01.vdi" format="VDI" type="Normal"> - <HardDisk uuid="{88bc8b6d-f248-468a-95fe-318084904f8b}" location="/tmp/virtualbox/np4/HardDisks/empty-diff-00.vdi" format="VDI"/> - <HardDisk uuid="{42f5033e-9913-41ff-8cba-1c986ba5db8d}" location="/tmp/virtualbox/np4/HardDisks/empty-diff-01.vdi" format="VDI"/> - <HardDisk uuid="{1b66fdcb-8ede-4bb8-aaec-417bc2074633}" location="/tmp/virtualbox/np4/HardDisks/empty-diff-02.vdi" format="VDI"/> - <HardDisk uuid="{563d2c5e-c9a2-4fbb-be51-8d279a558e6c}" location="/tmp/virtualbox/np4/HardDisks/empty-diff-03.vdi" format="VDI"/> - <HardDisk uuid="{efff0c85-c1c8-420d-a25f-6e66f117e1f2}" location="/tmp/virtualbox/np4/HardDisks/empty-diff-04.vdi" format="VDI"/> - </HardDisk> - </HardDisks> - <DVDImages/> - <FloppyImages/> - </MediaRegistry> - <NetserviceRegistry> - <DHCPServers> - <DHCPServer networkName="HostInterfaceNetworking-vboxnet0" IPAddress="192.168.56.100" networkMask="255.255.255.0" lowerIP="192.168.56.101" upperIP="192.168.56.254" enabled="1"/> - </DHCPServers> - </NetserviceRegistry> - <SystemProperties defaultMachineFolder="/tmp/virtualbox/np4/Machines" defaultHardDiskFolder="/tmp/virtualbox/np4/HardDisks" defaultHardDiskFormat="VDI" remoteDisplayAuthLibrary="VRDPAuth" webServiceAuthLibrary="VRDPAuth" LogHistoryCount="3"/> - <USBDeviceFilters/> - </Global> -</VirtualBox> diff --git a/os-plugins/plugins/virtualbox/files/machine.include b/os-plugins/plugins/virtualbox/files/machine.include index e11f95c5..125e45cd 100644 --- a/os-plugins/plugins/virtualbox/files/machine.include +++ b/os-plugins/plugins/virtualbox/files/machine.include @@ -1,5 +1,5 @@ # Include file (machine template) for run-virt.include of the virtualbox plugin -cat <<EOF +cat << EOF > "${machconfig}" <?xml version="1.0"?> <VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.9-linux"> <Machine uuid="{${machineuuid}}" name="${vm_name}" OSType="${vmostype}"> <!-- stateFile="Snapshots/{1e5f5eb0-6b13-4407-9906-36114eca1e61}.sav" lastStateChange="2010-03-09T19:48:32Z"> --> @@ -110,7 +110,7 @@ cat <<EOF <StorageControllers> <StorageController name="IDE-Controller" type="PIIX4" PortCount="2"> <AttachedDevice type="HardDisk" port="0" device="0"> - <Image uuid="{${snapshotuuid}}"/> + <Image uuid="{${imageuuid}}"/> </AttachedDevice> <!-- <AttachedDevice passthrough="false" type="DVD" port="0" device="0"> diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include index 11f8d0eb..6d300044 100644 --- a/os-plugins/plugins/virtualbox/files/run-virt.include +++ b/os-plugins/plugins/virtualbox/files/run-virt.include @@ -31,6 +31,7 @@ fi ################################################################################ PLUGINCONFVIRTUALBOX="${PLUGINCONFROOT}/${self}" +PLUGINDIRVIRTUALBOX="${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}" # create TMPDIR for all users TMPDIR=/tmp/${self} mkdir -m 1777 ${TMPDIR} 2>/dev/null @@ -48,15 +49,14 @@ diskfolder="${confdir}/HardDisks" snapshotdir=${machfolder}/${vm_shortname}/Snapshots mkdir -p ${diskfolder} ${snapshotdir} 2>/dev/null -# configure rwimg -if [ "${imgmode}" = "rwimg" ] && ! [ -e "${vmpath}" ]; then +# configure our own rwimg, empty image which we support +if [ "${imgmode}" = "rwimg" ]; then # what is our rwimg called? - imgname="${imgname}.vdi" + imgname="${vm_shortname}.vdi" vmpath=${imgpath}/${imgname} - cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/rwimg.vdi.gz \ - | gunzip > "${vmpath}" - # static rw share image uuid - #rwimguuid="ab20cb01-2d08-4d73-a33c-5594c5d0b8cb" + if ! [ -e "${vmpath}" ]; then + cat ${PLUGINDIRVIRTUALBOX}/rwimg.vdi.gz | gunzip > "${vmpath}" + fi fi # link to image @@ -65,9 +65,9 @@ ln -sf ${vmpath} ${diskfile} # check the file type if echo ${imgname} | grep -iE "vdi|vmdk|vhd" >/dev/null 2>&1; then - imgtype=$(echo ${imgname##*.} | tr [a-z] [A-Z]) + imgfmt=$(echo ${imgname##*.} | tr [a-z] [A-Z]) else - writelog "${imgname} is not a valid image type (vdi|vmdk|vhd), exiting!" + writelog "${imgname} is not a valid image format (vdi|vmdk|vhd), exiting!" exit 1 fi @@ -105,11 +105,42 @@ 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, only if rwimg.vdi not used +# get UUID of VBox image diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID \ | awk '{print $2}') +# make disk immutable +imgtype="Immutable" # snapshot UUID is static snapshotuuid="88bc8b6d-f248-468a-95fe-318084904f8b" +# imageuuid in machine.include, dafault snapshotuuid +imageuuid=${snapshotuuid} + +# check if rw image +# remove disk and add rwimg if set +if echo "${imgmode}" | grep -q rw; then + # lock existing? + if [ -e "${vmpath}.lock" ]; then + writelog "This rw image is already in use: ${vmpath}, exiting!" + writelog "Remove lock if you are shure that this is not the case" + exit 1 + # image rw? + elif ! [ -w ${vmpath} ]; then + writelog "You defined mode rw, but image is not rw! \c" + writelog "Please correct, exiting!" + exit 1 + fi + # add lock + touch "${vmpath}.lock" + # remove lock after VM stopped + RMDIRS="${RMDIRS} ${vmpath}.lock" + imgtype="Normal" + # replace image uuid in machine config + imageuuid=${diskuuid} +else + # use temp disk as snapshot + cat ${PLUGINDIRVIRTUALBOX}/empty-diff.vdi.gz \ + | gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi" +fi # TODO: MEM muss noch angepasst werden. Maschine crasht wenn nehr als 50% MEM # memory part equal to vmware plugin @@ -171,7 +202,6 @@ case "${network_kind}" in ;; *) network_kind="NAT" - ;; esac # external GUI @@ -207,6 +237,16 @@ if [ -n "${boot}" ]; then case ${boot} in n*) # usually support for a,c,d,n, stands for Floppy, HD, CD-ROM, Network boot="Network" + if [ "${network_kind}" = "NAT" ] && [ -n "${virtualbox_tftpdir}" ]; then + # remove spaces from VM name to avoid Problems /w TFTP in NAT + vm_name=$(echo ${vm_name} | sed -e "s, ,-,g") + # link TFTP dir for NAT TFTP boots + mkdir -p ${confdir}/TFTP + cp ${virtualbox_tftpdir}/pxelinux.0 ${confdir}/TFTP/${vm_name}.pxe + for i in $(ls ${virtualbox_tftpdir}); do + ln -sf ${virtualbox_tftpdir}/${i} ${confdir}/TFTP/${i} + done + fi ;; # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM *) @@ -219,8 +259,9 @@ fi writelog "\tSnapshots dir:\t\t$snapshotdir" writelog "Diskimage:" -writelog "\tDisk type:\t\t$imgtype" 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" @@ -246,35 +287,19 @@ writelog "\tShared Folders '${sharename}':\t${sharepath}" ### Pepare and configure virtual machine and disk image ################################################################################ -# TODO: date wichtig? -#date="$(date +%Y-%m-%dT%H:%M:%SZ)" -. ${PLUGINCONFVIRTUALBOX}/virtualbox.include > "${confdir}/VirtualBox.xml" +# create Virtualbox.xml +. ${PLUGINCONFVIRTUALBOX}/virtualbox.include -# remove disk and add rwimg if set -if echo "${imgmode}" | grep -q rw; then - if [ -e "${vmpath}.lock" ]; then - writelog "This rw image is already in use: ${vmpath}, exiting!" - writelog "Remove lock if you are shure that this is not the case" - exit 1 - fi - # add lock - touch "${vmpath}.lock" - # remove lock after VM stopped - RMDIRS="${RMDIRS} ${vmpath}.lock" - rwimghd="<HardDisk uuid=\"{${diskuuid}}\" location=\"${diskfile}\"" - rwimghd="${rwimghd} format=\"VDI\" type=\"Normal\"/>" - sed -i "/<HardDisk uuid/d;s,</HardDisk>,${rwimghd}," \ - "${confdir}/VirtualBox.xml" - # replace image uuid in machine config - snapshotuuid=${diskuuid} +# remove snapshot disk when using rw images +if [ "${imgtype}" != "Immutable" ]; then + sed -i "/${snapshotuuid}/d" "${confdir}/VirtualBox.xml" fi # TODO: add rawdisk if requested #"raw.vmdk" format="VMDK" type="Writethrough"/> -# shortened date YYYY-MM-DD -#date=${date%T*} -. ${PLUGINCONFVIRTUALBOX}/machine.include > "${machconfig}" +# create machine.xml +. ${PLUGINCONFVIRTUALBOX}/machine.include # add ssh port if linux and NAT if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then @@ -291,9 +316,6 @@ if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then writelog "\tGuest SSH port:\t\t${vmsshport}" fi -cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/empty-diff.vdi.gz | \ - gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi" - ################################################################################ ### finally set env for run-virt.sh ################################################################################ diff --git a/os-plugins/plugins/virtualbox/files/virtualbox.include b/os-plugins/plugins/virtualbox/files/virtualbox.include index e0c41290..49b3ce61 100644 --- a/os-plugins/plugins/virtualbox/files/virtualbox.include +++ b/os-plugins/plugins/virtualbox/files/virtualbox.include @@ -1,5 +1,5 @@ # Include file (general template) for run-virt.include of the virtualbox plugin -cat <<EOF +cat << EOF > "${confdir}/VirtualBox.xml" <?xml version="1.0"?> <VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.9-linux"> <!-- 1.7-linux --> <Global> @@ -20,7 +20,7 @@ cat <<EOF </MachineRegistry> <MediaRegistry> <HardDisks> - <HardDisk uuid="{${diskuuid}}" location="${diskfile}" format="${imgtype}" type="Immutable"> + <HardDisk uuid="{${diskuuid}}" location="${diskfile}" format="${imgfmt}" type="${imgtype}"> <HardDisk uuid="{${snapshotuuid}}" location="${snapshotdir}/{${snapshotuuid}}.vdi" format="VDI" autoReset="true"/> </HardDisk> </HardDisks> diff --git a/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm b/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm index c3186251..5ee52d0c 100644 --- a/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm +++ b/os-plugins/plugins/vmgrid/OpenSLX/OSPlugin/vmgrid.pm @@ -73,7 +73,7 @@ sub getAttrInfo End-of-Here content_regex => qr{^(vmware|virtualbox|qemukvm|xen)$}, #openvz|vserver - content_descr => 'possible values: vmware, virtualbox, qemukvm, xen', + content_descr => 'vmware, virtualbox, qemukvm, xen', #openvz, vserver default => undef, }, @@ -141,7 +141,7 @@ sub getAttrInfo (only if supported by plugin) End-of-Here content_regex => qr{^(0|1)$}, - content_descr => 'possible values: "0", "1" or "-" (for unset)', + content_descr => '"0", "1" or "-" (for unset)', default => undef, }, 'vmgrid::maxvcpus' => { @@ -153,7 +153,7 @@ sub getAttrInfo (only if supported by plugin) End-of-Here content_regex => qr{^(1|2|4|8|16)$}, - content_descr => 'possible values: 1, 2, 4, 8, 16', + content_descr => '1, 2, 4, 8, 16', default => undef, }, 'vmgrid::minvcpus' => { @@ -165,7 +165,7 @@ sub getAttrInfo (only if supported by plugin) End-of-Here content_regex => qr{^(1|2|4|8|16)$}, - content_descr => 'possible values: 1, 2, 4, 8, 16', + content_descr => '1, 2, 4, 8, 16', default => undef, }, 'vmgrid::memratio' => { @@ -183,7 +183,7 @@ sub getAttrInfo (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 => 'vals: \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' => { @@ -195,7 +195,7 @@ sub getAttrInfo (only if supported by plugin) End-of-Here content_regex => qr{^(1|2|3|4|5|6|7|8|9)}, - content_descr => 'values can be absolute or relative e.g. 512 or 50%', + content_descr => 'absolute or relative e.g. 512 or 50%', default => undef, }, 'vmgrid::minram' => { @@ -207,7 +207,7 @@ sub getAttrInfo (only if supported by plugin) End-of-Here content_regex => qr{^(1|2|3|4|5|6|7|8|9)}, - content_descr => 'values can be absolute or relative e.g. 512 or 50%', + content_descr => 'absolute or relative e.g. 512 or 50%', default => undef, }, }; diff --git a/os-plugins/plugins/vmgrid/XX_vmgrid.sh b/os-plugins/plugins/vmgrid/XX_vmgrid.sh index 39b8501a..3cac7c12 100644 --- a/os-plugins/plugins/vmgrid/XX_vmgrid.sh +++ b/os-plugins/plugins/vmgrid/XX_vmgrid.sh @@ -15,9 +15,6 @@ # include default directories . /etc/openslx.conf -# include functions -. /etc/functions - CONFFILE="/initramfs/plugin-conf/vmgrid.conf" PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/vmgrid VIRTUALIZATIONPLUGIN=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualization @@ -37,7 +34,9 @@ if [ -f $CONFFILE ]; then [ $DEBUGLEVEL -gt 0 ] && echo "executing the 'vmgrid' os-plugin ..." # load general configuration - . /initramfs/machine-setup + . /etc/initramfs-setup + # include functions + . /etc/functions testmkd ${PLUGINCONFDIR} # create folder for virtual virtualization plugin @@ -63,15 +62,14 @@ if [ -f $CONFFILE ]; then fi # create rw share - testmkd 1777 ${RWSHARE}/rwdir + 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 - # use rwdir because we want to use rwimg.vdi as well - testmkd /mnt/media/${id45part}/vmgrid/rwdir - mount --bind -n /mnt/media/${id45part}/vmgrid/rwdir ${RWSHARE}/rwdir \ + testmkd /mnt/media/${id45part}/vmgrid + mount --bind -n /mnt/media/${id45part}/vmgrid ${RWSHARE} \ >>/tmp/vmgrid.log 2>&1 fi # mount nfs rw share @@ -88,20 +86,17 @@ if [ -f $CONFFILE ]; then fsmount ${rwshareprot} ${rwshareserv} ${rwsharepath} ${rwtarget} rw # hostname? host_name=${host_name:=$clientip} - # use rwdir because we want to use rwimg.vdi as well - testmkd ${RWSHAREMNT}/${host_name}/rwdir - mount --bind ${RWSHAREMNT}/${host_name}/rwdir ${RWSHARE}/rwdir \ + testmkd ${RWSHAREMNT}/${host_name} + mount --bind ${RWSHAREMNT}/${host_name} ${RWSHARE} \ >>/tmp/vmgrid.log 2>&1 fi else - # use rwdir because we want to use rwimg.vdi as well - testmkd 1777 /mnt/tmp/vmgrid/rwdir - mount --bind -n /mnt/tmp/vmgrid/rwdir ${RWSHARE}/rwdir \ - >>/tmp/vmgrid.log 2>&1 + testmkd /mnt/tmp/vmgrid + mount --bind -n /mnt/tmp/vmgrid ${RWSHARE} >>/tmp/vmgrid.log 2>&1 fi # chmod so that everybody can write - chmod -R 1777 ${RWSHARE} - echo "vmgrid_rwdir=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf + chmod 1777 ${RWSHARE} + echo "vmgrid_rwmnt=${RWSHARE#/mnt}" >> ${PLUGINCONFDIR}/vmgrid.conf # TODO: virtual virtualization plugin diff --git a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh index ac1dd8fd..c300e9ce 100644 --- a/os-plugins/plugins/vmgrid/files/run-vmgrid.sh +++ b/os-plugins/plugins/vmgrid/files/run-vmgrid.sh @@ -38,14 +38,13 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share ################################################################################ # function to write to stdout and logfile -mkdir -m 1777 -p ${RWSHARE}/var/log/openslx 2>/dev/null 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" >> ${RWSHARE}/var/log/openslx/run-vmgrid.${USER}.$$.log + echo -e "$1" >> ${vmgrid_rwmnt}/logs/run-vmgrid.${USER}.$$.log } ################################################################################ @@ -81,6 +80,11 @@ if ! [ -r "${xmlfile}" ]; then 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) runningvms=$(expr ${runningvms} - 1) @@ -131,8 +135,7 @@ 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) $(df -h | \ - grep " /tmp$" | awk '{print $2}')" +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}" @@ -149,42 +152,47 @@ 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 }') if [ "${imgmode}" = "rwimg" ]; then # maybe you want to support the users /w an ampty rw imgae? - imgname="rwimg" + imgname="{special rw image}" + # 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") # add new path for rwimg - imgpath=${vmgrid_rwdir} + imgpath=${vmgrid_rwmnt}/specialrwimages + mkdir -m 1777 -p ${imgpath} elif echo ${imgname} 2>/dev/null | grep '/' >/dev/null 2>&1; then imgpath=$(dirname ${imgname}) imgname=$(basename ${imgname}) + vmpath=${imgpath}/${imgname} else imgpath=${vmgrid_imgpath} + vmpath=${imgpath}/${imgname} fi -# set default v path -vmpath=${imgpath}/${imgname} # check if virtual machine container file exists, only if not rwimg -if ! [ -e $vmpath ] && ! [ "${imgmode}" = "rwimg" ]; then +if ! [ -e "${vmpath}" ] && [ "${imgmode}" != "rwimg" ]; then writelog "\tVirtual machine image or directory ${vmpath} not found!" exit 1 fi writelog "\tVM file/dir:\t\t$vmpath" -# 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} - # is there an additional configuration provided? additional_config=$(grep -o 'additional_config param=.*"' ${xmlfile} | \ sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') @@ -289,7 +297,9 @@ scsi="FALSE" hddrv="ide" # add rw share -sharepath="${vmgrid_rwdir}/rwdir" +sharepath="${vmgrid_rwmnt}/folders/${vm_shortname}" +mkdir -p ${sharepath} +chmod 1777 "${vmgrid_rwmnt}/folders" sharename="share" # set hostname: using original hostname and adding string @@ -319,7 +329,9 @@ fi # start headless if [ -n "${VIRTCMDHL}" ]; then writelog "Starting ${vmgrid_virt} headless..." - ${VIRTCMDHL} ${VIRTCMDOPTSHL} + # TODO: for testing use VBox + VirtualBox + #${VIRTCMDHL} ${VIRTCMDOPTSHL} else writelog "${vmgrid_virt}: No headless mode defined, exiting!" exit 1 diff --git a/os-plugins/plugins/vmgrid/files/vmgrid b/os-plugins/plugins/vmgrid/files/vmgrid index b8806ab3..b60d8902 100644 --- a/os-plugins/plugins/vmgrid/files/vmgrid +++ b/os-plugins/plugins/vmgrid/files/vmgrid @@ -51,20 +51,24 @@ RWSHARE=/var/opt/openslx/plugins/vmgrid/share ################################################################################ # function to write to stdout and logfile -mkdir -m 1777 -p ${RWSHARE}/var/log/openslx 2>/dev/null 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" >> ${RWSHARE}/var/log/openslx/run-vmgrid.${USER}.$$.log + 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 +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") @@ -109,7 +113,7 @@ 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]},*//") + 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]},*//") |