Skip to content

Commit

Permalink
Merge pull request RackHD#514 from lanchongyizu/bugfix/ks-static-ip-mac
Browse files Browse the repository at this point in the history
Keep the MAC Address if possible when link it to the new portgroup
  • Loading branch information
yyscamper authored Apr 25, 2017
2 parents 58d6b3b + aa3ef92 commit e83027b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions data/templates/esx-ks
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,39 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
<% }); %>
<% } %>

#parameters:vmkName, portgroup, switchName
createVmk () {
vmkMac=`esxcli network ip interface list | sed -ne '/^.*\Name: $1.*$/{N;s/.*MAC Address: //;p}'`
esxcli network vswitch standard portgroup add -p $2 -v $3
esxcli network ip interface remove -i $1
if [ -z $vmkMac ]
then
esxcli network ip interface add -i $1 -p $2
else
esxcli network ip interface add -i $1 -p $2 -M $vmkMac
fi
}

<% vmkid = 0 %>
<% if( typeof networkDevices !== 'undefined' ) { %>
<% networkDevices.forEach(function(n) { %>
currdev=<%=n.device%>
esxSwitchName=<%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
<% if (n.device.substring(0,5) != 'vmnic') { %>
currdev=`esxcli network nic list | grep <%=n.device%> | cut -d ' ' -f 1`
<% } %>
<% if( undefined !== n.ipv4 ) { %>
<% if( undefined !== n.ipv4.vlanIds ) { %>
<% n.ipv4.vlanIds.forEach(function(vid) { %>
<% vmkname = 'vmk' + vmkid++ %>
esxcli network vswitch standard portgroup add -p $currdev.<%=vid%> -v "<%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>"
esxcli network ip interface remove -i <%=vmkname%>
esxcli network ip interface add -i <%=vmkname%> -p $currdev.<%=vid%>
createVmk <%=vmkname%> $currdev.<%=vid%> $esxSwitchName
esxcli network ip interface ipv4 set -i <%=vmkname%> -I <%=n.ipv4.ipAddr%> -N <%=n.ipv4.netmask%> -t static
esxcli network ip route ipv4 add -n default -g <%=n.ipv4.gateway%>
esxcli network vswitch standard portgroup set -p $currdev.<%=vid%> -v <%=vid %>
<% }); %>
<% } else { %>
<% vmkname = 'vmk' + vmkid++ %>
esxcli network vswitch standard portgroup add -p $currdev -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
esxcli network ip interface remove -i <%=vmkname%>
esxcli network ip interface add -i <%=vmkname%> -p $currdev
createVmk <%=vmkname%> $currdev $esxSwitchName
esxcli network ip interface ipv4 set -i <%=vmkname%> -I <%=n.ipv4.ipAddr%> -N <%=n.ipv4.netmask%> -t static
esxcli network ip route ipv4 add -n default -g <%=n.ipv4.gateway%>
<% } %>
Expand All @@ -163,25 +173,19 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
<% if( undefined !== n.ipv6.vlanIds ) { %>
<% n.ipv6.vlanIds.forEach(function(vid) { %>
<% vmkname = 'vmk' + vmkid++ %>
esxcli network vswitch standard portgroup add -p $currdev.<%=vid%> -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
esxcli network ip interface remove -i <%=vmkname%>
esxcli network ip interface add -i <%=vmkname%> -p $currdev.<%=vid%>
createVmk <%=vmkname%> $currdev.<%=vid%> $esxSwitchName
esxcli network ip interface ipv6 address add -i <%=vmkname%> -I <%=n.ipv6.ipAddr%>
esxcli network vswitch standard portgroup set -p $currdev.<%=vid%> -v <%=vid %>
<% }); %>
<% } else { %>
<% vmkname = 'vmk' + vmkid++ %>
esxcli network vswitch standard portgroup add -p $currdev -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
esxcli network ip interface remove -i <%=vmkname%>
esxcli network ip interface add -i <%=vmkname%> -p $currdev
createVmk <%=vmkname%> $currdev $esxSwitchName
esxcli network ip interface ipv6 address add -i <%=vmkname%> -I <%=n.ipv6.ipAddr%>
<% } %>
<% } %>
<% if( (undefined === n.ipv6) && (undefined === n.ipv4) ) { %>
<% vmkname = 'vmk' + vmkid++ %>
esxcli network vswitch standard portgroup add -p $currdev -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
esxcli network ip interface remove -i <%=vmkname%>
esxcli network ip interface add -i <%=vmkname%> -p $currdev
createVmk <%=vmkname%> $currdev $esxSwitchName
esxcli network ip interface ipv4 set -i <%=vmkname%> -t dhcp
<% } %>
<% }); %>
Expand Down

0 comments on commit e83027b

Please sign in to comment.