summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes
diff options
context:
space:
mode:
authorSimon Rettberg2019-05-17 12:30:24 +0200
committerSimon Rettberg2019-05-17 12:30:24 +0200
commite384d068e1f101087b85e97c35ef1d434cc7790a (patch)
treebc8130eed93bc8eee730fa3431f7fc8e70ddea25 /core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes
parent[screen-standby] Remove forgotten interfering module (diff)
downloadmltk-e384d068e1f101087b85e97c35ef1d434cc7790a.tar.gz
mltk-e384d068e1f101087b85e97c35ef1d434cc7790a.tar.xz
mltk-e384d068e1f101087b85e97c35ef1d434cc7790a.zip
[run-virt] Add hook system, remove legacy code
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes')
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/download_vm_metadata.inc69
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc3
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc62
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc28
4 files changed, 82 insertions, 80 deletions
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 17b679ea..dd3f63e3 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,16 +6,32 @@
# 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 CMDLINE
+ local EXTRA_ERROR=
+ declare -rg TMPCONFIG="$CONFDIR/vmx"
+
+ # Run hooks
+ if ! run_hooks "download" "$CONFDIR"; then
+ # No hooks found
+ download_metadata_default
+ fi
+ [ -s "$TMPCONFIG" ] && return 0
+ # Seems we are in legacy mode, which is no longer supported. Warn user and exit
+ EXIT_TYPE="user" EXIT_REASON="msg.vm.no-metadata
+Die Metadaten der Lehrumgebung konnten nicht vom bwLehrpool-Satelliten
+heruntergeladen werden. Bitte versuchen Sie es in wenigen Minuten erneut
+und wenden Sie sich an den Support, wenn das Problem bestehen bleibt.
+$EXTRA_ERROR
+" cleanexit 1
+}
+
+download_metadata_default() {
+ local TRIES WLOG TMPFILE RET ERRCODE CMDLINE
# Sanity checks
- if ! check_dep wget; then
+ if ! check_dep curl; then
writelog "Could not find 'wget' in PATH: $PATH"
EXIT_TYPE="internal" EXIT_REASON="Fehlendes Dienstprogramm 'wget'!" cleanexit 1
fi
- writelog "Detecting current/legacy mode..."
- declare -rg TMPCONFIG="$CONFDIR/vmx"
-
# Try new unified .tar.gz way
TMPFILE="$TMPDIR/metadata.tgz"
WLOG="$TMPDIR/wget-metadata.log"
@@ -26,51 +42,14 @@ download_metadata() {
RET=$?
if [ "$RET" = 0 ] && [ -n "$ERRCODE" ] && [ "$ERRCODE" -ge 200 ] && [ "$ERRCODE" -lt 300 ]; then
# Success, see if data is usable
- if tar -C "$CONFDIR" -x -f "$TMPFILE" && [ -s "$CONFDIR/vmx" ]; then
+ if tar -C "$CONFDIR" -x -f "$TMPFILE" && [ -s "$TMPCONFIG" ]; then
return 0
fi
rm -rf -- "$TMPFILE"
- writelog "Extracting metadata.tgz failed. Trying legacy mode."
+ writelog "Extracting metadata.tgz failed. Cannot start VM."
else
- writelog "Downloading metadata.tgz failed (HTTP $ERRCODE). Trying legacy mode."
- #slxlog --delete "run-virt-wget" "Downloading MetaData failed" "$WLOG"
+ writelog "Downloading metadata.tgz failed (HTTP $ERRCODE). Cannot start VM." "$WLOG"
fi
-
- TRIES=0
- while [ "$TRIES" -lt 3 ]; do
- TRIES=$(( TRIES + 1 ))
- writelog "wget try $TRIES"
- WLOG="$TMPDIR/wget-${TRIES}.log"
- if wget -T 6 -O "$TMPCONFIG" "${url_lecture_config}" &>"$WLOG"; then
- rm -f -- "$WLOG"
- writelog "Downloaded VM description from '${url_lecture_config}' successfully."
- if [ -s "$TMPCONFIG" ]; then
- # Downloaded a non-zero VM description file, all good
- return 0
- else
- writelog "Server sent zero byte virtual machine description file."
- EXTRA_ERROR="(Der Server hat eine leere Antwort gesendet)"
- fi
- else
- ERRCODE=$(grep -m1 -o -E '\b[0-9]{3}\b' "$WLOG")
- if [ -n "$ERRCODE" ]; then
- EXTRA_ERROR="(HTTP Error Code $ERRCODE)"
- else
- EXTRA_ERROR="(Der Server ist nicht erreichbar)"
- fi
- writelog "wget failed."
- fi
- done
-
- slxlog --delete "run-virt-wget" "Downloading VMX/Metadata failed" "$WLOG"
-
- # Seems we are in legacy mode, which is no longer supported. Warn user and exit
- EXIT_TYPE="user" EXIT_REASON="msg.vm.no-metadata
-Die Metadaten der Lehrumgebung konnten nicht vom bwLehrpool-Satelliten
-heruntergeladen werden. Bitte versuchen Sie es in wenigen Minuten erneut
-und wenden Sie sich an den Support, wenn das Problem bestehen bleibt.
-$EXTRA_ERROR
-" cleanexit 1
}
## Main ##
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc
index 0f1fab39..7a132fcc 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/load_configs.inc
@@ -17,9 +17,6 @@ load_configs() {
# Load general virtualization information
$(safesource --exit "$VMCHOOSER_CONF_DIR/virtualization.conf")
-
- # Load general openslx config
- $(safesource --exit "/opt/openslx/config")
# Load config for resource URLs
$(safesource "$VMCHOOSER_CONF_DIR/resource_urls.conf")
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc
index ea8afc7e..cc921228 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc
@@ -85,29 +85,25 @@ setup_fallback() {
readonly VM_DISKFILE_RO
}
-setup_jambo() {
- declare -r CMDLOG="$TMPDIR/sshfs.jambo"
- declare -rg CLIENTPARTITION_ADMIN="/var/lib/vmware_admin"
- #declare -r UPLOAD_KEYFILE="/var/lib/uploaduser"
- #sudo -n sshfs "uploaduser@$JAMBOSERVER:/vms/bwlehrpool_store" "$CLIENTPARTITION_ADMIN" -o allow_other -o PreferredAuthentications=publickey -o IdentityFile="$UPLOAD_KEYFILE" -o IdentitiesOnly=yes &> "$CMDLOG"
- sudo -n sshfs "uploaduser@$JAMBOSERVER:/vms/bwlehrpool_store" "$CLIENTPARTITION_ADMIN" -o allow_other -o PreferredAuthentications=publickey &> "$CMDLOG"
- RET=$?
- if [ "$RET" != "0" ]; then
- writelog "SSHFS Failed
- $(cat "$CMDLOG")"
- EXIT_TYPE="user" EXIT_REASON="Schreibbarer VM-Speicher konnte nicht eingebunden werden. Adminmodus fehlgeschlagen." cleanexit 1
- fi
- declare -rg VM_DISKFILE_RW="$CLIENTPARTITION_ADMIN/$SRC_IMG_RELATIVE"
-}
-
-
## MAIN PART / Sanity checks ##
setup_image_access() {
writelog "Setting up virtual hard disk access for virtualizer/emulator ..."
+ unset VM_DISKFILE_RO VM_DISKFILE_RW
+ declare -g VM_DISKFILE_RO VM_DISKFILE_RW
+
+ run_hooks "image-access"
- if [ "$VMCHOOSER_ADMIN_MODE" = "TRUE" ] && [ -n "$SLX_JAMBOSERVER" ]; then
- setup_jambo
- writelog "\tVM disk file RW:\t\t$VM_DISKFILE_RW"
+ if [ -n "$VM_DISKFILE_RW" ]; then
+ writelog "A hook in setup_image_access supplied a writable diskfile. Not running default setup."
+ elif [ -n "$VM_DISKFILE_RO" ]; then
+ writelog "A hook in setup_image_access supplied a read-only diskfile. Not running default setup."
+ else
+ setup_image_access_default
+ fi
+ readonly VM_DISKFILE_RO VM_DISKFILE_RW
+
+ if [ -n "$VM_DISKFILE_RW" ]; then
+ writelog "\tVM disk file (RW):\t\t$VM_DISKFILE_RW"
if ! [ -s "$VM_DISKFILE_RW" ]; then
writelog ".... not found!"
EXIT_TYPE="user" EXIT_REASON="Schreibbare VM nicht gefunden. Adminmodus fehlgeschlagen." cleanexit 1
@@ -116,12 +112,22 @@ setup_image_access() {
writelog ".... not writable!"
EXIT_TYPE="user" EXIT_REASON="VM-Image auf schreibbarem VM-Speicher nicht schreibbar. Adminmodus fehlgeschlagen." cleanexit 1
fi
- return 0
+ elif [ -n "$VM_DISKFILE_RO" ]; then
+ writelog "\tVM disk file (RO):\t\t$VM_DISKFILE_RO"
+ if ! [ -s "$VM_DISKFILE_RO" ]; then
+ writelog ".... not found!"
+ EXIT_TYPE="user" EXIT_REASON="VM-Image nicht gefunden." cleanexit 1
+ fi
+ if ! [ -r "$VM_DISKFILE_RO" ]; then
+ writelog ".... not readable!"
+ EXIT_TYPE="user" EXIT_REASON="VM-Image nicht lesbar." cleanexit 1
+ fi
+ else
+ EXIT_TYPE="user" EXIT_REASON="Kein VM-Image Dateiname angegeben/gefunden." cleanexit 1
fi
-
- unset VM_DISKFILE_RO
- declare -g VM_DISKFILE_RO
-
+}
+
+setup_image_access_default() {
# See if we should setup dnbd3 image access at all
if ! check_dep dnbd3-fuse fusermount; then
writelog "\tCan't use dnbd3 as dnbd3-fuse/fusermount binaries are not in PATH"
@@ -141,14 +147,6 @@ setup_image_access() {
writelog "Trying fallback image access via NFS/CIFS..."
setup_fallback
fi
-
- # Check if we finally found a valid, readable container
- if isempty VM_DISKFILE_RO || [ ! -r "${VM_DISKFILE_RO}" ]; then
- writelog "Virtual machine image ${VM_DISKFILE_RO} not found!"
- EXIT_TYPE="user" EXIT_REASON="Konnte virtuelle Festplatte der gewählten VM nicht finden!" cleanexit 1
- fi
-
- writelog "\tVM disk file:\t\t${VM_DISKFILE_RO}"
}
call_post_source setup_image_access
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
index 932c4aad..7b4554ea 100644
--- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc
@@ -220,6 +220,34 @@ translate() {
fi
}
+##
+# run_hooks type args...
+# eg run_hooks "download" "$CONFDIR"
+# returns 100 if no hooks exist
+run_hooks() {
+ local dir file retval r
+ declare -a files
+ dir="$BASEDIR/hooks/${1}.d"
+ [ -d "$dir" ] || return 100
+ shift
+ files=( "${dir}"/* )
+ retval=100
+ for file in "${files[@]}"; do
+ [ -e "${file}" ] || continue
+ r=100
+ if [ "${file##*.}" = "sh" ] && [ -x "$file" ]; then
+ export TMPDIR IMGUUID USER
+ "$file" "$@"
+ r="$?"
+ elif [ "${file##.*}" = "inc" ]; then
+ . "$file"
+ r="$?"
+ fi
+ [ "$r" -lt "$retval" ] && retval="$r"
+ done
+ return "$retval"
+}
+
################# SOURCING FUNCTIONS #################
# Wrapped 'source' that first checks for existence and
# syntax before actually sourcing the given file.