From d919efe86f80879848e1a43007680d3c92d7c40b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Nov 2017 14:36:46 +0100 Subject: [vmware*/run-virt] Implement NIC bridging Implements #3109 --- .../data/opt/openslx/scripts/systemd-vmware_env | 5 ++-- .../plugins/vmware/includes/write_final_vmx.inc | 32 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'core/modules/vmware12') diff --git a/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env b/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env index 0c0e5966..4e381bf0 100755 --- a/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env +++ b/core/modules/vmware12/data/opt/openslx/scripts/systemd-vmware_env @@ -67,18 +67,19 @@ vmnetif () { brctl addif vsw2 vmnet2 # 2) see if we should bridge additional interfaces NICS= - if [ "$SLX_BRIDGE_OTHER_NICS" = "ON" ]; then + if [ "$SLX_BRIDGE_OTHER_NICS" = "yes" ]; then # These will have been set up in our init NICS=$( ls -1 /sys/class/net | grep '^br-nic-' | cut -c 8- ) + vmnet=10 for nic in $NICS; do if ! [ "$nic" -gt 0 ] && ! [ "$nic" -eq 0 ]; then slxlog "vmware-other-nics" "NaN: br-nic-X has X='$nic'" continue fi # create vmnet10 - vmnetN for these - vmnet="$(( nic + 10 ))" vmnet_create "$vmnet" brctl addif "br-nic-${nic}" "vmnet${vmnet}" + vmnet="$(( vmnet + 1 ))" done fi diff --git a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc index a431560f..8bc6cb3d 100644 --- a/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc +++ b/core/modules/vmware12/data/opt/openslx/vmchooser/plugins/vmware/includes/write_final_vmx.inc @@ -22,6 +22,38 @@ replace_placeholders() { setup_ethernet() { echo 'ethernet0.addressType = "static"' >> "${TMPCONFIG}" echo 'ethernet0.address = "'"${VM_MAC_ADDR}"'"' >> "${TMPCONFIG}" + if [ -n "$OTHER_NICS" ]; then + local devtype mac cnt eth + # Copy type of eth0, in case the others don't specify a type in the vmx, we'll use the same + # so we know the drivers are there + devtype=$(grep -m1 -i '^ethernet0\.virtualDev' | sed -r 's/^[^=]+//;s/^(\s|=|")*//;s/(\s|")+$//') # TODO: Make a helper like "getVmxOption" + cnt=0 + for mac in $OTHER_NICS; do + vmnet=$(( cnt + 10 )) + cnt=$(( cnt + 1 )) + eth="ethernet${cnt}" + # Check device exists + if ! [ -c "/dev/vmnet${vmnet}" ]; then + slxlog "vmware-bridge-setup" "Cannot bridge NIC into VM: /dev/vmnet${vmnet} does not exist" + continue + fi + # Remove lines that could break things + sed -i "/^${eth}\.connectionType/Id;/^${eth}\.present/Id" "${TMPCONFIG}" + # Set up devType + devline= + if ! grep -q -i "^${eth}\.virtualDev" "${TMPCONFIG}" && [ -n "$devtype" ]; then + devline="${eth}.virtualDev = "'"'"${devtype}"'"' + fi + cat >> "${TMPCONFIG}" <<-HEND + ${eth}.connectionType = "custom" + ${eth}.present = "TRUE" + ${eth}.vnet = "vmnet${vmnet}" + ${eth}.addressType = "static" + ${eth}.address = "${mac}" + ${devline} + HEND + done + fi } # DVD, CDROM -- cgit v1.2.3-55-g7522