r1988 - Find provisioning interface via hwaddr instead of device name

23 views
Skip to first unread message

com...@warewulf.lbl.gov

unread,
May 27, 2016, 6:10:54 PM5/27/16
to warewul...@lbl.gov
Author: bsallen
Date: 2016-05-27 15:10:52 -0700 (Fri, 27 May 2016)
New Revision: 1988

Modified:
trunk/provision/initramfs/functions
trunk/provision/initramfs/init
trunk/provision/lib/Warewulf/Provision/Pxelinux.pm
Log:
Find provisioning interface via hwaddr instead of device name

Modified: trunk/provision/initramfs/functions
===================================================================
--- trunk/provision/initramfs/functions 2016-05-12 19:44:44 UTC (rev 1987)
+++ trunk/provision/initramfs/functions 2016-05-27 22:10:52 UTC (rev 1988)
@@ -22,6 +22,9 @@
WWIPADDR=`sed -e '/ wwipaddr=/!d;s/.*wwipaddr=\([^ ]*\).*/\1/' /proc/cmdline`
export WWIPADDR

+WWHWADDR=`sed -e '/ wwhwaddr=/!d;s/.*wwhwaddr=\([^ ]*\).*/\1/' /proc/cmdline`
+export WWHWADDR
+
WWNETMASK=`sed -e '/ wwnetmask=/!d;s/.*wwnetmask=\([^ ]*\).*/\1/' /proc/cmdline`
export WWNETMASK


Modified: trunk/provision/initramfs/init
===================================================================
--- trunk/provision/initramfs/init 2016-05-12 19:44:44 UTC (rev 1987)
+++ trunk/provision/initramfs/init 2016-05-27 22:10:52 UTC (rev 1988)
@@ -68,6 +68,10 @@

ifup() {
DEVICE=$1
+ HWADDR=$2
+ # Device name to use in the generated init config files
+ OSDEVICE=$3
+
RETVAL=1
msg_white "Checking for network device: $DEVICE "
if ifconfig $DEVICE up >/dev/null 2>&1; then
@@ -80,12 +84,6 @@
wwfailure
fi
fi
- if [ -f "/sys/class/net/$DEVICE/address" ]; then
- HWADDR=`cat /sys/class/net/$DEVICE/address`
- if [ ${#HWADDR} -eq 59 ]; then
- HWADDR=`expr substr $HWADDR 37 23`
- fi
- fi
if [ -n "$WWIPADDR" -a -n "$WWNETMASK" -a -n "$WWMASTER" ]; then
msg_white "Configuring $DEVICE statically: "
msg_gray "($WWIPADDR/$WWNETMASK)"
@@ -101,15 +99,16 @@
fi
fi

- if [ -z "$WWPOSTNETDOWN" ]; then
- wwlogger "Creating network initialization files"
+ if [ -z "$WWNETCFGFILE" ]; then
+ msg_white "Creating network initialization files: "
+ msg_gray "($OSDEVICE)"
# Debian based /etc/network/interfaces
echo "# This was created by the Warewulf bootstrap" > /tmp/interfaces
echo "auto lo" >> /tmp/interfaces
echo "iface lo inet loopback" >> /tmp/interfaces
echo '' >> /tmp/interfaces
- echo "auto $DEVICE" >> /tmp/interfaces
- echo "iface $DEVICE inet static" >> /tmp/interfaces
+ echo "auto $OSDEVICE" >> /tmp/interfaces
+ echo "iface $OSDEVICE inet static" >> /tmp/interfaces
echo " address $WWIPADDR" >> /tmp/interfaces
echo " netmask $WWNETMASK" >> /tmp/interfaces
if [ -n "$WWGATEWAY" ]; then
@@ -120,19 +119,24 @@
fi

# RHEL based ifcfg
- echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$DEVICE
- echo "DEVICE=$DEVICE" >> /tmp/ifcfg-$DEVICE
- echo "BOOTPROTO=static" >> /tmp/ifcfg-$DEVICE
- echo "ONBOOT=yes" >> /tmp/ifcfg-$DEVICE
- echo "IPADDR=$WWIPADDR" >> /tmp/ifcfg-$DEVICE
- echo "NETMASK=$WWNETMASK" >> /tmp/ifcfg-$DEVICE
- echo "GATEWAY=$WWGATEWAY" >> /tmp/ifcfg-$DEVICE
- echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$DEVICE
+ echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$OSDEVICE
+ echo "DEVICE=$OSDEVICE" >> /tmp/ifcfg-$OSDEVICE
+ echo "BOOTPROTO=static" >> /tmp/ifcfg-$OSDEVICE
+ echo "ONBOOT=yes" >> /tmp/ifcfg-$OSDEVICE
+ echo "IPADDR=$WWIPADDR" >> /tmp/ifcfg-$OSDEVICE
+ echo "NETMASK=$WWNETMASK" >> /tmp/ifcfg-$OSDEVICE
+ if [ -n "$WWGATEWAY" ]; then
+ echo "GATEWAY=$WWGATEWAY" >> /tmp/ifcfg-$OSDEVICE
+ fi
+ if [ -n "$HWADDR" ]; then
+ echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$OSDEVICE
+ fi

if [ -n "$WWMTU" ]; then
- echo "MTU=$WWMTU" >> /tmp/ifcfg-$DEVICE # RHEL
+ echo "MTU=$WWMTU" >> /tmp/ifcfg-$OSDEVICE # RHEL
echo " mtu $WWMTU" >> /tmp/interfaces # DEB
fi
+ wwsuccess
fi

COUNT=0
@@ -161,15 +165,16 @@
msg_gray "($IPADDR/$NETMASK)"
wwsuccess

- if [ -z "$WWPOSTNETDOWN" ]; then
- wwlogger "Creating network initialization files"
+ if [ -z "$WWNETCFGFILE" ]; then
+ msg_white "Creating network initialization files: "
+ msg_gray "($OSDEVICE)"
# DEB
echo "# This was created by the Warewulf bootstrap" > /tmp/interfaces
echo "auto lo" >> /tmp/interfaces
echo "iface lo inet loopback" >> /tmp/interfaces
echo '' >> /tmp/interfaces
- echo "auto $DEVICE" >> /tmp/interfaces
- echo "iface $DEVICE inet static" >> /tmp/interfaces
+ echo "auto $OSDEVICE" >> /tmp/interfaces
+ echo "iface $OSDEVICE inet static" >> /tmp/interfaces
echo " address $WWIPADDR" >> /tmp/interfaces
echo " netmask $WWNETMASK" >> /tmp/interfaces
if [ -n "$WWGATEWAY" ]; then
@@ -180,18 +185,18 @@
fi

# RHEL
- echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$DEVICE
- echo "DEVICE=$DEVICE" >> /tmp/ifcfg-$DEVICE
- echo "BOOTPROTO=static" >> /tmp/ifcfg-$DEVICE
- echo "ONBOOT=yes" >> /tmp/ifcfg-$DEVICE
- echo "IPADDR=$IPADDR" >> /tmp/ifcfg-$DEVICE
- echo "NETMASK=$NETMASK" >> /tmp/ifcfg-$DEVICE
- echo "GATEWAY=$GATEWAY" >> /tmp/ifcfg-$DEVICE
- echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$DEVICE
+ echo "# This was created by the Warewulf bootstrap" > /tmp/ifcfg-$OSDEVICE
+ echo "DEVICE=$OSDEVICE" >> /tmp/ifcfg-$OSDEVICE
+ echo "BOOTPROTO=static" >> /tmp/ifcfg-$OSDEVICE
+ echo "ONBOOT=yes" >> /tmp/ifcfg-$OSDEVICE
+ echo "IPADDR=$IPADDR" >> /tmp/ifcfg-$OSDEVICE
+ echo "NETMASK=$NETMASK" >> /tmp/ifcfg-$OSDEVICE
+ echo "GATEWAY=$GATEWAY" >> /tmp/ifcfg-$OSDEVICE
+ echo "HWADDR=$HWADDR" >> /tmp/ifcfg-$OSDEVICE
fi

if [ -n "$WWMTU" ]; then
- echo "MTU=$WWMTU" >> /tmp/ifcfg-$DEVICE # RHEL
+ echo "MTU=$WWMTU" >> /tmp/ifcfg-$OSDEVICE # RHEL
echo " mtu $WWMTU" >> /tmp/interfaces # DEB
fi
return 0
@@ -219,17 +224,30 @@
wwfailure
fi

-# First try the defined wwnetdev if it exists
-if [ -n "$WWNETDEV" ]; then
- if ifup $WWNETDEV; then
- echo "$WWNETDEV" > /tmp/wwdev
+# First try to find interface based on WWHWADDR
+for i in `echo /sys/class/net/* | xargs -n1 /usr/bin/basename | grep -v lo`; do
+ HWADDR=`cat /sys/class/net/$i/address`
+ # Use GUID if IB
+ if [ ${#HWADDR} -eq 59 ]; then
+ HWADDR=`expr substr $HWADDR 37 23`
fi
-fi
+ if [ $HWADDR == $WWHWADDR ]; then
+ if ifup $i $WWHWADDR $WWNETDEV; then
+ echo "$i" > /tmp/wwdev
+ fi
+ break
+ fi
+done

# If the above doesn't exist or fails, then try brute force
if [ ! -f /tmp/wwdev ]; then
- for i in eth0 eth1 eth2 eth3 eth4; do
- if ifup $i; then
+ for i in `echo /sys/class/net/* | xargs -n1 /usr/bin/basename | grep -v lo`; do
+ HWADDR=`cat /sys/class/net/$i/address`
+ # Use GUID if IB
+ if [ ${#HWADDR} -eq 59 ]; then
+ HWADDR=`expr substr $HWADDR 37 23`
+ fi
+ if ifup $i $HWADDR $WWNETDEV; then
echo "$i" > /tmp/wwdev
break
fi

Modified: trunk/provision/lib/Warewulf/Provision/Pxelinux.pm
===================================================================
--- trunk/provision/lib/Warewulf/Provision/Pxelinux.pm 2016-05-12 19:44:44 UTC (rev 1987)
+++ trunk/provision/lib/Warewulf/Provision/Pxelinux.pm 2016-05-27 22:10:52 UTC (rev 1988)
@@ -212,8 +212,9 @@
if ($hwaddr =~ /^([0-9a-zA-Z:]+)$/) {
$hwaddr = $1;
&iprint("Building Pxelinux configuration for: $nodename/$hwaddr\n");
- $hwaddr =~ s/:/-/g;
- my $config = $hwprefix ."-". $hwaddr;
+ my $config = $hwaddr;
+ $config =~ s/:/-/g;
+ $config = $hwprefix ."-". $config;

if (! $bootstrapid) {
&iprint("Skipping $nodename-$devname-$hwaddr: No bootstrap defined\n");
@@ -261,7 +262,7 @@
print PXELINUX "wwmaster=$master_ipaddr ";
}
if ($devname and $node_ipaddr and $node_netmask) {
- print PXELINUX "wwipaddr=$node_ipaddr wwnetmask=$node_netmask wwnetdev=$devname ";
+ print PXELINUX "wwipaddr=$node_ipaddr wwnetmask=$node_netmask wwnetdev=$devname wwhwaddr=$hwaddr ";
} else {
&dprint("$hostname: Skipping static network definition because configuration not complete\n");
}

Allen, Benjamin S.

unread,
May 29, 2016, 2:38:00 PM5/29/16
to warewul...@lbl.gov
Could someone with a Debian or Ubuntu setup test this and r1989?

This change lets you use whatever netdev name you want in Warewulf, the bootstrap will match against HWADDR. Then use WWNETDEV for the interface configuration file in the NEWROOT. This has been tested with RHEL7 so far.

Thanks,

Ben
> --
> You received this message because you are subscribed to the Google Groups "Warewulf-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to warewulf-deve...@lbl.gov.
>

Reply all
Reply to author
Forward
0 new messages