summaryrefslogtreecommitdiffstats
path: root/core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/qemu/data/opt/openslx/vmchooser/plugins/qemukvm')
-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
2 files changed, 90 insertions, 2 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')"