Have SvrUtils allow 'export' of sendmsg for brevity in calling code if calling code so desires it.

Get ready to have blade.pm do ssh out of the gate on at least CMMs
Get ready for SLP based 'node' discovery, including MM initial setup

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12039 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2012-03-28 21:06:04 +00:00
parent 73bc80c97b
commit db4d440467
3 changed files with 87 additions and 0 deletions

View File

@ -13,6 +13,9 @@ require xCAT::NetworkUtils;
use File::Basename;
use strict;
use Exporter;
our @ISA = qw/Exporter/;
our @EXPORT_OK = qw/sendmsg/;
#-------------------------------------------------------------------------------

View File

@ -18,6 +18,7 @@ use Thread qw(yield);
use xCAT::Utils;
use xCAT::Usage;
use IO::Socket;
use IO::Pty; #needed for ssh password login
use xCAT::GlobalDef;
use xCAT_monitoring::monitorctrl;
use strict;

View File

@ -0,0 +1,83 @@
package xCAT_plugin::slpdiscover;
use strict;
use xCAT::SvrUtils qw/sendmsg/;
use xCAT::SLP;
use xCAT::MacMap;
sub handled_commands {
return {
slpdiscover => "slpdiscover",
};
};
my $callback;
my $docmd;
my %ip4neigh;
my %ip6neigh;
my %searchmacs;
my %researchmacs;
my $macmap;
sub get_mac_for_addr {
my $neigh;
my $addr = shift;
if ($addr =~ /:/) {
get_ipv6_neighbors();
return $ip6neigh{$addr};
} else {
get_ipv4_neighbors();
return $ip4neigh{$addr};
}
}
sub get_ipv4_neighbors {
#TODO: something less 'hacky'
my @ipdata = `ip -4 neigh`;
%ip6neigh=();
foreach (@ipdata) {
if (/^(\S*)\s.*lladdr\s*(\S*)\s/) {
$ip4neigh{$1}=$2;
}
}
}
sub get_ipv6_neighbors {
#TODO: something less 'hacky'
my @ipdata = `ip -6 neigh`;
%ip6neigh=();
foreach (@ipdata) {
if (/^(\S*)\s.*lladdr\s*(\S*)\s/) {
$ip6neigh{$1}=$2;
}
}
}
sub handle_new_slp_entity {
my $data = shift;
delete $data->{sockaddr}; #won't need it
my $mac = get_mac_for_addr($data->{peername});
unless ($mac) { return; }
$searchmacs{$mac} = $data;
}
sub process_request {
my $request = shift;
$callback = shift;
$docmd = shift;
%searchmacs=();
my $srvtypes = [ qw/service:management-hardware.IBM:chassis-management-module service:management-hardware.IBM:management-module/ ];
xCAT::SLP::dodiscover(SrvTypes=>$srvtypes,Callback=>\&handle_new_slp_entity);
$macmap = xCAT::MacMap->new();
$macmap->refresh_table();
my @toconfig;
foreach my $mac (keys(%searchmacs)) {
my $node = $macmap->find_mac($mac,1);
unless ($node) {
next;
}
my $data = $searchmacs{$mac};
$data->{nodename}=$node;
push @toconfig,$data;
}
foreach my $data (@toconfig) {
sendmsg(":Found ".$data->{nodename}." which seems to be ".$data->{SrvType}." at address ".$data->{peername}." with scope index of ".$data->{scopeid},$callback);
}
}
1;