summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2021-11-29 01:11:46 +0100
committerJannik Schönartz2021-11-29 01:11:46 +0100
commit743f83acbec09e3e6f3c2e37e0f9798ad1c24d95 (patch)
tree08c349d99c6b844817a495592143643d0664f662
parent[qemu] Start virt-manager without any forks (diff)
downloadmltk-remote-edit-vm.tar.gz
mltk-remote-edit-vm.tar.xz
mltk-remote-edit-vm.zip
[qemu] Add edit support via remoteremote-edit-vm
vmchooser: fix so that autostart uuid parameter works run-virt: replace cleanuploop with a while, so firefox can interrup the session shutdown
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc68
-rw-r--r--core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include24
-rw-r--r--core/modules/qemu/data/opt/openslx/xsessions/README3
l---------core/modules/qemu/data/opt/openslx/xsessions/edit.desktop1
-rw-r--r--core/modules/qemu/data/root/.ssh/README3
-rw-r--r--core/modules/qemu/data/root/.ssh/authorized_keys2
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/hooks/image-access.d/create-rw-image.inc13
-rw-r--r--core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/vmchooser_runvirt_functions.inc3
-rwxr-xr-xcore/modules/vmchooser2/data/opt/openslx/bin/vmchooser4
9 files changed, 116 insertions, 5 deletions
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc
new file mode 100644
index 00000000..eb9030fa
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/includes/create-rw-diskimage.inc
@@ -0,0 +1,68 @@
+# -----------------------------------------------------------------------------
+#
+# Copyright (c) 2009..2021 bwLehrpool-Projektteam
+#
+# This program/file is free software distributed under the GPL version 2.
+# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
+#
+# If you have any feedback please consult https://bwlehrpool.de and
+# send your feedback to support@bwlehrpool.de.
+#
+# General information about bwLehrpool can be found at https://bwlehrpool.de
+#
+# -----------------------------------------------------------------------------
+# Utils and functions to parse Linux kernel command line options
+# -----------------------------------------------------------------------------
+
+#
+# Return :
+function create_rw_diskimage() {
+ # writelog "Creating rw image for qemu to safe and upload the snapshot later"
+
+ # Register upload function to trigger before the cleanup deletes the tmp image snapshot
+ add_cleanup upload_qemu_rw
+
+ # If the edit checkbox is checked the environment variable VMCHOOSER_ADMIN_MODE is TRUE
+ # ALLOW_EDIT=${VMCHOOSER_ADMIN_MODE}
+}
+
+# Helper to safe and upload the image before the cleanup deletes everything
+upload_qemu_rw() {
+
+ # writelog "Calling scp task trigger on SAT"
+ # SERVERIP=$SLX_PXE_SERVER_IP
+ # Call slx-admin api to trigger taskmanager ScpSnapshot task with all the info needed
+ # LECTUREID=$IMGUUID
+ # CLIENTIP=$SLX_PXE_CLIENT_IP
+ # curl "http://$SERVERIP/slx-admin/api.php?do=remoteaccess&action=scp&lectureid=$LECTUREID&clientip=$CLIENTIP"
+ # Image will be deleted by SAT via SSH after finished downloading
+
+
+ # LECTUREID=$IMGUUID
+ # CLIENTIP=$SLX_PXE_CLIENT_IP
+ SERVERIP=$SLX_PXE_SERVER_IP
+ SESSIONID=$(cat /var/lib/lightdm/editsession.id)
+
+ # Open firefox where the user can either safe or cancel
+ # Prepare firefox to not start the privacy "first launch" Page
+ firefox --CreateProfile progress
+ FFPROFILE=$(realpath ~/.mozilla/firefox/*.progress)
+ echo 'user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);' >> $FFPROFILE/user.js
+
+ # Start firefox and wait for the process
+ firefox --kiosk http://$SERVERIP:5000/progress/$SESSIONID -P progress &
+ FFPID="$!"
+ writelog "FF PID IS: $FFPID"
+ writelog "Waiting for firefox to exit"
+ wait $!
+ writelog "Firefox exited"
+
+ # At this point the snapshot was either downloaded by the sat or the edit session was cancelled and can be deleted
+ rm -rf /tmp/upload
+
+ # No permission to delete this file
+ # rm -f /var/lib/lightdm/editsession.id
+ # Remove the /var/lib/lightdm/edit.desktop that the slxgreeter created for autostart-editmode-login
+ # rm /var/lib/lightdm/edit.desktop
+}
+
diff --git a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
index fd251f04..893835e7 100644
--- a/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
+++ b/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm/run-virt.include
@@ -29,10 +29,30 @@ run_plugin() {
$(safesource "${QEMU_INCLUDE_DIR}/passthrough-pci.inc")
# include mediated device passthrough utils and functions
$(safesource "${QEMU_INCLUDE_DIR}/passthrough-mdev.inc")
+ # include function for creating the rw qcow2 image
+ $(safesource "${QEMU_INCLUDE_DIR}/create-rw-diskimage.inc")
- # setup RW image access for operation
local vm_diskfile
- if notempty VM_DISKFILE_RO; then
+ # If admin mode checkbox is set in the vmchooser, create the rw disk for the snapshot
+ if [ "${VMCHOOSER_ADMIN_MODE}" = TRUE ]; then
+ # Create tmp dir that survives cleanup
+ mkdir /tmp/upload
+
+ # Activate cleanup function for uploading
+ create_rw_diskimage
+
+ # Create snapshot file in upload dir that doesn't get deleted on cleanup
+ if [ -f /var/lib/lightdm/editsession.id ]; then
+ EDITID=$(cat /var/lib/lightdm/editsession.id)
+ vm_diskfile="/tmp/upload/$EDITID.qcow2"
+ else
+ writelog "No editid was found at /var/lib/lightdm/editsession.id, using IMGUUID as fallback"
+ vm_diskfile="/tmp/upload/$IMGUUID.qcow2"
+ fi
+ local vm_diskfile_type="$(qemu-img info --output=json ${VM_DISKFILE_RO} | jq -r '.format')"
+ qemu-img create -F "${vm_diskfile_type}" -b "${VM_DISKFILE_RO}" -f qcow2 "${vm_diskfile}"
+ # setup RW image access for operation
+ elif notempty VM_DISKFILE_RO; then
# create copy-on-write layer for readonly image
vm_diskfile="${TMPDIR}/$(basename ${VM_DISKFILE_RO}).cow.qcow2"
local vm_diskfile_type="$(qemu-img info --output=json ${VM_DISKFILE_RO} | jq -r '.format')"
diff --git a/core/modules/qemu/data/opt/openslx/xsessions/README b/core/modules/qemu/data/opt/openslx/xsessions/README
new file mode 100644
index 00000000..87dacaa0
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/xsessions/README
@@ -0,0 +1,3 @@
+# This symlink was created, because slx can't write in this directory.
+# So here is a symlink, that's only valid (and therefore used) if the slxgreeter creates the file:
+# /var/lib/lightdm/edit.desktop
diff --git a/core/modules/qemu/data/opt/openslx/xsessions/edit.desktop b/core/modules/qemu/data/opt/openslx/xsessions/edit.desktop
new file mode 120000
index 00000000..5a789391
--- /dev/null
+++ b/core/modules/qemu/data/opt/openslx/xsessions/edit.desktop
@@ -0,0 +1 @@
+/var/lib/lightdm/edit.desktop \ No newline at end of file
diff --git a/core/modules/qemu/data/root/.ssh/README b/core/modules/qemu/data/root/.ssh/README
new file mode 100644
index 00000000..8e73fe21
--- /dev/null
+++ b/core/modules/qemu/data/root/.ssh/README
@@ -0,0 +1,3 @@
+# The public key is used by the SAT to scp the snapshot after finishing a session
+# Currently this is a public key from the .51, but has to be replaced with a pub-key of the current used sat.
+# There might be better solutions but for the prototype it will do the job
diff --git a/core/modules/qemu/data/root/.ssh/authorized_keys b/core/modules/qemu/data/root/.ssh/authorized_keys
new file mode 100644
index 00000000..fb32e858
--- /dev/null
+++ b/core/modules/qemu/data/root/.ssh/authorized_keys
@@ -0,0 +1,2 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCjeHGg1UETeC3s7gAAu34kgpy6EQKrU0+fvP9gvaTU/A+DTTOE9PIhogU8sdKhA/RrHwuleEIQmNW8mFKW+BD3uoVlIt9kYN7wtxyZ130eJLEKpg7Qnt1Hkw4Dt1Vj6/kv0+j3RbzDuxDU9dODeSS/HzD//KwBiUNZ/9BtLglHXWKq7vhnEXOyU4OZm9J1LNQnLcxkCDyeMRlKZBsKIt1cPRZ+9tP82sWoqW6cwT8anAeqgJRib7JMKNeh5n6Ib8AeNX8u+YlhQiyIXHPI7vqIqwXfuyAjPEjdXF8Nqc7zz2+izOCpNtutHUvaZ2/1Yv/BJzC7TnGJ+qQVHY1fxqEHArqwcRoe3rtQnqXRQHL/JCcyc9O8vzR9BdBRIx5R24E7IyEfu3f8aBuguyJs/NhLUHWN2zB12MGn4Tjs8zERS69IG5ArVAZ3fYHR/f3LY4mNQIcB4LIXT4muboBvcx6/hv8vTVqBxVbIyf3BHQnKrXQlH8lX96P0bHG17hr3LMuYmm6H+Rk1OEiVUoebzlssK7mIGn458R2DkHnP0jsVeywB8aYb43/coQ0hLIUiljzr5H4Xmz0D6aFgAnDVNdhwiTveJ1JKlJENX81aa3iVwISPkPt14U5vEzCqmjLX2mzpEAK8f0E9GW477WEbE7AVFfcoO6VQWl+LT1Acq5H22w== root@lsfks-vm-01
+
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/hooks/image-access.d/create-rw-image.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/hooks/image-access.d/create-rw-image.inc
new file mode 100644
index 00000000..cf74cd09
--- /dev/null
+++ b/core/modules/run-virt/data/opt/openslx/vmchooser/hooks/image-access.d/create-rw-image.inc
@@ -0,0 +1,13 @@
+# This hook will be called in /opt/openslx/vmchooser/run-virt-includes/setup_image_access.inc
+# It needs to set either VM_DISKFILE_RW or VM_DISKFILE_RO
+# If none of them are set it will do default dnbd3/nfs fallbacks
+# However this module is called BEFORE any virtualizer specific plugins
+# Therefore used when implemented on a lower layer
+
+# Stuff neeeded for determination:
+# Image UUID: $IMGUUID
+# Edit Mode enabled (TRUE or FALSE): $VMCHOOSER_ADMIN_MODE
+
+writelog "Running setup image access hook: create-rw-image"
+writelog "Image UUID: ${IMGUUID}"
+writelog "EDIT MODE: ${VMCHOOSER_ADMIN_MODE}"
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 a5c20aea..4b50f537 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
@@ -135,7 +135,8 @@ cleanexit() {
"${TASK}" &
cleanups+=( "$!" )
done
- for i in 1 1 2 2 3 3 4 4; do
+ #for i in 1 1 2 2 3 3 4 4; do
+ while true; do
usleep 500000
kill -0 "${cleanups[@]}" &> /dev/null || break
done
diff --git a/core/modules/vmchooser2/data/opt/openslx/bin/vmchooser b/core/modules/vmchooser2/data/opt/openslx/bin/vmchooser
index a07fa143..cc1b25dc 100755
--- a/core/modules/vmchooser2/data/opt/openslx/bin/vmchooser
+++ b/core/modules/vmchooser2/data/opt/openslx/bin/vmchooser
@@ -49,7 +49,7 @@ fi
if [ -n "$SLX_EXAM" ]; then
EXTRA="$EXTRA --exam-mode"
elif [ -n "$SLX_AUTOSTART_UUID" ]; then
- SLX_EXAM_START="$SLX_AUTOSTART_UUID"
+ EXTRA="$EXTRA --start-uuid $SLX_AUTOSTART_UUID"
fi
if [ -z "$SLX_NO_PVS" ]; then
EXTRA="$EXTRA --pvs"
@@ -86,5 +86,5 @@ if [ -n "$SLX_SCREEN_SAVER_TIMEOUT" ]; then
fi
# No quotes around $EXTRA!
-exec vmchooser.real "$@" --url "$URL" --fullscreen --tab "$TAB" --start-uuid "$SLX_EXAM_START" $EXTRA
+exec vmchooser.real "$@" --url "$URL" --fullscreen --tab "$TAB" $EXTRA