2007-10-26 22:44:33 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT_plugin::sles ;
2008-09-12 22:40:15 +00:00
BEGIN
{
$ ::XCATROOT = $ ENV { 'XCATROOT' } ? $ ENV { 'XCATROOT' } : '/opt/xcat' ;
}
use lib "$::XCATROOT/lib/perl" ;
2007-10-26 22:44:33 +00:00
use Storable qw( dclone ) ;
use Sys::Syslog ;
2008-05-24 17:29:40 +00:00
use File::Temp qw/tempdir/ ;
2007-10-26 22:44:33 +00:00
use xCAT::Table ;
2008-03-12 19:16:44 +00:00
use xCAT::Utils ;
2010-05-10 09:16:24 +00:00
use xCAT::NetworkUtils ;
2009-09-17 09:53:14 +00:00
use xCAT::SvrUtils ;
2008-03-12 19:16:44 +00:00
use xCAT::MsgUtils ;
2009-09-18 23:12:22 +00:00
use Data::Dumper ;
2007-10-26 22:44:33 +00:00
use Getopt::Long ;
Getopt::Long:: Configure ( "bundling" ) ;
Getopt::Long:: Configure ( "pass_through" ) ;
use File::Path ;
use File::Copy ;
2010-08-23 08:00:51 +00:00
use File::Temp qw/mkdtemp/ ;
2010-04-02 09:19:02 +00:00
use Socket ;
2009-09-24 18:51:53 +00:00
#use strict;
2008-06-02 23:51:40 +00:00
my @ cpiopid ;
2007-10-26 22:44:33 +00:00
2008-03-12 19:16:44 +00:00
sub handled_commands
{
return {
copycd = > "sles" ,
2009-09-18 23:12:22 +00:00
mknetboot = > "nodetype:os=(sles.*)|(suse.*)" ,
2010-01-27 06:00:24 +00:00
mkinstall = > "nodetype:os=(sles.*)|(suse.*)" ,
mkstatelite = > "nodetype:os=(sles.*)"
2008-03-12 19:16:44 +00:00
} ;
2007-10-26 22:44:33 +00:00
}
2008-03-12 19:16:44 +00:00
2008-05-27 15:53:45 +00:00
sub mknetboot
{
my $ req = shift ;
my $ callback = shift ;
my $ doreq = shift ;
2010-01-27 06:00:24 +00:00
my $ statelite = 0 ;
if ( $ req - > { command } - > [ 0 ] =~ 'mkstatelite' ) {
$ statelite = "true" ;
}
2008-05-27 15:53:45 +00:00
my $ tftpdir = "/tftpboot" ;
2009-09-22 23:29:14 +00:00
my $ nodes = @ { $ req - > { node } } ;
2008-05-27 15:53:45 +00:00
my @ nodes = @ { $ req - > { node } } ;
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
2009-09-22 23:29:14 +00:00
my $ linuximagetab ;
2010-01-29 09:05:42 +00:00
my $ pkgdir ;
2009-09-22 23:29:14 +00:00
my $ osimagetab ;
2008-05-27 15:53:45 +00:00
my $ installroot ;
$ installroot = "/install" ;
2010-01-27 06:00:24 +00:00
my $ xcatdport = "3001" ;
2008-05-27 15:53:45 +00:00
if ( $ sitetab )
{
2009-09-22 23:29:14 +00:00
( my $ ref ) = $ sitetab - > getAttribs ( { key = > 'installdir' } , 'value' ) ;
2008-05-27 15:53:45 +00:00
if ( $ ref and $ ref - > { value } )
{
$ installroot = $ ref - > { value } ;
}
2010-01-27 06:00:24 +00:00
( $ ref ) = $ sitetab - > getAttribs ( { key = > 'xcatdport' } , 'value' ) ;
if ( $ ref and $ ref - > { value } )
{
$ xcatdport = $ ref - > { value } ;
}
2008-05-27 15:53:45 +00:00
}
2009-09-22 23:29:14 +00:00
my $ ntents = $ ostab - > getNodesAttribs ( $ req - > { node } , [ 'os' , 'arch' , 'profile' , 'provmethod' ] ) ;
my % img_hash = ( ) ;
2010-01-27 06:00:24 +00:00
my $ statetab ;
my $ stateHash ;
if ( $ statelite ) {
$ statetab = xCAT::Table - > new ( 'statelite' , - create = > 1 ) ;
$ stateHash = $ statetab - > getNodesAttribs ( \ @ nodes , [ 'statemnt' ] ) ;
}
2010-09-17 09:54:47 +00:00
# TODO: following the redhat change, get the necessary attributes before the next foreach
# get the mac addresses for all the nodes
my $ mactab = xCAT::Table - > new ( 'mac' ) ;
my $ machash = $ mactab - > getNodesAttribs ( \ @ nodes , [ 'interface' , 'mac' ] ) ;
my $ restab = xCAT::Table - > new ( 'noderes' ) ;
2010-10-18 10:13:44 +00:00
my $ reshash = $ restab - > getNodesAttribs ( \ @ nodes , [ 'primarynic' , 'tftpserver' , 'xcatmaster' , 'nfsserver' , 'nfsdir' , 'installnic' ] ) ;
2010-09-17 09:54:47 +00:00
2008-05-27 15:53:45 +00:00
my % donetftp = ( ) ;
2009-09-22 23:29:14 +00:00
foreach my $ node ( @ nodes )
2008-05-27 15:53:45 +00:00
{
2009-09-22 23:29:14 +00:00
my $ osver ;
my $ arch ;
my $ profile ;
my $ rootimgdir ;
2010-09-17 09:54:47 +00:00
my $ nodebootif ; # nodebootif will be used if noderes.installnic is not set
2011-01-06 06:54:06 +00:00
my $ rootfstype ;
2009-09-22 23:29:14 +00:00
2010-01-27 06:00:24 +00:00
my $ ent = $ ntents - > { $ node } - > [ 0 ] ;
if ( $ ent and $ ent - > { provmethod } and ( $ ent - > { provmethod } ne 'install' ) and ( $ ent - > { provmethod } ne 'netboot' ) and ( $ ent - > { provmethod } ne 'statelite' ) ) {
my $ imagename = $ ent - > { provmethod } ;
#print "imagename=$imagename\n";
if ( ! exists ( $ img_hash { $ imagename } ) ) {
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' , - create = > 1 ) ;
}
2011-01-06 06:54:06 +00:00
( my $ ref ) = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'osvers' , 'osarch' , 'profile' , 'rootfstype' , 'provmethod' ) ;
2010-01-27 06:00:24 +00:00
if ( $ ref ) {
$ img_hash { $ imagename } - > { osver } = $ ref - > { 'osvers' } ;
$ img_hash { $ imagename } - > { osarch } = $ ref - > { 'osarch' } ;
$ img_hash { $ imagename } - > { profile } = $ ref - > { 'profile' } ;
2011-01-06 06:54:06 +00:00
$ img_hash { $ imagename } - > { rootfstype } = $ ref - > { 'rootfstype' } ;
2010-01-27 06:00:24 +00:00
$ img_hash { $ imagename } - > { provmethod } = $ ref - > { 'provmethod' } ;
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' , - create = > 1 ) ;
}
2010-09-17 09:54:47 +00:00
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imagename } , 'rootimgdir' , 'nodebootif' ) ;
2010-01-27 06:00:24 +00:00
if ( ( $ ref1 ) && ( $ ref1 - > { 'rootimgdir' } ) ) {
$ img_hash { $ imagename } - > { rootimgdir } = $ ref1 - > { 'rootimgdir' } ;
}
2010-09-17 09:54:47 +00:00
if ( ( $ ref1 ) && ( $ ref1 - > { 'nodebootif' } ) ) {
$ img_hash { $ imagename } - > { nodebootif } = $ ref1 - > { 'nodebootif' } ;
}
2010-01-27 06:00:24 +00:00
} else {
$ callback - > (
{ error = > [ "The os image $imagename does not exists on the osimage table for $node" ] ,
errorcode = > [ 1 ] } ) ;
next ;
}
}
my $ ph = $ img_hash { $ imagename } ;
$ osver = $ ph - > { osver } ;
$ arch = $ ph - > { osarch } ;
$ profile = $ ph - > { profile } ;
2011-01-06 06:54:06 +00:00
$ rootfstype = $ ph - > { rootfstype } ;
2010-10-18 10:13:44 +00:00
$ nodebootif = $ ph - > { nodebootif } ;
2009-09-22 23:29:14 +00:00
2010-09-17 09:54:47 +00:00
$ rootimgdir = $ ph - > { rootimgdir } ;
unless ( $ rootimgdir ) {
$ rootimgdir = "$installroot/netboot/$osver/$arch/$profile" ;
2010-01-27 06:00:24 +00:00
}
}
else {
$ osver = $ ent - > { os } ;
$ arch = $ ent - > { arch } ;
$ profile = $ ent - > { profile } ;
2011-01-06 06:54:06 +00:00
$ rootfstype = "nfs" ; # TODO: try to get it from the option or table
2010-01-27 06:00:24 +00:00
$ rootimgdir = "$installroot/netboot/$osver/$arch/$profile" ;
2009-09-22 23:29:14 +00:00
}
2008-05-27 15:53:45 +00:00
2010-01-27 06:00:24 +00:00
unless ( $ osver and $ arch and $ profile )
{
$ callback - > (
{
error = > [ "Insufficient nodetype entry or osimage entry for $node" ] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
2009-09-22 23:29:14 +00:00
2010-01-27 06:00:24 +00:00
#print"osvr=$osver, arch=$arch, profile=$profile, imgdir=$rootimgdir\n";
my $ platform ;
2008-05-27 15:53:45 +00:00
if ( $ osver =~ /sles.*/ )
{
$ platform = "sles" ;
2010-09-17 09:54:47 +00:00
# TODO: should get the $pkgdir value from the linuximage table
2010-01-29 09:05:42 +00:00
$ pkgdir = "$installroot/$osver/$arch" ;
2009-09-18 23:12:22 +00:00
} elsif ( $ osver =~ /suse.*/ ) {
$ platform = "sles" ;
2010-01-27 06:00:24 +00:00
}
2008-05-27 15:53:45 +00:00
2009-09-22 23:29:14 +00:00
my $ suffix = 'gz' ;
if ( - r "$rootimgdir/rootimg.sfs" )
2008-05-27 15:53:45 +00:00
{
$ suffix = 'sfs' ;
}
2010-09-17 09:54:47 +00:00
if ( $ statelite ) {
2010-09-22 15:21:16 +00:00
unless ( - r "$rootimgdir/kernel" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2010-09-22 15:21:16 +00:00
error = > [ qq{ Did you run "genimage" before running "liteimg"? kernel cannot be found } ] ,
2010-09-17 09:54:47 +00:00
errorcode = > [ 1 ]
} ) ;
next ;
2010-09-22 15:21:16 +00:00
}
2011-01-06 06:54:06 +00:00
if ( $ rootfstype eq "ramdisk" and ! - r "$rootimgdir/rootimg-statelite.gz" ) {
$ callback - > ( {
error = > [ qq{ No packed rootimage for the platform $osver, arch $arch and profile $profile, please run liteimg to create it } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
2010-09-22 15:21:16 +00:00
if ( ! - r "$rootimgdir/initrd-statelite.gz" ) {
if ( ! - r "$rootimgdir/initrd.gz" ) {
$ callback - > ( {
error = > [ qq{ Did you run "genimage" before running "liteimg"? initrd.gz or initrd-statelite.gz cannot be found } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
else {
copy ( "$rootimgdir/initrd.gz" , "$rootimgdir/initrd-statelite.gz" ) ;
}
}
2010-09-17 09:54:47 +00:00
} else {
2010-09-22 15:21:16 +00:00
unless ( - r "$rootimgdir/kernel" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2010-09-22 15:21:16 +00:00
error = > [ qq{ Did you run "genimage" before running "packimage"? kernel cannot be found } ] ,
2010-09-17 09:54:47 +00:00
errorcode = > [ 1 ]
2010-09-22 15:21:16 +00:00
} ) ;
2010-09-17 09:54:47 +00:00
next ;
2010-09-22 15:21:16 +00:00
}
if ( ! - r "$rootimgdir/initrd-stateless.gz" ) {
if ( ! - r "$rootimgdir/initrd.gz" ) {
$ callback - > ( {
error = > [ qq{ Did you run "genimage" before running "packimage"? initrd.gz or initrd-stateless.gz cannot be found } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
else {
copy ( "$rootimgdir/initrd.gz" , "$rootimgdir/initrd-stateless.gz" ) ;
}
2010-09-17 09:54:47 +00:00
}
2010-09-22 15:21:16 +00:00
2010-09-17 09:54:47 +00:00
unless ( - r "$rootimgdir/rootimg.gz" or - r "$rootimgdir/rootimg.sfs" ) {
$ callback - > ( {
error = > [ qq{ No packed image for platform $osver, architecture $arch, and profile $profile, please run packimage before nodeset } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
2010-01-27 06:00:24 +00:00
}
2008-05-27 15:53:45 +00:00
}
mkpath ( "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
#TODO: only copy if newer...
unless ( $ donetftp { $ osver , $ arch , $ profile } ) {
2010-09-17 09:54:47 +00:00
copy ( "$rootimgdir/kernel" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
if ( $ statelite ) {
copy ( "$rootimgdir/initrd-statelite.gz" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
} else {
copy ( "$rootimgdir/initrd-stateless.gz" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
}
2008-05-27 15:53:45 +00:00
$ donetftp { $ osver , $ arch , $ profile } = 1 ;
}
2010-09-17 09:54:47 +00:00
if ( $ statelite ) {
unless ( - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel"
and - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd-statelite.gz" ) {
$ callback - > ( {
error = > [ qq{ copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
} else {
unless ( - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel"
and - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd-stateless.gz" ) {
$ callback - > ( {
error = > [ qq{ copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
2008-05-27 15:53:45 +00:00
}
2010-09-17 09:54:47 +00:00
# TODO: move the table operations out of the foreach loop
2008-05-27 15:53:45 +00:00
my $ bptab = xCAT::Table - > new ( 'bootparams' , - create = > 1 ) ;
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
my $ sent =
$ hmtab - > getNodeAttribs ( $ node ,
[ 'serialport' , 'serialspeed' , 'serialflow' ] ) ;
# determine image server, if tftpserver use it, else use xcatmaster
2009-03-12 16:34:54 +00:00
# last resort use self
2008-05-27 15:53:45 +00:00
my $ imgsrv ;
my $ ient ;
2010-03-01 03:18:05 +00:00
my $ xcatmaster ;
$ ient = $ restab - > getNodeAttribs ( $ node , [ 'xcatmaster' ] ) ;
if ( $ ient and $ ient - > { xcatmaster } )
{
$ xcatmaster = $ ient - > { xcatmaster } ;
} else {
2010-03-03 14:24:27 +00:00
$ xcatmaster = '!myipfn!' ; #allow service nodes to dynamically nominate themselves as a good contact point, this is of limited use in the event that xcat is not the dhcp/tftp server
2010-03-01 03:18:05 +00:00
}
2008-05-27 15:53:45 +00:00
$ ient = $ restab - > getNodeAttribs ( $ node , [ 'tftpserver' ] ) ;
if ( $ ient and $ ient - > { tftpserver } )
{
$ imgsrv = $ ient - > { tftpserver } ;
}
else
{
2010-03-01 03:18:05 +00:00
# $ient = $restab->getNodeAttribs($node, ['xcatmaster']);
# if ($ient and $ient->{xcatmaster})
# {
# $imgsrv = $ient->{xcatmaster};
# }
# else
# {
# # master removed, does not work for servicenode pools
# #$ient = $sitetab->getAttribs({key => master}, value);
# #if ($ient and $ient->{value})
# #{
# # $imgsrv = $ient->{value};
# #}
# #else
# #{
# $imgsrv = '!myipfn!';
# #}
# }
$ imgsrv = $ xcatmaster ;
2008-05-27 15:53:45 +00:00
}
unless ( $ imgsrv )
{
$ callback - > (
{
error = > [
"Unable to determine or reasonably guess the image server for $node"
] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
my $ kcmdline ;
2010-09-17 09:54:47 +00:00
if ( $ statelite )
2010-01-27 06:00:24 +00:00
{
2011-01-06 06:54:06 +00:00
if ( $ rootfstype ne "ramdisk" ) {
# get entry for nfs root if it exists;
# have to get nfssvr, nfsdir and xcatmaster from noderes table
my $ nfssrv = $ imgsrv ;
my $ nfsdir = $ rootimgdir ;
if ( $ restab ) {
my $ resHash = $ restab - > getNodeAttribs ( $ node , [ 'nfsserver' , 'nfsdir' ] ) ;
if ( $ resHash and $ resHash - > { nfsserver } ) {
$ nfssrv = $ resHash - > { nfsserver } ;
}
if ( $ resHash and $ resHash - > { nfsdir } ne '' ) {
$ nfsdir = $ resHash - > { nfsdir } . "/netboot/$osver/$arch/$profile" ;
}
2010-01-27 06:00:24 +00:00
}
2011-01-06 06:54:06 +00:00
$ kcmdline =
"NFSROOT=$nfssrv:$nfsdir STATEMNT=" ;
} else {
$ kcmdline =
"imgurl=http://$imgsrv/$rootimgdir/rootimg-statelite.gz STATEMNT=" ;
2010-01-27 06:00:24 +00:00
}
2010-02-26 07:14:59 +00:00
# add support for subVars in the value of "statemnt"
2010-04-16 10:31:23 +00:00
my $ statemnt = "" ;
2010-02-11 02:24:48 +00:00
if ( exists ( $ stateHash - > { $ node } ) ) {
2010-04-16 10:31:23 +00:00
$ statemnt = $ stateHash - > { $ node } - > [ 0 ] - > { statemnt } ;
2010-02-26 07:14:59 +00:00
if ( grep /\$/ , $ statemnt ) {
my ( $ server , $ dir ) = split ( /:/ , $ statemnt ) ;
#if server is blank, then its the directory
unless ( $ dir ) {
$ dir = $ server ;
$ server = '' ;
}
if ( grep /\$|#CMD/ , $ dir ) {
2010-05-04 14:24:08 +00:00
$ dir = xCAT::SvrUtils - > subVars ( $ dir , $ node , 'dir' , $ callback ) ;
2010-02-26 07:14:59 +00:00
$ dir = ~ s/\/\//\//g ;
}
if ( $ server ) {
2010-05-04 14:24:08 +00:00
$ server = xCAT::SvrUtils - > subVars ( $ server , $ node , 'server' , $ callback ) ;
2010-02-26 07:14:59 +00:00
}
2010-04-16 10:31:23 +00:00
$ statemnt = $ server . ":" . $ dir ;
2010-02-26 07:14:59 +00:00
}
2010-01-27 06:00:24 +00:00
}
2010-04-16 10:31:23 +00:00
$ kcmdline . = $ statemnt . " " ;
2010-03-01 03:18:05 +00:00
# get "xcatmaster" value from the "noderes" table
2011-01-06 06:54:06 +00:00
if ( $ rootfstype ne "ramdisk" ) {
#BEGIN service node
my $ isSV = xCAT::Utils - > isServiceNode ( ) ;
my $ res = xCAT::Utils - > runcmd ( "hostname" , 0 ) ;
my $ sip = xCAT::NetworkUtils - > getipaddr ( $ res ) ; # this is the IP of service node
if ( $ isSV and ( ( $ xcatmaster eq $ sip ) or ( $ xcatmaster eq $ res ) ) ) {
# if the NFS directory in litetree is on the service node,
# and it is not exported, then it will be mounted automatically
xCAT::SvrUtils - > setupNFSTree ( $ node , $ sip , $ callback ) ;
# then, export the statemnt directory if it is on the service node
if ( $ statemnt ) {
xCAT::SvrUtils - > setupStatemnt ( $ sip , $ statemnt , $ callback ) ;
}
2010-04-02 09:19:02 +00:00
}
2011-01-06 06:54:06 +00:00
#END sevice node
2010-04-02 09:19:02 +00:00
}
2010-01-27 06:00:24 +00:00
}
2008-05-27 15:53:45 +00:00
else
{
$ kcmdline =
"imgurl=http://$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.$suffix " ;
}
2010-09-17 09:54:47 +00:00
$ kcmdline . = "XCAT=$xcatmaster:$xcatdport " ;
# add the kernel-booting parameter: netdev=<eth0>, or BOOTIF=<mac>
my $ netdev = "" ;
my $ mac = $ machash - > { $ node } - > [ 0 ] - > { mac } ;
if ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { installnic } ) {
if ( $ reshash - > { $ node } - > [ 0 ] - > { installnic } ne "mac" ) {
$ kcmdline . = "netdev=" . $ reshash - > { $ node } - > [ 0 ] - > { installnic } . " " ;
}
} elsif ( $ nodebootif ) {
$ kcmdline . = "netdev=" . $ nodebootif . " " ;
} elsif ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { primarynic } ) {
$ kcmdline . = "netdev=" . $ reshash - > { $ node } - > [ 0 ] - > { primarynic } . " " ;
} else {
2010-09-21 20:47:47 +00:00
if ( $ arch =~ /x86/ ) {
#do nothing, we'll let pxe/xnba work their magic
} elsif ( $ mac ) {
2010-09-17 09:54:47 +00:00
$ kcmdline . = "BOOTIF=" . $ mac . " " ;
} else {
$ callback - > ( {
error = > [ qq{ "cannot get the mac address for $node in mac table" } ] ,
errorcode = > [ 1 ]
} ) ;
}
}
2008-05-27 15:53:45 +00:00
if ( defined $ sent - > { serialport } )
{
#my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']);
unless ( $ sent - > { serialspeed } )
{
$ callback - > (
{
error = > [
"serialport defined, but no serialspeed for $node in nodehm table"
] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
$ kcmdline . =
2009-09-15 17:59:11 +00:00
"console=tty0 console=ttyS" . $ sent - > { serialport } . "," . $ sent - > { serialspeed } ;
2008-05-27 15:53:45 +00:00
if ( $ sent - > { serialflow } =~ /(hard|tcs|ctsrts)/ )
{
$ kcmdline . = "n8r" ;
}
}
2010-09-17 09:54:47 +00:00
my $ initrdstr = "xcat/netboot/$osver/$arch/$profile/initrd-stateless.gz" ;
$ initrdstr = "xcat/netboot/$osver/$arch/$profile/initrd-statelite.gz" if ( $ statelite ) ;
2008-05-27 15:53:45 +00:00
$ bptab - > setNodeAttribs (
$ node ,
{
kernel = > "xcat/netboot/$osver/$arch/$profile/kernel" ,
2010-09-17 09:54:47 +00:00
initrd = > $ initrdstr ,
2008-05-27 15:53:45 +00:00
kcmdline = > $ kcmdline
}
) ;
}
}
2008-03-12 19:16:44 +00:00
sub process_request
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
my $ distname = undef ;
my $ arch = undef ;
my $ path = undef ;
if ( $ request - > { command } - > [ 0 ] eq 'copycd' )
{
return copycd ( $ request , $ callback , $ doreq ) ;
}
elsif ( $ request - > { command } - > [ 0 ] eq 'mkinstall' )
{
return mkinstall ( $ request , $ callback , $ doreq ) ;
}
2010-01-27 06:00:24 +00:00
elsif ( $ request - > { command } - > [ 0 ] eq 'mknetboot' or
$ request - > { command } - > [ 0 ] eq 'mkstatelite' )
2008-05-27 15:53:45 +00:00
{
return mknetboot ( $ request , $ callback , $ doreq ) ;
}
2007-10-26 22:44:33 +00:00
}
2008-03-12 19:16:44 +00:00
sub mkinstall
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
my @ nodes = @ { $ request - > { node } } ;
my $ node ;
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
2009-09-22 23:29:14 +00:00
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
my $ linuximagetab ;
my $ osimagetab ;
my $ ntents = $ ostab - > getNodesAttribs ( $ request - > { node } , [ 'os' , 'arch' , 'profile' , 'provmethod' ] ) ;
my % img_hash = ( ) ;
my $ installroot ;
$ installroot = "/install" ;
if ( $ sitetab )
{
( my $ ref ) = $ sitetab - > getAttribs ( { key = > 'installdir' } , 'value' ) ;
if ( $ ref and $ ref - > { value } )
{
$ installroot = $ ref - > { value } ;
}
}
2008-03-12 19:16:44 +00:00
my % doneimgs ;
2009-03-14 16:14:29 +00:00
require xCAT::Template ; #only used here, load so memory can be COWed
2008-03-12 19:16:44 +00:00
foreach $ node ( @ nodes )
{
2009-09-22 23:29:14 +00:00
my $ os ;
my $ arch ;
my $ profile ;
my $ tmplfile ;
my $ pkgdir ;
2010-07-27 18:16:27 +00:00
my $ pkglistfile ;
2008-03-12 19:16:44 +00:00
my $ osinst ;
2009-09-22 23:29:14 +00:00
my $ ent = $ ntents - > { $ node } - > [ 0 ] ;
2010-08-26 06:04:23 +00:00
my $ plat = "" ;
2009-09-22 23:29:14 +00:00
2010-02-19 18:39:56 +00:00
if ( $ ent and $ ent - > { provmethod } and ( $ ent - > { provmethod } ne 'install' ) and ( $ ent - > { provmethod } ne 'netboot' ) and ( $ ent - > { provmethod } ne 'statelite' ) ) {
2009-09-22 23:29:14 +00:00
my $ imagename = $ ent - > { provmethod } ;
#print "imagename=$imagename\n";
if ( ! exists ( $ img_hash { $ imagename } ) ) {
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' , - create = > 1 ) ;
}
( my $ ref ) = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'osvers' , 'osarch' , 'profile' , 'provmethod' ) ;
if ( $ ref ) {
$ img_hash { $ imagename } - > { osver } = $ ref - > { 'osvers' } ;
$ img_hash { $ imagename } - > { osarch } = $ ref - > { 'osarch' } ;
$ img_hash { $ imagename } - > { profile } = $ ref - > { 'profile' } ;
$ img_hash { $ imagename } - > { provmethod } = $ ref - > { 'provmethod' } ;
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' , - create = > 1 ) ;
}
2010-07-27 18:16:27 +00:00
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imagename } , 'template' , 'pkgdir' , 'pkglist' ) ;
2009-09-22 23:29:14 +00:00
if ( $ ref1 ) {
if ( $ ref1 - > { 'template' } ) {
$ img_hash { $ imagename } - > { template } = $ ref1 - > { 'template' } ;
}
if ( $ ref1 - > { 'pkgdir' } ) {
$ img_hash { $ imagename } - > { pkgdir } = $ ref1 - > { 'pkgdir' } ;
}
2010-07-27 18:16:27 +00:00
if ( $ ref1 - > { 'pkglist' } ) {
$ img_hash { $ imagename } - > { pkglist } = $ ref1 - > { 'pkglist' } ;
}
2009-09-22 23:29:14 +00:00
}
} else {
$ callback - > (
{ error = > [ "The os image $imagename does not exists on the osimage table for $node" ] ,
errorcode = > [ 1 ] } ) ;
next ;
}
}
my $ ph = $ img_hash { $ imagename } ;
$ os = $ ph - > { osver } ;
$ arch = $ ph - > { osarch } ;
$ profile = $ ph - > { profile } ;
$ tmplfile = $ ph - > { template } ;
$ pkgdir = $ ph - > { pkgdir } ;
if ( ! $ pkgdir ) {
$ pkgdir = "$installroot/$os/$arch" ;
}
2010-07-27 18:16:27 +00:00
$ pkglistfile = $ ph - > { pkglist } ;
2009-09-22 23:29:14 +00:00
}
else {
$ os = $ ent - > { os } ;
$ arch = $ ent - > { arch } ;
$ profile = $ ent - > { profile } ;
if ( $ os =~ /sles.*/ ) {
2009-09-18 23:12:22 +00:00
$ plat = "sles" ;
2009-09-22 23:29:14 +00:00
} elsif ( $ os =~ /suse.*/ ) {
2009-09-18 23:12:22 +00:00
$ plat = "suse" ;
2009-09-22 23:29:14 +00:00
} else {
2009-09-18 23:12:22 +00:00
$ plat = "foobar" ;
print "You should never get here! Programmer error!" ;
return ;
2009-09-22 23:29:14 +00:00
}
$ tmplfile = xCAT::SvrUtils:: get_tmpl_file_name ( "$installroot/custom/install/$plat" , $ profile , $ os , $ arch ) ;
if ( ! $ tmplfile ) { $ tmplfile = xCAT::SvrUtils:: get_tmpl_file_name ( "$::XCATROOT/share/xcat/install/$plat" , $ profile , $ os , $ arch ) ; }
2010-07-27 18:16:27 +00:00
$ pkglistfile = xCAT::SvrUtils:: get_pkglist_file_name ( "$installroot/custom/install/$plat" , $ profile , $ os , $ arch ) ;
if ( ! $ pkglistfile ) { $ pkglistfile = xCAT::SvrUtils:: get_pkglist_file_name ( "$::XCATROOT/share/xcat/install/$plat" , $ profile , $ os , $ arch ) ; }
2009-09-22 23:29:14 +00:00
$ pkgdir = "$installroot/$os/$arch" ;
}
unless ( $ os and $ arch and $ profile )
{
$ callback - > (
{
error = > [ "No profile defined in nodetype or osimage table for $node" ] ,
errorcode = > [ 1 ]
}
) ;
next ;
2009-09-18 23:12:22 +00:00
}
2009-09-22 23:29:14 +00:00
unless ( - r "$tmplfile" )
2008-03-12 19:16:44 +00:00
{
$ callback - > (
{
error = >
2010-08-26 06:04:23 +00:00
[ "No AutoYaST template exists for " . $ ent - > { profile } . " in directory $installroot/custom/install/$plat or $::XCATROOT/share/xcat/install/$plat" ] ,
2008-03-12 19:16:44 +00:00
errorcode = > [ 1 ]
}
) ;
next ;
}
#Call the Template class to do substitution to produce a kickstart file in the autoinst dir
my $ tmperr ;
2010-08-06 14:22:28 +00:00
if ( - r "$tmplfile" )
2008-03-12 19:16:44 +00:00
{
$ tmperr =
xCAT::Template - > subvars (
2010-08-06 14:22:28 +00:00
$ tmplfile ,
2009-09-22 23:29:14 +00:00
"$installroot/autoinst/$node" ,
2010-08-06 14:22:28 +00:00
$ node ,
$ pkglistfile
2008-03-12 19:16:44 +00:00
) ;
}
2008-09-12 22:40:15 +00:00
2008-03-12 19:16:44 +00:00
if ( $ tmperr )
{
$ callback - > (
{
node = > [
{
name = > [ $ node ] ,
error = > [ $ tmperr ] ,
errorcode = > [ 1 ]
}
]
}
) ;
next ;
}
2008-04-14 13:33:52 +00:00
2008-05-01 14:45:30 +00:00
# create the node-specific post script DEPRECATED, don't do
#mkpath "/install/postscripts/";
#xCAT::Postage->writescript($node, "/install/postscripts/".$node, "install", $callback);
2008-04-14 13:33:52 +00:00
2008-03-12 19:16:44 +00:00
if (
(
2008-04-04 15:52:39 +00:00
$ arch =~ /x86_64/
2009-09-22 23:29:14 +00:00
and - r "$pkgdir/1/boot/$arch/loader/linux"
and - r "$pkgdir/1/boot/$arch/loader/initrd"
2008-03-12 19:16:44 +00:00
)
2008-04-04 15:52:39 +00:00
or
(
$ arch =~ /x86$/
2009-09-22 23:29:14 +00:00
and - r "$pkgdir/1/boot/i386/loader/linux"
and - r "$pkgdir/1/boot/i386/loader/initrd"
2008-04-04 15:52:39 +00:00
)
2009-09-22 23:29:14 +00:00
or ( $ arch =~ /ppc/ and - r "$pkgdir/1/suseboot/inst64" )
2008-03-12 19:16:44 +00:00
)
{
2010-08-12 09:05:22 +00:00
# Define a variable for driver update list
my @ dd_drivers ;
2008-03-12 19:16:44 +00:00
#TODO: driver slipstream, targetted for network.
unless ( $ doneimgs { "$os|$arch" } )
{
mkpath ( "/tftpboot/xcat/$os/$arch" ) ;
2008-04-04 15:52:39 +00:00
if ( $ arch =~ /x86_64/ )
2008-03-12 19:16:44 +00:00
{
2009-09-22 23:29:14 +00:00
copy ( "$pkgdir/1/boot/$arch/loader/linux" ,
2008-03-12 19:16:44 +00:00
"/tftpboot/xcat/$os/$arch/" ) ;
2009-09-22 23:29:14 +00:00
copy ( "$pkgdir/1/boot/$arch/loader/initrd" ,
2008-03-12 19:16:44 +00:00
"/tftpboot/xcat/$os/$arch/" ) ;
2010-08-12 09:05:22 +00:00
@ dd_drivers = & insert_dd ( $ callback , $ os , $ arch , "/tftpboot/xcat/$os/$arch/initrd" ) ;
2008-04-04 15:52:39 +00:00
} elsif ( $ arch =~ /x86/ ) {
2009-09-22 23:29:14 +00:00
copy ( "$pkgdir/1/boot/i386/loader/linux" ,
2008-04-04 15:52:39 +00:00
"/tftpboot/xcat/$os/$arch/" ) ;
2009-09-22 23:29:14 +00:00
copy ( "$pkgdir/1/boot/i386/loader/initrd" ,
2008-04-04 15:52:39 +00:00
"/tftpboot/xcat/$os/$arch/" ) ;
2010-08-12 09:05:22 +00:00
@ dd_drivers = & insert_dd ( $ callback , $ os , $ arch , "/tftpboot/xcat/$os/$arch/initrd" ) ;
2008-03-12 19:16:44 +00:00
}
elsif ( $ arch =~ /ppc/ )
{
2009-09-22 23:29:14 +00:00
copy ( "$pkgdir/1/suseboot/inst64" ,
2008-03-12 19:16:44 +00:00
"/tftpboot/xcat/$os/$arch" ) ;
2010-08-12 09:05:22 +00:00
@ dd_drivers = & insert_dd ( $ callback , $ os , $ arch , "/tftpboot/xcat/$os/$arch/inst64" ) ;
2008-03-12 19:16:44 +00:00
}
$ doneimgs { "$os|$arch" } = 1 ;
}
#We have a shot...
my $ restab = xCAT::Table - > new ( 'noderes' ) ;
2008-05-20 19:04:45 +00:00
my $ bptab = xCAT::Table - > new ( 'bootparams' , - create = > 1 ) ;
2008-03-12 19:16:44 +00:00
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
my $ ent =
$ restab - > getNodeAttribs (
$ node ,
[
2008-04-25 15:36:56 +00:00
'nfsserver' ,
2008-03-12 19:16:44 +00:00
'primarynic' , 'installnic'
]
) ;
my $ sent =
2008-04-25 15:36:56 +00:00
$ hmtab - > getNodeAttribs ( $ node , [ 'serialport' , 'serialspeed' , 'serialflow' ] ) ;
2008-03-12 19:16:44 +00:00
unless ( $ ent and $ ent - > { nfsserver } )
{
$ callback - > (
{
error = > [ "No noderes.nfsserver for $node defined" ] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
my $ kcmdline =
"autoyast=http://"
. $ ent - > { nfsserver }
2009-09-22 23:29:14 +00:00
. "$installroot/autoinst/"
2008-03-12 19:16:44 +00:00
. $ node
. " install=http://"
. $ ent - > { nfsserver }
2009-09-22 23:29:14 +00:00
. "$pkgdir/1" ;
2009-06-15 10:34:19 +00:00
2010-08-20 05:22:41 +00:00
my $ netdev = "" ;
if ( $ ent - > { installnic } )
2009-04-14 19:11:41 +00:00
{
2010-08-20 05:22:41 +00:00
if ( $ ent - > { installnic } eq "mac" )
2009-06-15 10:34:19 +00:00
{
2010-08-20 05:22:41 +00:00
my $ mactab = xCAT::Table - > new ( "mac" ) ;
my $ macref = $ mactab - > getNodeAttribs ( $ node , [ 'mac' ] ) ;
$ netdev = $ macref - > { mac } ;
}
else
2009-06-15 10:34:19 +00:00
{
2010-08-20 05:22:41 +00:00
$ netdev = $ ent - > { installnic } ;
2009-06-15 10:34:19 +00:00
}
2010-08-20 05:22:41 +00:00
}
elsif ( $ ent - > { primarynic } )
2009-04-14 19:11:41 +00:00
{
2010-08-20 05:22:41 +00:00
if ( $ ent - > { primarynic } eq "mac" )
2009-06-15 10:34:19 +00:00
{
2010-08-20 05:22:41 +00:00
my $ mactab = xCAT::Table - > new ( "mac" ) ;
my $ macref = $ mactab - > getNodeAttribs ( $ node , [ 'mac' ] ) ;
$ netdev = $ macref - > { mac } ;
2009-06-15 10:34:19 +00:00
}
else
{
2010-08-20 05:22:41 +00:00
$ netdev = $ ent - > { primarynic } ;
2010-05-03 20:37:39 +00:00
}
2009-04-14 19:11:41 +00:00
}
2010-08-20 05:22:41 +00:00
else
{
$ netdev = "bootif" ;
}
if ( $ netdev eq "" ) #why it is blank, no mac defined?
{
$ callback - > (
{
error = > [ "No mac.mac for $node defined" ] ,
errorcode = > [ 1 ]
}
) ;
}
unless ( $ netdev eq "bootif" ) { #if going by bootif, BOOTIF will suffice
$ kcmdline . = " netdevice=" . $ netdev ;
}
2008-03-12 19:16:44 +00:00
2010-08-12 09:05:22 +00:00
# Add the kernel paramets for driver update disk loading
foreach ( @ dd_drivers ) {
$ kcmdline . = " dud=file:/cus_driverdisk/$_" ;
}
2008-04-25 15:36:56 +00:00
if ( defined $ sent - > { serialport } )
2008-03-12 19:16:44 +00:00
{
unless ( $ sent - > { serialspeed } )
{
$ callback - > (
{
error = > [
"serialport defined, but no serialspeed for $node in nodehm table"
] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
$ kcmdline . =
2009-09-15 17:59:11 +00:00
" console=tty0 console=ttyS"
2008-04-25 15:36:56 +00:00
. $ sent - > { serialport } . ","
2008-03-12 19:16:44 +00:00
. $ sent - > { serialspeed } ;
if ( $ sent and ( $ sent - > { serialflow } =~ /(ctsrts|cts|hard)/ ) )
{
$ kcmdline . = "n8r" ;
}
}
2009-08-11 11:49:15 +00:00
# for pSLES installation, the dhcp request may timeout
# due to spanning tree settings or multiple network adapters.
# use dhcptimeout=150 to avoid dhcp timeout
if ( $ arch =~ /ppc/ )
{
$ kcmdline . = " dhcptimeout=150" ;
}
2008-03-12 19:16:44 +00:00
if ( $ arch =~ /x86/ )
{
2008-04-25 15:36:56 +00:00
$ bptab - > setNodeAttribs (
2008-03-12 19:16:44 +00:00
$ node ,
{
kernel = > "xcat/$os/$arch/linux" ,
initrd = > "xcat/$os/$arch/initrd" ,
kcmdline = > $ kcmdline
}
) ;
}
elsif ( $ arch =~ /ppc/ )
{
2008-04-25 15:36:56 +00:00
$ bptab - > setNodeAttribs (
2008-03-12 19:16:44 +00:00
$ node ,
{
kernel = > "xcat/$os/$arch/inst64" ,
initrd = > "" ,
kcmdline = > $ kcmdline
}
) ;
}
2007-10-26 22:44:33 +00:00
}
2008-03-12 19:16:44 +00:00
else
{
$ callback - > (
{
error = > [
"Failed to detect copycd configured install source at /install/$os/$arch"
] ,
errorcode = > [ 1 ]
}
) ;
2007-10-26 22:44:33 +00:00
}
2008-03-12 19:16:44 +00:00
}
2008-05-01 14:45:30 +00:00
#my $rc = xCAT::Utils->create_postscripts_tar();
#if ($rc != 0)
#{
# xCAT::MsgUtils->message("S", "Error creating postscripts tar file.");
#}
2007-10-26 22:44:33 +00:00
}
2008-03-12 19:16:44 +00:00
sub copycd
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
2008-05-24 17:29:40 +00:00
my $ distname = "" ;
my $ detdistname = "" ;
2008-03-12 19:16:44 +00:00
my $ installroot ;
2009-09-22 23:29:14 +00:00
my $ arch ;
my $ path ;
2008-03-12 19:16:44 +00:00
$ installroot = "/install" ;
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
if ( $ sitetab )
{
2009-09-22 23:29:14 +00:00
( my $ ref ) = $ sitetab - > getAttribs ( { key = > 'installdir' } , 'value' ) ;
2009-09-18 23:12:22 +00:00
print Dumper ( $ ref ) ;
2008-03-12 19:16:44 +00:00
if ( $ ref and $ ref - > { value } )
{
$ installroot = $ ref - > { value } ;
}
}
@ ARGV = @ { $ request - > { arg } } ;
GetOptions (
'n=s' = > \ $ distname ,
'a=s' = > \ $ arch ,
'p=s' = > \ $ path
) ;
unless ( $ path )
{
#this plugin needs $path...
return ;
}
2009-09-18 23:12:22 +00:00
if ( $ distname and $ distname !~ /^sles|^suse/ )
2008-03-12 19:16:44 +00:00
{
2009-09-18 23:12:22 +00:00
#If they say to call it something other than SLES or SUSE, give up?
2008-03-12 19:16:44 +00:00
return ;
}
unless ( - r $ path . "/content" )
{
return ;
}
my $ dinfo ;
open ( $ dinfo , $ path . "/content" ) ;
2009-09-22 23:29:14 +00:00
my $ darch ;
2008-03-12 19:16:44 +00:00
while ( <$dinfo> )
{
if ( m/^DEFAULTBASE\s+(\S+)/ )
{
$ darch = $ 1 ;
chomp ( $ darch ) ;
last ;
}
2008-12-01 14:45:59 +00:00
if ( not $ darch and m/^BASEARCHS\s+(\S+)/ ) {
$ darch = $ 1 ;
}
2008-03-12 19:16:44 +00:00
}
close ( $ dinfo ) ;
unless ( $ darch )
{
return ;
}
my $ dirh ;
opendir ( $ dirh , $ path ) ;
my $ discnumber ;
my $ totaldiscnumber ;
while ( my $ pname = readdir ( $ dirh ) )
{
if ( $ pname =~ /media.(\d+)/ )
{
$ discnumber = $ 1 ;
chomp ( $ discnumber ) ;
my $ mfile ;
open ( $ mfile , $ path . "/" . $ pname . "/media" ) ;
<$mfile> ;
<$mfile> ;
$ totaldiscnumber = <$mfile> ;
chomp ( $ totaldiscnumber ) ;
close ( $ mfile ) ;
open ( $ mfile , $ path . "/" . $ pname . "/products" ) ;
my $ prod = <$mfile> ;
close ( $ mfile ) ;
if ( $ prod =~ m/SUSE-Linux-Enterprise-Server/ )
{
2010-05-25 15:29:28 +00:00
if ( - f "$path/content" ) {
my $ content ;
open ( $ content , "<" , "$path/content" ) ;
my @ contents = <$content> ;
close ( $ content ) ;
foreach ( @ contents ) {
if ( /^VERSION/ ) {
my @ verpair = split ;
$ detdistname = "sles" . $ verpair [ 1 ] ;
unless ( $ distname ) { $ distname = $ detdistname ; }
}
}
} else {
my @ parts = split /\s+/ , $ prod ;
my @ subparts = split /-/ , $ parts [ 2 ] ;
$ detdistname = "sles" . $ subparts [ 0 ] ;
unless ( $ distname ) { $ distname = "sles" . $ subparts [ 0 ] } ;
}
2009-11-05 06:59:59 +00:00
# check media.1/products for text.
# the cselx is a special GE built version.
# openSUSE is the normal one.
} elsif ( $ prod =~ m/cselx 1.0-0|openSUSE 11.1-0/ ) {
2009-09-18 23:12:22 +00:00
$ distname = "suse11" ;
$ detdistname = "suse11" ;
}
2008-03-12 19:16:44 +00:00
}
}
unless ( $ distname and $ discnumber )
{
return ;
}
if ( $ darch and $ darch =~ /i.86/ )
{
$ darch = "x86" ;
}
elsif ( $ darch and $ darch =~ /ppc/ )
{
$ darch = "ppc64" ;
}
if ( $ darch )
{
unless ( $ arch )
{
$ arch = $ darch ;
}
if ( $ arch and $ arch ne $ darch )
{
$ callback - > (
{
error = >
2008-03-26 15:04:32 +00:00
[ "Requested SLES architecture $arch, but media is $darch" ] ,
errorcode = > [ 1 ]
2008-03-12 19:16:44 +00:00
}
) ;
return ;
}
}
% { $ request } = ( ) ; #clear request we've got it.
$ callback - > (
{ data = > "Copying media to $installroot/$distname/$arch/$discnumber" } ) ;
my $ omask = umask 0022 ;
mkpath ( "$installroot/$distname/$arch/$discnumber" ) ;
umask $ omask ;
2008-04-21 20:43:07 +00:00
my $ rc ;
2008-06-02 23:51:40 +00:00
$ SIG { INT } = $ SIG { TERM } = sub {
foreach ( @ cpiopid ) {
kill 2 , $ _ ;
}
if ( $ ::CDMOUNTPATH ) {
2008-08-11 18:36:10 +00:00
chdir ( "/" ) ;
2008-05-15 15:48:34 +00:00
system ( "umount $::CDMOUNTPATH" ) ;
2008-06-02 23:51:40 +00:00
}
2008-05-15 15:48:34 +00:00
} ;
2008-04-21 20:43:07 +00:00
my $ kid ;
chdir $ path ;
2008-06-02 23:51:40 +00:00
my $ numFiles = `find . -print | wc -l` ;
2008-04-21 20:43:07 +00:00
my $ child = open ( $ kid , "|-" ) ;
unless ( defined $ child ) {
$ callback - > ( { error = > "Media copy operation fork failure" } ) ;
return ;
}
if ( $ child ) {
2008-06-02 23:51:40 +00:00
push @ cpiopid , $ child ;
2008-04-21 20:43:07 +00:00
my @ finddata = `find .` ;
for ( @ finddata ) {
print $ kid $ _ ;
}
close ( $ kid ) ;
$ rc = $? ;
} else {
2008-06-11 20:45:06 +00:00
my $ c = "nice -n 20 cpio -vdump $installroot/$distname/$arch/$discnumber" ;
2008-06-02 23:51:40 +00:00
my $ k2 = open ( PIPE , "$c 2>&1 |" ) ||
$ callback - > ( { error = > "Media copy operation fork failure" } ) ;
push @ cpiopid , $ k2 ;
my $ copied = 0 ;
my ( $ percent , $ fout ) ;
while ( <PIPE> ) {
next if /^cpio:/ ;
$ percent = $ copied / $ numFiles ;
$ fout = sprintf "%0.2f%%" , $ percent * 100 ;
$ callback - > ( { sinfo = > "$fout" } ) ;
+ + $ copied ;
}
exit ;
2008-04-21 20:43:07 +00:00
}
# system(
# "cd $path; find . | nice -n 20 cpio -dump $installroot/$distname/$arch/$discnumber/"
# );
2008-03-12 19:16:44 +00:00
chmod 0755 , "$installroot/$distname/$arch" ;
chmod 0755 , "$installroot/$distname/$arch/$discnumber" ;
2008-05-24 17:29:40 +00:00
if ( $ detdistname eq "sles10.2" and $ discnumber eq "1" ) { #Go and correct inst_startup.ycp in the install root
my $ tmnt = tempdir ( "xcat-sles.$$.XXXXXX" , TMPDIR = > 1 ) ;
my $ tdir = tempdir ( "xcat-slesd.$$.XXXXXX" , TMPDIR = > 1 ) ;
my $ startupfile ;
my $ ycparch = $ arch ;
if ( $ arch eq "x86" ) {
$ ycparch = "i386" ;
}
system ( "mount -o loop $installroot/$distname/$arch/$discnumber/boot/$ycparch/root $tmnt" ) ;
system ( "cd $tmnt;find . |cpio -dump $tdir" ) ;
system ( "umount $tmnt;rm $installroot/$distname/$arch/$discnumber/boot/$ycparch/root" ) ;
open ( $ startupfile , "<" , "$tdir/usr/share/YaST2/clients/inst_startup.ycp" ) ;
my @ ycpcontents = <$startupfile> ;
my @ newcontents ;
my $ writecont = 1 ;
close ( $ startupfile ) ;
foreach ( @ ycpcontents ) {
if ( /No hard disks/ ) {
$ writecont = 0 ;
} elsif ( /\}/ ) {
$ writecont = 1 ;
}
s/cancel/next/ ;
if ( $ writecont ) {
push @ newcontents , $ _ ;
}
}
open ( $ startupfile , ">" , "$tdir/usr/share/YaST2/clients/inst_startup.ycp" ) ;
foreach ( @ newcontents ) {
print $ startupfile $ _ ;
}
close ( $ startupfile ) ;
system ( "cd $tdir;mkfs.cramfs . $installroot/$distname/$arch/$discnumber/boot/$ycparch/root" ) ;
system ( "rm -rf $tmnt $tdir" ) ;
}
2008-03-12 19:16:44 +00:00
if ( $ rc != 0 )
{
$ callback - > ( { error = > "Media copy operation failed, status $rc" } ) ;
}
else
{
$ callback - > ( { data = > "Media copy operation successful" } ) ;
2009-09-19 17:03:14 +00:00
my @ ret = xCAT::SvrUtils - > update_tables_with_templates ( $ distname , $ arch ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables: " . $ ret [ 1 ] } ) ;
}
2008-03-12 19:16:44 +00:00
}
2007-10-26 22:44:33 +00:00
}
2010-08-12 09:05:22 +00:00
# Get the driver update disk from /install/driverdisk/<os>/<arch>
# Take out the drivers from driver update disk and insert them
# into the initrd
sub insert_dd {
my $ callback = shift ;
my $ os = shift ;
my $ arch = shift ;
my $ img = shift ;
my $ install_dir = xCAT::Utils - > getInstallDir ( ) ;
# Find out the dirver disk which need to be insert into initrd
if ( ! - d "$install_dir/driverdisk/$os/$arch" ) {
return ( ) ;
}
my $ cmd = "find $install_dir/driverdisk/$os/$arch -type f" ;
my @ dd_list = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
chomp ( @ dd_list ) ;
if ( ! @ dd_list ) {
return undef ;
}
# Create the tmp dir for dd hack
2010-08-23 08:00:51 +00:00
my $ dd_dir = mkdtemp ( "/tmp/ddtmpXXXXXXX" ) ;
2010-08-12 09:05:22 +00:00
mkpath "$dd_dir/initrd_img" ;
my $ pkgdir = "$install_dir/$os/$arch" ;
# Unzip the original initrd
if ( $ arch =~ /x86/ ) {
$ cmd = "gunzip --quiet -c $img > $dd_dir/initrd" ;
} elsif ( $ arch =~ /ppc/ ) {
$ cmd = "gunzip --quiet -c $pkgdir/1/suseboot/initrd64 > $dd_dir/initrd" ;
}
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not gunzip the initial initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return ( ) ;
}
# Unpack the initrd
$ cmd = "cd $dd_dir/initrd_img; cpio -id --quiet < $dd_dir/initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not extract files from the initial initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return ( ) ;
}
# Create the dir for driver update disk
$ cmd = "mkdir -p $dd_dir/initrd_img/cus_driverdisk" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
# insert the driver update disk into the cus_driverdisk dir
foreach my $ dd ( @ dd_list ) {
copy ( $ dd , "$dd_dir/initrd_img/cus_driverdisk" ) ;
}
# Repack the initrd
# In order to avoid the runcmd add the '2>&1' at end of the cpio
# cmd, the echo cmd is added at the end
$ cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not pack the hacked initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return ( ) ;
}
# zip the initrd
#move ("$dd_dir/initrd.new", "$dd_dir/initrd");
$ cmd = "gzip -f $dd_dir/initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ arch =~ /x86/ ) {
copy ( "$dd_dir/initrd.gz" , "$img" ) ;
} elsif ( $ arch =~ /ppc/ ) {
# make sure the src kernel existed
$ cmd = "gunzip -c $pkgdir/1/suseboot/linux64.gz > $dd_dir/kernel" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
# create the zimage
$ cmd = "env -u POSIXLY_CORRECT /lib/lilo/scripts/make_zimage_chrp.sh --vmlinux $dd_dir/kernel --initrd $dd_dir/initrd.gz --output $img" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not pack the hacked initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return ( ) ;
}
}
my $ rsp ;
push @ { $ rsp - > { data } } , "Inserted the driver update disk:" . join ( ',' , sort ( @ dd_list ) ) . "." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
my @ dd_files = ( ) ;
foreach my $ dd ( sort ( @ dd_list ) ) {
chomp ( $ dd ) ;
$ dd =~ s/^.*\/// ;
push @ dd_files , $ dd ;
}
return sort ( @ dd_files ) ;
}
2009-09-17 09:53:14 +00:00
#sub get_tmpl_file_name {
# my $base=shift;
# my $profile=shift;
# my $os=shift;
# my $arch=shift;
# if (-r "$base/$profile.$os.$arch.tmpl") {
# return "$base/$profile.$os.$arch.tmpl";
# }
# elsif (-r "$base/$profile.$os.tmpl") {
# return "$base/$profile.$os.tmpl";
# }
# elsif (-r "$base/$profile.$arch.tmpl") {
# return "$base/$profile.$arch.tmpl";
# }
# elsif (-r "$base/$profile.tmpl") {
# return "$base/$profile.tmpl";
# }
#
# return "";
#}
2008-09-12 22:40:15 +00:00
2007-10-26 22:44:33 +00:00
1 ;