Implement multi-nic discovery

-Table now returns multiple records if appropriate for getNodeAttribs (needed for switch table)
  -makedhcp moved to the ondiscover method (makedhcp not run until discovery method has a chance to modify mac table)


git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@264 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-01-14 22:19:17 +00:00
parent e47683853f
commit c048ba409a
5 changed files with 60 additions and 36 deletions

View File

@ -118,7 +118,7 @@ sub refresh_table {
else { #Would warn here..
}
my %checked_pairs;
my @entries = $self->{switchtab}->getAllNodeAttribs(['port','switch']);
my @entries = $self->{switchtab}->getAllNodeAttribs(['node','port','switch']);
#Build hash of switch port names per switch
$self->{switches} = {};
foreach $entry (@entries) {

View File

@ -7,6 +7,7 @@
#but going for prototype
#class xcattable
package xCAT::Table;
use Sys::Syslog;
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr';
@ -842,30 +843,33 @@ sub getNodeAttribs
my $self = shift;
my $node = shift;
my @attribs = @{shift()};
my ($data, $extra) = $self->getNodeAttribs_nosub($node, \@attribs);
my $datum;
my @data = $self->getNodeAttribs_nosub($node, \@attribs);
#my ($datum, $extra) = $self->getNodeAttribs_nosub($node, \@attribs);
if ($extra) { return undef; } # return (undef,"Ambiguous query"); }
defined($data)
defined($data[0])
|| return undef; #(undef,"No matching entry found in configuration");
my $attrib;
foreach $datum (@data) {
foreach $attrib (@attribs)
{
if ($data->{$attrib} =~ /^\/.*\/.*\//)
if ($datum->{$attrib} =~ /^\/.*\/.*\//)
{
my $exp = substr($data->{$attrib}, 1);
my $exp = substr($datum->{$attrib}, 1);
chop $exp;
my @parts = split('/', $exp, 2);
$node =~ s/$parts[0]/$parts[1]/;
$data->{$attrib} = $node;
$datum->{$attrib} = $node;
}
elsif ($data->{$attrib} =~ /^\|.*\|.*\|$/)
elsif ($datum->{$attrib} =~ /^\|.*\|.*\|$/)
{
#Perform arithmetic and only arithmetic operations in bracketed issues on the right.
#Tricky part: don't allow potentially dangerous code, only eval if
#to-be-evaled expression is only made up of ()\d+-/%$
#Futher paranoia? use Safe module to make sure I'm good
my $exp = substr($data->{$attrib}, 1);
my $exp = substr($datum->{$attrib}, 1);
chop $exp;
my @parts = split('\|', $exp, 2);
my $curr;
@ -894,13 +898,14 @@ sub getNodeAttribs
($curr, $next, $prev) =
extract_bracketed($retval, '()', qr/[^()]*/);
}
$data->{$attrib} = $retval;
$datum->{$attrib} = $retval;
#print Dumper(extract_bracketed($parts[1],'()',qr/[^()]*/));
#use text::balanced extract_bracketed to parse earch atom, make sure nothing but arith operators, parans, and numbers are in it to guard against code execution
}
}
return $data;
}
return wantarray ? @data : $data[0];
}
#--------------------------------------------------------------------------
@ -930,21 +935,26 @@ sub getNodeAttribs_nosub
my $self = shift;
my $node = shift;
my $attref = shift;
my $data;
my $tent;
my @data;
my $datum;
my @tents;
my $return = 0;
foreach (@$attref)
{
($tent) = $self->getNodeAttribs_nosub_returnany($node, [$_]);
@tents = $self->getNodeAttribs_nosub_returnany($node, $attref);
foreach my $tent (@tents) {
$datum={};
foreach (@$attref)
{
if ($tent and defined($tent->{$_}))
{
$return = 1;
$data->{$_} = $tent->{$_};
$return = 1;
$datum->{$_} = $tent->{$_};
}
}
push(@data,$datum);
}
if ($return)
{
return $data;
return wantarray ? @data : $data[0];
}
else
{
@ -979,9 +989,11 @@ sub getNodeAttribs_nosub_returnany
my $self = shift;
my $node = shift;
my @attribs = @{shift()};
my @results;
#my $recurse = ((scalar(@_) == 1) ? shift : 1);
my ($data, $extra) = $self->getAttribs({node => $node}, @attribs);
@results = $self->getAttribs({node => $node}, @attribs);
my $data = $results[0];
if (!defined($data))
{
my ($nodeghash) =
@ -994,11 +1006,14 @@ sub getNodeAttribs_nosub_returnany
my $group;
foreach $group (@nodegroups)
{
($data, $extra) = $self->getAttribs({node => $group}, @attribs);
@results = $self->getAttribs({node => $group}, @attribs);
$data = $results[0];
if ($data != undef)
{
if ($data->{node}) { $data->{node} = $node; }
return ($data, $extra);
foreach (@results) {
if ($_->{node}) { $_->{node} = $node; }
};
return @results;
}
}
}
@ -1006,7 +1021,7 @@ sub getNodeAttribs_nosub_returnany
{
#Don't need to 'correct' node attribute, considering result of the if that governs this code block?
return ($data, $extra);
return @results;
}
return undef; #Made it here, config has no good answer
}
@ -1172,14 +1187,17 @@ sub getAllNodeAttribs
# $attrs->{$_}=$attr->{$_};
# }
#} else {
$attrs =
my @attrs =
$self->getNodeAttribs($_, $attribq)
; #Logic moves to getNodeAttribs
#}
#populate node attribute by default, this sort of expansion essentially requires it.
$attrs->{node} = $_;
#$attrs->{node} = $_;
foreach my $att (@attrs) {
$att->{node} = $_;
}
$donenodes{$_} = 1;
push @results, $attrs; #$self->getNodeAttribs($_,@attribs);
push @results, @attrs; #$self->getNodeAttribs($_,@attribs);
}
}
}

View File

@ -894,11 +894,11 @@ sub process_request {
my $mactab = xCAT::Table->new('mac',-create=>1);
$mactab->setNodeAttribs($macmap{$mac},{mac=>$mac});
$mactab->close();
my %request = (
command => ['makedhcp'],
node => [$macmap{$mac}]
);
$doreq->(\%request);
#my %request = (
# command => ['makedhcp'],
# node => [$macmap{$mac}]
# );
#$doreq->(\%request);
$request->{command}=['discovered'];
$request->{noderange} = [$macmap{$mac}];
$doreq->($request);

View File

@ -84,6 +84,7 @@ sub handled_commands {
sub process_request {
my $request = shift;
my $callback = shift;
my $doreq = shift;
my $node = $request->{node}->[0];
my $ip = $request->{'!xcat_clientip'};
openlog("xCAT node discovery",'','local0');
@ -121,6 +122,11 @@ sub process_request {
}
}
$mactab->setNodeAttribs($node,{mac=>$macstring});
my %request = (
command => ['makedhcp'],
node => [$node]
);
$doreq->(\%request);
}
#TODO: mac table? on the one hand, 'the' definitive interface was determined earlier...
#Delete the state it was in to make it traverse destiny once agoin

View File

@ -36,11 +36,11 @@ sub process_request {
my $mactab = xCAT::Table->new('mac',-create=>1);
$mactab->setNodeAttribs($node,{mac=>$mac});
$mactab->close();
my %request = (
command => ['makedhcp'],
node => [$node]
);
$doreq->(\%request);
#my %request = (
# command => ['makedhcp'],
# node => [$node]
#);
#$doreq->(\%request);
$req->{command}=['discovered'];
$req->{noderange} = [$node];
$doreq->($req);