for item: clean up Utils.pm, the code in perl-xCAT/xCAT

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13461 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
zhaoertao 2012-08-09 03:48:50 +00:00
parent 21a301f6af
commit 571f3e3962
21 changed files with 3572 additions and 3612 deletions

View File

@ -714,7 +714,7 @@ sub dispatch_request {
if (ref $_->{'_xcatdest'} and (ref $_->{'_xcatdest'}) eq 'ARRAY') {
_->{'_xcatdest'} = $_->{'_xcatdest'}->[0];
}
if ($onlyone and not ($_->{'_xcatdest'} and xCAT::Utils->thishostisnot($_->{'_xcatdest'}))) {
if ($onlyone and not ($_->{'_xcatdest'} and xCAT::NetworkUtils->thishostisnot($_->{'_xcatdest'}))) {
$SIG{CHLD}='DEFAULT';
${"xCAT_plugin::".$modname."::"}{process_request}->($_,$dispatch_cb,\&do_request);
return;
@ -755,7 +755,7 @@ sub dispatch_request {
my $request_satisfied=0;
foreach $xcatdest (@xcatdests) {
my $dlock;
if ($xcatdest and xCAT::Utils->thishostisnot($xcatdest)) {
if ($xcatdest and xCAT::NetworkUtils->thishostisnot($xcatdest)) {
#----- added to Client.pm -----#
$dispatch_cb->({warning=>['XCATBYPASS is set, skipping hierarchy call to '.$_->{'_xcatdest'}.'']});
#----- end added to Client.pm -----#

View File

@ -14,6 +14,7 @@ use Getopt::Long;
require xCAT::DSHCore;
use xCAT::MsgUtils;
use xCAT::Utils;
use xCAT::TableUtils;
use lib '/opt/xcat/xdsh';
our @dsh_available_contexts = ();
our @dsh_valid_contexts = ();
@ -3906,7 +3907,7 @@ sub parse_and_run_dsh
#
# setup ssh keys on the nodes or ib switch
#
my $rc = xCAT::Utils->setupSSH($options{'nodes'});
my $rc = xCAT::TableUtils->setupSSH($options{'nodes'});
my @results = "return code = $rc";
return (@results);
}
@ -4262,13 +4263,13 @@ sub parse_and_run_dcp
$nodesyncfiledir = "/var/xcat/node/syncfiles";
# get the directory on the servicenode to put the rsync files in
my @syndir = xCAT::Utils->get_site_attribute("SNsyncfiledir");
my @syndir = xCAT::TableUtils->get_site_attribute("SNsyncfiledir");
if ($syndir[0])
{
$synfiledir = $syndir[0];
}
# get the directory on the node to put the rsync files in
my @syndir = xCAT::Utils->get_site_attribute("nodesyncfiledir");
my @syndir = xCAT::TableUtils->get_site_attribute("nodesyncfiledir");
if ($syndir[0])
{
$nodesyncfiledir = $syndir[0];

View File

@ -23,6 +23,7 @@ require xCAT::InstUtils;
require xCAT::NetworkUtils;
require xCAT::Schema;
require xCAT::Utils;
require xCAT::TableUtils;
#use Data::Dumper;
require xCAT::NodeRange;
use xCAT::MsgUtils qw(verbose_message);
@ -130,7 +131,7 @@ sub getIPaddress
my $type = shift;
my $nodetocheck = shift;
my $port = shift;
if (xCAT::Utils::isIpaddr($nodetocheck)) {
if (xCAT::NetworkUtils::isIpaddr($nodetocheck)) {
return $nodetocheck;
}
my $side = "[A|B]";
@ -188,7 +189,7 @@ sub getIPaddress
if ($tmp_s and $tmp_s =~ /^$side-$port$/i) {
$tmp_s =~ s/a/A/;
$tmp_s =~ s/b/B/;
if (xCAT::Utils::isIpaddr($tmp_n)) {
if (xCAT::NetworkUtils::isIpaddr($tmp_n)) {
$node_side_pairs{$tmp_s} = $tmp_n;
$children_num++;
} else {
@ -346,7 +347,7 @@ sub fsp_api_action {
}
my $cmd;
my $install_dir = xCAT::Utils->getInstallDir();
my $install_dir = xCAT::TableUtils->getInstallDir();
if( $action =~ /^(code_update|get_compatible_version_from_rpm)$/) {
$cmd = "$fsp_api -a $action -T $tooltype -t $type:$fsp_ip:$id:$node_name:$parameter -d $install_dir/packages_fw/";
} elsif($action =~ /^code_updateD$/) {

View File

@ -6,6 +6,7 @@ use Getopt::Long;
use xCAT::Usage;
use xCAT::Utils;
use xCAT::FSPUtils;
use xCAT::TableUtils;
use xCAT::PPCcfg;
#use Data::Dumper;
#use xCAT::PPCcli;
@ -224,7 +225,7 @@ sub parse_args {
my $ppc_cmds_string = &array_to_string(\@ppc_cmds);
return (usage("Invalid command array: $fsp_cmds_string can not execute with $ppc_cmds_string."));
} elsif(scalar(@ppc_cmds)) {
my @enableASMI = xCAT::Utils->get_site_attribute("enableASMI");
my @enableASMI = xCAT::TableUtils->get_site_attribute("enableASMI");
if (defined($enableASMI[0])) {
$enableASMI[0] =~ tr/a-z/A-Z/; # convert to upper
if (($enableASMI[0] eq "1") || ($enableASMI[0] eq "YES")) {
@ -871,8 +872,8 @@ sub fsp_api_passwd {
############################
# Get IP address
############################
#$fsp_ip = xCAT::Utils::get_hdwr_ip($fsp_name);
#$fsp_ip = xCAT::Utils::getNodeIPaddress($fsp_name);
#$fsp_ip = xCAT::NetworkUtils::get_hdwr_ip($fsp_name);
#$fsp_ip = xCAT::NetworkUtils::getNodeIPaddress($fsp_name);
#$fsp_ip = xCAT::Utils::getIPaddress($fsp_name);
$fsp_ip = xCAT::FSPUtils::getIPaddress($request, $$attrs[4], $fsp_name );
if(!defined($fsp_ip) or ($fsp_ip == -3)) {

View File

@ -23,7 +23,7 @@ use File::Path;
use strict;
require xCAT::Schema;
use xCAT::NetworkUtils;
use xCAT::TableUtils;
#require Data::Dumper;
#use Data::Dumper;
require xCAT::NodeRange;
@ -67,10 +67,10 @@ sub getnimprime
# the primary NIM master is either specified in the site table
# or it is the xCAT management node.
my $nimprime = xCAT::Utils->get_site_Master();
my $nimprime = xCAT::TableUtils->get_site_Master();
#my $sitetab = xCAT::Table->new('site');
#(my $et) = $sitetab->getAttribs({key => "nimprime"}, 'value');
my @nimprimes = xCAT::Utils->get_site_attribute("nimprime");
my @nimprimes = xCAT::TableUtils->get_site_attribute("nimprime");
my $tmp = $nimprimes[0];
if (defined($tmp))
{
@ -126,7 +126,7 @@ sub myxCATname
if (xCAT::Utils->isMN())
{
# read the site table, master attrib
my $hostname = xCAT::Utils->get_site_Master();
my $hostname = xCAT::TableUtils->get_site_Master();
if (($hostname =~ /\d+\.\d+\.\d+\.\d+/) || ($hostname =~ /:/))
{
$name = xCAT::NetworkUtils->gethostname($hostname);
@ -750,11 +750,11 @@ sub get_server_nodes
else
{
# get ip facing node
$serv = xCAT::Utils->my_ip_facing($node);
$serv = xCAT::NetworkUtils->my_ip_facing($node);
}
chomp $serv;
if (xCAT::Utils->validate_ip($serv)) {
if (xCAT::NetworkUtils->validate_ip($serv)) {
push (@{$servernodes{$serv}}, $node);
}
}
@ -1253,7 +1253,7 @@ sub dolitesetup
# add aixlitesetup to ..inst_root/aixlitesetup
# this will wind up in the root dir on the node ("/")
my $install_dir = xCAT::Utils->getInstallDir();
my $install_dir = xCAT::TableUtils->getInstallDir();
my $cpcmd = "/bin/cp $install_dir/postscripts/aixlitesetup $instrootloc/aixlitesetup; chmod +x $instrootloc/aixlitesetup";
my $out = xCAT::Utils->runcmd("$cpcmd", -1);

View File

@ -8,6 +8,7 @@ use strict;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use xCAT::TableUtils;
use IO::Select;
use IO::Handle;
use Sys::Syslog;
@ -167,7 +168,7 @@ sub rvlan {
my $community = "public";
#$self->{sitetab} = xCAT::Table->new('site');
#my $tmp = $self->{sitetab}->getAttribs({key=>'snmpc'},'value');
my @snmpcs = xCAT::Utils->get_site_attribute("snmpc");
my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc");
my $tmp = $snmpcs[0];
if ( defined($tmp) ) { $community = $tmp }
my %args = @_;
@ -292,7 +293,7 @@ sub refresh_table {
#$self->{sitetab} = xCAT::Table->new('site');
#my $tmp = $self->{sitetab}->getAttribs({key=>'snmpc'},'value');
#if ($tmp and $tmp->{value}) { $community = $tmp->{value} }
my @snmpcs = xCAT::Utils->get_site_attribute("snmpc");
my @snmpcs = xCAT::TableUtils->get_site_attribute("snmpc");
my $tmp = $snmpcs[0];
if ( defined($tmp) ) { $community = $tmp }
else { #Would warn here..

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::MsgUtils;
use xCAT::LparNetbootExp;
@ -469,7 +470,7 @@ sub rnetboot {
#my $sitetab = xCAT::Table->new('site');
#my $vcon = $sitetab->getAttribs({key => "conserverondemand"}, 'value');
my @vcons = xCAT::Utils->get_site_attribute("conserverondemand");
my @vcons = xCAT::TableUtils->get_site_attribute("conserverondemand");
my $vcon = $vcons[0];
#if ($vcon and $vcon->{"value"} and $vcon->{"value"} eq "yes" ) {
if ( defined($vcon) and $vcon eq "yes" ) {

View File

@ -7,6 +7,7 @@ use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use Storable qw(freeze thaw);
use POSIX "WNOHANG";
use xCAT::NetworkUtils;
use xCAT::MsgUtils qw(verbose_message);
use LWP;
@ -736,7 +737,7 @@ sub doresetnet {
$nodetype = ( $nodetype =~ /^frame$/i ) ? "bpa" : "fsp";
if ($cnodep) {
foreach my $cnode (@$cnodep) {
my $ip = xCAT::Utils::getNodeIPaddress( $cnode );
my $ip = xCAT::NetworkUtils::getNodeIPaddress( $cnode );
my $oi = $oihash{$cnode};
if(!defined $ip) {
send_msg($req, "doresetnet: can't get $cnode ip");
@ -785,7 +786,7 @@ sub doresetnet {
# this brunch is just for the xcat 2.5(or 2.5-) databse
} elsif ( $nodetype =~ /^(fsp|bpa)$/ ) {
foreach my $nn ( @{ $req->{node}} ) {
my $ip = xCAT::Utils::getNodeIPaddress( $nn );
my $ip = xCAT::NetworkUtils::getNodeIPaddress( $nn );
if(!defined $ip) {
send_msg($req, "doresetnet: can't get $nn ip");
next;

View File

@ -6,7 +6,7 @@ require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(SUCCESS RC_ERROR EXPECT_ERROR NR_ERROR);
use Expect;
use xCAT::NetworkUtils;
#############################################
# Removes Ctrl characters from term output
@ -1335,7 +1335,7 @@ sub getHMCcontrolIP
#my @newnodes = split(/,/, $nodes_found->[0]);
#$Rc = shift(@newnodes);
#for my $entry (@newnodes) {
# if(xCAT::Utils->isIpaddr($entry)) {
# if(xCAT::NetworkUtils->isIpaddr($entry)) {
# push @ips,$entry;
# }
# $ip_result = join( ",", @ips );

View File

@ -5,6 +5,7 @@ use strict;
use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use xCAT::NetworkUtils;
use xCAT::DBobjUtils;
use xCAT::FSPUtils;
use xCAT::MsgUtils qw(verbose_message);
@ -506,8 +507,8 @@ sub mkhwconn
for my $nn ( @newnodes )
{
my $node_ip;
unless ( xCAT::Utils->isIpaddr($nn) ) {
$node_ip = xCAT::Utils::getNodeIPaddress( $nn );
unless ( xCAT::NetworkUtils->isIpaddr($nn) ) {
$node_ip = xCAT::NetworkUtils::getNodeIPaddress( $nn );
} else {
$node_ip = $nn;
}
@ -642,7 +643,7 @@ sub lshwconn
{
#my $node_ip_hash = $hosttab->getNodeAttribs( $node_name,[qw(ip)]);
#$node_ip = $node_ip_hash->{ip};
#$node_ip = xCAT::Utils::getNodeIPaddress( $node_name );
#$node_ip = xCAT::NetworkUtils::getNodeIPaddress( $node_name );
my $d = $node_hash->{$node_name};
$node_ip = xCAT::FSPUtils::getIPaddress($request, $$d[4], $node_name );
}

View File

@ -4,7 +4,9 @@ package xCAT::PPCdb;
use strict;
use xCAT::Table;
use xCAT::GlobalDef;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::NetworkUtils;
###########################################
# Factory defaults
@ -947,7 +949,7 @@ sub get_host {
#######################################
if ($ip)
{
my $nets = xCAT::Utils::my_nets();
my $nets = xCAT::NetworkUtils::my_nets();
my $avip = getip_from_iplist( $ip, $nets);
#if ( !defined( $ip )) {
# return undef;
@ -984,7 +986,7 @@ sub get_host {
}
if ( $tmpmtm eq $mtm and $tmpsn eq $sn) {
my $ifip = xCAT::Utils->isIpaddr($oldnode);
my $ifip = xCAT::NetworkUtils->isIpaddr($oldnode);
if ( $ifip ) {# which means that the node is defined by the new lsslp
if ( $tmpside eq $side ) {# match! which means that node is the same as the new one
if ( $ip eq $tmpip ) { #which means that the ip is not changed
@ -1104,7 +1106,7 @@ sub get_host {
}
# not matched, use the new name
my $ifip = xCAT::Utils->isIpaddr($nodename);
my $ifip = xCAT::NetworkUtils->isIpaddr($nodename);
unless ($ifip) {
return $nodename;
}else {
@ -1150,8 +1152,8 @@ sub getip_from_iplist
for my $net ( keys %$nets)
{
my ($n,$m) = split /\//,$net;
if ( xCAT::Utils::isInSameSubnet( $n, $ip, $m, 1) and
xCAT::Utils::isPingable( $ip))
if ( xCAT::NetworkUtils::isInSameSubnet( $n, $ip, $m, 1) and
xCAT::NetworkUtils::isPingable( $ip))
{
return $ip;
}
@ -1211,7 +1213,7 @@ sub read_from_table {
@{$::OLD_DATA_CACHE{$entry->{node}}}[1] = @{$vpdhash{$entry->{node}}}[1];#sn
@{$::OLD_DATA_CACHE{$entry->{node}}}[2] = @{$vpdhash{$entry->{node}}}[2];#side
# find node ip address, check node name first, then check hosts table
my $ifip = xCAT::Utils->isIpaddr($entry->{node});
my $ifip = xCAT::NetworkUtils->isIpaddr($entry->{node});
if ( $ifip )
{
@{$::OLD_DATA_CACHE{$entry->{node}}}[3] = $entry->{node};#ip

View File

@ -8,7 +8,7 @@ use xCAT::Usage;
use xCAT::NodeRange;
use xCAT::DBobjUtils;
use xCAT::FSPUtils;
use xCAT::TableUtils qw(get_site_Master);
%::QUERY_ATTRS = (
'savingstatus' => 1,
'dsavingstatus' => 1,
@ -251,7 +251,7 @@ sub renergy {
if( !defined($fsps) ) {
return ([[$node, "Failed to get the FSPs for the cec $hcphost.", -1]]);
}
#my $hcp_ip = xCAT::Utils::getNodeIPaddress($hcphost);
#my $hcp_ip = xCAT::NetworkUtils::getNodeIPaddress($hcphost);
my $hcp_ip = xCAT::FSPUtils::getIPaddress($request, $hw_type, $hcphost);
if (!defined($hcp_ip) or ($hcp_ip == -3)) {
return ([[$node, "Failed to get IP address for $hcphost.", -1]]);
@ -264,7 +264,7 @@ sub renergy {
}
} else {
# for the case that hcp is hmc or fsp
push @hcps_ip, xCAT::Utils::getNodeIPaddress($hcphost);
push @hcps_ip, xCAT::NetworkUtils::getNodeIPaddress($hcphost);
}
if (!$user || !$password) {
@ -279,7 +279,7 @@ sub renergy {
}
$verbose = $tmpv;
my $master = xCAT::Utils->get_site_Master();
my $master = xCAT::TableUtils->get_site_Master();
my $masterip = xCAT::NetworkUtils->getipaddr($master);
if ($masterip =~ /:/) { #IPv6, needs fping6 support
if (!-x '/usr/bin/fping6')

View File

@ -11,7 +11,9 @@ use xCAT::Usage;
use Socket;
use xCAT::PPCdb;
use xCAT::MsgUtils qw(verbose_message);
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::NetworkUtils;
##########################################
# Globals
##########################################

View File

@ -6,6 +6,9 @@ use strict;
use Getopt::Long;
use Data::Dumper;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::ServiceNodeUtils;
use xCAT::NetworkUtils;
use xCAT::MsgUtils qw(verbose_message);
use xCAT::LparNetbootExp;
@ -90,9 +93,9 @@ sub parse_args {
if ( exists($opt{S}) ) {
push @network, $_;
} else {
$server = xCAT::Utils->getSNformattedhash( $node, "xcat", "node", "primary" );
$server = xCAT::ServiceNodeUtils->getSNformattedhash( $node, "xcat", "node", "primary" );
foreach my $key ( keys %$server ) {
my $valid_ip = xCAT::Utils->validate_ip( $key );
my $valid_ip = xCAT::NetworkUtils->validate_ip( $key );
if ( $valid_ip ) {
###################################################
# Service node is returned as hostname, Convert
@ -197,7 +200,7 @@ sub parse_args {
if ( scalar(@network) != 3 ) {
return( usage() );
}
my $result = xCAT::Utils->validate_ip( $opt{C}, $opt{G}, $opt{S} );
my $result = xCAT::NetworkUtils->validate_ip( $opt{C}, $opt{G}, $opt{S} );
if ( @$result[0] ) {
return(usage( @$result[1] ));
}
@ -683,7 +686,7 @@ sub getmacs {
#my $vcon = $sitetab->getAttribs({key => "conserverondemand"}, 'value');
#there may be something wrong with the conserverondemand attribute.
# Currently, the code is not used. So not fix this time. Just keep it here.
my @vcons = xCAT::Utils->get_site_attribute("conserverondemand");
my @vcons = xCAT::TableUtils->get_site_attribute("conserverondemand");
my $vcon = $vcons[0];
#if ($vcon and $vcon->{"value"} and $vcon->{"value"} eq "yes" ) {
if ( defined($vcon) and $vcon eq "yes" ) {

View File

@ -8,6 +8,8 @@ use xCAT::Usage;
use xCAT::PPCinv;
use xCAT::DSHCLI;
use xCAT::Table;
use xCAT::Utils;
use xCAT::TableUtils;
use Getopt::Long;
use File::Spec;
use POSIX qw(tmpnam);
@ -320,7 +322,7 @@ sub preprocess_for_rflash {
my $request = shift;
my $opt = shift;
my $callback = $request->{callback};
my $install_dir = xCAT::Utils->getInstallDir();
my $install_dir = xCAT::TableUtils->getInstallDir();
my $packages_fw = "$install_dir/packages_fw";
my $c = 0;
my $packages_d;

View File

@ -5,7 +5,7 @@ package xCAT::RSYNC;
# cannot use strict
use base xCAT::DSHRemoteShell;
use xCAT::TableUtils qw(get_site_attribute);
# Determine if OS is AIX or Linux
# Configure standard locations of commands based on OS
@ -77,7 +77,7 @@ sub remote_copy_command
my $usersh=0;
if ($^O eq 'aix')
{
my @useSSH = xCAT::Utils->get_site_attribute("useSSHonAIX");
my @useSSH = xCAT::TableUtils->get_site_attribute("useSSHonAIX");
if (defined($useSSH[0])) {
$useSSH[0] =~ tr/a-z/A-Z/; # convert to upper
if (($useSSH[0] eq "0") || ($useSSH[0] eq "NO"))

View File

@ -1,6 +1,7 @@
package xCAT::Scope;
use xCAT::Utils;
use xCAT::Table;
use xCAT::ServiceNodeUtils qw(getSNList);
sub get_broadcast_scope {
my $req = shift;
if ($req =~ /xCAT::Scope/) {
@ -10,8 +11,8 @@ sub get_broadcast_scope {
if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
#Exit if the packet has been preprocessed in its history
my @requests = ({%$req}); #Start with a straight copy to reflect local instance
foreach (xCAT::Utils->getSNList()) {
if (xCAT::Utils->thishostisnot($_)) {
foreach (xCAT::ServiceNodeUtils->getSNList()) {
if (xCAT::NetworkUtils->thishostisnot($_)) {
my $reqcopy = {%$req};
$reqcopy->{'_xcatdest'} = $_;
$reqcopy->{_xcatpreprocessed}->[0] = 1;
@ -24,7 +25,7 @@ sub get_broadcast_scope {
#$sitetab->close;
#if ($ent and $ent->{value}) {
# foreach (split /,/,$ent->{value}) {
# if (xCAT::Utils->thishostisnot($_)) {
# if (xCAT::NetworkUtils->thishostisnot($_)) {
# my $reqcopy = {%$req};
# $reqcopy->{'_xcatdest'} = $_;
# push @requests,$reqcopy;

View File

@ -0,0 +1,685 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::ServiceNodeUtils;
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
# if AIX - make sure we include perl 5.8.2 in INC path.
# Needed to find perl dependencies shipped in deps tarball.
if ($^O =~ /^aix/i) {
use lib "/usr/opt/perl5/lib/5.8.2/aix-thread-multi";
use lib "/usr/opt/perl5/lib/5.8.2";
use lib "/usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi";
use lib "/usr/opt/perl5/lib/site_perl/5.8.2";
}
use lib "$::XCATROOT/lib/perl";
#-----------------------------------------------------------------------------
=head3 readSNInfo
Read resource, NFS server, Master node, OS an ARCH from the database
for the service node
Input: service nodename
Output: Masternode, OS and ARCH
=cut
#-----------------------------------------------------------------------------
sub readSNInfo
{
my ($class, $nodename) = @_;
my $rc = 0;
my $et;
my $masternode;
my $os;
my $arch;
$rc = xCAT::Utils->exportDBConfig();
if ($rc == 0)
{
if ($nodename)
{
$masternode = xCAT::TableUtils->GetMasterNodeName($nodename);
if (!($masternode))
{
xCAT::MsgUtils->message('S',
"Could not get Master for node $nodename\n");
return 1;
}
$et = xCAT::TableUtils->GetNodeOSARCH($nodename);
if ($et == 1)
{
xCAT::MsgUtils->message('S',
"Could not get OS/ARCH for node $nodename\n");
return 1;
}
if (!($et->{'os'} || $et->{'arch'}))
{
xCAT::MsgUtils->message('S',
"Could not get OS/ARCH for node $nodename\n");
return 1;
}
}
$et->{'master'} = $masternode;
return $et;
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 isServiceReq
Checks the service node table in the database to see
if input Service should be setup on the
input service node
Input:servicenodename,ipaddres(s) and hostnames of service node
Output:
array of services to setup for this service node
Globals:
$::RUNCMD_RC = 0; good
$::RUNCMD_RC = 1; error
Error:
none
Example:
@servicestosetup=xCAT::ServiceNodeUtils->isServiceReq($servicenodename, @serviceip) { blah; }
=cut
#-----------------------------------------------------------------------------
sub isServiceReq
{
require xCAT::Table;
my ($class, $servicenodename, $serviceip) = @_;
# list of all services from service node table
# note this must be updated if more services added
my @services = (
"nameserver", "dhcpserver", "tftpserver", "nfsserver",
"conserver", "monserver", "ldapserver", "ntpserver",
"ftpserver", "ipforward"
);
my @ips = @$serviceip; # list of service node ip addresses and names
my $rc = 0;
$rc = xCAT::Utils->exportDBConfig(); # export DB env
if ($rc != 0)
{
xCAT::MsgUtils->message('S', "Unable export DB environment.\n");
$::RUNCMD_RC = 1;
return;
}
# get handle to servicenode table
my $servicenodetab = xCAT::Table->new('servicenode');
unless ($servicenodetab)
{
xCAT::MsgUtils->message('S', "Unable to open servicenode table.\n");
$::RUNCMD_RC = 1;
return; # do not setup anything
}
my @process_service_list = ();
# read all the nodes from the table, for each service
foreach my $service (@services)
{
my @snodelist = $servicenodetab->getAllNodeAttribs([$service]);
foreach $serviceip (@ips) # check the table for this servicenode
{
foreach my $node (@snodelist)
{
if ($serviceip eq $node->{'node'})
{ # match table entry
if ($node->{$service})
{ # returns service, only if set
my $value = $node->{$service};
$value =~ tr/a-z/A-Z/; # convert to upper
# value 1 or yes then we setup the service
if (($value eq "1") || ($value eq "YES"))
{
push @process_service_list,
$service; # found service to setup
}
}
}
}
}
}
$servicenodetab->close;
$::RUNCMD_RC = 0;
return @process_service_list;
}
#-----------------------------------------------------------------------------
=head3 getAllSN
Returns an array of all service nodes from service node table
Arguments:
none
Returns:
array of Service Nodes or empty array, if none
Globals:
none
Error:
1 - error
Example:
@allSN=xCAT::ServiceNodeUtils->get_AllSN
Comments:
none
=cut
#-----------------------------------------------------------------------------
sub getAllSN
{
require xCAT::Table;
# reads all nodes from the service node table
my @servicenodes;
my $servicenodetab = xCAT::Table->new('servicenode');
unless ($servicenodetab) # no servicenode table
{
xCAT::MsgUtils->message('I', "Unable to open servicenode table.\n");
$servicenodetab->close;
return @servicenodes;
}
my @nodes = $servicenodetab->getAllNodeAttribs(['tftpserver']);
foreach my $nodes (@nodes)
{
push @servicenodes, $nodes->{node};
}
$servicenodetab->close;
return @servicenodes;
}
#-----------------------------------------------------------------------------
=head3 getSNandNodes
Returns an hash-array of all service nodes and the nodes they service
Arguments:
none
#-----------------------------------------------------------------------------
=head3 getSNandNodes
Returns an hash-array of all service nodes and the nodes they service
Arguments:
none
Returns:
Service Nodes and the nodes they service or empty , if none
Globals:
none
Error:
1 - error
Example:
$sn=xCAT::ServiceNodeUtils->getSNandNodes()
Comments:
none
=cut
#-----------------------------------------------------------------------------
sub getSNandNodes
{
require xCAT::Table;
# read all the nodes from the nodelist table
# call get_ServiceNode to find which Service Node
# the node belongs to.
my %sn;
my @nodes;
my $nodelisttab = xCAT::Table->new('nodelist');
my $recs = $nodelisttab->getAllEntries();
foreach (@$recs)
{
push @nodes, $_->{node};
}
$nodelisttab->close;
my $sn = xCAT::ServiceNodeUtils->get_ServiceNode(\@nodes, "xcat", "MN");
return $sn;
}
#-----------------------------------------------------------------------------
=head3 getSNList
Reads the servicenode table. Will return all the enabled Service Nodes
that will setup the input Service ( e.g tftpserver,nameserver,etc)
If service is blank, then will return the list of all enabled Service
Nodes.
Arguments:
Servicename ( xcat,tftpserver,dhcpserver,conserver,etc)
Returns:
Array of service node names
Globals:
none
Error:
1 - error
Example:
$sn= xCAT::ServiceNodeUtils->getSNList($servicename) { blah; }
$sn= xCAT::ServiceNodeUtils->getSNList() { blah; }
Comments:
none
=cut
#-----------------------------------------------------------------------------
sub getSNList
{
require xCAT::Table;
my ($class, $service) = @_;
# reads all nodes from the service node table
my @servicenodes;
my $servicenodetab = xCAT::Table->new('servicenode', -create => 1);
unless ($servicenodetab) # no servicenode table
{
xCAT::MsgUtils->message('I', "Unable to open servicenode table.\n");
return ();
}
my @nodes = $servicenodetab->getAllNodeAttribs([$service]);
$servicenodetab->close;
foreach my $node (@nodes)
{
if ($service eq "") # want all the service nodes
{
push @servicenodes, $node->{node};
}
else
{ # looking for a particular service
if ($node->{$service})
{ # if null then do not add node
my $value = $node->{$service};
$value =~ tr/a-z/A-Z/; # convert to upper
# value 1 or yes or blank then we setup the service
if (($value == 1) || ($value eq "YES"))
{
push @servicenodes, $node->{node};
}
}
}
}
return @servicenodes;
}
#-----------------------------------------------------------------------------
=head3 get_ServiceNode
Will get the Service node ( name or ipaddress) as known by the Management
Node or Node for the input nodename or ipadress of the node
which can be a Service Node.
If the input node is a Service Node then it's Service node
is always the Management Node.
input: list of nodenames and/or node ipaddresses (array ref)
service name
"MN" or "Node" determines if you want the Service node as known
by the Management Node or by the node.
recognized service names: xcat,tftpserver,
nfsserver,conserver,monserver
service "xcat" is used by command like xdsh that need to know the
service node that will process the command but are not tied to a
specific service like tftp
Todo: Handle dhcpserver and nameserver from the networks table
output: A hash ref of arrays, the key is the service node pointing to
an array of nodes that are serviced by that service node
Globals:
$::ERROR_RC
Error:
$::ERROR_RC=0 no error $::ERROR_RC=1 error
example: $sn =xCAT::ServiceNodeUtils->get_ServiceNode(\@nodes,$service,"MN");
$sn =xCAT::ServiceNodeUtils->get_ServiceNode(\@nodes,$service,"Node");
Note: this rountine is important to hierarchical support in xCAT
and used in many places. Any changes to the logic should be
reviewed by xCAT architecture
=cut
#-----------------------------------------------------------------------------
sub get_ServiceNode
{
require xCAT::Table;
my ($class, $node, $service, $request) = @_;
my @node_list = @$node;
my $cmd;
my %snhash;
my $nodehash;
my $sn;
my $nodehmtab;
my $noderestab;
my $snattribute;
my $oshash;
my $nodetab;
$::ERROR_RC = 0;
# determine if the request is for the service node as known by the MN
# or the node
if ($request eq "MN")
{
$snattribute = "servicenode";
}
else # Node
{
$snattribute = "xcatmaster";
}
# get site.master this will be the default
my $master = xCAT::TableUtils->get_site_Master();
$noderestab = xCAT::Table->new('noderes');
unless ($noderestab) # no noderes table, use default site.master
{
xCAT::MsgUtils->message('I',
"Unable to open noderes table. Using site->Master.\n");
if ($master) # use site Master value
{
foreach my $node (@node_list)
{
push @{$snhash{$master}}, $node;
}
}
else
{
xCAT::MsgUtils->message('E', "Unable to read site Master value.\n");
$::ERROR_RC = 1;
}
return \%snhash;
}
if ($service eq "xcat")
{ # find all service nodes for the nodes in the list
$nodehash = $noderestab->getNodesAttribs(\@node_list, [$snattribute]);
foreach my $node (@node_list)
{
foreach my $rec (@{$nodehash->{$node}})
{
if ($rec and $rec->{$snattribute}) # use noderes.servicenode
{
my $key = $rec->{$snattribute};
push @{$snhash{$key}}, $node;
}
else # use site.master
{
push @{$snhash{$master}}, $node;
}
}
}
$noderestab->close;
return \%snhash;
}
else
{
if (
($service eq "tftpserver") # all from noderes table
|| ($service eq "nfsserver") || ($service eq "monserver")
)
{
$nodehash =
$noderestab->getNodesAttribs(\@node_list,
[$service, $snattribute]);
foreach my $node (@node_list)
{
foreach my $rec (@{$nodehash->{$node}})
{
if ($rec and $rec->{$service})
{
# see if both MN and Node address in attribute
my ($msattr, $nodeattr) = split ':', $rec->{$service};
my $key = $msattr;
if ($request eq "Node")
{
if ($nodeattr) # override with Node, if it exists
{
$key = $nodeattr;
}
}
push @{$snhash{$key}}, $node;
}
else
{
if ($rec and $rec->{$snattribute}) # if it exists
{
my $key = $rec->{$snattribute};
push @{$snhash{$key}}, $node;
}
else
{ # use site.master
push @{$snhash{$master}}, $node;
}
}
}
}
$noderestab->close;
return \%snhash;
}
else
{
if ($service eq "conserver")
{
# read the nodehm table
$nodehmtab = xCAT::Table->new('nodehm');
unless ($nodehmtab) # no nodehm table
{
xCAT::MsgUtils->message('I',
"Unable to open nodehm table.\n");
# use servicenode
$nodehash =
$noderestab->getNodesAttribs(\@node_list, [$snattribute]);
foreach my $node (@node_list)
{
foreach my $rec (@{$nodehash->{$node}})
{
if ($rec and $rec->{$snattribute})
{
my $key = $rec->{$snattribute};
push @{$snhash{$key}}, $node;
}
else
{ # use site.master
push @{$snhash{$master}}, $node;
}
}
}
$noderestab->close;
return \%snhash;
}
# can read the nodehm table
$nodehash =
$nodehmtab->getNodesAttribs(\@node_list, ['conserver']);
foreach my $node (@node_list)
{
foreach my $rec (@{$nodehash->{$node}})
{
if ($rec and $rec->{'conserver'})
{
# see if both MN and Node address in attribute
my ($msattr, $nodeattr) = split ':',
$rec->{'conserver'};
my $key = $msattr;
if ($request eq "Node")
{
if ($nodeattr
) # override with Node, if it exists
{
$key = $nodeattr;
}
}
push @{$snhash{$key}}, $node;
}
else
{ # use service node for this node
$sn =
$noderestab->getNodeAttribs($node,
[$snattribute]);
if ($sn and $sn->{$snattribute})
{
my $key = $sn->{$snattribute};
push @{$snhash{$key}}, $node;
}
else
{ # no service node use master
push @{$snhash{$master}}, $node;
}
}
}
}
$noderestab->close;
$nodehmtab->close;
return \%snhash;
}
else
{
xCAT::MsgUtils->message('E',
"Invalid service=$service input.\n");
$::ERROR_RC = 1;
}
}
}
return \%snhash;
}
#-----------------------------------------------------------------------------
=head3 getSNformattedhash
Will call get_ServiceNode to get the Service node ( name or ipaddress)
as known by the Management
Server or Node for the input nodename or ipadress of the node
It will then format the output into a single servicenode key with values
the list of nodes service by that service node. This routine will
break up pools of service nodes into individual node in the hash unlike
get_ServiceNode which leaves the pool as the key.
input: Same as get_ServiceNode to call get_ServiceNode
list of nodenames and/or node ipaddresses (array ref)
service name
"MN" or "Node" determines if you want the Service node as known
by the Management Node or by the node.
recognized service names: xcat,tftpserver,
nfsserver,conserver,monserver
service "xcat" is used by command like xdsh that need to know the
service node that will process the command but are not tied to a
specific service like tftp
output: A hash ref of arrays, the key is a single service node
pointing to
a list of nodes that are serviced by that service node
'rra000-m'=>['blade01', 'testnode']
'sn1'=>['blade01', 'testnode']
'sn2'=>['blade01']
'sn3'=>['testnode']
Globals:
$::ERROR_RC
Error:
$::ERROR_RC=0 no error $::ERROR_RC=1 error
example: $sn =xCAT::ServiceNodeUtils->getSNformattedhash(\@nodes,$service,"MN", $type);
$sn =xCAT::ServiceNodeUtils->getSNformattedhash(\@nodes,$service,"Node", "primary");
=cut
#-----------------------------------------------------------------------------
sub getSNformattedhash
{
my ($class, $node, $service, $request, $btype) = @_;
my @node_list = @$node;
my $cmd;
my %newsnhash;
my $type="";
if ($btype) {
$type=$btype;
}
# get the values of either the servicenode or xcatmaster attributes
my $sn = xCAT::ServiceNodeUtils->get_ServiceNode(\@node_list, $service, $request);
# get the keys which are the service nodes and break apart any pool lists
# format into individual service node keys pointing to node lists
if ($sn)
{
foreach my $snkey (keys %$sn)
{
# split the key if pool of service nodes
push my @tmpnodes, $sn->{$snkey};
my @nodes;
for my $i (0 .. $#tmpnodes) {
for my $j ( 0 .. $#{$tmpnodes[$i]}) {
my $check=$tmpnodes[$i][$j];
push @nodes,$check;
}
}
# for SN backup we might only want the primary or backup
my @servicenodes;
my ($primary, $backup) = split /,/, $snkey;
if (($primary) && ($type eq "primary")) {
push @servicenodes, $primary;
} elsif (($backup) && ($type eq "backup")) {
push @servicenodes, $backup;
} else {
@servicenodes = split /,/, $snkey;
}
# now build new hash of individual service nodes
foreach my $newsnkey (@servicenodes) {
push @{$newsnhash{$newsnkey}}, @nodes;
}
}
}
return \%newsnhash;
}
1;

1471
perl-xCAT/xCAT/TableUtils.pm Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff