Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions data/templates/esx-ks
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,6 @@ reboot

%firstboot --interpreter=busybox

postLookup () {
echo "Attempting postLookup operation on $1" >> /vmfs/volumes/datastore1/firstboot.log
mac=`esxcli --debug --formatter=csv network ip interface list | grep $1 | awk -F, '{print $3}'`
if [ "<%=version%>" == "5.5" ]; then
mac=`esxcli --debug --formatter=csv network ip interface list | grep $1 | awk -F, '{print $2}'`
fi
BODY="{"
BODY=$BODY"\"macAddress\": \"$mac\","
BODY=$BODY"\"ipAddress\": \"$2\","
BODY=$BODY"\"node\": \"<%=nodeId%>\""
BODY=$BODY"}"
BODYLEN=$(echo -n ${BODY} | wc -c )
echo ${BODY} >> /vmfs/volumes/datastore1/firstboot.log
result=`echo -ne "POST /api/current/lookups HTTP/1.0\r\nHost: $2\r\nContent-Type: application/json\r\nContent-Length: ${BODYLEN}\r\n\r\n${BODY}" | nc -i 3 <%=server%> <%=port%> | grep -oE 'HTTP/1.1 [0-9]{3}' | awk '{print $2}'`
if [ "$result" -ge "400" ]; then
# Make an attempt to PATCH if we can find the node id. This is to handle the case where the
# ARP poller added the lookup entry when we tried to POST above causing a collision.
id=`wget http://<%=server%>:<%=port%>/api/current/lookups?q=$2 -qO - | grep -oE '\"id\":\"(.)*\"'`
if [ "$?" -eq "0" ]; then
id=`echo $id | awk -F: '{gsub(/"/,"",$2); print $2}'`
result=`echo -ne "PATCH /api/current/lookups/$id HTTP/1.0\r\nHost: $2\r\nContent-Type: application/json\r\nContent-Length: ${BODYLEN}\r\n\r\n${BODY}" | nc -i 3 <%=server%> <%=port%> | grep -oE 'HTTP/1.1 [0-9]{3}' | awk '{print $2}'`
echo "Patch result: $result to id: $id" >> /vmfs/volumes/datastore1/firstboot.log
fi
fi
wget http://<%=server%>:<%=port%>/api/current/lookups?q=$2 -qO - >> /vmfs/volumes/datastore1/firstboot.log
}

# enable VHV (Virtual Hardware Virtualization to run nested 64bit Guests + Hyper-V VM)
grep -i "vhv.enable" /etc/vmware/config || echo "vhv.enable = \"TRUE\"" >> /etc/vmware/config

Expand Down Expand Up @@ -170,7 +143,6 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
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 %>
postLookup <%=vmkname%> <%=n.ipv4.ipAddr%>
<% }); %>
<% } else { %>
<% vmkname = 'vmk' + vmkid++ %>
Expand All @@ -179,7 +151,6 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
esxcli network ip interface add -i <%=vmkname%> -p $currdev
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%>
postLookup <%=vmkname%> <%=n.ipv4.ipAddr%>
<% } %>
<% } %>
<% if( undefined !== n.ipv6 ) { %>
Expand Down Expand Up @@ -216,7 +187,7 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
<% }); %>
<% } %>

# Download the service to callback to RackHD after OS installation/reboot completion
# The service to callback to RackHD after OS installation/reboot completion
# %firstboot ends with a reboot, this script will run afterwards to signify completion
# of the installer and all reboot steps.
#
Expand All @@ -236,15 +207,22 @@ cp /var/log/esxi_install.log "/vmfs/volumes/datastore1/firstboot-esxi_install.lo
#
# NOTE: this script will execute right away as a result of writing it to local.sh
# along with executing on every subsequent boot
wget http://<%=server%>:<%=port%>/api/current/templates/<%=rackhdCallbackScript%> -O /etc/rc.local.d/local.sh
cat /vmfs/volumes/datastore1/callback.script > /etc/rc.local.d/local.sh

#backup ESXi configuration to persist it
/sbin/auto-backup.sh

#reboot the system after host configuration
esxcli system shutdown reboot -d 10 -r "Rebooting after first boot host configuration"

%pre --interpreter=busybox
#disable firewall
localcli network firewall set --enabled no
# Download the service to callback to RackHD after OS installation/reboot completion
wget http://<%=server%>:<%=port%>/api/current/templates/<%=rackhdCallbackScript%> -O /tmp/callback.script

%post --interpreter=busybox
mv /tmp/callback.script /vmfs/volumes/datastore1/callback.script
#disable firewall
localcli network firewall set --enabled no
#signify ORA the installation completed
Expand Down