From 571c1bae2d14ccb25471cca6e008c87b623e1678 Mon Sep 17 00:00:00 2001 From: sikorsky Date: Wed, 10 Sep 2008 15:04:32 +0000 Subject: [PATCH] Allows diskless nodes to boot via other interfaces aside of primary boot interface, ie. provides ethernet failover. 1) In initrd, bring up aside from main interface (genimage -i option) also other interfaces (-r option). 2) /etc/resolv.conf creation needed to be rewritten, othewise it gets confused by several dhcpcd records. 3) Fill database with MAC addresses for all interfaces. Since it't not possible to have several stanzas of the same name in dhcpd.conf, we need to define unique "alias" for every interface. For example, for host "host1" we will add '00:1A:64:5D:1B:84!host1e0|00:1A:64:5D:1B:86!host1e1' to macs table. Of course, this aliases have to be defined in DNS, otherwise makedhcp command will not use this aliases: /etc/hosts: 10.217.249.232 host1 host1e0 host1e1 Since this are aliases (need not be nessesary), both interfaces get the same IP address during initrd, but this doesn't break anything. a) blades - changed getmacs function to gather all MAC addresses. Which interfaces we are interested in are defined in noderes.installnic or noderes.primarynic as "eth0|eth1". b) all other - TODO. We have only 8 non-blade nodes, so we fill database manually. Backwards compatible: - if there is only one interface in noderes.installnic, getmacs function gathers only this one MAC address - if we run genimage without -r option, only one interface is brought up git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2124 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/blade.pm | 39 +++++++++++++------- xCAT-server/share/xcat/netboot/sles/genimage | 22 +++++++---- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/blade.pm b/xCAT-server/lib/xcat/plugins/blade.pm index 418d0e4bf..1dcbc75c2 100644 --- a/xCAT-server/lib/xcat/plugins/blade.pm +++ b/xCAT-server/lib/xcat/plugins/blade.pm @@ -928,6 +928,7 @@ sub rscan_stanza { sub getmacs { (my $code,my @macs)=inv('mac'); my $midx=0; + my @midxary; my $nrtab = xCAT::Table->new('noderes'); if ($nrtab) { my $nent = $nrtab->getNodeAttribs($curn,['primarynic','installnic']); @@ -939,24 +940,36 @@ sub getmacs { $mkey="primarynic"; } if ($mkey) { - $nent->{$mkey} =~ /(\d+)/; - $midx=$1; + while ( $nent->{$mkey} =~ /(\d+)/g ) { + push @midxary,$1; + } } } } if ($code==0) { #my @macs = split /\n/,$macs; - (my $macd,my $mac) = split (/:/,$macs[$midx],2); - $mac =~ s/\s+//g; - if ($macd =~ /mac address \d/i) { - $mac =~ s/\s*->.*$//; - my $mactab = xCAT::Table->new('mac',-create=>1); - $mactab->setNodeAttribs($curn,{mac=>$mac}); - $mactab->close; - return 0,":mac.mac set to $mac"; - } else { - return 1,"Unable to retrieve MAC address from Management Module"; - } + my @allmacs; + foreach my $midx ( @midxary) { + (my $macd,my $mac) = split (/:/,$macs[$midx],2); + $mac =~ s/\s+//g; + if ($macd =~ /mac address \d/i) { + $mac =~ s/\s*->.*$//; + } else { + return 1,"Unable to retrieve MAC address for interface $midx from Management Module"; + } + + if ( $#midxary == 0 ) { #-- backward compatibility mode - do not add host name to mac.mac if only one iface is used + push @allmacs,$mac; + } else { + push @allmacs,$mac."!".$curn."e".$midx; + } + } + + my $macstring = join("|",@allmacs); + my $mactab = xCAT::Table->new('mac',-create=>1); + $mactab->setNodeAttribs($curn,{mac=>$macstring}); + $mactab->close; + return 0,":mac.mac set to $macstring"; } else { return $code,$macs[0]; } diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index ad1a4cf1b..7f9023e3d 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -388,12 +388,20 @@ EOMS open($inifile,">"."/tmp/xcatinitrd.$$/bin/netstart"); print $inifile "#!/bin/bash\n"; print $inifile "dhcpcd $prinic\n"; - print $inifile "echo -n 'search '> /etc/resolv.conf\n"; - print $inifile "grep DOMAIN /var/lib/dhcpcd/*info|awk -F= '{print \$2}'|awk -F\\' '{print \$2}' >> /etc/resolv.conf\n"; - print $inifile "grep HOSTNAME /var/lib/dhcpcd/*info|awk -F= '{print \$2}'|awk -F\\' '{print \$2}' >> /etc/HOSTNAME\n"; - print $inifile "for names in `grep DNS /var/lib/dhcpcd/*info|awk -F= '{print \$2}'`; do\n"; - print $inifile ' echo nameserver $names >> /etc/resolv.conf'."\n"; - print $inifile "done\n"; + + #-- Bring other NICs up in /bin/netstart in initrd for NIC failover + foreach (split /,/,$othernics) { + if (/^$/) { next; } + print $inifile "dhcpcd $_\n"; + } + + print $inifile <> /etc/resolv.conf +cat /var/lib/dhcpcd/*info | grep HOSTNAME | uniq | awk -F= '{print \$2}'| sed \"s/'//g\" >> /etc/HOSTNAME +for names in \$(cat /var/lib/dhcpcd/*info | grep DNS | uniq | awk -F= '{print \$2}' | sed 's/,/\\n/'); do + echo nameserver \$names >> /etc/resolv.conf +done +END close($inifile); chmod(0755,"/tmp/xcatinitrd.$$/init"); @@ -404,7 +412,7 @@ EOMS push @filestoadd,[$_,"lib/$_"]; } } - foreach ("usr/bin/grep","bin/cpio","bin/sleep","bin/mount","sbin/dhcpcd","bin/bash","sbin/insmod","bin/mkdir","bin/mknod","sbin/ip","bin/cat","usr/bin/awk","usr/bin/wget","bin/cp","usr/bin/cpio","usr/bin/zcat","lib/mkinitrd/bin/run-init") { + foreach ("usr/bin/grep","bin/cpio","bin/sleep","bin/mount","sbin/dhcpcd","bin/bash","sbin/insmod","bin/mkdir","bin/mknod","sbin/ip","bin/cat","usr/bin/awk","usr/bin/wget","bin/cp","usr/bin/cpio","usr/bin/zcat","lib/mkinitrd/bin/run-init","usr/bin/uniq","usr/bin/sed") { getlibs($_); push @filestoadd,$_; }