From db4d44046702be85d0f893b1e44553cd9a6b17db Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 28 Mar 2012 21:06:04 +0000 Subject: [PATCH] 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 --- xCAT-server/lib/perl/xCAT/SvrUtils.pm | 3 + xCAT-server/lib/xcat/plugins/blade.pm | 1 + xCAT-server/lib/xcat/plugins/slpdiscover.pm | 83 +++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 xCAT-server/lib/xcat/plugins/slpdiscover.pm diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index 58fad5fe3..e3cf47140 100644 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -13,6 +13,9 @@ require xCAT::NetworkUtils; use File::Basename; use strict; +use Exporter; +our @ISA = qw/Exporter/; +our @EXPORT_OK = qw/sendmsg/; #------------------------------------------------------------------------------- diff --git a/xCAT-server/lib/xcat/plugins/blade.pm b/xCAT-server/lib/xcat/plugins/blade.pm index 0f97bfd19..6241107bf 100644 --- a/xCAT-server/lib/xcat/plugins/blade.pm +++ b/xCAT-server/lib/xcat/plugins/blade.pm @@ -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; diff --git a/xCAT-server/lib/xcat/plugins/slpdiscover.pm b/xCAT-server/lib/xcat/plugins/slpdiscover.pm new file mode 100644 index 000000000..37763a6bd --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/slpdiscover.pm @@ -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;