From 73cd343bf5d80da11010212a36594f9f46f67d4b Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 4 Apr 2012 14:35:13 +0000 Subject: [PATCH] Have slpdiscover get more fleshed out for CMM git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12115 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/slpdiscover.pm | 86 ++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/slpdiscover.pm b/xCAT-server/lib/xcat/plugins/slpdiscover.pm index 37763a6bd..8732b54fe 100644 --- a/xCAT-server/lib/xcat/plugins/slpdiscover.pm +++ b/xCAT-server/lib/xcat/plugins/slpdiscover.pm @@ -3,6 +3,9 @@ use strict; use xCAT::SvrUtils qw/sendmsg/; use xCAT::SLP; use xCAT::MacMap; +my $defaultbladeuser; +my $defaultbladepass; +my $mpahash; sub handled_commands { return { @@ -73,11 +76,92 @@ sub process_request { } my $data = $searchmacs{$mac}; $data->{nodename}=$node; + $data->{macaddress}=$mac; push @toconfig,$data; } + my $mpatab=xCAT::Table->new("mpa",-create=>0); + my @mpaentries; + $mpahash={}; + if ($mpatab) { + @mpaentries = $mpatab->getAllNodeAttribs([qw/mpa username password/]); + foreach (@mpaentries) { + $mpahash->{$_->{mpa}}=$_; + } + } + my $passwdtab=xCAT::Table->new("passwd",-create=>0); + $defaultbladeuser="USERID"; + $defaultbladepass=""; + if ($passwdtab) { + my @ents = $passwdtab->getAttribs({key=>'blade'},'username','password'); + foreach (@ents) { + if ($_->{username} eq "HMC") { next; } + if ($_->{username}) { $defaultbladeuser=$_->{username}; } + if ($_->{password}) { $defaultbladepass=$_->{password}; } + } + } + my $mactab = xCAT::Table->new("mac"); + my @maclist = $mactab->getAllNodeAttribs([qw/node mac/]); + my %machash; + foreach (@maclist) { + $machash{$_->{node}}=$_->{mac}; + } + + + + my $macupdatehash; 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); + my $mac = $data->{macaddress}; + my $nodename = $data->{nodename}; + my $addr = $data->{peername}; #todo, use sockaddr and remove the 427 port from it instead? + if ($addr =~ /^fe80/) { #Link local address requires scope index + $addr .= "%".$data->{scopeid}; + } + if ($machash{$nodename} =~ /$mac/) { #ignore prospects already known to mac table + next; + } + sendmsg(":Found ".$nodename." which seems to be ".$data->{SrvType}." at address $addr",$callback); + if ($data->{SrvType} eq "service:management-hardware.IBM:chassis-management-module") { + unless (do_blade_setup($data,curraddr=>$addr)) { + next; + } + } } } +sub do_blade_setup { + my $data = shift; + my %args = @_; + my $addr = $args{curraddr}; + my $nodename = $data->{nodename}; + my $localuser=$defaultbladeuser; + my $localpass=$defaultbladepass; + if ($mpahash->{$nodename}) { + if ($mpahash->{$nodename}->{username}) { + $localuser = $mpahash->{$nodename}->[0]->{username}; + } + if ($mpahash->{$nodename}->{password}) { + $localuser = $mpahash->{$nodename}->[0]->{password}; + } + } + if (not $localpass or $localpass eq "PASSW0RD") { + sendmsg([1,":Password for blade must be specified in either mpa or passwd tables, and it must not be PASSW0RD"],$callback,$nodename); + return 0; + } + require xCAT_plugin::blade; + my @cmds = qw/snmpcfg=enable sshcfg=enable initnetwork=*/; + my $result = xCAT_plugin::blade::clicmds( + $nodename, + $localuser, + $localpass, + $nodename, + 0, + curraddr=>$addr, + defaultcfg=>1, + cmds=>\@cmds ); + if ($result) { + if ($result->[0]) { + sendmsg([$result->[0],$result->[2]],$callback,$nodename); + } + } +} 1;