metal/bsp-files/kickstarts/post_net_common.cfg
Saul Wold 8d1695fa6a Convert BOOTIF MAC to NIC name
When booting via PXE one can set the ksdevice=bootif and add
'IPAPPEND 2' to the PXE boot config, this will set the MAC
address in the BOOTIF kernel cmdline which can then be used to
determine the NIC name to be used for the installation.

Tested with both valid and invalid input to BOOTIF=

Story: 2007486
Task: 39205
Change-Id: Iec1e8215571a6bb8fb79a461ce9210dddf2c764f
Signed-off-by: Saul Wold <sgw@linux.intel.com>
2020-04-03 09:56:41 -07:00

145 lines
4.0 KiB
INI
Executable File

%pre --erroronfail
# Source common functions
. /tmp/ks-functions.sh
http_port=$(get_http_port)
echo "repo --name=base --baseurl=http://pxecontroller:${http_port:-8080}/feed/rel-xxxPLATFORM_RELEASExxx/" > /tmp/repo-include
echo "repo --name=updates --baseurl=http://pxecontroller:${http_port:-8080}/updates/rel-xxxPLATFORM_RELEASExxx/" > /tmp/repo-include
%end
# Repository arguments from %pre
%include /tmp/repo-include
%post --erroronfail
# Source common functions
. /tmp/ks-functions.sh
# Persist the http port to the platform configuration
echo http_port=$(get_http_port) >> /etc/platform/platform.conf
# Obtain the boot interface from the PXE boot
BOOTIF=$(cat /proc/cmdline |xargs -n1 echo |grep BOOTIF=)
BOOTIF=${BOOTIF#BOOTIF=}
mgmt_dev=none
mgmt_vlan=0
if [ -n "$BOOTIF" ] ; then
BOOTIF=$(echo $BOOTIF | sed -r -e 's/.*(..-..-..-..-..-..)$/\1/' -e 's/-/:/g')
ndev=$(ip -br link | awk -v mac="$BOOTIF" '$0 ~ mac {print $1}')
if [ -n "$ndev" ] ; then
mgmt_dev=$ndev
# Retrieve the management VLAN from sysinv if it exists
mgmt_vlan=`curl -sf http://pxecontroller:6385/v1/isystems/mgmtvlan`
if [ $? -ne 0 ]
then
report_post_failure_with_msg "ERROR: Unable to communicate with System Inventory REST API. Aborting installation."
fi
else
report_post_failure_with_msg "ERROR: Unable to determine mgmt interface from BOOTIF=$BOOTIF."
fi
else
report_post_failure_with_msg "ERROR: BOOTIF is not set. Unable to determine mgmt interface."
fi
if [ $mgmt_vlan -eq 0 ] ; then
# Persist the boot device to the platform configuration. This will get
# overwritten later if the management_interface is on a bonded interface.
echo management_interface=$mgmt_dev >> /etc/platform/platform.conf
# Build networking scripts
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
IPV6_AUTOCONF=no
NAME=loopback
EOF
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$mgmt_dev
DEVICE=$mgmt_dev
BOOTPROTO=dhcp
ONBOOT=yes
IPV6_AUTOCONF=no
LINKDELAY=20
EOF
else
# Check whether to use inet or inet6
ipv6_addr=$(dig +short AAAA controller)
if [[ -n "$ipv6_addr" ]]
then
mgmt_address_family=inet6
ipv6init=yes
dhcpv6c=yes
dhclientargs=-1
else
mgmt_address_family=inet
ipv6init=no
dhcpv6c=no
dhclientargs=
fi
# Persist the boot device to the platform configuration. This will get
# overwritten later if the management_interface is on a bonded interface.
echo management_interface=vlan$mgmt_vlan >> /etc/platform/platform.conf
# Build networking scripts
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
IPV6_AUTOCONF=no
NAME=loopback
EOF
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-$mgmt_dev
DEVICE=$mgmt_dev
BOOTPROTO=none
ONBOOT=yes
IPV6_AUTOCONF=no
LINKDELAY=20
EOF
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-vlan$mgmt_vlan
DEVICE=vlan$mgmt_vlan
BOOTPROTO=dhcp
DHCLIENTARGS=$dhclientargs
IPV6INIT=$ipv6init
DHCPV6C=$dhcpv6c
ONBOOT=yes
IPV6_AUTOCONF=no
PHYSDEV=$mgmt_dev
VLAN=yes
LINKDELAY=20
EOF
# Reject DHCPOFFER from DHCP server that doesn't send
# wrs-install-uuid option
echo "require wrs-install-uuid;" >>/etc/dhcp/dhclient.conf
echo "require dhcp6.wrs-install-uuid;" >>/etc/dhcp/dhclient.conf
# Bring up the mgmt vlan so that a dhcp lease is acquired and an address is
# setup prior to the post-install reboot. This is so that the timing of the IP
# address allocation is similar to how normal/non-pxe installation works.
mgmt_iface=vlan$mgmt_vlan
dhclient_family=$([[ $mgmt_address_family == "inet" ]] && echo -4 || echo -6)
ip link add link $mgmt_dev name $mgmt_iface type vlan id $mgmt_vlan
ip link set up dev $mgmt_iface
dhclient $dhclient_family $mgmt_iface || true
fi
%end