diff options
author | Jonathan Bauer | 2017-02-14 17:58:28 +0100 |
---|---|---|
committer | Jonathan Bauer | 2017-02-14 17:58:28 +0100 |
commit | b21ee6b876c851010bfe24c944c6a5034a6c0ba6 (patch) | |
tree | c83d41a7fd8b2cd0f25417ca4b6309e4fbc63ef1 /core/modules/run-virt/data/opt/openslx/vmchooser | |
parent | [rootfs-stage31] Don't open debug shell if we're booting with splash screen (diff) | |
download | mltk-b21ee6b876c851010bfe24c944c6a5034a6c0ba6.tar.gz mltk-b21ee6b876c851010bfe24c944c6a5034a6c0ba6.tar.xz mltk-b21ee6b876c851010bfe24c944c6a5034a6c0ba6.zip |
[runvirt] introduced wrapper script to start ...
... runvirt with to hopefully always have either a user notification
or a log entry on the satellites if anything goes wrong.
Also fixed the MAC address generation: the prefix is now fully defined
in the systemd-run_virt_env script and correctly written in the vmware's
dhcp configuration file (so that VMs the default local IP by default)
Diffstat (limited to 'core/modules/run-virt/data/opt/openslx/vmchooser')
4 files changed, 24 insertions, 36 deletions
diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc index 8e83811c..e551e5e8 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/init_core.inc @@ -5,9 +5,17 @@ declare -rg VMCHOOSER_DIR="/opt/openslx/vmchooser" declare -rg VMCHOOSER_CONF_DIR="$VMCHOOSER_DIR/config" declare -rg USER="$(whoami)" -declare -rg LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" declare -rg TMPDIR="/tmp/virt/${USER}/$$" +# Check if the path to the logfile was given externally (by the wrapper) +unset WRAPPED +if isset LOGFILE; then + # given by wrapper + declare -rg WRAPPED=aye +else + declare -rg LOGFILE="/var/log/openslx/run-virt.${USER}.$$.log" +fi + # Create temporary directory for current invocation if check_dep mkdir && ! mkdir -p "$TMPDIR"; then writelog "Could not create temporary directory '$TMPDIR' for session" diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc index 5fb14806..4bf46023 100644 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/run-virt-includes/set_runvirt_hardware_variables.inc @@ -10,12 +10,6 @@ # is the last in the list, use the first one again. # This way we support up to 10 nested/concurrent VMs. # Use: 00:FF:00 for firtual machines ;) -declare -gA MAC_PREFIXES -for i in {0..9}; do - # make an associate array, it will make our life easier later - MAC_PREFIXES["00:FF:0$i"]="$i" -done - ## Functions ## # Sets the VM's hostname to the original hostname prefixed with a fixed string and its ID @@ -71,20 +65,7 @@ set_virt_memory() { set_virt_mac() { # First, determine prefix of the host's MAC address isset HOSTMACADDR || writelog "Host's MAC address was not defined in ${VMCHOOSER_CONF_DIR}/virtualizer.conf" - local HOST_MAC_PREFIX=$(echo "$HOSTMACADDR" | tr '[a-z]' '[A-Z]' | grep -o -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}') - unset MACADDRPREFIX - if notempty HOST_MAC_PREFIX && notempty MAC_PREFIXES[${HOST_MAC_PREFIX}]; then - # the host's prefix was in our list, so use the next one in the list - local -i HOST_MAC_PREFIX_INDEX="${MAC_PREFIXES[${HOST_MAC_PREFIX}]}" # this will be at least 0 - # increment if its between 0 and 8 - if [[ $HOST_MAC_PREFIX_INDEX =~ ^[0-8]$ ]]; then - declare -g MACADDRPREFIX="${HOST_MAC_PREFIX%?}$(( ++HOST_MAC_PREFIX_INDEX ))" - fi - fi - # host's mac prefix could not be determined (practically this should never happen) - # or the prefix is not in our mac address list or we reached the end of the list. - # Either way, use first mac prefix in the list - notempty MACADDRPREFIX || declare -g MACADDRPREFIX="$(echo ${!MAC_PREFIXES[@]} | awk '{print $1}')" + isset MACADDRPREFIX || writelog "No MAC address prefix was defined in ${VMCHOOSER_CONF_DIR}/virtualizer.conf" # Fill in VM_ID local MACADDRSUFFIX=${MACADDRSUFFIX//%VMID%/"${VM_ID}"} 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 d09f6a75..2222b0af 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 @@ -134,10 +134,10 @@ cleanexit() { fi # Now see if we need to do the catch all error stuff - # no exit code given, return 129 - [ $# -eq 0 ] && exit 129 # if 0 given, exit 0 [ "x$1" = "x0" ] && exit 0 + # if no code was given, exit 129 + [ $# -eq 0 ] && writelog "Cleanexit called without arguments! Dev error?" # given exit code is set and not 0, handle the error now # now evaluate the EXIT_{TYPE,REASON} variables and generate error title/text @@ -168,8 +168,8 @@ cleanexit() { fi # first send the logfile (in case the user does not close the error before using magic keys e.g.) - # for any other error types besides 'user'. - [ "x${EXIT_TYPE}" != "xuser" ] && \ + # for any other error types besides 'user'. Do no slxlog if we run wrapped (from /opt/openslx/scripts/vmchooser-run_virt) + [ "x${EXIT_TYPE}" != "xuser" ] && ! isset WRAPPED && \ slxlog "runvirt-exit-${EXIT_TYPE}" "Critical error happened in '${BASH_SOURCE[1]}:${FUNCNAME[1]}', see logs." "${LOGFILE}" # finally display the error @@ -179,7 +179,8 @@ ${ERR_TEXT} ${ERR_FOOTER} " writelog "All done. Exiting." - exit "$1" + # if no exit code was given as $1, exit 129 + exit "${1:-129}" } ################# SOURCING FUNCTIONS ################# @@ -360,13 +361,13 @@ is_array() { # array_contains ARRAY_TO_TEST <values...> array_contains() { if [ $# -lt 2 ]; then - writelog "${FUNCNAME[0]}: Expects at least 2 arguments, $# given." + #writelog "${FUNCNAME[0]}: Expects at least 2 arguments, $# given." return 1 fi # is $1 even defined? local ARRAY_DEF="$(declare -p $1 2>/dev/null)" if isempty ARRAY_DEF; then - writelog "${FUNCNAME[0]}: '$1' not defined!" + #writelog "${FUNCNAME[0]}: '$1' not defined!" return 1 fi local ARRAY_NAME="$1" @@ -374,7 +375,7 @@ array_contains() { # sanity check on $ARRAY_DEF being either indexed or associative array if ! is_array "${ARRAY_NAME}"; then - writelog "${FUNCNAME[0]}: '${ARRAY_NAME}' not an array! Declared as:\t${ARRAY_DEF}" + #writelog "${FUNCNAME[0]}: '${ARRAY_NAME}' not an array! Declared as:\t${ARRAY_DEF}" return 1 fi @@ -382,7 +383,7 @@ array_contains() { while [ $# -gt 0 ]; do # check if ARRAY_DEF contains '"<value>"' if [[ ! "${ARRAY_DEF}" =~ '="'${1}'"'[^\]]+ ]]; then - writelog "${FUNCNAME[0]}: '${1}' not in '${ARRAY_NAME}'" + #writelog "${FUNCNAME[0]}: '${1}' not in '${ARRAY_NAME}'" return 1 fi shift diff --git a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt index 1bf9de3e..c4c053af 100755 --- a/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt +++ b/core/modules/run-virt/data/opt/openslx/vmchooser/vmchooser-run_virt @@ -18,18 +18,16 @@ # tools and then include the specific plugin which configures the speci- # fied virtualization tool. ################################################################################ - -# HACK: workaround if $0 is a symlink, exec its symlink target instead SELF=$(readlink -f "$0") -if [ -n "$SELF" ] && [ "$0" != "$SELF" ]; then - exec "$SELF" "$@" -fi -declare -rg RUN_VIRT_INCLUDE_DIR="$(dirname $SELF)/run-virt-includes" # 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 -rg 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 |