diff options
author | Jonathan Bauer | 2016-12-23 13:12:09 +0100 |
---|---|---|
committer | Jonathan Bauer | 2016-12-23 13:12:09 +0100 |
commit | 6806ae4a850fc7785a8c05304237cf53b5b8f951 (patch) | |
tree | b1dd8413d6c7b9a250251da7f0d49bb52b4ddc57 /core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc | |
parent | wrong kernel version variable used (diff) | |
download | mltk-6806ae4a850fc7785a8c05304237cf53b5b8f951.tar.gz mltk-6806ae4a850fc7785a8c05304237cf53b5b8f951.tar.xz mltk-6806ae4a850fc7785a8c05304237cf53b5b8f951.zip |
merge with latest dev version (tm-scripts commit f5a59daf8d70a9027118292cd40b18c221897408)
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc')
-rw-r--r-- | core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc new file mode 100644 index 00000000..fdacc69c --- /dev/null +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/get_xml_file_variables.inc @@ -0,0 +1,63 @@ +############################################ +# Include: Get needed values from XML file # +############################################ + +writelog "Parsing XML..." + +declare -rg VMSTORE_PATH=/mnt/vmstore + +get_xml () { + xmlextract "//settings/eintrag/${1}/@param" "${xmlfile}" +} + +IMGUUID=$(get_xml "uuid") + +# # Name of the virt image +SRC_IMG_ABSOLUTE=$(get_xml "image_path") +SRC_IMG_RELATIVE=$(get_xml "image_name") + +if [ -z "${SRC_IMG_ABSOLUTE}${SRC_IMG_RELATIVE}" ]; then + writelog "Neither relative nor absolute path for image found in xml" + cleanexit 1 +fi + +if [ -n "$SRC_IMG_ABSOLUTE" ] && [ "${SRC_IMG_ABSOLUTE:0:1}" != "/" ]; then + writelog "Error parsing XML for absolute image path: given value doesn't start with '/': '$SRC_IMG_ABSOLUTE'" + cleanexit 1 +fi + +if [ -z "$SRC_IMG_ABSOLUTE" ]; then + SRC_IMG_ABSOLUTE="${VMSTORE_PATH}/${SRC_IMG_RELATIVE}" +fi + +IMG_BASENAME=$(basename "$SRC_IMG_ABSOLUTE") +writelog "Virtual image file name: $IMG_BASENAME" + +VM_DISPLAYNAME=$(get_xml "short_description") +[ -z "$VM_DISPLAYNAME" ] && VM_DISPLAYNAME="${IMG_BASENAME}" + +# Define VM_NAME_CLEAN since VM_DISPLAYNAME can be long and contain weird characters +VM_NAME_CLEAN=$(echo "${VM_DISPLAYNAME:0:32}" | sed -r 's/[^0-9a-zA-Z_-\.]+/_/g') + +# image is for the following virtual machine +PLUGIN_ID=$(grep -o 'virtualmachine param=.*"' "${xmlfile}" \ + | sed -e "s/&.*;/; /g" | awk -F '"' '{print $2}') + +# Extracting OS type (VM_OS_TYPE) from xml file. We don't care here whether VM_OS_TYPE is empty, as then +# it will yield the default entries later on. +VM_OS_TYPE=$(get_xml "os") + +readonly IMGUUID +readonly SRC_IMG_ABSOLUTE SRC_IMG_RELATIVE +readonly IMG_BASENAME +readonly VM_DISPLAYNAME VM_NAME_CLEAN +readonly PLUGIN_ID +readonly VM_OS_TYPE + +writelog "VM UUID: $IMGUUID" +writelog "Virtualization plugin: $PLUGIN_ID" +writelog "VM name: $VM_DISPLAYNAME" +writelog "VM short name: $VM_NAME_CLEAN" +writelog "VM OS: $VM_OS_TYPE" +writelog "Done parsing XML." + |