From 5e935ac9439a8b5d579dbc6cc5f42813066d77eb Mon Sep 17 00:00:00 2001 From: daniceexi Date: Tue, 10 Jun 2014 08:03:22 -0400 Subject: [PATCH] restructure the code in Template.pm->subvars to handle recusive #INCLUDE. It also fixed the support of #INCLUDE in osimage.partitionfile --- xCAT-server/lib/perl/xCAT/Template.pm | 295 ++++++++++++-------------- 1 file changed, 141 insertions(+), 154 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 37010b51f..302cd96a4 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -154,167 +154,154 @@ sub subvars { #do *all* includes, recursive and all my $doneincludes=0; while (not $doneincludes) { - $doneincludes=1; - if ($inc =~ /#INCLUDE_PKGLIST:[^#^\n]+#/) { - $doneincludes=0; - $inc =~ s/#INCLUDE_PKGLIST:([^#^\n]+)#/includefile($1, 0, 1)/eg; - } - if ($inc =~ /#INCLUDE_PTRNLIST:[^#^\n]+#/) { - $doneincludes=0; - $inc =~ s/#INCLUDE_PTRNLIST:([^#^\n]+)#/includefile($1, 0, 2)/eg; - } - if ($inc =~ /#INCLUDE_RMPKGLIST:[^#^\n]+#/) { - $doneincludes=0; - $inc =~ s/#INCLUDE_RMPKGLIST:([^#^\n]+)#/includefile($1, 0, 3)/eg; - } - if ($inc =~ /#INCLUDE:[^#^\n]+#/) { - $doneincludes=0; - $inc =~ s/#INCLUDE:([^#^\n]+)#/includefile($1, 0, 0)/eg; - } - } - - #support multiple paths of osimage in rh/sles diskfull installation - my @pkgdirs; - if ( defined($media_dir) ) { - @pkgdirs = split(",", $media_dir); - my $source; - my $source_in_pre; - my $c = 0; - foreach my $pkgdir(@pkgdirs) { - if( $platform =~ /^(rh|SL|centos|fedora)$/ ) { - if ( $c == 0 ) { - # After some tests, if we put the repo in pre scripts in the kickstart like for rhels6.x - # the rhels5.9 will not be installed successfully. So put in kickstart directly. - $source_in_pre .= "echo 'url --url http://'\$nextserver'/$pkgdir' >> /tmp/repos"; - $source .= "url --url http://#TABLE:noderes:\$NODE:nfsserver#/$pkgdir\n"; #For rhels5.9 - } else { - $source_in_pre .= "\necho 'repo --name=pkg$c --baseurl=http://'\$nextserver'/$pkgdir' >> /tmp/repos"; - $source .= "repo --name=pkg$c --baseurl=http://#TABLE:noderes:\$NODE:nfsserver#/$pkgdir\n"; #for rhels5.9 + #support multiple paths of osimage in rh/sles diskfull installation + my @pkgdirs; + if ( defined($media_dir) ) { + @pkgdirs = split(",", $media_dir); + my $source; + my $source_in_pre; + my $c = 0; + foreach my $pkgdir(@pkgdirs) { + if( $platform =~ /^(rh|SL|centos|fedora)$/ ) { + if ( $c == 0 ) { + # After some tests, if we put the repo in pre scripts in the kickstart like for rhels6.x + # the rhels5.9 will not be installed successfully. So put in kickstart directly. + $source_in_pre .= "echo 'url --url http://'\$nextserver'/$pkgdir' >> /tmp/repos"; + $source .= "url --url http://#TABLE:noderes:\$NODE:nfsserver#/$pkgdir\n"; #For rhels5.9 + } else { + $source_in_pre .= "\necho 'repo --name=pkg$c --baseurl=http://'\$nextserver'/$pkgdir' >> /tmp/repos"; + $source .= "repo --name=pkg$c --baseurl=http://#TABLE:noderes:\$NODE:nfsserver#/$pkgdir\n"; #for rhels5.9 + } + } elsif ($platform =~ /^(sles|suse)/) { + my $http = "http://#TABLE:noderes:\$NODE:nfsserver#$pkgdir"; + $source .= " + $http + SuSE-Linux-pkg$c + / + false + SuSE-Linux-pkg$c + "; + $source_in_pre .="http://'\$nextserver'$pkgdirSuSE-Linux-pkg$c/falseSuSE-Linux-pkg$c"; + } + $c++; + } + + $inc =~ s/#INSTALL_SOURCES#/$source/g; + $inc =~ s/#INSTALL_SOURCES_IN_PRE#/$source_in_pre/g; + } + + #ok, now do everything else.. + my $shortname = $node; + $shortname =~ s/\..*//; + $inc =~ s/#TABLE:([^:]+):([^:]+):([^#]+)#/tabdb($1,$2,$3)/eg; + $inc =~ s/#TABLEBLANKOKAY:([^:]+):([^:]+):([^#]+)#/tabdb($1,$2,$3,'1')/eg; + $inc =~ s/#INCLUDE_NOP:([^#^\n]+)#/includefile($1,1,0)/eg; + $inc =~ s/#XCATVAR:([^#]+)#/envvar($1)/eg; + $inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; + $inc =~ s/#MACHINEPASSWORD#/machinepassword()/eg; + $inc =~ s/#CRYPT:([^:]+):([^:]+):([^#]+)#/crydb($1,$2,$3)/eg; + $inc =~ s/#COMMAND:([^#]+)#/command($1)/eg; + $inc =~ s/#KICKSTARTNET#/kickstartnetwork()/eg; + $inc =~ s/#YAST2NET#/yast2network()/eg; + $inc =~ s/#ESXIPV6SETUP#/esxipv6setup()/eg; + $inc =~ s/#WINTIMEZONE#/xCAT::TZUtils::get_wintimezone()/eg; + $inc =~ s/#WINPRODKEY:([^#]+)#/get_win_prodkey($1)/eg; + $inc =~ s/#WINNETCFG#/windows_net_cfg()/eg; + $inc =~ s/#WINADJOIN#/windows_join_data()/eg; + $inc =~ s/#WINPOSTSCRIPTS#/windows_postscripts()/eg; + $inc =~ s/#WINDNSCFG#/windows_dns_cfg()/eg; + $inc =~ s/#WINACCOUNTDATA#/windows_account_data()/eg; + $inc =~ s/#WINDISABLENULLADMIN#/windows_disable_null_admin()/eg; + $inc =~ s/#MANAGEDADDRESSMODE#/managed_address_mode()/eg; + $inc =~ s/#HOSTNAME#/$node/g; + $inc =~ s/#SHORTNAME#/$shortname/g; + $inc =~ s/#GETNODEDOMAIN:([^#]+)#/get_node_domain($1)/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 user specify the partion file, replace the default partition strategy + if ($partitionfile){ + #if the content of the partition file is definition replace the default is ok + my $partcontent = ''; + my $scriptflag = 0; + + if ($partitionfile =~ /^s:(.*)/){ + $scriptflag = 1; + $partitionfile = $1; + } + + if (-r $partitionfile){ + open ($inh, "<", $partitionfile); + while (<$inh>){ + $partcontent .= $_; + } + close ($inh); + + #the content of the specified file is a script which can write partition definition into /tmp/partitionfile + if ($scriptflag){ + #for redhat/sl/centos/kvm/fedora + if ($inc =~ /#XCAT_PARTITION_START#/) { + my $tempstr = "%include /tmp/partitionfile\n"; + $inc =~ s/#XCAT_PARTITION_START#[\s\S]*#XCAT_PARTITION_END#/$tempstr/; + #modify the content in the file, and write into %pre part + #$partcontent = "cat > /tmp/partscript << EOFEOF\n" . $partcontent . "\nEOFEOF\n"; + $partcontent = "echo " . "'". $partcontent . "'" . ">/tmp/partscript\n"; + + $partcontent .= "chmod 755 /tmp/partscript\n"; + $partcontent .= "/tmp/partscript\n"; + #replace the #XCA_PARTITION_SCRIPT# + $inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/; + } + #for sles/suse + elsif ($inc =~ //){ + my $tempstr = "XCATPARTITIONTEMP"; + $inc =~ s/[\s\S]*/$tempstr/; + #$partcontent = "cat > /tmp/partscript << EOFEOF\n" . $partcontent . "\nEOFEOF\n"; + $partcontent = "echo " . "'". $partcontent . "'" . ">/tmp/partscript\n"; + $partcontent .= "chmod 755 /tmp/partscript\n"; + $partcontent .= "/tmp/partscript\n"; + $inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/; + } + } + else{ + $partcontent =~ s/\s$//; + if ($inc =~ /#XCAT_PARTITION_START#/){ + $inc =~ s/#XCAT_PARTITION_START#[\s\S]*#XCAT_PARTITION_END#/$partcontent/; + } + elsif ($inc =~ //){ + $inc =~ s/[\s\S]*/$partcontent/; + } } - } elsif ($platform =~ /^(sles|suse)/) { - my $http = "http://#TABLE:noderes:\$NODE:nfsserver#$pkgdir"; - $source .= " - $http - SuSE-Linux-pkg$c - / - false - SuSE-Linux-pkg$c - "; - $source_in_pre .="http://'\$nextserver'$pkgdirSuSE-Linux-pkg$c/falseSuSE-Linux-pkg$c"; } - $c++; } - $inc =~ s/#INSTALL_SOURCES#/$source/g; - $inc =~ s/#INSTALL_SOURCES_IN_PRE#/$source_in_pre/g; - } - - - - - #Support hierarchical include - $inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; - if ($inc =~ /#INCLUDE:[^#^\n]+#/) { - $inc =~ s/#INCLUDE:([^#^\n]+)#/includefile($1, 0, 0)/eg; - } - - #ok, now do everything else.. - my $shortname = $node; - $shortname =~ s/\..*//; - $inc =~ s/#TABLE:([^:]+):([^:]+):([^#]+)#/tabdb($1,$2,$3)/eg; - $inc =~ s/#TABLEBLANKOKAY:([^:]+):([^:]+):([^#]+)#/tabdb($1,$2,$3,'1')/eg; - $inc =~ s/#INCLUDE_NOP:([^#^\n]+)#/includefile($1,1,0)/eg; - $inc =~ s/#INCLUDE_PKGLIST:([^#^\n]+)#/includefile($1,0,1)/eg; - $inc =~ s/#INCLUDE_PTRNLIST:([^#^\n]+)#/includefile($1,0,2)/eg; - $inc =~ s/#INCLUDE_RMPKGLIST:([^#^\n]+)#/includefile($1,0,3)/eg; - $inc =~ s/#INCLUDE:([^#^\n]+)#/includefile($1, 0, 0)/eg; - $inc =~ s/#XCATVAR:([^#]+)#/envvar($1)/eg; - $inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; - $inc =~ s/#MACHINEPASSWORD#/machinepassword()/eg; - $inc =~ s/#CRYPT:([^:]+):([^:]+):([^#]+)#/crydb($1,$2,$3)/eg; - $inc =~ s/#COMMAND:([^#]+)#/command($1)/eg; - $inc =~ s/#KICKSTARTNET#/kickstartnetwork()/eg; - $inc =~ s/#YAST2NET#/yast2network()/eg; - $inc =~ s/#ESXIPV6SETUP#/esxipv6setup()/eg; - $inc =~ s/#WINTIMEZONE#/xCAT::TZUtils::get_wintimezone()/eg; - $inc =~ s/#WINPRODKEY:([^#]+)#/get_win_prodkey($1)/eg; - $inc =~ s/#WINNETCFG#/windows_net_cfg()/eg; - $inc =~ s/#WINADJOIN#/windows_join_data()/eg; - $inc =~ s/#WINPOSTSCRIPTS#/windows_postscripts()/eg; - $inc =~ s/#WINDNSCFG#/windows_dns_cfg()/eg; - $inc =~ s/#WINACCOUNTDATA#/windows_account_data()/eg; - $inc =~ s/#WINDISABLENULLADMIN#/windows_disable_null_admin()/eg; - $inc =~ s/#MANAGEDADDRESSMODE#/managed_address_mode()/eg; - $inc =~ s/#HOSTNAME#/$node/g; - $inc =~ s/#SHORTNAME#/$shortname/g; - $inc =~ s/#GETNODEDOMAIN:([^#]+)#/get_node_domain($1)/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 user specify the partion file, replace the default partition strategy - if ($partitionfile){ - #if the content of the partition file is definition replace the default is ok - my $partcontent = ''; - my $scriptflag = 0; - - if ($partitionfile =~ /^s:(.*)/){ - $scriptflag = 1; - $partitionfile = $1; - } - - if (-r $partitionfile){ - open ($inh, "<", $partitionfile); - while (<$inh>){ - $partcontent .= $_; - } - close ($inh); - - #the content of the specified file is a script which can write partition definition into /tmp/partitionfile - if ($scriptflag){ - #for redhat/sl/centos/kvm/fedora - if ($inc =~ /#XCAT_PARTITION_START#/) { - my $tempstr = "%include /tmp/partitionfile\n"; - $inc =~ s/#XCAT_PARTITION_START#[\s\S]*#XCAT_PARTITION_END#/$tempstr/; - #modify the content in the file, and write into %pre part - #$partcontent = "cat > /tmp/partscript << EOFEOF\n" . $partcontent . "\nEOFEOF\n"; - $partcontent = "echo " . "'". $partcontent . "'" . ">/tmp/partscript\n"; - - $partcontent .= "chmod 755 /tmp/partscript\n"; - $partcontent .= "/tmp/partscript\n"; - #replace the #XCA_PARTITION_SCRIPT# - $inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/; - } - #for sles/suse - elsif ($inc =~ //){ - my $tempstr = "XCATPARTITIONTEMP"; - $inc =~ s/[\s\S]*/$tempstr/; - #$partcontent = "cat > /tmp/partscript << EOFEOF\n" . $partcontent . "\nEOFEOF\n"; - $partcontent = "echo " . "'". $partcontent . "'" . ">/tmp/partscript\n"; - $partcontent .= "chmod 755 /tmp/partscript\n"; - $partcontent .= "/tmp/partscript\n"; - $inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/; - } - } - else{ - $partcontent =~ s/\s$//; - if ($inc =~ /#XCAT_PARTITION_START#/){ - $inc =~ s/#XCAT_PARTITION_START#[\s\S]*#XCAT_PARTITION_END#/$partcontent/; - } - elsif ($inc =~ //){ - $inc =~ s/[\s\S]*/$partcontent/; - } - } - } + $doneincludes=1; + if ($inc =~ /#INCLUDE_PKGLIST:[^#^\n]+#/) { + $doneincludes=0; + $inc =~ s/#INCLUDE_PKGLIST:([^#^\n]+)#/includefile($1, 0, 1)/eg; + } + if ($inc =~ /#INCLUDE_PTRNLIST:[^#^\n]+#/) { + $doneincludes=0; + $inc =~ s/#INCLUDE_PTRNLIST:([^#^\n]+)#/includefile($1, 0, 2)/eg; + } + if ($inc =~ /#INCLUDE_RMPKGLIST:[^#^\n]+#/) { + $doneincludes=0; + $inc =~ s/#INCLUDE_RMPKGLIST:([^#^\n]+)#/includefile($1, 0, 3)/eg; + } + if ($inc =~ /#INCLUDE:[^#^\n]+#/) { + $doneincludes=0; + $inc =~ s/#INCLUDE:([^#^\n]+)#/includefile($1, 0, 0)/eg; + } } if ($tmplerr) { - close ($outh); - return $tmplerr; - } + close ($outh); + return $tmplerr; + } print $outh $inc; close($outh); return 0;