diff options
| author | Jonathan Bauer | 2016-07-12 13:02:53 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2016-07-12 13:02:53 +0200 |
| commit | a2e4686cf67f80e29c902bbb3437c6926029b0e6 (patch) | |
| tree | bf2e16fe38a167ab19ac9a3e355ba28e3592fdb9 /remote/modules/run-virt/data/opt/openslx/scripts/includes | |
| parent | Merge branch 'master' of git.openslx.org:openslx-ng/tm-scripts (diff) | |
| parent | [kernel-vanilla] 4.4.13 (diff) | |
| download | tm-scripts-a2e4686cf67f80e29c902bbb3437c6926029b0e6.tar.gz tm-scripts-a2e4686cf67f80e29c902bbb3437c6926029b0e6.tar.xz tm-scripts-a2e4686cf67f80e29c902bbb3437c6926029b0e6.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/tm-scripts
Diffstat (limited to 'remote/modules/run-virt/data/opt/openslx/scripts/includes')
| -rw-r--r-- | remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc b/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc index 1b386092..9a46bc88 100644 --- a/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc +++ b/remote/modules/run-virt/data/opt/openslx/scripts/includes/set_runvirt_hardware_variables.inc @@ -2,8 +2,26 @@ # Include: Set hardware related variables # ########################################### -# take last two digits of current pid... -VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2) +get_vm_id() { + local script=${BASH_SOURCE[-1]} + [ -z "$script" ] && script="$0" + if [ -n "$script" ]; then + script=$(readlink -f "$script") + if [ -n "$script" ] && [ -s "$script" ]; then + #bingo + VM_ID=$(ps ax | grep -F "$script" | grep -v 'grep' | grep -o -- "${script}.*\$" | sort -u | wc -l) + if [ "$VM_ID" -gt 0 ]; then + [ "${#VM_ID}" -eq 1 ] && VM_ID="0${VM_ID}" + [ "${#VM_ID}" -gt 2 ] && VM_ID="${VM_ID:0:2}" + [ "${#VM_ID}" -eq 2 ] && return + fi + fi + fi + # fallback: take last two digits of current pid... + VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2) +} + +get_vm_id # Make sure cpu_cores is not empty cpu_cores=${cpu_cores:-"1"} @@ -33,18 +51,16 @@ if [ -n "$mainvirtmem" ]; then fi hostmem="$[ $totalmem - $mem ]" -# TODO: We should only generate the suffix here (last 3 octets) as the first 3 are -# dependant on the virtualizer/emulator. Check if any run-virt.include still relies on -# $macguestpart/$macaddr. If so, fix it to use its specific first 3 bytes -# and append $macaddrssuffix -macguestpart="00:50:56:${VM_ID}" -machostpart=$(echo "${hostmacaddr}" | awk -F ":" '{print $(NF-1)":"$NF}') -macaddr=$(echo "${macguestpart}:${machostpart}" | tr "[a-z]" "[A-Z]") -macaddrsuffix=$(echo "${VM_ID}:${machostpart}" | tr "[a-z]" "[A-Z]") +# Fill in VMID +macaddrsuffix=$(echo "$macaddrsuffix" | sed "s/%VMID%/${VM_ID}/") +if ! echo "$macaddrprefix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then + slxlog "virt-mac" "Could not properly generate mac address prefix (got $macaddrprefix)" +fi if ! echo "$macaddrsuffix" | grep -q -E '^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$'; then slxlog "virt-mac" "Could not properly generate mac address suffix (got $macaddrsuffix)" fi +macaddr="$macaddrprefix:$macaddrsuffix" # Virtual fd/cd/dvd and drive devices, floppy b: for configuration # if $floppy_0 from virtualization.conf set then fdtest="TRUE" |
