From e822d0406ef23e1fda8f6202e763cc316980136d Mon Sep 17 00:00:00 2001 From: zhaoertao Date: Thu, 9 Aug 2012 04:00:45 +0000 Subject: [PATCH] for item: clean up Utils.pm, the code in xCAT-server/lib/per/xCAT/ git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13464 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/perl/xCAT/PPC.pm | 26 ++++++++++++++------------ xCAT-server/lib/perl/xCAT/Postage.pm | 7 ++++--- xCAT-server/lib/perl/xCAT/SvrUtils.pm | 15 ++++++++------- xCAT-server/lib/perl/xCAT/Template.pm | 14 ++++++++------ 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm index e82ea225e..665499ece 100644 --- a/xCAT-server/lib/perl/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -5,6 +5,8 @@ use strict; use lib "/opt/xcat/lib/perl"; use xCAT::Table; use xCAT::Utils; +use xCAT::TableUtils; +use xCAT::ServiceNodeUtils; use xCAT::SvrUtils; use xCAT::FSPUtils; use xCAT::Usage; @@ -191,7 +193,7 @@ sub process_command { # Get site table attributes ####################################### foreach ( @site ) { - my @val = xCAT::Utils->get_site_attribute($_); + my @val = xCAT::TableUtils->get_site_attribute($_); if ( defined($val[0]) ) { $request->{$_} = $val[0]; } @@ -217,7 +219,7 @@ sub process_command { my @allerrornodes=(); my $check=0; my $global_check=1; - my @val = xCAT::Utils->get_site_attribute("nodestatus"); + my @val = xCAT::TableUtils->get_site_attribute("nodestatus"); if (defined($val[0])) { if ($val[0] =~ /0|n|N/) { $global_check=0; } } @@ -1003,7 +1005,7 @@ sub resolve_netwk { my $gateway = $nethash{$_}{gateway}; my $gateway_ip; if ( defined( $gateway )) { - $ip = xCAT::Utils::toIP( $gateway ); + $ip = xCAT::NetworkUtils::toIP( $gateway ); if ( @$ip[0] != 0 ) { send_msg( $request, 1, "$_: Cannot resolve '$gateway'" ); next; @@ -1021,12 +1023,12 @@ sub resolve_netwk { ################################# # Get server (-S) ################################# - my $server = xCAT::Utils->GetMasterNodeName( $_ ); + my $server = xCAT::TableUtils->GetMasterNodeName( $_ ); if ( $server == 1 ) { send_msg( $request, 1, "$_: Unable to identify master" ); next; } - $ip = xCAT::Utils::toIP( $server ); + $ip = xCAT::NetworkUtils::toIP( $server ); if ( @$ip[0] != 0 ) { send_msg( $request, 1, "$_: Cannot resolve '$server'" ); next; @@ -1036,7 +1038,7 @@ sub resolve_netwk { ################################# # Get client (-C) ################################# - $ip = xCAT::Utils::toIP( $_ ); + $ip = xCAT::NetworkUtils::toIP( $_ ); if ( @$ip[0] != 0 ) { send_msg( $request, 1, "$_: Cannot resolve '$_'" ); next; @@ -1956,14 +1958,14 @@ sub preprocess_request { } } - my @masters = xCAT::Utils->get_site_attribute("master"); + my @masters = xCAT::TableUtils->get_site_attribute("master"); #When run mkhwconn/lshwconn/rmhwconn with -T fnm for CNM, it will send the command to CEC/Frame direclty, #not through the service node if specified. if ($req->{command}->[0] =~ /^(mkhwconn|lshwconn|rmhwconn|rpower)$/ && ( $req->{opt}->{T} == 1) ) { #for fnm my $reqcopy = {%$req}; - #my @masters = xCAT::Utils->get_site_attribute("master"); + #my @masters = xCAT::TableUtils->get_site_attribute("master"); if( $masters[0] ) { $reqcopy->{'_xcatdest'} = $masters[0]; push @requests,$reqcopy; @@ -1978,7 +1980,7 @@ sub preprocess_request { # build an individual request for each service node my $service = "xcat"; my @hcps=keys(%hcp_hash); - my $sn = xCAT::Utils->get_ServiceNode(\@hcps, $service, "MN"); + my $sn = xCAT::ServiceNodeUtils->get_ServiceNode(\@hcps, $service, "MN"); # build each request for each service node foreach my $snkey (keys %$sn) @@ -2002,14 +2004,14 @@ sub preprocess_request { if(($req->{command}->[0] eq "rflash") && ( exists( $req->{opt}->{activate} ) ) ) { my $linuxrequired = 0; if ( xCAT::Utils->isLinux() ) { - my @installloc = xCAT::Utils->get_site_attribute("installloc"); + my @installloc = xCAT::TableUtils->get_site_attribute("installloc"); if (! ($installloc[0])) { $linuxrequired = 1; } } if ( ($linuxrequired || xCAT::Utils->isAIX()) && ( $masters[0] ne $snkey )) { - my $install_dir = xCAT::Utils->getInstallDir(); + my $install_dir = xCAT::TableUtils->getInstallDir(); my $cmd = "$::XCATROOT/bin/xdcp $snkey -R $install_dir/packages_fw $install_dir/"; my $result = xCAT::Utils->runcmd("$cmd", -1); if ($::RUNCMD_RC != 0) { @@ -2316,7 +2318,7 @@ sub process_request { $request->{hwtype} ne 'hmc' && $request_new->{fsp_api} ne '0') { if ($request_new->{command} =~ /^(rspconfig|rpower|reventlog)$/){ - my @enableASMI = xCAT::Utils->get_site_attribute("enableASMI"); + my @enableASMI = xCAT::TableUtils->get_site_attribute("enableASMI"); if (defined($enableASMI[0])) { if (($request_new->{command} !~ /^rspconfig$/) || (ref($request_new->{method} eq 'HASH'))) { diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 8bb6cdaef..69cc6b103 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -13,6 +13,7 @@ use xCAT::Table; use xCAT::MsgUtils; use xCAT::NodeRange; use xCAT::Utils; +use xCAT::TableUtils; use xCAT::SvrUtils; #use Data::Dumper; use File::Basename; @@ -169,7 +170,7 @@ sub makescript else { my $sitemaster_value = $value; - $value = xCAT::Utils->my_ip_facing($node); + $value = xCAT::NetworkUtils->my_ip_facing($node); if ($value eq "0") { $value = $sitemaster_value; @@ -194,7 +195,7 @@ sub makescript push @scriptd, "GROUP=$groups->{groups}\n"; push @scriptd, "export GROUP\n"; # read the sshbetweennodes attribute and process - my $enablessh=xCAT::Utils->enablessh($node); + my $enablessh=xCAT::TableUtils->enablessh($node); if ($enablessh == 1) { push @scriptd, "ENABLESSHBETWEENNODES=YES\n"; push @scriptd, "export ENABLESSHBETWEENNODES\n"; @@ -496,7 +497,7 @@ sub makescript else { my $stat = "install"; - my $installroot = xCAT::Utils->getInstallDir(); + my $installroot = xCAT::TableUtils->getInstallDir(); if ($profile) { my $platform = "rh"; diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm index c3a1dff0f..90f97f977 100644 --- a/xCAT-server/lib/perl/xCAT/SvrUtils.pm +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -9,6 +9,7 @@ BEGIN use lib "$::XCATROOT/lib/perl"; require xCAT::Table; require xCAT::Utils; +require xCAT::TableUtils; require xCAT::NetworkUtils; use File::Basename; use File::Path; @@ -264,7 +265,7 @@ sub getsynclistfile() my ($os, $arch, $profile, $inst_type, $imgname) = @_; - my $installdir = xCAT::Utils->getInstallDir(); + my $installdir = xCAT::TableUtils->getInstallDir(); # for aix node, use the node figure out the profile, then use the value of # profile (osimage name) to get the synclist file path (osimage.synclists) @@ -565,7 +566,7 @@ sub update_tables_with_templates #print "osver=$osver, arch=$arch, osname=$osname, genos=$genos\n"; - my $installroot = xCAT::Utils->getInstallDir(); + my $installroot = xCAT::TableUtils->getInstallDir(); #my $sitetab = xCAT::Table->new('site'); #if ($sitetab) { # (my $ref) = $sitetab->getAttribs({key => "installdir"}, "value"); @@ -573,7 +574,7 @@ sub update_tables_with_templates # $installroot = $ref->{value}; # } #} - my @installdirs = xCAT::Utils->get_site_attribute("installdir"); + my @installdirs = xCAT::TableUtils->get_site_attribute("installdir"); my $tmp = $installdirs[0]; if ( defined($tmp)) { $installroot = $tmp; @@ -735,7 +736,7 @@ sub update_tables_with_diskless_image } #print "osver=$osver, arch=$arch, osname=$osname, genos=$genos, profile=$profile\n"; - my $installroot = xCAT::Utils->getInstallDir(); + my $installroot = xCAT::TableUtils->getInstallDir(); #my $sitetab = xCAT::Table->new('site'); #if ($sitetab) { # (my $ref) = $sitetab->getAttribs({key => "installdir"}, "value"); @@ -743,7 +744,7 @@ sub update_tables_with_diskless_image # $installroot = $ref->{value}; # } #} - my @installdirs = xCAT::Utils->get_site_attribute("installdir"); + my @installdirs = xCAT::TableUtils->get_site_attribute("installdir"); my $tmp = $installdirs[0]; if ( defined($tmp)) { $installroot = $tmp; @@ -907,7 +908,7 @@ sub get_mac_by_arp () foreach my $n ( @$nodes ) { if ( $node->{$n}->{reachable} ) { my $output; - my $IP = xCAT::Utils::toIP( $n ); + my $IP = xCAT::NetworkUtils::toIP( $n ); if ( xCAT::Utils->isAIX() ) { $output = `/usr/sbin/arp -a`; } else { @@ -1054,7 +1055,7 @@ sub subVars { if($table eq 'site'){ #$val = $tab->getAttribs( { key => "$col" }, 'value' ); #$val = $val->{'value'}; - my @vals = xCAT::Utils->get_site_attribute($col); + my @vals = xCAT::TableUtils->get_site_attribute($col); $val = $vals[0]; }else{ $ent = $tab->getNodeAttribs($node,[$col]); diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 0c64ca94f..dd59e35f8 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -9,7 +9,9 @@ use File::Path; #use Data::Dumper; use Sys::Syslog; use xCAT::ADUtils; #to allow setting of one-time machine passwords - +use xCAT::Utils; +use xCAT::TableUtils; +use xCAT::NetworkUtils; BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; @@ -74,12 +76,12 @@ sub subvars { #my $sitetab = xCAT::Table->new('site'); my $noderestab = xCAT::Table->new('noderes'); #(my $et) = $sitetab->getAttribs({key=>"master"},'value'); - my @masters = xCAT::Utils->get_site_attribute("master"); + my @masters = xCAT::TableUtils->get_site_attribute("master"); my $tmp = $masters[0]; if ( defined($tmp) ) { $master = $tmp; } - my $ipfn = xCAT::Utils->my_ip_facing($node); + my $ipfn = xCAT::NetworkUtils->my_ip_facing($node); if ($ipfn) { $master = $ipfn; } @@ -324,7 +326,7 @@ sub machinepassword { #} my $domain; #(my $et) = $sitetab->getAttribs({key=>"domain"},'value'); - my @domains = xCAT::Utils->get_site_attribute("domain"); + my @domains = xCAT::TableUtils->get_site_attribute("domain"); my $tmp = $domains[0]; if (defined($tmp)) { $domain = $tmp; @@ -350,7 +352,7 @@ sub machinepassword { } #my $server = $sitetab->getAttribs({key=>'directoryserver'},['value']); my $server; - my @servers = xCAT::Utils->get_site_attribute("directoryserver"); + my @servers = xCAT::TableUtils->get_site_attribute("directoryserver"); $tmp = $servers[0]; if (defined($tmp)) { $server = $tmp; @@ -552,7 +554,7 @@ sub tabdb unless($ent and defined($ent->{$field})) { unless ($blankok) { if ($field eq "xcatmaster") { - my $ipfn = xCAT::Utils->my_ip_facing($node); + my $ipfn = xCAT::NetworkUtils->my_ip_facing($node); if ($ipfn) { return $ipfn; }