From f68aa9065d64970d8ac8da370f431f90704ec7de Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Sat, 26 Jan 2008 19:06:21 +0000 Subject: [PATCH] -Add Hierarchical behavior to makenetworks (trouncing mgtifname for the near term) git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@330 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server-2.0/lib/xcat/plugins/networks.pm | 39 ++++++++++++++++++- .../lib/xcat/plugins/nodediscover.pm | 1 + 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/xCAT-server-2.0/lib/xcat/plugins/networks.pm b/xCAT-server-2.0/lib/xcat/plugins/networks.pm index a5d4c4622..6fb74b623 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/networks.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/networks.pm @@ -3,6 +3,7 @@ package xCAT_plugin::networks; use xCAT::Table; use Data::Dumper; use Sys::Syslog; +use Socket; sub handled_commands { @@ -11,7 +12,43 @@ sub handled_commands { } } +sub preprocess_request { + my $req = shift; + my $cb = shift; + if ($req->{_xcatdest}) { return [$req]; } #exit if preprocessed + my @requests = ({%$req}); #first element is 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 (thishostisnot($_)) { + my $reqcopy = {%$req}; + $reqcopy->{'_xcatdest'} = $_; + push @requests,$reqcopy; + } + } + } + return \@requests; +} +sub thishostisnot { + my $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; +} sub process_request { my $nettab = xCAT::Table->new('networks',-create=>1,-autocommit=>0); my @rtable = split /\n/,`/bin/netstat -rn`; @@ -43,7 +80,7 @@ sub process_request { $mask = $ent[2]; $mgtifname = $ent[7]; $nettab->setAttribs({'net'=>$net},{'mask'=>$mask,'mgtifname'=>$mgtifname}); - my $tent = $nettab->getAttribs({'net'=>$net},nameservers); + my $tent = $nettab->getAttribs({'net'=>$net},'nameservers'); unless ($tent and $tent->{nameservers}) { my $text = join ',',@nameservers; $nettab->setAttribs({'net'=>$net},{nameservers=>$text}); diff --git a/xCAT-server-2.0/lib/xcat/plugins/nodediscover.pm b/xCAT-server-2.0/lib/xcat/plugins/nodediscover.pm index 0e1600abd..c3a4b5786 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/nodediscover.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/nodediscover.pm @@ -37,6 +37,7 @@ sub gethosttag { my $defn=""; my @netents = @{$nettab->getAllEntries()}; my $pass; + #TODO: mgtifname field will get trounced in hierarchical setup, use a live check to match accurately foreach $pass (1,2) { #two passes to allow for mgtifname matching foreach (@netents) { if ($_->{net} eq $netn or ($mgtifname and $mgtifname eq $_->{mgtifname})) {