From 529660fe6ae81661de9c9826e53a55a6de81e601 Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 20 Mar 2009 21:36:49 +0000 Subject: [PATCH] removed dependencies on the xCAT-server package from perl-xCAT package git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2952 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Utils.pm | 166 ---------------- .../lib/perl}/xCAT/PPC.pm | 5 +- .../lib/perl}/xCAT/Postage.pm | 3 +- xCAT-server/lib/perl/xCAT/SvrUtils.pm | 183 ++++++++++++++++++ xCAT-server/lib/xcat/plugins/blade.pm | 3 +- xCAT-server/lib/xcat/plugins/ipmi.pm | 3 +- xCAT-server/lib/xcat/plugins/kvm.pm | 3 +- xCAT-server/lib/xcat/plugins/xen.pm | 3 +- xCAT-server/xCAT-server.spec | 4 + 9 files changed, 200 insertions(+), 173 deletions(-) rename {perl-xCAT => xCAT-server/lib/perl}/xCAT/PPC.pm (99%) rename {perl-xCAT => xCAT-server/lib/perl}/xCAT/Postage.pm (99%) create mode 100644 xCAT-server/lib/perl/xCAT/SvrUtils.pm diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 1f5c9894f..eb6a8d76e 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -2915,172 +2915,6 @@ sub runxcatd return 0; } -#------------------------------------------------------------------------------- - -=head3 getNodesetStates - get current nodeset stat for the given nodes - Arguments: - nodes -- a pointer to an array of nodes - hashref -- A pointer to a hash that contains the nodeset status. - Returns: - (ret code, error message) - -=cut - -#------------------------------------------------------------------------------- -sub getNodesetStates -{ - my $noderef = shift; - if ($noderef =~ /xCAT::Utils/) - { - $noderef = shift; - } - my @nodes = @$noderef; - my $hashref = shift; - - if (@nodes > 0) - { - my $tab = xCAT::Table->new('noderes'); - if (!$tab) { return (1, "Unable to open noderes table."); } - - #initialize all nodes - foreach (@nodes) { $hashref->{$_} = "undefined"; } - - my @aixnodes = (); - my @pxenodes = (); - my @yabootnodes = (); - my $tabdata = $tab->getNodesAttribs(\@nodes, ['node', 'netboot']); - foreach my $node (@nodes) - { - my $nb = "aixinstall"; - my $tmp1 = $tabdata->{$node}->[0]; - if (($tmp1) && ($tmp1->{netboot})) { $nb = $tmp1->{netboot}; } - if ($nb eq "yaboot") - { - push(@yabootnodes, $node); - } - elsif ($nb eq "pxe") - { - push(@pxenodes, $node); - } - elsif ($nb eq "aixinstall") - { - push(@aixnodes, $node); - } - } - - my @retarray; - my $retcode = 0; - my $errormsg; - - # print "ya=@yabootnodes, pxe=@pxenodes, aix=@aixnodes\n"; - if (@yabootnodes > 0) - { - require xCAT_plugin::yaboot; - @retarray = - xCAT_plugin::yaboot::getNodesetStates(\@yabootnodes, $hashref); - if ($retarray[0]) - { - $retcode = $retarray[0]; - $errormsg .= $retarray[1]; - xCAT::MsgUtils->message('E', $retarray[1]); - } - } - if (@pxenodes > 0) - { - require xCAT_plugin::pxe; - @retarray = - xCAT_plugin::pxe::getNodesetStates(\@pxenodes, $hashref); - if ($retarray[0]) - { - $retcode = $retarray[0]; - $errormsg .= $retarray[1]; - xCAT::MsgUtils->message('E', $retarray[1]); - } - } - if (@aixnodes > 0) - { - require xCAT_plugin::aixinstall; - @retarray = - xCAT_plugin::aixinstall::getNodesetStates(\@aixnodes, $hashref); - if ($retarray[0]) - { - $retcode = $retarray[0]; - $errormsg .= $retarray[1]; - xCAT::MsgUtils->message('E', $retarray[1]); - } - } - } - return (0, ""); -} - -#------------------------------------------------------------------------------- - -=head3 get_nodeset_state - get current nodeset stat for the given node. - Arguments: - nodes -- node name. - Returns: - nodesetstate - -=cut - -#------------------------------------------------------------------------------- -sub get_nodeset_state -{ - my $node = shift; - if ($node =~ /xCAT::Utils/) - { - $node = shift; - } - - my $state = "undefined"; - - #get boot type (pxe, yaboot or aixinstall) for the node - my $noderestab = xCAT::Table->new('noderes', -create => 0); - my $ent = $noderestab->getNodeAttribs($node, [qw(netboot)]); - if ($ent && $ent->{netboot}) - { - my $boottype = $ent->{netboot}; - - #get nodeset state from corresponding files - if ($boottype eq "pxe") - { - require xCAT_plugin::pxe; - my $tmp = xCAT_plugin::pxe::getstate($node); - my @a = split(' ', $tmp); - $state = $a[0]; - - } - elsif ($boottype eq "yaboot") - { - require xCAT_plugin::yaboot; - my $tmp = xCAT_plugin::yaboot::getstate($node); - my @a = split(' ', $tmp); - $state = $a[0]; - } - elsif ($boottype eq "aixinstall") - { - require xCAT_plugin::aixinstall; - $state = xCAT_plugin::aixinstall::getNodesetState($node); - } - } - else - { #default to AIX because AIX does not set noderes.netboot value - require xCAT_plugin::aixinstall; - $state = xCAT_plugin::aixinstall::getNodesetState($node); - } - - #get the nodeset state from the chain table as a backup. - if ($state eq "undefined") - { - my $chaintab = xCAT::Table->new('chain'); - my $stref = $chaintab->getNodeAttribs($node, ['currstate']); - if ($stref and $stref->{currstate}) { $state = $stref->{currstate}; } - } - - return $state; -} #------------------------------------------------------------------------------- diff --git a/perl-xCAT/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm similarity index 99% rename from perl-xCAT/xCAT/PPC.pm rename to xCAT-server/lib/perl/xCAT/PPC.pm index 493eec173..e8bee9bb9 100644 --- a/perl-xCAT/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -5,6 +5,7 @@ use strict; use lib "/opt/xcat/lib/perl"; use xCAT::Table; use xCAT::Utils; +use xCAT::SvrUtils; use xCAT::Usage; use POSIX "WNOHANG"; use Storable qw(freeze thaw); @@ -141,7 +142,7 @@ sub process_command { #get the current nodeset stat if (@allnodes>0) { my $nsh={}; - my ($ret, $msg)=xCAT::Utils->getNodesetStates(\@allnodes, $nsh); + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); if ($ret) { trace( $request, $msg );} else { foreach (keys %$nsh) { @@ -159,7 +160,7 @@ sub process_command { #get the current nodeset stat if (@allnodes>0) { my $nsh={}; - my ($ret, $msg)=xCAT::Utils->getNodesetStates(\@allnodes, $nsh); + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); if ($ret) { trace( $request, $msg );} else { foreach (keys %$nsh) { diff --git a/perl-xCAT/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm similarity index 99% rename from perl-xCAT/xCAT/Postage.pm rename to xCAT-server/lib/perl/xCAT/Postage.pm index d253115a8..2e0631286 100644 --- a/perl-xCAT/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -4,6 +4,7 @@ use xCAT::Table; use xCAT::MsgUtils; use xCAT::NodeRange; use xCAT::Utils; +use xCAT::SvrUtils; use Data::Dumper; use strict; BEGIN @@ -323,7 +324,7 @@ sub makescript { #----------------------------------------------------------------------------- sub getnodesetstate { my $node=shift; - return xCAT::Utils->get_nodeset_state($node); + return xCAT::SvrUtils->get_nodeset_state($node); } sub get_otherpkg_file_name { diff --git a/xCAT-server/lib/perl/xCAT/SvrUtils.pm b/xCAT-server/lib/perl/xCAT/SvrUtils.pm new file mode 100644 index 000000000..3f79fd1a4 --- /dev/null +++ b/xCAT-server/lib/perl/xCAT/SvrUtils.pm @@ -0,0 +1,183 @@ +#!/usr/bin/env perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +package xCAT::SvrUtils; + +BEGIN +{ + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; +} +use lib "$::XCATROOT/lib/perl"; +require xCAT::Table; + +use strict; + + +#------------------------------------------------------------------------------- + +=head3 getNodesetStates + get current nodeset stat for the given nodes + Arguments: + nodes -- a pointer to an array of nodes + hashref -- A pointer to a hash that contains the nodeset status. + Returns: + (ret code, error message) + +=cut + +#------------------------------------------------------------------------------- +sub getNodesetStates +{ + my $noderef = shift; + if ($noderef =~ /xCAT::Utils/) + { + $noderef = shift; + } + my @nodes = @$noderef; + my $hashref = shift; + + if (@nodes > 0) + { + my $tab = xCAT::Table->new('noderes'); + if (!$tab) { return (1, "Unable to open noderes table."); } + + #initialize all nodes + foreach (@nodes) { $hashref->{$_} = "undefined"; } + + my @aixnodes = (); + my @pxenodes = (); + my @yabootnodes = (); + my $tabdata = $tab->getNodesAttribs(\@nodes, ['node', 'netboot']); + foreach my $node (@nodes) + { + my $nb = "aixinstall"; + my $tmp1 = $tabdata->{$node}->[0]; + if (($tmp1) && ($tmp1->{netboot})) { $nb = $tmp1->{netboot}; } + if ($nb eq "yaboot") + { + push(@yabootnodes, $node); + } + elsif ($nb eq "pxe") + { + push(@pxenodes, $node); + } + elsif ($nb eq "aixinstall") + { + push(@aixnodes, $node); + } + } + + my @retarray; + my $retcode = 0; + my $errormsg; + + # print "ya=@yabootnodes, pxe=@pxenodes, aix=@aixnodes\n"; + if (@yabootnodes > 0) + { + require xCAT_plugin::yaboot; + @retarray = + xCAT_plugin::yaboot::getNodesetStates(\@yabootnodes, $hashref); + if ($retarray[0]) + { + $retcode = $retarray[0]; + $errormsg .= $retarray[1]; + xCAT::MsgUtils->message('E', $retarray[1]); + } + } + if (@pxenodes > 0) + { + require xCAT_plugin::pxe; + @retarray = + xCAT_plugin::pxe::getNodesetStates(\@pxenodes, $hashref); + if ($retarray[0]) + { + $retcode = $retarray[0]; + $errormsg .= $retarray[1]; + xCAT::MsgUtils->message('E', $retarray[1]); + } + } + if (@aixnodes > 0) + { + require xCAT_plugin::aixinstall; + @retarray = + xCAT_plugin::aixinstall::getNodesetStates(\@aixnodes, $hashref); + if ($retarray[0]) + { + $retcode = $retarray[0]; + $errormsg .= $retarray[1]; + xCAT::MsgUtils->message('E', $retarray[1]); + } + } + } + return (0, ""); +} + +#------------------------------------------------------------------------------- + +=head3 get_nodeset_state + get current nodeset stat for the given node. + Arguments: + nodes -- node name. + Returns: + nodesetstate + +=cut + +#------------------------------------------------------------------------------- +sub get_nodeset_state +{ + my $node = shift; + if ($node =~ /xCAT::Utils/) + { + $node = shift; + } + + my $state = "undefined"; + + #get boot type (pxe, yaboot or aixinstall) for the node + my $noderestab = xCAT::Table->new('noderes', -create => 0); + my $ent = $noderestab->getNodeAttribs($node, [qw(netboot)]); + if ($ent && $ent->{netboot}) + { + my $boottype = $ent->{netboot}; + + #get nodeset state from corresponding files + if ($boottype eq "pxe") + { + require xCAT_plugin::pxe; + my $tmp = xCAT_plugin::pxe::getstate($node); + my @a = split(' ', $tmp); + $state = $a[0]; + + } + elsif ($boottype eq "yaboot") + { + require xCAT_plugin::yaboot; + my $tmp = xCAT_plugin::yaboot::getstate($node); + my @a = split(' ', $tmp); + $state = $a[0]; + } + elsif ($boottype eq "aixinstall") + { + require xCAT_plugin::aixinstall; + $state = xCAT_plugin::aixinstall::getNodesetState($node); + } + } + else + { #default to AIX because AIX does not set noderes.netboot value + require xCAT_plugin::aixinstall; + $state = xCAT_plugin::aixinstall::getNodesetState($node); + } + + #get the nodeset state from the chain table as a backup. + if ($state eq "undefined") + { + my $chaintab = xCAT::Table->new('chain'); + my $stref = $chaintab->getNodeAttribs($node, ['currstate']); + if ($stref and $stref->{currstate}) { $state = $stref->{currstate}; } + } + + return $state; +} + + +1; diff --git a/xCAT-server/lib/xcat/plugins/blade.pm b/xCAT-server/lib/xcat/plugins/blade.pm index 8ef8de321..b41f93af7 100644 --- a/xCAT-server/lib/xcat/plugins/blade.pm +++ b/xCAT-server/lib/xcat/plugins/blade.pm @@ -34,6 +34,7 @@ use IO::Handle; use Time::HiRes qw(gettimeofday sleep); use xCAT::DBobjUtils; use Getopt::Long; +use xCAT::SvrUtils; sub handled_commands { return { @@ -2832,7 +2833,7 @@ sub dompa { #get the current nodeset stat if (@allnodes>0) { - my ($ret, $msg)=xCAT::Utils->getNodesetStates(\@allnodes, $nsh); + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); if ($ret) { xCAT::MsgUtils->message('S', "Cannot update node status: $msg\n"); } } } diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index a9d4871c1..f6cb43f71 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -18,6 +18,7 @@ use xCAT::SPD qw/decode_spd/; use POSIX qw(ceil floor); use Storable qw(store_fd retrieve_fd thaw freeze); use xCAT::Utils; +use xCAT::SvrUtils; use xCAT::Usage; use Thread qw(yield); use LWP 5.64; @@ -5893,7 +5894,7 @@ sub process_request { #get the current nodeset stat if (@allnodes>0) { my $nsh={}; - my ($ret, $msg)=xCAT::Utils->getNodesetStates(\@allnodes, $nsh); + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); if (!$ret) { foreach (keys %$nsh) { my $currstate=$nsh->{$_}; diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 7d22b7d85..77ad7a3bc 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -35,6 +35,7 @@ use IO::Handle; use Time::HiRes qw(gettimeofday sleep); use xCAT::DBobjUtils; use Getopt::Long; +use xCAT::SvrUtils; my %runningstates; my $vmmaxp=64; @@ -906,7 +907,7 @@ sub process_request { #get the current nodeset stat if (@allnodes>0) { my $nsh={}; - my ($ret, $msg)=xCAT::Utils->getNodesetStates(\@allnodes, $nsh); + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); if (!$ret) { foreach (keys %$nsh) { my $currstate=$nsh->{$_}; diff --git a/xCAT-server/lib/xcat/plugins/xen.pm b/xCAT-server/lib/xcat/plugins/xen.pm index 424b0ecc3..8d4a8e021 100644 --- a/xCAT-server/lib/xcat/plugins/xen.pm +++ b/xCAT-server/lib/xcat/plugins/xen.pm @@ -34,6 +34,7 @@ use IO::Handle; use Time::HiRes qw(gettimeofday sleep); use xCAT::DBobjUtils; use Getopt::Long; +use xCAT::SvrUtils; my %runningstates; my $vmmaxp=64; @@ -766,7 +767,7 @@ sub process_request { #get the current nodeset stat if (@allnodes>0) { my $nsh={}; - my ($ret, $msg)=xCAT::Utils->getNodesetStates(\@allnodes, $nsh); + my ($ret, $msg)=xCAT::SvrUtils->getNodesetStates(\@allnodes, $nsh); if (!$ret) { foreach (keys %$nsh) { my $currstate=$nsh->{$_}; diff --git a/xCAT-server/xCAT-server.spec b/xCAT-server/xCAT-server.spec index 6b8382fc2..8c84fd69b 100644 --- a/xCAT-server/xCAT-server.spec +++ b/xCAT-server/xCAT-server.spec @@ -48,6 +48,7 @@ mkdir -p $RPM_BUILD_ROOT/opt/xcat/xdsh/Context mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_monitoring/samples mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_monitoring/pcp mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_schema/samples +mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT %ifos linux cp -a share/xcat/install/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/install/ @@ -88,6 +89,9 @@ ln -sf /%{prefix}/share/xcat/cons/hmc $RPM_BUILD_ROOT/%{prefix}/share/xcat/cons/ cp lib/xcat/plugins/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin/* +cp lib/perl/xCAT/* $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT +chmod 644 $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT/* + # For now, don't ship these plugins - to avoid AIX dependency on SNMP. %ifnos linux rm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin/blade.pm