diff --git a/perl-xCAT-2.0/xCAT/Postage.pm b/perl-xCAT-2.0/xCAT/Postage.pm index d830cf891..15f1507e2 100644 --- a/perl-xCAT-2.0/xCAT/Postage.pm +++ b/perl-xCAT-2.0/xCAT/Postage.pm @@ -2,179 +2,15 @@ package xCAT::Postage; use xCAT::Table; use xCAT::NodeRange; -use xCAT::MsgUtils; use Data::Dumper; - -#------------------------------------------------------------------------------- - -=head1 Postage - -=head2 xCAT post script support. - -This program module file is a set of utilities to support xCAT post scripts. - -=cut - -#------------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- - -=head3 writescript - - Create a node-specific post script for an xCAT node - - Arguments: - Returns: - 0 - All was successful. - 1 - An error occured. - Globals: - Error: - Example: - - xCAT::Postage->writescript($node, "/install/postscripts/" . $node, $state); - - Comments: - -=cut - -#----------------------------------------------------------------------------- +my $depsfile = "/etc/xcat/postscripts.dep"; +my $rulesfile = "/etc/xcat/postscripts.rules"; +my $rules; +my $deps; +my $rulec; +my $node; sub writescript { - - if (scalar(@_) eq 4) { shift; } #Discard self - my $node = shift; - my $scriptfile = shift; - my $nodesetstate = shift; # install or netboot - - my ($master, $ps, $os, $arch, $profile); - - unless (open(SCRIPT,">",$scriptfile)){ - my $rsp; - push @{$rsp->{data}}, "Could not open $scriptfile for writing.\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; - } - - # - # get attribute values from DB... - # - # get noderes, nodetype, & site tables - my $noderestab=xCAT::Table->new('noderes'); - my $typetab=xCAT::Table->new('nodetype'); - my $sitetab = xCAT::Table->new('site'); - my $posttab = xCAT::Table->new('postscripts'); - - unless ($noderestab and $typetab and $sitetab) { - my $rsp; - push @{$rsp->{data}}, "Unable to open noderes or nodetype or site table.\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; - } - - # the master is either the site "master" or the noderes "servicenode" - # or the xcatmaster - in that order - (my $et) = $sitetab->getAttribs({key=>"master"},'value'); - if ($et and $et->{value}) { - $master = $et->{value}; - } - - # get servicenode - $et = $noderestab->getNodeAttribs($node,['servicenode']); - if ($et and $et->{'servicenode'}) { - $master = $et->{'servicenode'}; - } - - # get xcatmaster - $et = $noderestab->getNodeAttribs($node,['xcatmaster']); - if ($et and $et->{'xcatmaster'}) { - $master = $et->{'xcatmaster'}; - } - - unless ($master) { - my $rsp; - push @{$rsp->{data}}, "Unable to identify master for $node.\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; - } - - # get os & arch - my $et = $typetab->getNodeAttribs($node,['os','arch','profile']); - $os = $et->{'os'}; - $arch = $et->{'arch'}; - $profile = $et->{'profile'}; - - # get postscripts - my $et = $posttab->getNodeAttribs($node, ['postscripts']); - $ps = $et->{'postscripts'}; - - # get the xcatdefaults entry in the postscripts table - my $et = $posttab->getAttribs({node=>"xcatdefaults"},'postscripts'); - $defscripts = $et->{'postscripts'}; - - # - # build the node-specific script - # - -#print "master=$master, node=$node, os = $os, postscripts= $ps\n"; - - print SCRIPT "MASTER=".$master."\n"; - print SCRIPT "export MASTER\n"; - print SCRIPT "NODE=$node\n"; - print SCRIPT "export NODE\n"; - - if ($os) { - print SCRIPT "OSVER=".$os ."\n"; - print SCRIPT "export OSVER\n"; - } - if ($arch) { - print SCRIPT "ARCH=".$arch."\n"; - print SCRIPT "export ARCH\n"; - } - if ($profile) { - print SCRIPT "PROFILE=".$profile."\n"; - print SCRIPT "export PROFILE\n"; - } - if ($nodesetstate) { - print SCRIPT "NODESETSTATE=".$nodesetstate."\n"; - print SCRIPT "export NODESETSTATE\n"; - } - print SCRIPT 'PATH=`dirname $0`:$PATH'."\n"; - print SCRIPT "export PATH\n"; - - if ($defscripts) { - foreach my $n (split(/,/, $defscripts)) { - print SCRIPT $n."\n"; - } - } - - if ($ps) { - foreach my $n (split(/,/, $ps)) { - print SCRIPT $n."\n"; - } - } - - close(SCRIPT); - - my $cmd = "chmod 0755 $scriptfile"; - my @result = xCAT::Utils->runcmd("$cmd", -1); - if ($::RUNCMD_RC != 0) - { - my $rsp; - push @{$rsp->{data}}, "Could not run the chmod command.\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; - } - - return 0; -} - - -########################## -# old code -############################# - - -sub old_writescript { if (scalar(@_) eq 3) { shift; } #Discard self $node = shift; my $scriptfile = shift; @@ -189,6 +25,17 @@ sub old_writescript { return undef; } #Some common variables... + my @scriptcontents = makescript($node); + foreach (@scriptcontents) { + print $script $_; + } + close($script); + chmod 0755,$scriptfile; +} + +sub makescript { + $node = shift; + my @scriptd; my $noderestab=xCAT::Table->new('noderes'); my $typetab=xCAT::Table->new('nodetype'); unless ($noderestab and $typetab) { @@ -211,19 +58,19 @@ sub old_writescript { unless ($master) { die "Unable to identify master for $node"; } - print $script "MASTER=".$master."\n"; - print $script "export MASTER\n"; - print $script "NODE=$node\n"; - print $script "export NODE\n"; + push @scriptd, "MASTER=".$master."\n"; + push @scriptd, "export MASTER\n"; + push @scriptd, "NODE=$node\n"; + push @scriptd, "export NODE\n"; my $et = $typetab->getNodeAttribs($node,['os','arch']); unless ($et and $et->{'os'} and $et->{'arch'}) { die "No os/arch setting in nodetype table for $node"; } - print $script "OSVER=".$et->{'os'}."\n"; - print $script "ARCH=".$et->{'arch'}."\n"; - print $script "export OSVER ARCH\n"; - print $script 'PATH=`dirname $0`:$PATH'."\n"; - print $script "export PATH\n"; + push @scriptd, "OSVER=".$et->{'os'}."\n"; + push @scriptd, "ARCH=".$et->{'arch'}."\n"; + push @scriptd, "export OSVER ARCH\n"; + push @scriptd, 'PATH=`dirname $0`:$PATH'."\n"; + push @scriptd, "export PATH\n"; $rulec=""; my @scripts; my $inlist = 0; @@ -287,10 +134,9 @@ sub old_writescript { } } foreach (@scripts) { - print $script $_."\n"; + push @scriptd, $_."\n"; } - close($script); - chmod 0755,$scriptfile; + return @scriptd; } #shamelessly brought forth from postrules.pl in xCAT 1.3 diff --git a/xCAT-server-2.0/lib/xcat/plugins/anaconda.pm b/xCAT-server-2.0/lib/xcat/plugins/anaconda.pm index ef2d83a0f..5d6958e3b 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/anaconda.pm @@ -161,7 +161,7 @@ sub mknetboot { # create the node-specific post scripts mkpath "/install/postscripts/"; - xCAT::Postage->writescript($node,"/install/postscripts/".$node, "netboot"); + xCAT::Postage->writescript($node,"/install/postscripts/".$node); # , "netboot"); mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); #TODO: only copy if newer... @@ -264,7 +264,7 @@ sub mkinstall { # create the node-specific post scripts mkpath "/install/postscripts/"; - xCAT::Postage->writescript($node,"/install/postscripts/".$node, "install"); + xCAT::Postage->writescript($node,"/install/postscripts/".$node); #, "install"); if ( diff --git a/xCAT-server-2.0/lib/xcat/plugins/sles.pm b/xCAT-server-2.0/lib/xcat/plugins/sles.pm index b527230d2..9a28db0ed 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/sles.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/sles.pm @@ -133,7 +133,7 @@ sub mkinstall # create the node-specific post script mkpath "/install/postscripts/"; - xCAT::Postage->writescript($node, "/install/postscripts/" . $node, "install"); + xCAT::Postage->writescript($node, "/install/postscripts/" . $node); #, "install"); if ( (