diff --git a/xCAT-rmc/plugin/rmcmon.pm b/xCAT-rmc/plugin/rmcmon.pm index d41916c29..5803e09ec 100644 --- a/xCAT-rmc/plugin/rmcmon.pm +++ b/xCAT-rmc/plugin/rmcmon.pm @@ -274,7 +274,7 @@ sub startNodeStatusMon { foreach my $key (keys (%$noderef)) { my @key_a=split(',', $key); if (! $iphash{$key_a[0]}) { push @servicenodes, $key_a[0]; } - my $mon_nodes=$monservers->{$key}; + my $mon_nodes=$noderef->{$key}; foreach(@$mon_nodes) { my $node_info=$_; $status_hash{$node_info->[0]}=$node_info->[2]; @@ -519,7 +519,11 @@ sub addNodes_noChecking { my $ms_node_id; my $mn_node_id; - my $ms_name,$ms_aliases,$ms_addrtype,$ms_length,@ms_addrs; + my $ms_name; + my $ms_aliases; + my $ms_addrtype; + my $ms_length; + my @ms_addrs; my $ms_ipaddresses; my $first_time=1; @@ -760,3 +764,78 @@ sub getNodeConfData { return; } +#-------------------------------------------------------------------------------- +=head3 configMaster4Nodes + This function configures the current the localhost to accept the given nodes + into the monitoring domain. + Arguments: + noderef a pointer to an array of nodes. + Returns: + (code, message) +=cut +#-------------------------------------------------------------------------------- +sub configMaster4Nodes { + my $noderef=shift; + if ($noderef =~ /xCAT_monitoring::rmcmon/) { + $noderef=shift; + } + if (!$noderef) { return (0, "");} + + #check if rsct is installed or not + if (! -e "/usr/bin/lsrsrc") { + return (0, ""); + } + + #restart rmc daemon if it is not active + chomp(my $pid= `/bin/ps -ef | /bin/grep rmcd | /bin/grep -v grep | /bin/awk '{print \$2}'`); + unless($pid){ + #restart rmc daemon + $result=`startsrc -s ctrmc`; + if ($?) { + return (1, "RMC deamon cannot be started\n"); + } + } + + my $message; + my $ret=0; + my $table3=xCAT::Table->new("nodetype", -create =>0); + foreach(@$noderef) { + my $node=$_; + + #check if the node is OSI, akip if not + my $tmp3=$table3->getNodeAttribs($node, ['nodetype']); + my $nodetype=$::NODETYPE_OSI; #default + if (defined($tmp3) && ($tmp3)) { + if ($tmp3->{nodetype}) { $nodetype=$tmp3->{nodetype}; } + } + if ($nodetype !~ /$::NODETYPE_OSI/) { next; } + + #check if the node is already defined, skip if it is + $result=`/usr/bin/lsrsrc-api -s IBM.MngNode::"Name==\'$node\'"::Name 2>&1`; + if ($?==0) { next;} + + #get info for the node + my $mn_node_id=getNodeID($node); + my ($mn_name,$mn_aliases,$mn_addrtype,$mn_length,@mn_addrs) = gethostbyname($node); + chomp($mn_name); + my $mn_ipaddresses="{"; + foreach (@mn_addrs) { + $mn_ipaddresses .= '"'.inet_ntoa($_) . '",'; + } + chop($mn_ipaddresses); + $mn_ipaddresses .= "}"; + # print " mn_name=$mn_name, mn_aliases=$mn_aliases, mn_ipaddr=$mn_ipaddresses, mn_node_id=$mn_node_id\n"; + + # define resource in IBM.MngNode class on server + $result=`mkrsrc-api IBM.MngNode::Name::"$node"::KeyToken::"$node"::IPAddresses::"$mn_ipaddresses"::NodeID::0x$mn_node_id 2>&1`; + if ($?) { + $ret=$?; + $message .= "define resource in IBM.MngNode class result=$result\n"; + xCAT::MsgUtils->message('S', "[mon]: $message"); + next; + } + } + if ( $table3) { $table3->close(); } + + return ($ret, $message); +} diff --git a/xCAT-rmc/scripts/configrmcnode b/xCAT-rmc/scripts/configrmcnode index 709a7d4a7..dcfa68bc6 100755 --- a/xCAT-rmc/scripts/configrmcnode +++ b/xCAT-rmc/scripts/configrmcnode @@ -12,7 +12,11 @@ # To remove node to the cluster # NODE=nodename configrmcnode -1 ########################################################################################## -ADD=$1; +if [ -n "$1" ]; then + ADD=$1 +else + ADD=1 +fi logger xCAT "configrmcnode: ADD=$ADD, NODE=$NODE, NODEID=$NODEID MONSERVER=$MONSERVER,MS_NODEID=$MS_NODEID" diff --git a/xCAT-server/lib/xcat/monitoring/monitorctrl.pm b/xCAT-server/lib/xcat/monitoring/monitorctrl.pm index 4536203a2..721b8efb4 100644 --- a/xCAT-server/lib/xcat/monitoring/monitorctrl.pm +++ b/xCAT-server/lib/xcat/monitoring/monitorctrl.pm @@ -908,7 +908,7 @@ sub getNodeMonServerPair { my $table2=xCAT::Table->new("noderes", -create =>0); my $pairs; my $tmp2=$table2->getNodeAttribs($node, ['monserver', 'servicenode', 'xcatmaster']); - if (defined($tmp2) && ($tmp2)) { + if ($tmp2) { if ($tmp2->{monserver}) { $pairs=$tmp2->{monserver}; #when there is only one hostname specified in noderes.monserver, @@ -1280,6 +1280,73 @@ sub getNodeConfData { return %ret; } + + +#-------------------------------------------------------------------------------- +=head3 configMaster4Nodes + This function goes to every monitoring plug-in module and configures the current + the localhost to accept the given nodes into the monitoring domain. + Arguments: + noderef a pointer to an array of nodes. + Returns: + (code, message) +=cut +#-------------------------------------------------------------------------------- +sub configMaster4Nodes { + my $noderef=shift; + if ($noderef =~ /xCAT_monitoring::monitorctrl/) { + $noderef=shift; + } + + #get all the module names from /opt/xcat/lib/perl/XCAT_monitoring directory + my %names=(); + my @plugins=glob("$::XCATROOT/lib/perl/xCAT_monitoring/*.pm"); + foreach (@plugins) { + /.*\/([^\/]*).pm$/; + $names{$1}=1; + } + # remove 2 files that are not plug-ins + delete($names{monitorctrl}); + delete($names{montbhandler}); + + #get node conf data from each plug-in module + my $message; + my $retcode=0; + foreach my $pname (keys(%names)) { + my $file_name="$::XCATROOT/lib/perl/xCAT_monitoring/$pname.pm"; + my $module_name="xCAT_monitoring::$pname"; + #load the module in memory + eval {require($file_name)}; + if (!$@) { + if (defined(${$module_name."::"}{configMaster4Nodes})) { + my ($c, $m)=${$module_name."::"}{configMaster4Nodes}->($noderef); + if ($c) {$retcode=$c; $message .= "$pname: $m\n";} + } + } + } + + return ($retcode, $message); +} + + + + + + + + + + + + + + + + + + + + diff --git a/xCAT-server/lib/xcat/plugins/monctrlcmds.pm b/xCAT-server/lib/xcat/plugins/monctrlcmds.pm index 265e67b81..60a1710a1 100644 --- a/xCAT-server/lib/xcat/plugins/monctrlcmds.pm +++ b/xCAT-server/lib/xcat/plugins/monctrlcmds.pm @@ -45,9 +45,66 @@ sub handled_commands { monls => "monctrlcmds", monaddnode => "monctrlcmds", monrmnode => "monctrlcmds", + moncfgmaster => "monctrlcmds", } } +#------------------------------------------------------- +=head3 preprocess_request + + Check and setup for hierarchy + +=cut +#------------------------------------------------------- +sub preprocess_request +{ + my $req = shift; + my $cb = shift; + my $command = $req->{command}->[0]; + if ($req->{_xcatdest}) { return [$req]; } #exit if preprocessed + + my @requests=(); + + if ($command ne "moncfgmaster") { + my $reqcopy = {%$req}; + push @requests, $reqcopy; + } else { + my $nodes = $req->{node}; + my $noderef=xCAT_monitoring::monitorctrl->getMonServer($nodes); + + #the identification of this node + my @hostinfo=xCAT::Utils->determinehostname(); + my $isSV=xCAT::Utils->isServiceNode(); + %iphash=(); + foreach(@hostinfo) {$iphash{$_}=1;} + if (!$isSV) { $iphash{'noservicenode'}=1;} + + foreach my $key (keys (%$noderef)) { + my @key_a=split(',', $key); + my $mon_nodes=$noderef->{$key}; + @nodes_to_add=(); + if ($mon_nodes) { + foreach(@$mon_nodes) { + my $node=$_->[0]; + push(@nodes_to_add, $node); + } + } + if ($iphash{$key_a[0]}) { #current node is the master for the nodes + my $reqcopy = {%$req}; + $reqcopy->{node}=\@nodes_to_add; + push @requests, $reqcopy; + } else { #push the request to the monitoring server + my $reqcopy = {%$req}; + $reqcopy->{node}=\@nodes_to_add; + $reqcopy->{'_xcatdest'} = $key_a[0]; + push @requests, $reqcopy; + } + } + } + return \@requests; +} + + #-------------------------------------------------------------------------------- =head3 process_request It processes the monitoring control commands. @@ -120,6 +177,23 @@ sub process_request { } return $ret; } + elsif ($command eq "moncfgmaster") { + my $nodes = $request->{node}; + if ($nodes) { + my ($ret, $msg) = moncfgmaster($nodes, $callback); + if ($msg) { + my %rsp=(); + $rsp->{data}->[0]= $msg; + $callback->($rsp); + } + return $ret; + } else { + my %rsp=(); + $rsp->{data}->[0]= "This command requires noderange."; + $callback->($rsp); + return 1; + } + } else { my %rsp=(); $rsp->{data}->[0]= "unsupported command: $command."; @@ -821,6 +895,32 @@ sub monrmnode { +#-------------------------------------------------------------------------------- +=head3 moncfgmaster + This function goes asks the monitoring plug-ins to configure the local host + to include the given nodes into the monitoring domain. (The nodes configuration + is done via post installation scripts during deployment process). + Arguments: + nodes - a pointer to a array of nodes. + callback - the pointer to the callback function. + Returns: + 0 for success. The output is returned through the callback pointer. + 1. for unsuccess. The error messages are returns through the callback pointer. +=cut +#-------------------------------------------------------------------------------- +sub moncfgmaster { + my $noderef=shift; + my $callback=shift; + + my ($ret, $msg) = xCAT_monitoring::monitorctrl->configMaster4Nodes($noderef); + if ($ret) { + my %rsp1; + $rsp1->{data}->[0]="$msg"; + $callback->($rsp1); + } + return $ret; +} + diff --git a/xCAT-server/lib/xcat/plugins/pxe.pm b/xCAT-server/lib/xcat/plugins/pxe.pm index 3d65293e1..b6736fafd 100644 --- a/xCAT-server/lib/xcat/plugins/pxe.pm +++ b/xCAT-server/lib/xcat/plugins/pxe.pm @@ -232,6 +232,15 @@ sub process_request { } return; } + + #give monitoring code a chance to prepare the master for the node deployment + my %new_request = ( + command => ['moncfgmaster'], + node => \@rnodes + ); + $sub_req->(\%new_request, \&pass_along); + + #back to normal business #if not shared, then help sync up if ($req->{_disparatetftp}) { #reading hint from preprocess_command @nodes = (); diff --git a/xCAT-server/lib/xcat/plugins/yaboot.pm b/xCAT-server/lib/xcat/plugins/yaboot.pm index 0f407316d..a717d4fbd 100644 --- a/xCAT-server/lib/xcat/plugins/yaboot.pm +++ b/xCAT-server/lib/xcat/plugins/yaboot.pm @@ -160,6 +160,7 @@ sub preprocess_request { #they specify no sharedtftp in site table my $stab = xCAT::Table->new('site'); my $req = shift; + my $sent = $stab->getAttribs({key=>'sharedtftp'},'value'); if ($sent and ($sent->{value} == 0 or $ent->{value} =~ /no/i)) { $req->{'_disparatetftp'}=[1]; @@ -207,6 +208,7 @@ sub process_request { $request = shift; $callback = shift; $sub_req = shift; + my @args; my @nodes; my @rnodes; @@ -221,6 +223,15 @@ sub process_request { } return; } + + #give monitoring code a chance to prepare the master for the node deployment + my %new_request = ( + command => ['moncfgmaster'], + node => \@rnodes + ); + $sub_req->(\%new_request, \&pass_along); + + #back to normal business #if not shared tftpdir, then filter, otherwise, set up everything if ($req->{_disparatetftp}) { #reading hint from preprocess_command @nodes = ();