Skip to content

Commit e83027b

Browse files
authored
Merge pull request RackHD#514 from lanchongyizu/bugfix/ks-static-ip-mac
Keep the MAC Address if possible when link it to the new portgroup
2 parents 58d6b3b + aa3ef92 commit e83027b

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

data/templates/esx-ks

+19-15
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,39 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
132132
<% }); %>
133133
<% } %>
134134

135+
#parameters:vmkName, portgroup, switchName
136+
createVmk () {
137+
vmkMac=`esxcli network ip interface list | sed -ne '/^.*\Name: $1.*$/{N;s/.*MAC Address: //;p}'`
138+
esxcli network vswitch standard portgroup add -p $2 -v $3
139+
esxcli network ip interface remove -i $1
140+
if [ -z $vmkMac ]
141+
then
142+
esxcli network ip interface add -i $1 -p $2
143+
else
144+
esxcli network ip interface add -i $1 -p $2 -M $vmkMac
145+
fi
146+
}
147+
135148
<% vmkid = 0 %>
136149
<% if( typeof networkDevices !== 'undefined' ) { %>
137150
<% networkDevices.forEach(function(n) { %>
138151
currdev=<%=n.device%>
152+
esxSwitchName=<%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
139153
<% if (n.device.substring(0,5) != 'vmnic') { %>
140154
currdev=`esxcli network nic list | grep <%=n.device%> | cut -d ' ' -f 1`
141155
<% } %>
142156
<% if( undefined !== n.ipv4 ) { %>
143157
<% if( undefined !== n.ipv4.vlanIds ) { %>
144158
<% n.ipv4.vlanIds.forEach(function(vid) { %>
145159
<% vmkname = 'vmk' + vmkid++ %>
146-
esxcli network vswitch standard portgroup add -p $currdev.<%=vid%> -v "<%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>"
147-
esxcli network ip interface remove -i <%=vmkname%>
148-
esxcli network ip interface add -i <%=vmkname%> -p $currdev.<%=vid%>
160+
createVmk <%=vmkname%> $currdev.<%=vid%> $esxSwitchName
149161
esxcli network ip interface ipv4 set -i <%=vmkname%> -I <%=n.ipv4.ipAddr%> -N <%=n.ipv4.netmask%> -t static
150162
esxcli network ip route ipv4 add -n default -g <%=n.ipv4.gateway%>
151163
esxcli network vswitch standard portgroup set -p $currdev.<%=vid%> -v <%=vid %>
152164
<% }); %>
153165
<% } else { %>
154166
<% vmkname = 'vmk' + vmkid++ %>
155-
esxcli network vswitch standard portgroup add -p $currdev -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
156-
esxcli network ip interface remove -i <%=vmkname%>
157-
esxcli network ip interface add -i <%=vmkname%> -p $currdev
167+
createVmk <%=vmkname%> $currdev $esxSwitchName
158168
esxcli network ip interface ipv4 set -i <%=vmkname%> -I <%=n.ipv4.ipAddr%> -N <%=n.ipv4.netmask%> -t static
159169
esxcli network ip route ipv4 add -n default -g <%=n.ipv4.gateway%>
160170
<% } %>
@@ -163,25 +173,19 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
163173
<% if( undefined !== n.ipv6.vlanIds ) { %>
164174
<% n.ipv6.vlanIds.forEach(function(vid) { %>
165175
<% vmkname = 'vmk' + vmkid++ %>
166-
esxcli network vswitch standard portgroup add -p $currdev.<%=vid%> -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
167-
esxcli network ip interface remove -i <%=vmkname%>
168-
esxcli network ip interface add -i <%=vmkname%> -p $currdev.<%=vid%>
176+
createVmk <%=vmkname%> $currdev.<%=vid%> $esxSwitchName
169177
esxcli network ip interface ipv6 address add -i <%=vmkname%> -I <%=n.ipv6.ipAddr%>
170178
esxcli network vswitch standard portgroup set -p $currdev.<%=vid%> -v <%=vid %>
171179
<% }); %>
172180
<% } else { %>
173181
<% vmkname = 'vmk' + vmkid++ %>
174-
esxcli network vswitch standard portgroup add -p $currdev -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
175-
esxcli network ip interface remove -i <%=vmkname%>
176-
esxcli network ip interface add -i <%=vmkname%> -p $currdev
182+
createVmk <%=vmkname%> $currdev $esxSwitchName
177183
esxcli network ip interface ipv6 address add -i <%=vmkname%> -I <%=n.ipv6.ipAddr%>
178184
<% } %>
179185
<% } %>
180186
<% if( (undefined === n.ipv6) && (undefined === n.ipv4) ) { %>
181187
<% vmkname = 'vmk' + vmkid++ %>
182-
esxcli network vswitch standard portgroup add -p $currdev -v <%= typeof n.esxSwitchName!='undefined' ? n.esxSwitchName : 'vSwitch0' %>
183-
esxcli network ip interface remove -i <%=vmkname%>
184-
esxcli network ip interface add -i <%=vmkname%> -p $currdev
188+
createVmk <%=vmkname%> $currdev $esxSwitchName
185189
esxcli network ip interface ipv4 set -i <%=vmkname%> -t dhcp
186190
<% } %>
187191
<% }); %>

0 commit comments

Comments
 (0)