summaryrefslogtreecommitdiffstats
path: root/remote/modules/run-virt/data/opt/openslx/scripts/includes/detect_legacy.inc
blob: f77e955baaabf63e10184a5ad057e689f8f6e1cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
########################################################
# Include: Detect, whether runvirt runs in legacy mode #
########################################################

# Legacy mode: As runvirt has been before.
# New mode: uuid in xml _and_ vmx given via http.

writelog "Detecting current/legacy mode ..."

# First, let's try to extract an imguuid from xmlfile:
declare -rg IMGUUID=$(grep -i -o '<uuid param=.*"' "${xmlfile}" | sed -e "s/&.*;/; /g" | awk -F '"' '{ print $2 }')
declare -rg TMPCONFIG="$TMPDIR/vmconfig.tmp"

writelog "IMGUUID extracted: $IMGUUID"

# Assume legacy mode by default, only trigger "current" mode if everything else below worked
LEGACY=yes
if [ -z "$IMGUUID" ]; then	# Keine uuid: Abbruch, Legacy
	writelog "Could not extract a uuid param from ${xmlfile}. Triggering legacy mode."
else
	# Now getting template file:
	if ! wget -O "$TMPCONFIG" "${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}" 2>/dev/null >&2; then
		writelog "wget ${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID}. Triggering legacy mode."
	else
		writelog "wget ${SLX_VMCHOOSER_BASE_URL}/lecture/${IMGUUID} successful."
		if [ ! -s "$TMPCONFIG" ]; then
			writelog "Server sent zero byte virtual machine description file. Triggering legacy mode."
		else
			writelog "Triggering current (non-legacy) mode."
			LEGACY=		# everything worked - clear legacy mode variable (so we use the "current" mode)
		fi
	fi
fi