-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
This commit is contained in:
parent
0f029bcc8d
commit
a4c0b58fe8
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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}};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user