the subroutines to generate the mypostscript for each node, according to the template mypostscript.tmpl
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13989 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
5209a92de1
commit
521da69833
@ -639,4 +639,922 @@ sub get_replacement {
|
||||
return $rep;
|
||||
}
|
||||
|
||||
|
||||
my $os;
|
||||
my $profile;
|
||||
my $arch;
|
||||
my $provmethod;
|
||||
my $nodesetstate;
|
||||
sub subvars_for_mypostscript {
|
||||
my $self = shift;
|
||||
my $nodes = shift;
|
||||
$nodesetstate = shift;
|
||||
my $callback = shift;
|
||||
#my $tmpl = shift; #tmplfile default: "/opt/xcat/share/xcat/templates/mypostscript/mypostscript.tmpl" customized: /install/postscripts/mypostscript.tmpl
|
||||
$tmplerr=undef; #clear tmplerr since we are starting fresh
|
||||
my %namedargs = @_; #further expansion of this function will be named arguments, should have happened sooner.
|
||||
|
||||
my $installroot =
|
||||
my @entries = xCAT::TableUtils->get_site_attribute("installdir");
|
||||
if($entries[0]) {
|
||||
$installroot = $entries[0];
|
||||
}
|
||||
my $tmpl="$installroot/postscripts/mypostscript.tmpl";
|
||||
|
||||
unless ( -r $tmpl) {
|
||||
$tmpl="$::XCATROOT/share/xcat/templates/mypostscript/mypostscript.tmpl";
|
||||
}
|
||||
|
||||
unless ( -r "$tmpl") {
|
||||
$callback->(
|
||||
{
|
||||
error => [
|
||||
"site.precreatemypostscripts is set to 1 or yes. But No mypostscript template exists"
|
||||
. " in directory $installroot/install/postscripts or $::XCATROOT/share/xcat/templates/mypostscript/mypostscript.tmpl"
|
||||
],
|
||||
errorcode => [1]
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $outh;
|
||||
my $inh;
|
||||
$idir = dirname($tmpl);
|
||||
open($inh,"<",$tmpl);
|
||||
unless ($inh) {
|
||||
my $rsp;
|
||||
$rsp->{errorcode}->[0]=1;
|
||||
$rsp->{error}->[0]="Unable to open $tmpl, aborting\n";
|
||||
$callback->($rsp);
|
||||
return;
|
||||
}
|
||||
|
||||
my $inc;
|
||||
my $t_inc;
|
||||
#First load input into memory..
|
||||
while (<$inh>) {
|
||||
$t_inc.=$_;
|
||||
}
|
||||
|
||||
close($inh);
|
||||
|
||||
|
||||
my %script_fp;
|
||||
my $allattribsfromsitetable;
|
||||
|
||||
# read all attributes for the site table and write an export
|
||||
# only run this function once for one command with noderange
|
||||
$allattribsfromsitetable = getAllAttribsFromSiteTab();
|
||||
|
||||
my $masterhash = getMasters($nodes);
|
||||
|
||||
## nfsserver,installnic,primarynic
|
||||
my $attribsfromnoderes = getNoderes($nodes);
|
||||
|
||||
foreach my $n (@$nodes ) {
|
||||
$node = $n;
|
||||
$inc = $t_inc;
|
||||
my $tftpdir = xCAT::TableUtils::getTftpDir();
|
||||
my $script;
|
||||
my $scriptfile;
|
||||
$scriptfile = "$tftpdir/mypostscripts/mypostscript.$node";
|
||||
mkpath(dirname($scriptfile));
|
||||
open($script, ">$scriptfile");
|
||||
|
||||
unless ($script)
|
||||
{
|
||||
my $rsp;
|
||||
push @{$rsp->{data}}, "Could not open $scriptfile for writing.\n";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback);
|
||||
return 1;
|
||||
}
|
||||
$script_fp{$node}=$script;
|
||||
`/bin/chmod ugo+x $scriptfile`;
|
||||
|
||||
##attributes from site tab
|
||||
#
|
||||
my $master = $masterhash->{$node};
|
||||
|
||||
if( defined($master) ) {
|
||||
$allattribsfromsitetable =~ s/MASTER=([^\n]+)\n/MASTER=$master\n/;
|
||||
}
|
||||
|
||||
# ENABLESSHBETWEENNODES
|
||||
|
||||
## nfsserver,installnic,primarynic
|
||||
my ($nfsserver, $installnic, $primarynic, $route_vars);
|
||||
|
||||
my $noderesent;
|
||||
|
||||
if(exists($attribsfromnoderes->{$node})) {
|
||||
$noderesent = $attribsfromnoderes->{$node};
|
||||
}
|
||||
|
||||
if ($noderesent ){
|
||||
if($noderesent->{nfsserver}) {
|
||||
$nfsserver = $noderesent->{nfsserver};
|
||||
}
|
||||
if($noderesent->{installnic}) {
|
||||
$installnic = $noderesent->{installnic};
|
||||
}
|
||||
if($noderesent->{primarynic}) {
|
||||
$primarynic = $noderesent->{primarynic};
|
||||
}
|
||||
|
||||
}
|
||||
#print Dumper($noderesent);
|
||||
#routes
|
||||
if ($noderesent and defined($noderesent->{'routenames'}))
|
||||
{
|
||||
my $rn=$noderesent->{'routenames'};
|
||||
my @rn_a=split(',', $rn);
|
||||
my $routestab = xCAT::Table->new('routes');
|
||||
if ((@rn_a > 0) && ($routestab)) {
|
||||
$route_vars .= "NODEROUTENAMES=$rn\n";
|
||||
$route_vars .= "export NODEROUTENAMES\n";
|
||||
foreach my $route_name (@rn_a) {
|
||||
my $routesent = $routestab->getAttribs({routename => $route_name}, 'net', 'mask', 'gateway', 'ifname');
|
||||
if ($routesent and defined($routesent->{net}) and defined($routesent->{mask})) {
|
||||
my $val="ROUTE_$route_name=" . $routesent->{net} . "," . $routesent->{mask};
|
||||
$val .= ",";
|
||||
if (defined($routesent->{gateway})) {
|
||||
$val .= $routesent->{gateway};
|
||||
}
|
||||
$val .= ",";
|
||||
if (defined($routesent->{ifname})) {
|
||||
$val .= $routesent->{ifname};
|
||||
}
|
||||
$route_vars .= "$val\n";
|
||||
$route_vars .= "export ROUTE_$route_name\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#NODESETSTATE
|
||||
|
||||
### vlan related item
|
||||
# for #VLAN_VARS_EXPORT#
|
||||
my $vlan_vars;
|
||||
$vlan_vars = getVlanItems($node);
|
||||
|
||||
## get monitoring server and other configuration data for monitoring setup on nodes
|
||||
# for #MONITORING_VARS_EXPORT#
|
||||
my $mon_vars;
|
||||
$mon_vars = getMonItems($node);
|
||||
|
||||
## OSPKGDIR export
|
||||
# for #OSIMAGE_VARS_EXPORT#
|
||||
if (!$nodesetstate) { $nodesetstate = xCAT::Postage::getnodesetstate($node); }
|
||||
|
||||
my $typetab = xCAT::Table->new('nodetype');
|
||||
my $et =
|
||||
$typetab->getNodeAttribs($node, ['os', 'arch', 'profile', 'provmethod'],prefetchcache=>1);
|
||||
if ($^O =~ /^linux/i)
|
||||
{
|
||||
unless ($et and $et->{'os'} and $et->{'arch'})
|
||||
{
|
||||
my $rsp;
|
||||
push @{$rsp->{data}},
|
||||
"No os or arch setting in nodetype table for $node.\n";
|
||||
xCAT::MsgUtils->message("E", $rsp, $callback);
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
$provmethod = $et->{'provmethod'};
|
||||
$os = $et->{'os'};
|
||||
$arch = $et->{'arch'};
|
||||
$profile = $et->{'profile'};
|
||||
|
||||
my $osimage_vars;
|
||||
$osimage_vars = getOsimageItems($node);
|
||||
|
||||
## network
|
||||
# for #NETWORK_FOR_DISKLESS_EXPORT#
|
||||
#
|
||||
my $diskless_net_vars;
|
||||
$diskless_net_vars = getDisklessNet();
|
||||
|
||||
## postscripts
|
||||
# for #INCLUDE_POSTSCRIPTS_LIST#
|
||||
#
|
||||
my $postscripts;
|
||||
$postscripts = getPostScripts();
|
||||
|
||||
## postbootscripts
|
||||
# for #INCLUDE_POSTBOOTSCRIPTS_LIST#
|
||||
my $postbootscripts;
|
||||
$postbootscripts = getPostbootScripts();
|
||||
|
||||
|
||||
|
||||
|
||||
#ok, now do everything else..
|
||||
$inc =~ s/#XCATVAR:([^#]+)#/envvar($1)/eg;
|
||||
$inc =~ s/#ENV:([^#]+)#/envvar($1)/eg;
|
||||
$inc =~ s/#SITE_TABLE_ALL_ATTRIBS_EXPORT#/$allattribsfromsitetable/eg;
|
||||
$inc =~ s/#TABLE:([^:]+):([^:]+):([^#]+)#/tabdb($1,$2,$3)/eg;
|
||||
$inc =~ s/#ROUTES_VARS_EXPORT#/$route_vars/eg;
|
||||
$inc =~ s/#VLAN_VARS_EXPORT#/$vlan_vars/eg;
|
||||
$inc =~ s/#MONITORING_VARS_EXPORT#/$mon_vars/eg;
|
||||
$inc =~ s/#OSIMAGE_VARS_EXPORT#/$osimage_vars/eg;
|
||||
$inc =~ s/#NETWORK_FOR_DISKLESS_EXPORT#/$diskless_net_vars/eg;
|
||||
$inc =~ s/#INCLUDE_POSTSCRIPTS_LIST#/$postscripts/eg;
|
||||
$inc =~ s/#INCLUDE_POSTBOOTSCRIPTS_LIST#/$postbootscripts/eg;
|
||||
|
||||
$inc =~ s/#COMMAND:([^#]+)#/command($1)/eg;
|
||||
$inc =~ s/#NODE#/$node/eg;
|
||||
$inc =~ s/\$NODE/$node/eg;
|
||||
$inc =~ s/#NFSSERVER#/$nfsserver/eg;
|
||||
$inc =~ s/#INSTALLNIC#/$installnic/eg;
|
||||
$inc =~ s/#PRIMARYNIC#/$primarynic/eg;
|
||||
$inc =~ s/#Subroutine:([^:]+)::([^:]+)::([^:]+):([^#]+)#/subroutine($1,$2,$3,$4)/eg;
|
||||
|
||||
#my $nrtab = xCAT::Table->new("noderes");
|
||||
#my $tftpserver = $nrtab->getNodeAttribs($node, ['tftpserver']);
|
||||
#my $sles_sdk_media = "http://" . $tftpserver->{tftpserver} . $media_dir . "/sdk1";
|
||||
|
||||
#$inc =~ s/#SLES_SDK_MEDIA#/$sles_sdk_media/eg;
|
||||
|
||||
#if ($tmplerr) {
|
||||
# close ($outh);
|
||||
# return $tmplerr;
|
||||
# }
|
||||
#print $outh $inc;
|
||||
#close($outh);
|
||||
print $script $inc;
|
||||
close($script_fp{$node});
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub getMasterFromNoderes
|
||||
{
|
||||
my $node = shift;
|
||||
my $value;
|
||||
|
||||
my $noderestab = xCAT::Table->new('noderes');
|
||||
# if node has service node as master then override site master
|
||||
my $et = $noderestab->getNodeAttribs($node, ['xcatmaster'],prefetchcache=>1);
|
||||
if ($et and defined($et->{'xcatmaster'}))
|
||||
{
|
||||
$value = $et->{'xcatmaster'};
|
||||
}
|
||||
else
|
||||
{
|
||||
my $sitemaster_value = $value;
|
||||
$value = xCAT::NetworkUtils->my_ip_facing($node);
|
||||
if ($value eq "0")
|
||||
{
|
||||
$value = $sitemaster_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
sub getMasters
|
||||
{
|
||||
my $nodes = shift;
|
||||
my %masterhash;
|
||||
|
||||
my $noderestab = xCAT::Table->new('noderes');
|
||||
# if node has service node as master then override site master
|
||||
my $ethash = $noderestab->getNodesAttribs($nodes, ['xcatmaster'],prefetchcache=>1);
|
||||
|
||||
|
||||
if ($ethash) {
|
||||
foreach my $node ($nodes) {
|
||||
if( $ethash->{$node}->[0] ) {
|
||||
$masterhash{$node} = $ethash->{$node}->[0]->{xcatmaster};
|
||||
}
|
||||
|
||||
if ( ! exists($masterhash{$node}))
|
||||
{
|
||||
my $value;
|
||||
$value = xCAT::NetworkUtils->my_ip_facing($node);
|
||||
if ($value eq "0")
|
||||
{
|
||||
undef($value);
|
||||
}
|
||||
$masterhash{$node} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return \%masterhash;
|
||||
}
|
||||
|
||||
sub getNoderes
|
||||
{
|
||||
my $nodes = shift;
|
||||
my %nodereshash;
|
||||
|
||||
my $noderestab = xCAT::Table->new('noderes');
|
||||
|
||||
## nfsserver,installnic,primarynic
|
||||
my ($nfsserver, $installnic, $primarynic, $route_vars);
|
||||
|
||||
my $noderestab = xCAT::Table->new('noderes');
|
||||
|
||||
my $ethash =
|
||||
$noderestab->getNodesAttribs($nodes,
|
||||
['nfsserver', 'installnic', 'primarynic','routenames'],prefetchcache=>1);
|
||||
if ($ethash ){
|
||||
foreach my $node (@$nodes) {
|
||||
if( defined( $ethash->{$node}->[0]) ) {
|
||||
$nodereshash{$node}{nfsserver} = $ethash->{$node}->[0]->{nfsserver};
|
||||
$nodereshash{$node}{installnic} = $ethash->{$node}->[0]->{installnic};
|
||||
$nodereshash{$node}{primarynic} = $ethash->{$node}->[0]->{primarynic};
|
||||
$nodereshash{$node}{routenames} = $ethash->{$node}->[0]->{routenames};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return \%nodereshash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub getAllAttribsFromSiteTab {
|
||||
|
||||
my $sitetab = xCAT::Table->new('site');
|
||||
my $master;
|
||||
my $result;
|
||||
|
||||
# read all attributes for the site table and write an export
|
||||
# for them in the post install file
|
||||
my $recs = $sitetab->getAllEntries();
|
||||
my $noderestab = xCAT::Table->new('noderes');
|
||||
my $attribute;
|
||||
my $value;
|
||||
my $masterset = 0;
|
||||
foreach (@$recs) # export the attribute
|
||||
{
|
||||
$attribute = $_->{key};
|
||||
$attribute =~ tr/a-z/A-Z/;
|
||||
$value = $_->{value};
|
||||
if ($attribute eq "MASTER")
|
||||
{
|
||||
$masterset = 1;
|
||||
$result .= "SITEMASTER=" . $value . "\n";
|
||||
$result .= "export SITEMASTER\n";
|
||||
|
||||
# if node has service node as master then override site master
|
||||
#my $et = $noderestab->getNodeAttribs($node, ['xcatmaster'],prefetchcache=>1);
|
||||
#if ($et and defined($et->{'xcatmaster'}))
|
||||
#{
|
||||
# $value = $et->{'xcatmaster'};
|
||||
#}
|
||||
#else
|
||||
#{
|
||||
# my $sitemaster_value = $value;
|
||||
# $value = xCAT::Utils->my_ip_facing($node);
|
||||
# if ($value eq "0")
|
||||
# {
|
||||
# $value = $sitemaster_value;
|
||||
# }
|
||||
#}
|
||||
$result .= "$attribute=" . $value . "\n";
|
||||
$result .= "export $attribute\n";
|
||||
|
||||
}
|
||||
else
|
||||
{ # not Master attribute
|
||||
$result .= "$attribute='" . $value . "'\n";
|
||||
$result .= "export $attribute\n";
|
||||
}
|
||||
} # end site table attributes
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub enablesshbetweennodes
|
||||
{
|
||||
my $node = shift;
|
||||
my $result;
|
||||
|
||||
my $enablessh=xCAT::TableUtils->enablessh($node);
|
||||
if ($enablessh == 1) {
|
||||
$result = "YES";
|
||||
} else {
|
||||
$result = "NO";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub subroutine
|
||||
{
|
||||
my $prefix = shift;
|
||||
my $module = shift;
|
||||
my $subroutine_name = shift;
|
||||
my $key = shift;
|
||||
my $result;
|
||||
|
||||
if ($key eq "THISNODE" or $key eq '$NODE') {
|
||||
$key=$node;
|
||||
}
|
||||
my $function = join("::",$prefix,$module,$subroutine_name);
|
||||
|
||||
{
|
||||
no strict 'refs';
|
||||
$result=$function->($key);
|
||||
use strict;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub getVlanItems
|
||||
{
|
||||
|
||||
my $node = shift;
|
||||
my $result;
|
||||
|
||||
#get vlan related items
|
||||
my $vlan;
|
||||
my $swtab = xCAT::Table->new("switch", -create => 0);
|
||||
if ($swtab) {
|
||||
my $tmp = $swtab->getNodeAttribs($node, ['vlan'],prefetchcache=>1);
|
||||
if (defined($tmp) && ($tmp) && $tmp->{vlan})
|
||||
{
|
||||
$vlan = $tmp->{vlan};
|
||||
$result .= "VLANID='" . $vlan . "'\n";
|
||||
$result .= "export VLANID\n";
|
||||
} else {
|
||||
my $vmtab = xCAT::Table->new("vm", -create => 0);
|
||||
if ($vmtab) {
|
||||
my $tmp1 = $vmtab->getNodeAttribs($node, ['nics'],prefetchcache=>1);
|
||||
if (defined($tmp1) && ($tmp1) && $tmp1->{nics})
|
||||
{
|
||||
$result .= "VMNODE='YES'\n";
|
||||
$result .= "export VMNODE\n";
|
||||
|
||||
my @nics=split(',', $tmp1->{nics});
|
||||
foreach my $nic (@nics) {
|
||||
if ($nic =~ /^vl([\d]+)$/) {
|
||||
$vlan = $1;
|
||||
$result .= "VLANID='" . $vlan . "'\n";
|
||||
$result .= "export VLANID\n";
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($vlan) {
|
||||
my $nwtab=xCAT::Table->new("networks", -create =>0);
|
||||
if ($nwtab) {
|
||||
my $sent = $nwtab->getAttribs({vlanid=>"$vlan"},'net','mask');
|
||||
my $subnet;
|
||||
my $netmask;
|
||||
if ($sent and ($sent->{net})) {
|
||||
$subnet=$sent->{net};
|
||||
$netmask=$sent->{mask};
|
||||
}
|
||||
if (($subnet) && ($netmask)) {
|
||||
my $hoststab = xCAT::Table->new("hosts", -create => 0);
|
||||
if ($hoststab) {
|
||||
my $tmp = $hoststab->getNodeAttribs($node, ['otherinterfaces'],prefetchcache=>1);
|
||||
if (defined($tmp) && ($tmp) && $tmp->{otherinterfaces})
|
||||
{
|
||||
my $otherinterfaces = $tmp->{otherinterfaces};
|
||||
my @itf_pairs=split(/,/, $otherinterfaces);
|
||||
foreach (@itf_pairs) {
|
||||
my ($name,$ip)=split(/:/, $_);
|
||||
if(xCAT::NetworkUtils->ishostinsubnet($ip, $netmask, $subnet)) {
|
||||
if ($name =~ /^-/ ) {
|
||||
$name = $node.$name;
|
||||
}
|
||||
$result .= "VLANHOSTNAME='" . $name . "'\n";
|
||||
$result .= "export VLANHOSTNAME\n";
|
||||
$result .= "VLANIP='" . $ip . "'\n";
|
||||
$result .= "export VLANIP\n";
|
||||
$result .= "VLANSUBNET='" . $subnet . "'\n";
|
||||
$result .= "export VLANSUBNET\n";
|
||||
$result .= "VLANNETMASK='" . $netmask . "'\n";
|
||||
$result .= "export VLANNETMASK\n";
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
sub getMonItems
|
||||
{
|
||||
|
||||
my $node = shift;
|
||||
my $result;
|
||||
|
||||
#get monitoring server and other configuration data for monitoring setup on nodes
|
||||
my %mon_conf = xCAT_monitoring::monitorctrl->getNodeConfData($node);
|
||||
foreach (keys(%mon_conf))
|
||||
{
|
||||
$result .= "$_=" . $mon_conf{$_} . "\n";
|
||||
$result .= "export $_\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
sub getOsimageItems
|
||||
{
|
||||
|
||||
my $result;
|
||||
|
||||
#get packge names for extra rpms
|
||||
my $pkglist;
|
||||
my $ospkglist;
|
||||
if ( ($^O =~ /^linux/i)
|
||||
&& ($provmethod)
|
||||
&& ($provmethod ne "install")
|
||||
&& ($provmethod ne "netboot")
|
||||
&& ($provmethod ne "statelite"))
|
||||
{
|
||||
|
||||
#this is the case where image from the osimage table is used
|
||||
my $linuximagetab = xCAT::Table->new('linuximage', -create => 1);
|
||||
(my $ref1) =
|
||||
$linuximagetab->getAttribs({imagename => $provmethod},
|
||||
'pkglist', 'pkgdir', 'otherpkglist',
|
||||
'otherpkgdir');
|
||||
if ($ref1)
|
||||
{
|
||||
if ($ref1->{'pkglist'})
|
||||
{
|
||||
$ospkglist = $ref1->{'pkglist'};
|
||||
if ($ref1->{'pkgdir'})
|
||||
{
|
||||
$result .= "OSPKGDIR=" . $ref1->{'pkgdir'} . "\n";
|
||||
$result .= "export OSPKGDIR\n";
|
||||
}
|
||||
}
|
||||
if ($ref1->{'otherpkglist'})
|
||||
{
|
||||
$pkglist = $ref1->{'otherpkglist'};
|
||||
if ($ref1->{'otherpkgdir'})
|
||||
{
|
||||
$result .=
|
||||
"OTHERPKGDIR=" . $ref1->{'otherpkgdir'} . "\n";
|
||||
$result .= "export OTHERPKGDIR\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
my $stat = "install";
|
||||
my $installroot = xCAT::TableUtils->getInstallDir();
|
||||
if ($profile)
|
||||
{
|
||||
my $platform = "rh";
|
||||
if ($os)
|
||||
{
|
||||
if ($os =~ /rh.*/) { $platform = "rh"; }
|
||||
elsif ($os =~ /centos.*/) { $platform = "centos"; }
|
||||
elsif ($os =~ /fedora.*/) { $platform = "fedora"; }
|
||||
elsif ($os =~ /SL.*/) { $platform = "SL"; }
|
||||
elsif ($os =~ /sles.*/) { $platform = "sles"; }
|
||||
elsif ($os =~ /ubuntu.*/) { $platform = "ubuntu"; }
|
||||
elsif ($os =~ /debian.*/) { $platform = "debian"; }
|
||||
elsif ($os =~ /aix.*/) { $platform = "aix"; }
|
||||
elsif ($os =~ /AIX.*/) { $platform = "AIX"; }
|
||||
}
|
||||
if (($nodesetstate) && ($nodesetstate eq "netboot" || $nodesetstate eq "statelite"))
|
||||
{
|
||||
$stat = "netboot";
|
||||
}
|
||||
|
||||
$ospkglist =
|
||||
xCAT::SvrUtils->get_pkglist_file_name(
|
||||
"$installroot/custom/$stat/$platform",
|
||||
$profile, $os, $arch);
|
||||
if (!$ospkglist)
|
||||
{
|
||||
$ospkglist =
|
||||
xCAT::SvrUtils->get_pkglist_file_name(
|
||||
"$::XCATROOT/share/xcat/$stat/$platform",
|
||||
$profile, $os, $arch);
|
||||
}
|
||||
|
||||
$pkglist =
|
||||
xCAT::SvrUtils->get_otherpkgs_pkglist_file_name(
|
||||
"$installroot/custom/$stat/$platform",
|
||||
$profile, $os, $arch);
|
||||
if (!$pkglist)
|
||||
{
|
||||
$pkglist =
|
||||
xCAT::SvrUtils->get_otherpkgs_pkglist_file_name(
|
||||
"$::XCATROOT/share/xcat/$stat/$platform",
|
||||
$profile, $os, $arch);
|
||||
}
|
||||
}
|
||||
}
|
||||
#print "pkglist=$pkglist\n";
|
||||
#print "ospkglist=$ospkglist\n";
|
||||
require xCAT::Postage;
|
||||
if ($ospkglist)
|
||||
{
|
||||
my $pkgtext = xCAT::Postage::get_pkglist_tex($ospkglist);
|
||||
my ($envlist,$pkgtext) = xCAT::Postage::get_envlist($pkgtext);
|
||||
if ($envlist) {
|
||||
$result .= "ENVLIST='".$envlist."'\n";
|
||||
$result .= "export ENVLIST\n";
|
||||
}
|
||||
if ($pkgtext)
|
||||
{
|
||||
$result .= "OSPKGS='".$pkgtext."'\n";
|
||||
$result .= "export OSPKGS\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($pkglist)
|
||||
{
|
||||
my $pkgtext = xCAT::Postage::get_pkglist_tex($pkglist);
|
||||
if ($pkgtext)
|
||||
{
|
||||
my @sublists = split('#NEW_INSTALL_LIST#', $pkgtext);
|
||||
my $sl_index = 0;
|
||||
foreach (@sublists)
|
||||
{
|
||||
$sl_index++;
|
||||
my $tmp = $_;
|
||||
my ($envlist, $tmp) = xCAT::Postage::get_envlist($tmp);
|
||||
if ($envlist) {
|
||||
$result .= "ENVLIST$sl_index='".$envlist."'\n";
|
||||
$result .= "export ENVLIST$sl_index\n";
|
||||
}
|
||||
$result .= "OTHERPKGS$sl_index='".$tmp."'\n";
|
||||
$result .= "export OTHERPKGS$sl_index\n";
|
||||
}
|
||||
if ($sl_index > 0)
|
||||
{
|
||||
$result .= "OTHERPKGS_INDEX=$sl_index\n";
|
||||
$result .= "export OTHERPKGS_INDEX\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# SLES sdk
|
||||
if ($os =~ /sles.*/)
|
||||
{
|
||||
my $installdir = $::XCATSITEVALS{'installdir'} ? $::XCATSITEVALS{'installdir'} : "/install";
|
||||
my $sdkdir = "$installdir/$os/$arch/sdk1";
|
||||
if (-e "$sdkdir")
|
||||
{
|
||||
$result .= "SDKDIR='" . $sdkdir . "'\n";
|
||||
$result .= "export SDKDIR\n";
|
||||
}
|
||||
}
|
||||
|
||||
# check if there are sync files to be handled
|
||||
my $syncfile;
|
||||
if ( ($provmethod)
|
||||
&& ($provmethod ne "install")
|
||||
&& ($provmethod ne "netboot")
|
||||
&& ($provmethod ne "statelite"))
|
||||
{
|
||||
my $osimagetab = xCAT::Table->new('osimage', -create => 1);
|
||||
if ($osimagetab)
|
||||
{
|
||||
(my $ref) =
|
||||
$osimagetab->getAttribs(
|
||||
{imagename => $provmethod}, 'osvers',
|
||||
'osarch', 'profile',
|
||||
'provmethod', 'synclists'
|
||||
);
|
||||
if ($ref)
|
||||
{
|
||||
$syncfile = $ref->{'synclists'};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$syncfile)
|
||||
{
|
||||
my $stat = "install";
|
||||
if (($nodesetstate) && ($nodesetstate eq "netboot" || $nodesetstate eq "statelite")) {
|
||||
$stat = "netboot";
|
||||
}
|
||||
$syncfile =
|
||||
xCAT::SvrUtils->getsynclistfile(undef, $os, $arch, $profile, $stat);
|
||||
}
|
||||
if (!$syncfile)
|
||||
{
|
||||
$result .= "NOSYNCFILES=1\n";
|
||||
$result .= "export NOSYNCFILES\n";
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
my $setbootfromnet = 0;
|
||||
sub getDisklessNet()
|
||||
{
|
||||
my $result;
|
||||
my $isdiskless = 0;
|
||||
my $bootfromnet = 0;
|
||||
if (($arch eq "ppc64") || ($os =~ /aix.*/i))
|
||||
{
|
||||
|
||||
# on Linux, the provmethod can be install,netboot or statelite,
|
||||
# on AIX, the provmethod can be null or image name
|
||||
#this is for Linux
|
||||
if ( ($provmethod)
|
||||
&& (($provmethod eq "netboot") || ($provmethod eq "statelite")))
|
||||
{
|
||||
$isdiskless = 1;
|
||||
}
|
||||
|
||||
if ($isdiskless)
|
||||
{
|
||||
(my $ip, my $mask, my $gw) = net_parms($node);
|
||||
if (!$ip || !$mask || !$gw)
|
||||
{
|
||||
xCAT::MsgUtils->message(
|
||||
'S',
|
||||
"Unable to determine IP, netmask or gateway for $node, can not set the node to boot from network"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$bootfromnet = 1;
|
||||
$result .= "NETMASK=$mask\n";
|
||||
$result .= "export NETMASK\n";
|
||||
$result .= "GATEWAY=$gw\n";
|
||||
$result .= "export GATEWAY\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$setbootfromnet = $bootfromnet;
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
my $et;
|
||||
my $et1;
|
||||
my $et2;
|
||||
|
||||
sub getPostScripts
|
||||
{
|
||||
|
||||
my $node = shift;
|
||||
my $result;
|
||||
my $ps;
|
||||
my %post_hash = (); #used to reduce duplicates
|
||||
|
||||
|
||||
my $posttab = xCAT::Table->new('postscripts');
|
||||
my $ostab = xCAT::Table->new('osimage');
|
||||
# get the xcatdefaults entry in the postscripts table
|
||||
my $et =
|
||||
$posttab->getAttribs({node => "xcatdefaults"},
|
||||
'postscripts', 'postbootscripts');
|
||||
my $defscripts = $et->{'postscripts'};
|
||||
if ($defscripts)
|
||||
{
|
||||
|
||||
foreach my $n (split(/,/, $defscripts))
|
||||
{
|
||||
if (!exists($post_hash{$n}))
|
||||
{
|
||||
$post_hash{$n} = 1;
|
||||
$result .= $n . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# get postscripts for images
|
||||
my $osimgname = $provmethod;
|
||||
|
||||
if($osimgname =~ /install|netboot|statelite/){
|
||||
$osimgname = "$os-$arch-$provmethod-$profile";
|
||||
}
|
||||
my $et2 =
|
||||
$ostab->getAttribs({'imagename' => "$osimgname"}, ['postscripts', 'postbootscripts']);
|
||||
$ps = $et2->{'postscripts'};
|
||||
if ($ps)
|
||||
{
|
||||
foreach my $n (split(/,/, $ps))
|
||||
{
|
||||
if (!exists($post_hash{$n}))
|
||||
{
|
||||
$post_hash{$n} = 1;
|
||||
$result .= $n . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# get postscripts for node specific
|
||||
my $et1 =
|
||||
$posttab->getNodeAttribs($node, ['postscripts', 'postbootscripts'],prefetchcache=>1);
|
||||
$ps = $et1->{'postscripts'};
|
||||
if ($ps)
|
||||
{
|
||||
foreach my $n (split(/,/, $ps))
|
||||
{
|
||||
if (!exists($post_hash{$n}))
|
||||
{
|
||||
$post_hash{$n} = 1;
|
||||
$result .= $n . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($setbootfromnet)
|
||||
{
|
||||
$result .= "setbootfromnet\n";
|
||||
}
|
||||
|
||||
# add setbootfromdisk if the nodesetstate is install and arch is ppc64
|
||||
if (($nodesetstate) && ($nodesetstate eq "install") && ($arch eq "ppc64"))
|
||||
{
|
||||
$result .= "setbootfromdisk\n";
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
sub getPostbootScripts
|
||||
{
|
||||
|
||||
my $node = shift;
|
||||
my $result;
|
||||
my $ps;
|
||||
|
||||
|
||||
my %postboot_hash = (); #used to reduce duplicates
|
||||
my $defscripts = $et->{'postbootscripts'};
|
||||
if ($defscripts)
|
||||
{
|
||||
foreach my $n (split(/,/, $defscripts))
|
||||
{
|
||||
if (!exists($postboot_hash{$n}))
|
||||
{
|
||||
$postboot_hash{$n} = 1;
|
||||
$result .= $n . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# get postbootscripts for image
|
||||
my $ips = $et2->{'postbootscripts'};
|
||||
if ($ips)
|
||||
{
|
||||
foreach my $n (split(/,/, $ips))
|
||||
{
|
||||
if (!exists($postboot_hash{$n}))
|
||||
{
|
||||
$postboot_hash{$n} = 1;
|
||||
$result .= $n . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# get postscripts
|
||||
$ps = $et1->{'postbootscripts'};
|
||||
if ($ps)
|
||||
{
|
||||
foreach my $n (split(/,/, $ps))
|
||||
{
|
||||
if (!exists($postboot_hash{$n}))
|
||||
{
|
||||
$postboot_hash{$n} = 1;
|
||||
$result .= $n . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user