Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vnic-fix doesn't work since esxcli report "connection failed" #15

Open
leslie-qiwa opened this issue Aug 3, 2018 · 3 comments
Open

Comments

@leslie-qiwa
Copy link

Thanks for the patch. It is exactly useful. I'm trying to do nested ESX with the template, but MAC address is not updated when new VM boots. I tried to log message, and turned out it reports "connection failed" by esxcli.

My ESX version is 6.5.0.

@icnocop
Copy link

icnocop commented Feb 22, 2021

Hi @leslie-qiwa

Did you ever resolve this issue?
If so, how did you resolve it?

Thank you.

@leslie-qiwa
Copy link
Author

unfortunately, not yet.

@icnocop
Copy link

icnocop commented Feb 22, 2021

I was able to resolve this issue by delaying/waiting until a connection could be established.

I got the hint from this post:
https://communities.vmware.com/t5/ESXi-Discussions/Imaging-ESX-5-1-MAC-address-issues-with-DHCP/td-p/2152927
Sleep command is critical with out this delay the script executes too fast during the boot process and script will not work at boot time,

#!/bin/sh

# When an ESX VM is cloned, vnic0 gets a new mac from the vmx's
# ethernet0.generatedAddress, but vmk0's mac is persisted in /etc/vmware/esx.conf
# vagrant uses ethernet0.generatedAddress to lookup the VM ip in
# vmnet-dhcpd-vmnet8.leases, reconfigure here if needed.

os_ver=$(uname -r | awk -F. '{print $1}')

while [ "$vnic0_mac" == "" -o "$vmk0_mac" == "" ]
do
  if [ "$os_ver" -lt 6 ] ; then
    vnic0_mac=$(esxcli --formatter csv network nic list | grep vmnic0 | awk -F, '{print $5}')
    vmk0_mac=$(esxcli --formatter csv network ip interface list | grep vmk0 | awk -F, '{print $2}')
  else
    vnic0_mac=$(esxcli --formatter csv network nic list | grep vmnic0 | awk -F, '{print $7}')
    vmk0_mac=$(esxcli --formatter csv network ip interface list | grep vmk0 | awk -F, '{print $3}')
  fi
done

if [ "$vnic0_mac" != "$vmk0_mac" ] ; then
  esxcli network ip interface remove -i vmk0

  esxcli network ip interface add -i vmk0 -M $vnic0_mac -p "Management Network"

  esxcli network ip interface ipv4 set -i vmk0 -t dhcp
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants