summaryrefslogblamecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt
blob: d8f7d6ba0b749f47671cdf45a74ed3d85177b27c (plain) (tree)
1
2
3
4
5
6


                                                                               
 
                                                 
 






                                                                            
 






                                                                                
                        
 

                                                                              
 
                                                       
                       
 
                                                                                
                                                                     


                                                                                                    

  
                                                       
 


                                                                                   
 


                                                                   
 

                                                                                   
 

                                                                           
 

                                                                         
 

                                                                       
 

                                                                                 
 

                                                                     
 
 


                                                                                 
 

                                                               
 







                                                                                                                 
                                                  























                                                                                               

                                                   
                        






                                                                                        


                                                
 
                                             


           
#!/bin/bash
# Full bash required
# -----------------------------------------------------------------------------
#
# Copyright (c) 2007..2018 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 bwlehrpool@hs-offenburg.de.
#
# General information about bwLehrpool can be found at https://bwlehrpool.de
#
# -----------------------------------------------------------------------------
# run-virt.sh
#    - This is the generic wrapper for the several virtualization solutions.
#      The idea is to setup a set of variables used by at least two different
#      tools and then include the specific plugin which configures the speci-
#      fied virtualization tool.
################################################################################
SELF=$(readlink -f "$0")

# This script expects the path to the xml file describing the VM to be started
declare -rg XML_FILE="$1"

# A path to the logfile can be given as second argument
declare -g LOGFILE="$2"

# Functions needed by vmchooser-run_virt (writelog(), cleanexit(), safesource())
declare -rg RUN_VIRT_INCLUDE_DIR="$(dirname $SELF)/run-virt-includes"
if ! source "${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc"; then
	slxlog "run-virt" "Could not source ${RUN_VIRT_INCLUDE_DIR}/vmchooser_runvirt_functions.inc"
	exit 1
fi

trap 'trap "" SIGINT SIGTERM; cleanexit' SIGINT SIGTERM

# Starting sourcing the includes files. Note that the critical ones should use
# the '--exit' option of safesource to trigger cleanexit in case of a corrupted/bad
# include file.

# Set core runvirt variables and directories
$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/init_core.inc")
writelog "#################### Initialization ####################"

# Window manager required early for user feedback through popups (e.g. errors) etc.
$(safesource "${RUN_VIRT_INCLUDE_DIR}/start_windowmanager.inc")

# Read vmchooser.conf, (generated) virtualization.conf and slx config files
$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/load_configs.inc")

# Read needed variables from XML file
$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/get_xml_file_variables.inc")

# Download metadata from server (e.g. vmx for vmware)
$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/download_vm_metadata.inc")

# Declaration of hardware related variables
$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/set_runvirt_hardware_variables.inc")

# Try to use dnbd3 to access the image, nfs/cifs fallback
$(safesource --exit "${RUN_VIRT_INCLUDE_DIR}/setup_image_access.inc")


# Mark the end of generic run-virt part
writelog "Done with generic run-virt. Now loading virtualizer specific includes."
writelog "#################### Plugin init: $PLUGIN_ID ####################"

# NG: first include the hypervisor includes
$(safesource "${RUN_VIRT_INCLUDE_DIR}/setup_vm_hypervisor.inc")

# It must declare PLUGIN_FEATURES to set which features are needed.
# Features are those defined by run-virt.d include files.
# After sourcing the plugin, check that it defined both PLUGIN_FEATURES and
# the main function 'run_plugin' which will be called later by the main scripts.
if ! isset PLUGIN_FEATURES || ! is_function run_plugin; then
	writelog "Bad plugin '$PLUGIN_ID': either it did not set PLUGIN_FEATURES or did not define 'run_plugin'."
	EXIT_TYPE="internal" EXIT_REASON="Fehlerhaftes vmchooser plugin: '$PLUGIN_ID'." cleanexit 1
fi
writelog "Requested features:\t${PLUGIN_FEATURES}"

# Source the *.inc files in run-virt.d
for FILE in ${VMCHOOSER_DIR}/run-virt.d/*.inc; do
	$(safesource "$FILE")
done

# Now look which features were requested and call the handler if one is defined.
for FEAT in $PLUGIN_FEATURES; do
	if notempty FEATURE_HANDLERS["${FEAT}"]; then
		writelog "Initialising '${FEAT}'..."
		if ! ${FEATURE_HANDLERS["$FEAT"]}; then
			writelog "\tFailed to run '${FEATURE_HANDLERS["$FEAT"]}'."
			error_user "Konnte Feature namens '$FEAT' nicht initialisieren!
Diese Funktion wird nicht verfügbar sein!" # not critical, do not exit!
		fi
	else
		writelog "\tFeature '$FEAT' has no handler! This function will be unavailable."
		notify_user "Feature '$FEAT' nicht unterstützt"
	fi
done
# The features should now be initialized, call the main 'run_plugin' function of the hypervisor
writelog "#################### Plugin run: $PLUGIN_ID ####################"
writelog "Calling 'run_plugin' of '$PLUGIN_ID'..."
run_plugin || writelog "Failed to run 'run_plugin' of '$PLUGIN_ID'."

# It should have set this variable if all went well
if isempty VIRTCMD; then
	error_user "Fehler beim Starten der VM-Sitzung" "
Das Start-Script für den Virtualisierer $PLUGIN_ID hat kein Kommando
zum Starten der Sitzung definiert. Kann Sitzung nicht initialisieren."
	slxlog "virt-plugin-error" "run-virt.include for $PLUGIN_ID did not set VIRTCMD"
	cleanexit 1
fi

writelog "VM command: ${VIRTCMD} ${VIRTCMDOPTS}"
# This will start the VM (no eval needed!)
${VIRTCMD} ${VIRTCMDOPTS}

writelog "Virtualizer exited with '$?'. Bye."

cleanexit 0