From a4c0b58fe8cae17ab663bad44311c194ee044b04 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Sat, 2 Feb 2008 19:39:33 +0000 Subject: [PATCH] -Change such that servicenode is not preferred ofer dhcp server for tftp (tftpserver will be the only way to trump the dhcp server) -Do not warn in the now preferred case of no explicit tftp server -Fix PXE and yaboot to clean stale links -PXE preprocess now specifies nodeset should be sent to all servers -PXE and DHCP only initiate meaningful work if specified node is on the same network -Utils now has nodeonmynet and thisisnothost functions which are commonly needed in scope detirmination git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@379 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/Utils.pm | 52 ++++++++++++ xCAT-server-2.0/lib/xcat/plugins/dhcp.pm | 14 ++-- xCAT-server-2.0/lib/xcat/plugins/pxe.pm | 96 ++++++++++++++-------- xCAT-server-2.0/lib/xcat/plugins/yaboot.pm | 1 + 4 files changed, 121 insertions(+), 42 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index daffc3a1b..277cddfd9 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -2,6 +2,7 @@ # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html package xCAT::Utils; use xCAT::Table; +use Socket; use xCAT::Schema; use Data::Dumper; use xCAT::NodeRange; @@ -995,4 +996,55 @@ sub isServiceNode return $::XCATMasterPort{$value}; } } + +sub nodeonmynet { + my $nodetocheck = shift; + if (scalar(@_)) { + $nodetocheck = shift; + } + my $nodeip = inet_ntoa(inet_aton($nodetocheck)); + unless ($nodeip =~ /\d+\.\d+\.\d+\.\d+/) { + return 0; #Not supporting IYv6 here IPV6TODO + } + my $noden = unpack("N",inet_aton($nodeip)); + my @nets = split /\n/,`/sbin/ip route`; + foreach (@nets) { + my @elems = split /\s+/; + unless ($elems[1] =~ /dev/) { + next; + } + (my $curnet,my $maskbits) = split /\//,$elems[0]; + my $curmask = 2**$maskbits-1<<(32-$maskbits); + my $curn = unpack("N",inet_aton($curnet)); + if (($noden & $curmask) == $curn) { + return 1; + } + } + return 0; +} + + + + +sub thishostisnot { + my $comparison = shift; + if (scalar(@_)) { + $comparison = shift; + } + + my @ips = split /\n/,`/sbin/ip addr`; + my $comp=inet_aton($comparison); + foreach (@ips) { + if (/^\s*inet/) { + my @ents = split(/\s+/); + my $ip=$ents[2]; + $ip =~ s/\/.*//; + if (inet_aton($ip) eq $comp) { + return 0; + } + #print Dumper(inet_aton($ip)); + } + } + return 1; +} 1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm b/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm index c744e355a..c8660b9bf 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/dhcp.pm @@ -87,12 +87,12 @@ sub addnode { $ent = $nrtab->getNodeAttribs($node,['tftpserver']); if ($ent and $ent->{tftpserver}) { $statements = 'next-server = \"'.inet_ntoa(inet_aton($ent->{tftpserver})).'\";'.$statements; - } else { - $ent = $nrtab->getNodeAttribs($node,['servicenode']); - if ($ent and $ent->{servicenode}) { - $statements = 'next-server = \"'.inet_ntoa(inet_aton($ent->{servicenode})).'\";'.$statements; - } - } + } #else { + # $ent = $nrtab->getNodeAttribs($node,['servicenode']); + # if ($ent and $ent->{servicenode}) { + # $statements = 'next-server = \"'.inet_ntoa(inet_aton($ent->{servicenode})).'\";'.$statements; + # } + #} } my $mactab = xCAT::Table->new('mac'); unless ($mactab) { @@ -340,8 +340,6 @@ sub addnet { } if ($ent and $ent->{tftpserver}) { $tftp = $ent->{tftpserver}; - } else { - $callback->({warning=>["No tftp server designated for $net, systems attempting to netboot from this network may fail"]}); } if ($ent and $ent->{gateway}) { $gateway = $ent->{gateway}; diff --git a/xCAT-server-2.0/lib/xcat/plugins/pxe.pm b/xCAT-server-2.0/lib/xcat/plugins/pxe.pm index 702e741c6..785d5ae64 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/pxe.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/pxe.pm @@ -71,7 +71,7 @@ sub setstate { } print $pcfg "DEFAULT xCAT\n"; print $pcfg "LABEL xCAT\n"; - my $chaintab = xCAT::Table->new('chain'); + $chaintab = xCAT::Table->new('chain'); my $stref = $chaintab->getNodeAttribs($node,['currstate']); if ($stref and $stref->{currstate} eq "boot") { print $pcfg "LOCALBOOT 0\n"; @@ -107,6 +107,7 @@ sub setstate { } my @ipa=split(/\./,$ip); my $pname = sprintf("%02X%02X%02X%02X",@ipa); + unlink($tftpdir."/pxelinux.cfg/".$pname); link($tftpdir."/pxelinux.cfg/".$node,$tftpdir."/pxelinux.cfg/".$pname); } @@ -126,37 +127,56 @@ sub pass_along { sub preprocess_request { my $req = shift; - my $callback = shift; - my %localnodehash; - my %dispatchhash; - my $nrtab = xCAT::Table->new('noderes'); - foreach my $node (@{$req->{node}}) { - my $nodeserver; - my $tent = $nrtab->getNodeAttribs($node,['tftpserver']); - if ($tent) { $nodeserver = $tent->{tftpserver} } - unless ($tent and $tent->{tftpserver}) { - $tent = $nrtab->getNodeAttribs($node,['servicenode']); - if ($tent) { $nodeserver = $tent->{servicenode} } - } - if ($nodeserver) { - $dispatchhash{$nodeserver}->{$node} = 1; - } else { - $localnodehash{$node} = 1; - } - } - my @requests; - my $reqc = {%$req}; - $reqc->{node} = [ keys %localnodehash ]; - if (scalar(@{$reqc->{node}})) { push @requests,$reqc } - - foreach my $dtarg (keys %dispatchhash) { #iterate dispatch targets - my $reqcopy = {%$req}; #deep copy - $reqcopy->{'_xcatdest'} = $dtarg; - $reqcopy->{node} = [ keys %{$dispatchhash{$dtarg}}]; - push @requests,$reqcopy; - } - return \@requests; + $callback = shift; + if ($req->{_xcatdest}) { return [$req]; } #Exit if the packet has been preprocessed in its history + my @requests = ({%$req}); #Start with a straight copy to reflect local instance + my $sitetab = xCAT::Table->new('site'); + (my $ent) = $sitetab->getAttribs({key=>'xcatservers'},'value'); + $sitetab->close; + if ($ent and $ent->{value}) { + foreach (split /,/,$ent->{value}) { + if (xCAT::Utils->thishostisnot($_)) { + my $reqcopy = {%$req}; + $reqcopy->{'_xcatdest'} = $_; + push @requests,$reqcopy; + } + } + } + return \@requests; } +#sub preprocess_request { +# my $req = shift; +# my $callback = shift; +# my %localnodehash; +# my %dispatchhash; +# my $nrtab = xCAT::Table->new('noderes'); +# foreach my $node (@{$req->{node}}) { +# my $nodeserver; +# my $tent = $nrtab->getNodeAttribs($node,['tftpserver']); +# if ($tent) { $nodeserver = $tent->{tftpserver} } +# unless ($tent and $tent->{tftpserver}) { +# $tent = $nrtab->getNodeAttribs($node,['servicenode']); +# if ($tent) { $nodeserver = $tent->{servicenode} } +# } +# if ($nodeserver) { +# $dispatchhash{$nodeserver}->{$node} = 1; +# } else { +# $localnodehash{$node} = 1; +# } +# } +# my @requests; +# my $reqc = {%$req}; +# $reqc->{node} = [ keys %localnodehash ]; +# if (scalar(@{$reqc->{node}})) { push @requests,$reqc } +# +# foreach my $dtarg (keys %dispatchhash) { #iterate dispatch targets +# my $reqcopy = {%$req}; #deep copy +# $reqcopy->{'_xcatdest'} = $dtarg; +# $reqcopy->{node} = [ keys %{$dispatchhash{$dtarg}}]; +# push @requests,$reqcopy; +# } +# return \@requests; +#} sub process_request { $request = shift; @@ -164,17 +184,25 @@ sub process_request { my $sub_req = shift; my @args; my @nodes; + my @rnodes; if (ref($request->{node})) { - @nodes = @{$request->{node}}; + @rnodes = @{$request->{node}}; } else { - if ($request->{node}) { @nodes = ($request->{node}); } + if ($request->{node}) { @rnodes = ($request->{node}); } } - unless (@nodes) { + unless (@rnodes) { if ($usage{$request->{command}->[0]}) { $callback->({data=>$usage{$request->{command}->[0]}}); } return; } + @nodes = (); + foreach (@rnodes) { + if (xCAT::Utils->nodeonmynet($_)) { + push @nodes,$_; + } + } + if (ref($request->{arg})) { @args=@{$request->{arg}}; diff --git a/xCAT-server-2.0/lib/xcat/plugins/yaboot.pm b/xCAT-server-2.0/lib/xcat/plugins/yaboot.pm index 7ac5eb59a..9cfc7a98b 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/yaboot.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/yaboot.pm @@ -109,6 +109,7 @@ sub setstate { } my @ipa=split(/\./,$ip); my $pname = sprintf("%02x%02x%02x%02x",@ipa); + unlink($tftpdir."/etc/".$pname); link($tftpdir."/etc/".$node,$tftpdir."/etc/".$pname); }