From a732cb476d4616a0f69ba1c06f994faf9fb40b9b Mon Sep 17 00:00:00 2001 From: zhaoertao Date: Thu, 23 Aug 2012 04:21:28 +0000 Subject: [PATCH] fix bug 3556007: modifications related to Utils.pm git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13581 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 41 ++++++++++++++++++ perl-xCAT/xCAT/Utils.pm | 44 ++------------------ xCAT-rmc/scripts/logeventtoxcat | 3 +- xCAT-server/lib/xcat/monitoring/nagiosmon.pm | 7 ++-- xCAT-server/lib/xcat/plugins/aixinstall.pm | 2 +- 5 files changed, 51 insertions(+), 46 deletions(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index f1a7f9274..a7cbc7865 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -18,6 +18,7 @@ use POSIX qw(ceil); use File::Path; use Math::BigInt; use Socket; +use xCAT::GlobalDef; use strict; use warnings "all"; my $socket6support = eval { require Socket6 }; @@ -1972,4 +1973,44 @@ sub get_hdwr_ip return $ip; } + +#-------------------------------------------------------------------------------- +=head3 pingNodeStatus + This function takes an array of nodes and returns their status using fping. + Arguments: + nodes-- an array of nodes. + Returns: + a hash that has the node status. The format is: + {alive=>[node1, node3,...], unreachable=>[node4, node2...]} +=cut +#-------------------------------------------------------------------------------- +sub pingNodeStatus { + my ($class, @mon_nodes)=@_; + my %status=(); + my @active_nodes=(); + my @inactive_nodes=(); + if ((@mon_nodes)&& (@mon_nodes > 0)) { + #get all the active nodes + my $nodes= join(' ', @mon_nodes); + my $temp=`fping -a $nodes 2> /dev/null`; + chomp($temp); + @active_nodes=split(/\n/, $temp); + + #get all the inactive nodes by substracting the active nodes from all. + my %temp2; + if ((@active_nodes) && ( @active_nodes > 0)) { + foreach(@active_nodes) { $temp2{$_}=1}; + foreach(@mon_nodes) { + if (!$temp2{$_}) { push(@inactive_nodes, $_);} + } + } + else {@inactive_nodes=@mon_nodes;} + } + + $status{$::STATUS_ACTIVE}=\@active_nodes; + $status{$::STATUS_INACTIVE}=\@inactive_nodes; + + return %status; +} + 1; diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 354e4b0da..ecf2fd8b0 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -33,7 +33,7 @@ eval { }; use warnings "all"; require xCAT::InstUtils; -require xCAT::NetworkUtils; +#require xCAT::NetworkUtils; require xCAT::Schema; #require Data::Dumper; require xCAT::NodeRange; @@ -94,7 +94,7 @@ our @EXPORT_OK = qw(genpassword runcmd3); # xCAT::Utils::getNodeIPaddress ====> xCAT::NetworkUtils::getNodeIPaddress # xCAT::Utils->thishostisnot ====> xCAT::NetworkUtils->thishostisnot # xCAT::Utils->gethost_ips ====> xCAT::NetworkUtils->gethost_ips -# xCAT::Utils::get_subnet_aix ===> xCAT::NetworkUtils::get_subnet_aix +# xCAT::Utils::get_subnet_aix ====> xCAT::NetworkUtils::get_subnet_aix # xCAT::Utils->determinehostname ====> xCAT::NetworkUtils->determinehostname # xCAT::Utils::toIP ====> xCAT::NetworkUtils::toIP # xCAT::Utils->validate_ip ====> xCAT::NetworkUtils->validate_ip @@ -102,7 +102,7 @@ our @EXPORT_OK = qw(genpassword runcmd3); # xCAT::Utils->isIpaddr ====> xCAT::NetworkUtils->isIpaddr # xCAT::Utils::getNodeNetworkCfg ====> xCAT::NetworkUtils::getNodeNetworkCfg # xCAT::Utils::get_hdwr_ip ====> xCAT::NetworkUtils::get_hdwr_ip - +# xCAT::Utils->pingNodeStatus ====> xCAT::NetworkUtils->pingNodeStatus #-------------------------------------------------------------------------------- @@ -2914,44 +2914,6 @@ sub isSELINUX #------------------------------------------------------------------------------- -#-------------------------------------------------------------------------------- -=head3 pingNodeStatus - This function takes an array of nodes and returns their status using fping. - Arguments: - nodes-- an array of nodes. - Returns: - a hash that has the node status. The format is: - {alive=>[node1, node3,...], unreachable=>[node4, node2...]} -=cut -#-------------------------------------------------------------------------------- -sub pingNodeStatus { - my ($class, @mon_nodes)=@_; - my %status=(); - my @active_nodes=(); - my @inactive_nodes=(); - if ((@mon_nodes)&& (@mon_nodes > 0)) { - #get all the active nodes - my $nodes= join(' ', @mon_nodes); - my $temp=`fping -a $nodes 2> /dev/null`; - chomp($temp); - @active_nodes=split(/\n/, $temp); - - #get all the inactive nodes by substracting the active nodes from all. - my %temp2; - if ((@active_nodes) && ( @active_nodes > 0)) { - foreach(@active_nodes) { $temp2{$_}=1}; - foreach(@mon_nodes) { - if (!$temp2{$_}) { push(@inactive_nodes, $_);} - } - } - else {@inactive_nodes=@mon_nodes;} - } - - $status{$::STATUS_ACTIVE}=\@active_nodes; - $status{$::STATUS_INACTIVE}=\@inactive_nodes; - - return %status; -} #------------------------------------------------------------------------------- =head3 noderangecontainsMN diff --git a/xCAT-rmc/scripts/logeventtoxcat b/xCAT-rmc/scripts/logeventtoxcat index 2c7216e4a..592119f14 100755 --- a/xCAT-rmc/scripts/logeventtoxcat +++ b/xCAT-rmc/scripts/logeventtoxcat @@ -13,6 +13,7 @@ use strict; use Getopt::Std; use POSIX qw(strftime); use xCAT::Utils; +use xCAT::TableUtils; use xCAT::MsgUtils; use IO::File; @@ -97,7 +98,7 @@ if (!$batch) { #handle single event } } -my ($rc, $msg)=xCAT::Utils->logEventsToDatabase(\@a); +my ($rc, $msg)=xCAT::TableUtils->logEventsToDatabase(\@a); if ($rc) { xCAT::MsgUtils->message('S', "logeventtoxcat:$msg. The condition is $condname. The response is $respname.\n"); } diff --git a/xCAT-server/lib/xcat/monitoring/nagiosmon.pm b/xCAT-server/lib/xcat/monitoring/nagiosmon.pm index c2452f792..24ded6ddd 100644 --- a/xCAT-server/lib/xcat/monitoring/nagiosmon.pm +++ b/xCAT-server/lib/xcat/monitoring/nagiosmon.pm @@ -16,6 +16,7 @@ use xCAT_monitoring::monitorctrl; use xCAT::MsgUtils; use xCAT::DBobjUtils; use xCAT::TableUtils; +use xCAT::NetworkUtils; use Data::Dumper; 1; @@ -78,7 +79,7 @@ sub start { my $inactive_nodes=[]; if (($scope) && ($noderef)) { my @mon_nodes=@$noderef; - my %nodes_status=xCAT::Utils->pingNodeStatus(@mon_nodes); + my %nodes_status=xCAT::NetworkUtils->pingNodeStatus(@mon_nodes); $inactive_nodes=$nodes_status{$::STATUS_INACTIVE}; if (@$inactive_nodes>0) { my $error="The following nodes cannot have nrpe started because they are inactive:\n @$inactive_nodes."; @@ -141,7 +142,7 @@ sub stop { #go to nodes to start nrpe if (($scope) && ($noderef)) { my @mon_nodes=@$noderef; - my %nodes_status=xCAT::Utils->pingNodeStatus(@mon_nodes); + my %nodes_status=xCAT::NetworkUtils->pingNodeStatus(@mon_nodes); my $active_nodes=$nodes_status{$::STATUS_ACTIVE}; if (@$active_nodes > 0) { @@ -706,7 +707,7 @@ cfg_file=/etc/nagios/objects/mychildren.cfg my $inactive_nodes=[]; if ($scope) { #print "Configuring the nodes.\n"; - my %nodes_status=xCAT::Utils->pingNodeStatus(@mon_nodes); + my %nodes_status=xCAT::NetworkUtils->pingNodeStatus(@mon_nodes); $inactive_nodes=$nodes_status{$::STATUS_INACTIVE}; if (@$inactive_nodes>0) { my $error="The following nodes cannot be configured because they are inactive:\n @$inactive_nodes."; diff --git a/xCAT-server/lib/xcat/plugins/aixinstall.pm b/xCAT-server/lib/xcat/plugins/aixinstall.pm index 8343e88b8..e36b2ee7f 100644 --- a/xCAT-server/lib/xcat/plugins/aixinstall.pm +++ b/xCAT-server/lib/xcat/plugins/aixinstall.pm @@ -6897,7 +6897,7 @@ sub updatespot # if this has a shared_root resource then # it might need statelite setup - my $sharedinstall=xCAT::Utils->get_site_attribute('sharedinstall'); + my $sharedinstall=xCAT::TableUtils->get_site_attribute('sharedinstall'); chomp $sharedinstall; if ( $sharedinstall eq "sns" ) { my $rc=xCAT::InstUtils->dolitesetup($image, \%imghash, \@nodelist, $callback, $subreq);