From 9c56eb8b8c34106fb23826b17a6e82368dc91109 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 7 Dec 2018 17:20:29 +0100 Subject: [run-virt] Download VM data as combined .tgz --- .../run-virt-includes/download_vm_metadata.inc | 28 ++++++++++++++++++---- .../vmchooser/run-virt.d/setup_virtual_floppy.inc | 11 +++++---- 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'core') diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc index 807c2840..df5a8367 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc @@ -6,6 +6,7 @@ # Legacy mode: As runvirt has been before. # New mode: uuid in xml _and_ vmx given via http. download_metadata() { + local TRIES EXTRA_ERROR WLOG TMPFILE RET ERRCODE # Sanity checks if ! check_dep wget; then writelog "Could not find 'wget' in PATH: $PATH" @@ -18,11 +19,30 @@ download_metadata() { fi writelog "Detecting current/legacy mode..." - declare -rg TMPCONFIG="$TMPDIR/vmconfig.tmp" - local TRIES=0 - local EXTRA_ERROR= - local WLOG= + # Try new unified .tar.gz way + TMPFILE="$TMPDIR/metadata.tgz" + WLOG="$TMPDIR/wget-metadata.log" + curl -L -o "$TMPFILE" -w '\nretval:%{http_code}\n' --retry 3 --max-time 6 --retry-max-time 15 "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}/metadata" &> "$WLOG" + ERRCODE=$( awk -F: '{ if ($1 == "retval") print $2 }' "$WLOG" ) + RET=$? + if [ "$RET" = 0 ] && [ -n "$ERRCODE" ] && [ "$ERRCODE" -ge 200 ] && [ "$ERRCODE" -lt 300 ]; then + # Success, see if data is usable + mkdir -p "$TMPDIR/metadata" + if tar -C "$TMPDIR/metadata" -x -f "$TMPFILE" && [ -s "$TMPDIR/metadata/vmx" ]; then + declare -rg TMPCONFIG="$TMPDIR/metadata/vmx" + declare -rg CONFDIR="$TMPDIR/metadata" + return 0 + fi + rm -rf -- "$TMPDIR/metadata" "$TMPFILE" + writelog "Extracting metadata.tgz failed. Trying legacy mode." + elif [ -n "$ERRCODE" ] && [ "$ERRCODE" -ge 500 ]; then + slxlog --delete "run-virt-wget" "Downloading MetaData failed" "$WLOG" + fi + + writelog "Metadata download failed, trying legacy approach..." + declare -rg TMPCONFIG="$TMPDIR/vmconfig.tmp" + TRIES=0 while [ "$TRIES" -lt 3 ]; do TRIES=$(( TRIES + 1 )) writelog "wget try $TRIES" diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc index e2854f77..5729373a 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt.d/setup_virtual_floppy.inc @@ -81,11 +81,14 @@ setup_virtual_floppy() { done fi + local NETSHARES="$CONFDIR/netshares" + local RUNSCRIPT="$CONFDIR/runscript" + ## Network shares # openslx.exe expects network shares line in the following format: # # which is coincidentally the one we received from dmsd :) - if load_dmsd_resource NETSHARES; then + if [ -f "$NETSHARES" ] || load_dmsd_resource NETSHARES; then if [ -s "${NETSHARES}" ]; then # try to detect if we are running windows and replace '/' with '\' # in an attempt to fix an improperly given samba path @@ -104,7 +107,7 @@ setup_virtual_floppy() { # Check downloaded runscript and handle options like # extension, visibility flag, ... # options are 'key=value' pairs separated with ';' - if load_dmsd_resource RUNSCRIPT; then + if [ -f "$RUNSCRIPT" ] || load_dmsd_resource RUNSCRIPT; then if [ -s "$RUNSCRIPT" ]; then IFS=$'\n' for OPT in $(head -n 1 "$RUNSCRIPT" | tr ";" "\n"); do @@ -175,8 +178,8 @@ setup_virtual_floppy() { fi # Admin supplied runscript(s) - if [ -d "${VMCHOOSER_DIR}/adminrun" ]; then - mcopy -s -i "${SLX_FLOPPY_IMG}" "${VMCHOOSER_DIR}/adminrun" "::/" + if [ -d "${CONFDIR}/adminrun" ]; then + mcopy -s -i "${SLX_FLOPPY_IMG}" "${CONFDIR}/adminrun" "::/" fi rm -f -- "${SHARES}" "${TMPDIR}/openslx.ini" "${TMPDIR}/HOSTRES.TXT" -- cgit v1.2.3-55-g7522