From 1d2f52245e0cb876cecb4b758fb2ebdac2d706c9 Mon Sep 17 00:00:00 2001 From: David Galloway Date: Fri, 17 Nov 2017 12:28:01 -0500 Subject: [PATCH] cobbler: Configure testnode NIC on firstboot after FOG image Signed-off-by: David Galloway --- .../templates/snippets/cephlab_rc_local | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/roles/cobbler/templates/snippets/cephlab_rc_local b/roles/cobbler/templates/snippets/cephlab_rc_local index 9bb5aab1..bc4a642a 100644 --- a/roles/cobbler/templates/snippets/cephlab_rc_local +++ b/roles/cobbler/templates/snippets/cephlab_rc_local @@ -18,6 +18,35 @@ set -ex {% if rclocal_nameserver is defined %} #raw +if [ ! -f /.cephlab_net_configured ]; then + nics=$(ls -1 /sys/class/net | grep -v lo) + + for nic in $nics; do + # Bring the NIC up so we can detect if a link is present + ifconfig $nic up + # Sleep for a bit to let the NIC come up + sleep 5 + if ethtool $nic | grep -q "Link detected: yes"; then + if command -v apt-get &>/dev/null; then + echo -e "auto lo\niface lo inet loopback\n\nauto $nic\niface $nic inet dhcp" > /etc/network/interfaces + else + #if [ ! -f /etc/sysconfig/network-scripts/ifcfg-$nic ]; then + echo -e "DEVICE=$nic\nBOOTPROTO=dhcp\nONBOOT=yes" > /etc/sysconfig/network-scripts/ifcfg-$nic + #fi + fi + # Bounce the NIC so it gets a DHCP address + ifdown $nic + ifup $nic + # Write our lockfile so this only gets run on firstboot + touch /.cephlab_net_configured + # Quit loop after first NIC is configured + break + else + # Take the NIC back down if it's not connected + ifconfig $nic down + fi + done +fi # Don't error out if the `ip` command returns rc 1 set +e -- 2.47.3