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 ;
2012-08-09 04:07:40 +00:00
use xCAT::TableUtils ;
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/ ;
2012-06-19 20:17:42 +00:00
my $ httpmethod = "http" ;
my $ httpport = "80" ;
2013-10-10 17:57:18 +00:00
my $ useflowcontrol = "0" ;
2012-07-05 14:59:08 +00:00
use File::Find ;
use File::Basename ;
2013-01-07 08:39:52 +00:00
use Digest::MD5 qw( md5_hex ) ;
2010-04-02 09:19:02 +00:00
use Socket ;
2012-02-15 21:04:42 +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.*)" ,
2013-08-23 06:32:02 +00:00
mkstatelite = > "nodetype:os=(sles.*)" ,
mksysclone = > "nodetype:os=(sles.*)|(suse.*)"
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" ;
}
2012-02-15 21:04:42 +00:00
my $ globaltftpdir = "/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 } } ;
2013-09-26 07:04:36 +00:00
my $ noupdateinitrd = $ req - > { 'noupdateinitrd' } ;
2013-11-19 11:27:11 +00:00
my $ ignorekernelchk = $ req - > { 'ignorekernelchk' } ;
2008-05-27 15:53:45 +00:00
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
2012-05-23 05:50:08 +00:00
#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" ;
2013-08-16 09:50:59 +00:00
my $ xcatiport = "3002" ;
my $ nodestatus = "y" ;
2012-05-23 05:50:08 +00:00
#if ($sitetab)
#{
#(my $ref) = $sitetab->getAttribs({key => 'installdir'}, 'value');
2012-08-09 04:07:40 +00:00
my @ entries = xCAT::TableUtils - > get_site_attribute ( "installdir" ) ;
2012-05-23 05:50:08 +00:00
my $ t_entry = $ entries [ 0 ] ;
if ( defined ( $ t_entry ) ) {
$ installroot = $ t_entry ;
2008-05-27 15:53:45 +00:00
}
2012-05-23 05:50:08 +00:00
#($ref) = $sitetab->getAttribs({key => 'xcatdport'}, 'value');
2012-08-09 04:07:40 +00:00
@ entries = xCAT::TableUtils - > get_site_attribute ( "xcatdport" ) ;
2012-05-23 05:50:08 +00:00
$ t_entry = $ entries [ 0 ] ;
if ( defined ( $ t_entry ) ) {
$ xcatdport = $ t_entry ;
2010-01-27 06:00:24 +00:00
}
2013-08-16 09:50:59 +00:00
@ entries = xCAT::TableUtils - > get_site_attribute ( "xcatiport" ) ;
$ t_entry = $ entries [ 0 ] ;
if ( defined ( $ t_entry ) ) {
$ xcatiport = $ t_entry ;
}
@ entries = xCAT::TableUtils - > get_site_attribute ( "nodestatus" ) ;
$ t_entry = $ entries [ 0 ] ;
if ( defined ( $ t_entry ) ) {
$ nodestatus = $ t_entry ;
}
2012-05-23 05:50:08 +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' ) ;
2012-02-15 21:04:42 +00:00
my $ reshash = $ restab - > getNodesAttribs ( \ @ nodes , [ 'primarynic' , 'tftpserver' , 'tftpdir' , 'xcatmaster' , 'nfsserver' , 'nfsdir' , 'installnic' ] ) ;
2010-09-17 09:54:47 +00:00
2008-05-27 15:53:45 +00:00
my % donetftp = ( ) ;
2013-01-05 07:39:45 +00:00
# Warning message for nodeset <noderange> install/netboot/statelite
foreach my $ knode ( keys % { $ ntents } )
{
my $ ent = $ ntents - > { $ knode } - > [ 0 ] ;
if ( $ ent && $ ent - > { provmethod }
&& ( ( $ ent - > { provmethod } eq 'install' ) || ( $ ent - > { provmethod } eq 'netboot' ) || ( $ ent - > { provmethod } eq 'statelite' ) ) )
{
2013-01-23 07:52:19 +00:00
my @ ents = xCAT::TableUtils - > get_site_attribute ( "disablenodesetwarning" ) ;
my $ site_ent = $ ents [ 0 ] ;
if ( ! defined ( $ site_ent ) || ( $ site_ent =~ /no/i ) || ( $ site_ent =~ /0/ ) )
{
$ callback - > (
{
warning = > [ "The options \"install\", \"netboot\", and \"statelite\" have been deprecated. They should continue to work in this release, but have not been tested as carefully, and some new functions are not available with these options. For full function and support, use \"nodeset <noderange> osimage=<osimage_name>\" instead." ] ,
}
) ;
# Do not print this warning message multiple times
last ;
}
2013-01-05 07:39:45 +00:00
}
}
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 ;
2012-02-15 21:04:42 +00:00
my $ provmethod ;
2009-09-22 23:29:14 +00:00
my $ rootimgdir ;
2010-09-17 09:54:47 +00:00
my $ nodebootif ; # nodebootif will be used if noderes.installnic is not set
2012-03-26 07:35:16 +00:00
my $ dump ; #for kdump
my $ crashkernelsize ;
2011-01-06 06:54:06 +00:00
my $ rootfstype ;
2012-11-16 14:02:36 +00:00
my $ cfgpart ;
2013-01-10 13:56:49 +00:00
my $ imagename ; # set it if running of 'nodeset osimage=xxx'
2009-09-22 23:29:14 +00:00
2012-11-16 14:02:36 +00:00
my $ ent = $ ntents - > { $ node } - > [ 0 ] ;
2010-01-27 06:00:24 +00:00
if ( $ ent and $ ent - > { provmethod } and ( $ ent - > { provmethod } ne 'install' ) and ( $ ent - > { provmethod } ne 'netboot' ) and ( $ ent - > { provmethod } ne 'statelite' ) ) {
2013-01-10 13:56:49 +00:00
$ imagename = $ ent - > { provmethod } ;
2012-11-16 14:02:36 +00:00
if ( ! exists ( $ img_hash { $ imagename } ) ) {
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' , - create = > 1 ) ;
}
( my $ ref ) = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'osvers' , 'osarch' , 'profile' , 'rootfstype' , 'provmethod' ) ;
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' } ;
2012-11-16 14:02:36 +00:00
$ img_hash { $ imagename } - > { provmethod } = $ ref - > { 'provmethod' } ;
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' , - create = > 1 ) ;
}
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imagename } , 'rootimgdir' , 'nodebootif' , 'dump' , 'crashkernelsize' , 'partitionfile' ) ;
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' } ;
2012-03-26 07:35:16 +00:00
}
2012-11-16 14:02:36 +00:00
if ( ( $ ref1 ) && ( $ ref1 - > { 'dump' } ) ) {
$ img_hash { $ imagename } - > { dump } = $ ref1 - > { 'dump' } ;
}
if ( ( $ ref1 ) && ( $ ref1 - > { 'crashkernelsize' } ) ) {
2012-03-26 07:35:16 +00:00
$ img_hash { $ imagename } - > { crashkernelsize } = $ ref1 - > { 'crashkernelsize' } ;
2010-09-17 09:54:47 +00:00
}
2012-11-16 14:02:36 +00:00
if ( $ ref1 && $ ref1 - > { 'partitionfile' } ) {
# check the validity of the partition configuration file
if ( $ ref1 - > { 'partitionfile' } =~ /^s:(.*)/ ) {
# the configuration file is a script
if ( - r $ 1 ) {
$ img_hash { $ imagename } - > { 'cfgpart' } = "yes" ;
}
} else {
if ( open ( FILE , "<$ref1->{'partitionfile'}" ) ) {
while ( <FILE> ) {
if ( /enable=yes/ ) {
$ img_hash { $ imagename } - > { 'cfgpart' } = "yes" ;
last ;
}
}
}
close ( FILE ) ;
}
$ img_hash { $ imagename } - > { 'partfile' } = $ ref1 - > { 'partitionfile' } ;
}
} 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 } ;
2012-11-16 14:02:36 +00:00
$ provmethod = $ ph - > { provmethod } ;
$ dump = $ ph - > { dump } ;
$ crashkernelsize = $ ph - > { crashkernelsize } ;
$ cfgpart = $ ph - > { 'cfgpart' } ;
$ rootimgdir = $ ph - > { rootimgdir } ;
unless ( $ rootimgdir ) {
$ rootimgdir = "$installroot/netboot/$osver/$arch/$profile" ;
}
} 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
2011-05-09 02:45:24 +00:00
my $ imgname ;
if ( $ statelite ) {
$ imgname = "$osver-$arch-statelite-$profile" ;
} else {
$ imgname = "$osver-$arch-netboot-$profile" ;
}
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' ) ;
}
if ( $ osimagetab ) {
my ( $ ref1 ) = $ osimagetab - > getAttribs ( { imagename = > $ imgname } , 'rootfstype' ) ;
if ( ( $ ref1 ) && ( $ ref1 - > { 'rootfstype' } ) ) {
$ rootfstype = $ ref1 - > { 'rootfstype' } ;
}
} else {
$ callback - > (
{ error = > [ qq{ Cannot find the linux image called "$osver-$arch-$provmethod-$profile", maybe you need to use the "nodeset <nr> osimage=<osimage name>" command to set the boot state } ] ,
errorcode = > [ 1 ] }
) ;
}
2012-11-16 14:02:36 +00:00
#get the dump path and kernel crash memory side for kdump on sles
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' ) ;
}
if ( $ linuximagetab ) {
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imgname } , 'dump' , 'crashkernelsize' , 'partitionfile' ) ;
if ( $ ref1 && $ ref1 - > { 'dump' } ) {
$ dump = $ ref1 - > { 'dump' } ;
}
if ( $ ref1 and $ ref1 - > { 'crashkernelsize' } ) {
$ crashkernelsize = $ ref1 - > { 'crashkernelsize' } ;
}
if ( $ ref1 and $ ref1 - > { 'partitionfile' } ) {
# check the validity of the partition configuration file
if ( $ ref1 - > { 'partitionfile' } =~ /^s:(.*)/ ) {
# the configuration file is a script
if ( - r $ 1 ) {
$ cfgpart = "yes" ;
}
} else {
if ( - r $ ref1 - > { 'partitionfile' } && open ( FILE , "<$ref1->{'partitionfile'}" ) ) {
while ( <FILE> ) {
if ( /enable=yes/ ) {
$ cfgpart = "yes" ;
last ;
}
}
}
close ( FILE ) ;
}
}
}
else {
$ callback - > (
{ error = > [ qq{ Cannot find the linux image called "$osver-$arch-$imgname-$profile", maybe you need to use the "nodeset <nr> osimage=<your_image_name>" command to set the boot state } ] ,
errorcode = > [ 1 ] }
2012-03-26 07:35:16 +00:00
) ;
2012-11-16 14:02:36 +00:00
}
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";
2012-11-16 14:02:36 +00:00
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
}
2012-02-15 21:04:42 +00:00
my $ tftpdir ;
if ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { tftpdir } ) {
$ tftpdir = $ reshash - > { $ node } - > [ 0 ] - > { tftpdir } ;
} else {
$ tftpdir = $ globaltftpdir ;
}
2008-05-27 15:53:45 +00:00
2013-01-10 13:56:49 +00:00
# Copy the boot resource to /tftpboot and check to only copy once
my $ docopy = 0 ;
my $ tftppath ;
my $ rtftppath ; # the relative tftp path without /tftpboot/
if ( $ imagename ) {
$ tftppath = "$tftpdir/xcat/osimage/$imagename" ;
$ rtftppath = "xcat/osimage/$imagename" ;
unless ( $ donetftp { $ imagename } ) {
$ docopy = 1 ;
$ donetftp { $ imagename } = 1 ;
}
} else {
$ tftppath = "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ;
$ rtftppath = "xcat/netboot/$osver/$arch/$profile/" ;
unless ( $ donetftp { $ osver , $ arch , $ profile , $ tftpdir } ) {
$ docopy = 1 ;
$ donetftp { $ osver , $ arch , $ profile , $ tftpdir } = 1 ;
}
}
2008-05-27 15:53:45 +00:00
2013-09-26 07:04:36 +00:00
if ( $ docopy && ! $ noupdateinitrd ) {
2013-01-10 13:56:49 +00:00
mkpath ( "$tftppath" ) ;
copy ( "$rootimgdir/kernel" , "$tftppath" ) ;
2010-09-17 09:54:47 +00:00
if ( $ statelite ) {
2013-01-10 13:56:49 +00:00
copy ( "$rootimgdir/initrd-statelite.gz" , "$tftppath" ) ;
2010-09-17 09:54:47 +00:00
} else {
2013-01-10 13:56:49 +00:00
copy ( "$rootimgdir/initrd-stateless.gz" , "$tftppath" ) ;
2010-09-17 09:54:47 +00:00
}
2008-05-27 15:53:45 +00:00
}
2010-09-17 09:54:47 +00:00
if ( $ statelite ) {
2013-01-10 13:56:49 +00:00
unless ( - r "$tftppath/kernel" and - r "$tftppath/initrd-statelite.gz" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2013-01-10 13:56:49 +00:00
error = > [ qq{ copying to $tftppath failed } ] ,
2010-09-17 09:54:47 +00:00
errorcode = > [ 1 ]
} ) ;
next ;
}
} else {
2013-01-10 13:56:49 +00:00
unless ( - r "$tftppath/kernel"
and - r "$tftppath/initrd-stateless.gz" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2013-01-10 13:56:49 +00:00
error = > [ qq{ copying to $tftppath failed } ] ,
2010-09-17 09:54:47 +00:00
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 =
2012-06-19 20:17:42 +00:00
"imgurl=$httpmethod://$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 ) ;
2011-05-10 11:32:51 +00:00
$ dir =~ s/\/\//\//g ;
2010-02-26 07:14:59 +00:00
}
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 =
2012-06-19 20:17:42 +00:00
"imgurl=$httpmethod://$imgsrv/$rootimgdir/rootimg.$suffix " ;
2008-05-27 15:53:45 +00:00
}
2011-11-22 15:50:35 +00:00
$ kcmdline . = "XCAT=$xcatmaster:$xcatdport quiet " ;
2013-08-16 09:50:59 +00:00
#if site.nodestatus="n", append "nonodestatus" to kcmdline
#to inform the statelite/stateless node not to update the nodestatus during provision
if ( ( $ nodestatus eq "n" ) or ( $ nodestatus eq "N" ) or ( $ nodestatus eq "0" ) ) {
$ kcmdline . = " nonodestatus " ;
}
2013-05-28 12:20:12 +00:00
$ kcmdline . = "NODE=$node " ;
2013-10-10 17:57:18 +00:00
# add flow control setting
$ kcmdline . = "FC=$useflowcontrol " ;
2010-09-17 09:54:47 +00:00
# add the kernel-booting parameter: netdev=<eth0>, or BOOTIF=<mac>
my $ netdev = "" ;
my $ mac = $ machash - > { $ node } - > [ 0 ] - > { mac } ;
2012-06-28 04:11:39 +00:00
if ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { installnic } and ( $ reshash - > { $ node } - > [ 0 ] - > { installnic } ne "mac" ) ) {
2010-09-17 09:54:47 +00:00
$ kcmdline . = "netdev=" . $ reshash - > { $ node } - > [ 0 ] - > { installnic } . " " ;
} elsif ( $ nodebootif ) {
$ kcmdline . = "netdev=" . $ nodebootif . " " ;
2012-06-28 04:11:39 +00:00
} elsif ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { primarynic } and ( $ reshash - > { $ node } - > [ 0 ] - > { primarynic } ne "mac" ) ) {
2010-09-17 09:54:47 +00:00
$ 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 ]
} ) ;
}
}
2012-11-16 14:02:36 +00:00
if ( defined $ sent - > { serialport } ) {
2008-05-27 15:53:45 +00:00
#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
2012-11-16 14:02:36 +00:00
#create the kcmd for node to support kdump
if ( $ dump ) {
if ( $ crashkernelsize ) {
$ kcmdline . = " crashkernel=$crashkernelsize dump=$dump " ;
}
else {
# for ppc64, the crashkernel paramter should be "128M@32M", otherwise, some kernel crashes will be met
if ( $ arch eq "ppc64" ) {
$ kcmdline . = " crashkernel=256M\@64M dump=$dump " ;
}
if ( $ arch =~ /86/ ) {
$ kcmdline . = " crashkernel=128M dump=$dump " ;
}
}
}
# add the cmdline parameters for handling the local disk for stateless
if ( $ cfgpart eq "yes" ) {
2013-04-27 07:46:54 +00:00
if ( $ statelite ) {
$ kcmdline . = " PARTITION_SLES" ;
} else {
$ kcmdline . = " PARTITION_DOMOUNT_SLES" ;
}
2012-11-16 14:02:36 +00:00
}
2012-03-26 07:35:16 +00:00
2013-01-10 13:56:49 +00:00
my $ initrdstr = "$rtftppath/initrd-stateless.gz" ;
$ initrdstr = "$rtftppath/initrd-statelite.gz" if ( $ statelite ) ;
This is to enable client to indicate options when mounting persistent directories on statelite(nfs/ramdisk) CNs, if not, "nolock,tcp" will be used as default options. This implementation aims for SLES11.
client can revise the statelite table to benefit from this, like:
#node,image,statemnt,mntopts,comments,disable
"935n02",,"192.168.0.244:/tmp","soft,timeo=200",,
------------------------------------------------------
Another change in sles.pm: we do insmod for net interfaces (ibmveth, ehea, etc...) after all other modules, to avoid failure when do 'netstart' during installation.
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9817 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2011-06-16 03:06:56 +00:00
2012-11-16 14:02:36 +00:00
if ( $ statelite )
{
my $ statelitetb = xCAT::Table - > new ( 'statelite' ) ;
my $ mntopts = $ statelitetb - > getNodeAttribs ( $ node , [ 'mntopts' ] ) ;
my $ mntoptions = $ mntopts - > { 'mntopts' } ;
if ( defined ( $ mntoptions ) ) {
$ kcmdline . = "MNTOPTS=\'$mntoptions\'" ;
}
}
2008-05-27 15:53:45 +00:00
$ bptab - > setNodeAttribs (
2012-11-16 14:02:36 +00:00
$ node ,
{
2013-01-10 13:56:49 +00:00
kernel = > "$rtftppath/kernel" ,
2012-11-16 14:02:36 +00:00
initrd = > $ initrdstr ,
kcmdline = > $ kcmdline
} ) ;
2008-05-27 15:53:45 +00:00
}
}
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 ;
2012-06-19 20:20:47 +00:00
if ( $ ::XCATSITEVALS { "httpmethod" } ) { $ httpmethod = $ ::XCATSITEVALS { "httpmethod" } ; }
if ( $ ::XCATSITEVALS { "httpport" } ) { $ httpport = $ ::XCATSITEVALS { "httpport" } ; }
2013-10-10 17:57:18 +00:00
if ( $ ::XCATSITEVALS { "useflowcontrol" } ) { $ useflowcontrol = $ ::XCATSITEVALS { "useflowcontrol" } ; }
2008-03-12 19:16:44 +00:00
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 ) ;
}
2013-08-23 06:32:02 +00:00
elsif ( $ request - > { command } - > [ 0 ] eq 'mksysclone' )
{
return mksysclone ( $ 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 ;
2012-08-09 04:07:40 +00:00
my $ globaltftpdir = xCAT::TableUtils - > getTftpDir ( ) ;
2012-02-15 21:04:42 +00:00
2013-07-04 05:06:50 +00:00
my $ noupdateinitrd = $ request - > { 'noupdateinitrd' } ;
2013-11-19 11:27:11 +00:00
my $ ignorekernelchk = $ request - > { 'ignorekernelchk' } ;
2008-03-12 19:16:44 +00:00
my @ nodes = @ { $ request - > { node } } ;
my $ node ;
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
2012-05-23 05:50:08 +00:00
#my $sitetab = xCAT::Table->new('site');
2009-09-22 23:29:14 +00:00
my $ linuximagetab ;
my $ osimagetab ;
2013-07-04 05:06:50 +00:00
my $ osdistrouptab ;
2009-09-22 23:29:14 +00:00
my $ ntents = $ ostab - > getNodesAttribs ( $ request - > { node } , [ 'os' , 'arch' , 'profile' , 'provmethod' ] ) ;
my % img_hash = ( ) ;
my $ installroot ;
$ installroot = "/install" ;
2012-02-15 21:04:42 +00:00
my $ restab = xCAT::Table - > new ( 'noderes' ) ;
my $ bptab = xCAT::Table - > new ( 'bootparams' , - create = > 1 ) ;
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
my $ resents =
$ restab - > getNodesAttribs (
\ @ nodes ,
[
2012-02-20 07:20:41 +00:00
'nfsserver' , 'tftpdir' , 'xcatmaster' ,
2012-02-15 21:04:42 +00:00
'primarynic' , 'installnic'
]
) ;
my $ hments =
$ hmtab - > getNodesAttribs ( \ @ nodes , [ 'serialport' , 'serialspeed' , 'serialflow' ] ) ;
2009-09-22 23:29:14 +00:00
2012-05-23 05:50:08 +00:00
#if ($sitetab)
#{
#(my $ref) = $sitetab->getAttribs({key => 'installdir'}, 'value');
2012-08-09 04:07:40 +00:00
my @ entries = xCAT::TableUtils - > get_site_attribute ( "installdir" ) ;
2012-05-23 05:50:08 +00:00
my $ t_entry = $ entries [ 0 ] ;
if ( defined ( $ t_entry ) ) {
$ installroot = $ t_entry ;
2009-09-22 23:29:14 +00:00
}
2012-05-23 05:50:08 +00:00
#}
2009-09-22 23:29:14 +00:00
2013-01-10 13:56:49 +00:00
my % donetftp ;
2009-03-14 16:14:29 +00:00
require xCAT::Template ; #only used here, load so memory can be COWed
2012-10-16 05:58:29 +00:00
# Define a variable for driver update list
my @ dd_drivers ;
2013-01-05 07:39:45 +00:00
# Warning message for nodeset <noderange> install/netboot/statelite
foreach my $ knode ( keys % { $ ntents } )
{
my $ ent = $ ntents - > { $ knode } - > [ 0 ] ;
if ( $ ent && $ ent - > { provmethod }
&& ( ( $ ent - > { provmethod } eq 'install' ) || ( $ ent - > { provmethod } eq 'netboot' ) || ( $ ent - > { provmethod } eq 'statelite' ) ) )
{
2013-01-23 07:52:19 +00:00
my @ ents = xCAT::TableUtils - > get_site_attribute ( "disablenodesetwarning" ) ;
my $ site_ent = $ ents [ 0 ] ;
if ( ! defined ( $ site_ent ) || ( $ site_ent =~ /no/i ) || ( $ site_ent =~ /0/ ) )
{
$ callback - > (
{
warning = > [ "The options \"install\", \"netboot\", and \"statelite\" have been deprecated. They should continue to work in this release, but have not been tested as carefully, and some new functions are not available with these options. For full function and support, use \"nodeset <noderange> osimage=<osimage_name>\" instead." ] ,
}
) ;
# Do not print this warning message multiple times
last ;
}
2013-01-05 07:39:45 +00:00
}
}
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 ;
2013-01-10 13:56:49 +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 ] ;
2013-01-10 13:56:49 +00:00
my $ plat = "" ;
2012-02-15 21:04:42 +00:00
my $ tftpdir ;
2012-07-04 06:11:22 +00:00
my $ partfile ;
2012-07-05 14:59:08 +00:00
my $ netdrivers ;
my $ driverupdatesrc ;
2013-07-04 05:06:50 +00:00
my $ osupdir ;
2013-01-10 13:56:49 +00:00
my $ imagename ; # set it if running of 'nodeset osimage=xxx'
if ( $ resents - > { $ node } and $ resents - > { $ node } - > [ 0 ] - > { tftpdir } ) {
2012-02-15 21:04:42 +00:00
$ tftpdir = $ resents - > { $ node } - > [ 0 ] - > { tftpdir } ;
} else {
$ tftpdir = $ globaltftpdir ;
}
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' ) ) {
2013-01-10 13:56:49 +00:00
$ imagename = $ ent - > { provmethod } ;
2009-09-22 23:29:14 +00:00
if ( ! exists ( $ img_hash { $ imagename } ) ) {
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' , - create = > 1 ) ;
}
2013-07-04 05:06:50 +00:00
( my $ ref ) = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'osvers' , 'osarch' , 'profile' , 'provmethod' , 'osupdatename' ) ;
2009-09-22 23:29:14 +00:00
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 ) ;
}
2012-07-10 06:14:04 +00:00
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imagename } , 'template' , 'pkgdir' , 'pkglist' , 'partitionfile' , 'driverupdatesrc' , 'netdrivers' ) ;
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' } ;
}
2012-07-04 06:11:22 +00:00
if ( $ ref1 - > { 'partitionfile' } ) {
$ img_hash { $ imagename } - > { partitionfile } = $ ref1 - > { 'partitionfile' } ;
}
2012-07-05 14:59:08 +00:00
if ( $ ref1 - > { 'driverupdatesrc' } ) {
$ img_hash { $ imagename } - > { driverupdatesrc } = $ ref1 - > { 'driverupdatesrc' } ;
}
if ( $ ref1 - > { 'netdrivers' } ) {
$ img_hash { $ imagename } - > { netdrivers } = $ ref1 - > { 'netdrivers' } ;
}
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 ;
}
2013-07-04 05:06:50 +00:00
# get the path list of the osdistroupdate
if ( $ ref - > { 'osupdatename' } ) {
my $ osdisupdir ;
my @ osupdatenames = split ( /,/ , $ ref - > { 'osupdatename' } ) ;
unless ( $ osdistrouptab ) {
$ osdistrouptab = xCAT::Table - > new ( 'osdistroupdate' , - create = > 1 ) ;
unless ( $ osdistrouptab ) {
$ callback - > ( { error = > [ "Cannot open the table osdistroupdate." ] , errorcode = > [ 1 ] } ) ;
next ;
}
}
my @ osdup = $ osdistrouptab - > getAllAttribs ( "osupdatename" , "dirpath" ) ;
foreach my $ upname ( @ osupdatenames ) {
foreach my $ upref ( @ osdup ) {
if ( $ upref - > { 'osupdatename' } eq $ upname ) {
$ osdisupdir . = ",$upref->{'dirpath'}" ;
last ;
}
}
}
$ osdisupdir =~ s/^,// ;
$ img_hash { $ imagename } - > { 'osupdir' } = $ osdisupdir ;
}
2009-09-22 23:29:14 +00:00
}
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 } ;
2012-07-04 06:11:22 +00:00
$ partfile = $ ph - > { partitionfile } ;
2012-07-05 14:59:08 +00:00
$ netdrivers = $ ph - > { netdrivers } ;
$ driverupdatesrc = $ ph - > { driverupdatesrc } ;
2013-07-04 05:06:50 +00:00
$ osupdir = $ ph - > { 'osupdir' } ;
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
}
To make the code easier to maintain we decided not to select autoyast config template file (compute.sdk.sles11.tmpl/compute.sles11), instead if the user want to do a SDK included full install, he should prepare a customized template from compute.sdk.sles11.tmpl, and copy it to /install/custom directory.
This is for SLES 11 SP1 SDK DVD support (Patch 1)
====================================================================
Patch Reason: Design changed, To make the code easier to maintain
we decided not to automate select autoyast config template file
(compute.sdk.sles11.tmpl/compute.sles11),
Patch detail: If the user want to do a SDK DVD included full install,
he/she should prepare a customized template originated from
compute.sdk.sles11.tmpl, and copy it under /install/custom
====================================================================
====================================================================
Target Dist: SLES 11 SP1, for both full install and statelite install
Aim: To enable users to install packages from SDK DVD during installation
user impact: If the user add packages in .pkglist files, he/she should first do 'copycds' using SDK DVD iso.
For full install, the user should prepare a .tmpl file for autoyast
By-effect: N/A
Limitations: 2nd installation DVD and 2nd SDK DVD not supported, both carries source packages.
It seems they are not recognized by autoyast, and it's of no use to install sources pkgs on CNs.
====================================================================
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9980 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2011-06-29 10:03:58 +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" ;
2012-07-04 06:11:22 +00:00
#get the partition file from the linuximage table
my $ imgname = "$os-$arch-install-$profile" ;
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' ) ;
}
if ( $ linuximagetab ) {
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imgname } , 'partitionfile' ) ;
if ( $ ref1 and $ ref1 - > { 'partitionfile' } ) {
$ partfile = $ ref1 - > { 'partitionfile' } ;
}
2012-07-11 07:39:59 +00:00
}
else {
$ callback - > (
{ error = > [ qq{ Cannot find the linux image called "$imgname", maybe you need to use the "nodeset <nr> osimage=<your_image_name>" command to set the boot state } ] , errorcode = > [ 1 ] }
2012-07-04 06:11:22 +00:00
) ;
}
2009-09-22 23:29:14 +00:00
}
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 ;
}
2012-12-21 08:30:39 +00:00
#To support multiple paths for osimage.pkgdir. We require the first value of osimage.pkgdir
# should be the os base pkgdir.
2013-02-28 06:20:30 +00:00
my $ tmppkgdir = $ pkgdir ;
2012-12-21 08:30:39 +00:00
my @ srcdirs = split ( "," , $ pkgdir ) ;
$ pkgdir = $ srcdirs [ 0 ] ;
2014-04-11 20:43:13 +00:00
# trim the "/" in /install/sles11.3/x86_64/
$ pkgdir =~ s/\/$// ;
2013-02-28 06:20:30 +00:00
if ( $ pkgdir =~ /^($installroot\/$os\/$arch)$/ ) {
$ srcdirs [ 0 ] = "$pkgdir/1" ;
$ tmppkgdir = join ( "," , @ srcdirs ) ;
}
2012-12-21 08:30:39 +00:00
2008-03-12 19:16:44 +00:00
#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 ,
2011-06-27 03:46:29 +00:00
$ pkglistfile ,
2013-02-28 06:20:30 +00:00
$ tmppkgdir ,
$ os ,
2012-07-04 06:11:22 +00:00
$ partfile
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/";
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
)
{
#TODO: driver slipstream, targetted for network.
2013-01-10 13:56:49 +00:00
# Copy the install resource to /tftpboot and check to only copy once
my $ docopy = 0 ;
my $ tftppath ;
my $ rtftppath ; # the relative tftp path without /tftpboot/
if ( $ imagename ) {
$ tftppath = "/$tftpdir/xcat/osimage/$imagename" ;
$ rtftppath = "xcat/osimage/$imagename" ;
unless ( $ donetftp { $ imagename } ) {
$ docopy = 1 ;
$ donetftp { $ imagename } = 1 ;
}
} else {
$ tftppath = "/$tftpdir/xcat/$os/$arch/$profile" ;
$ rtftppath = "xcat/$os/$arch/$profile" ;
unless ( $ donetftp { "$os|$arch|$profile|$tftpdir" } ) {
$ docopy = 1 ;
$ donetftp { "$os|$arch|$profile|$tftpdir" } = 1 ;
2012-07-05 14:59:08 +00:00
}
2013-01-10 13:56:49 +00:00
}
if ( $ docopy ) {
2012-07-05 14:59:08 +00:00
mkpath ( "$tftppath" ) ;
2008-04-04 15:52:39 +00:00
if ( $ arch =~ /x86_64/ )
2008-03-12 19:16:44 +00:00
{
2013-07-04 05:06:50 +00:00
unless ( $ noupdateinitrd ) {
2013-07-15 03:04:36 +00:00
copy ( "$pkgdir/1/boot/$arch/loader/linux" , "$tftppath" ) ;
2013-07-04 05:06:50 +00:00
copy ( "$pkgdir/1/boot/$arch/loader/initrd" , "$tftppath" ) ;
2013-11-19 11:27:11 +00:00
@ dd_drivers = & insert_dd ( $ callback , $ os , $ arch , "$tftppath/initrd" , "$tftppath/linux" , $ driverupdatesrc , $ netdrivers , $ osupdir , $ ignorekernelchk ) ;
2013-07-04 05:06:50 +00:00
}
2008-04-04 15:52:39 +00:00
} elsif ( $ arch =~ /x86/ ) {
2013-07-04 05:06:50 +00:00
unless ( $ noupdateinitrd ) {
2013-07-15 03:04:36 +00:00
copy ( "$pkgdir/1/boot/i386/loader/linux" , "$tftppath" ) ;
2013-07-04 05:06:50 +00:00
copy ( "$pkgdir/1/boot/i386/loader/initrd" , "$tftppath" ) ;
2013-11-19 11:27:11 +00:00
@ dd_drivers = & insert_dd ( $ callback , $ os , $ arch , "$tftppath/initrd" , "$tftppath/linux" , $ driverupdatesrc , $ netdrivers , $ osupdir , $ ignorekernelchk ) ;
2013-07-04 05:06:50 +00:00
}
2008-03-12 19:16:44 +00:00
}
elsif ( $ arch =~ /ppc/ )
{
2013-07-04 05:06:50 +00:00
unless ( $ noupdateinitrd ) {
copy ( "$pkgdir/1/suseboot/inst64" , "$tftppath" ) ;
2013-11-19 11:27:11 +00:00
@ dd_drivers = & insert_dd ( $ callback , $ os , $ arch , "$tftppath/inst64" , undef , $ driverupdatesrc , $ netdrivers , $ osupdir , $ ignorekernelchk ) ;
2013-07-04 05:06:50 +00:00
}
2008-03-12 19:16:44 +00:00
}
}
#We have a shot...
2012-02-15 21:04:42 +00:00
my $ ent = $ resents - > { $ node } - > [ 0 ] ;
my $ sent = $ hments - > { $ node } - > [ 0 ] ; #hmtab->getNodeAttribs($node, ['serialport', 'serialspeed', 'serialflow']);
2012-02-20 07:20:41 +00:00
my $ netserver ;
if ( $ ent and $ ent - > { xcatmaster } ) {
$ netserver = $ ent - > { xcatmaster } ;
} else {
$ netserver = '!myipfn!' ;
}
2011-11-21 16:14:12 +00:00
if ( $ ent and $ ent - > { nfsserver } )
2008-03-12 19:16:44 +00:00
{
2011-11-21 16:14:12 +00:00
$ netserver = $ ent - > { nfsserver } ;
2008-03-12 19:16:44 +00:00
}
2014-04-11 09:40:34 +00:00
if ( $ ::XCATSITEVALS { managedaddressmode } =~ /static/ ) {
2014-04-17 10:04:54 +00:00
unless ( $ netserver eq '!myipfn!' ) {
my ( $ host , $ ip ) = xCAT::NetworkUtils - > gethostnameandip ( $ netserver ) ;
$ netserver = $ ip ;
}
2014-04-11 09:40:34 +00:00
}
2013-01-16 18:44:54 +00:00
my $ httpprefix = $ pkgdir ;
if ( $ installroot =~ /\/$/ ) { #must prepend /install/
$ httpprefix =~ s/^$installroot/\/install\// ;
} else {
$ httpprefix =~ s/^$installroot/\/install/ ;
}
2008-03-12 19:16:44 +00:00
my $ kcmdline =
2012-06-19 20:17:42 +00:00
"quiet autoyast=$httpmethod://"
2012-06-20 19:29:00 +00:00
. $ netserver . ":" . $ httpport
2013-01-16 18:44:54 +00:00
. "/install/autoinst/"
2008-03-12 19:16:44 +00:00
. $ node
2012-06-19 20:17:42 +00:00
. " install=$httpmethod://"
2012-06-20 19:29:00 +00:00
. $ netserver . ":" . $ httpport
2013-01-16 18:44:54 +00:00
. "$httpprefix/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/$_" ;
}
2014-04-11 09:40:34 +00:00
#if site.managedaddressmode=static, specify the network configuration as kernel options
#to avoid multicast dhcp
if ( $ ::XCATSITEVALS { managedaddressmode } =~ /static/ ) {
my ( $ ipaddr , $ hostname , $ gateway , $ netmask ) = xCAT::NetworkUtils - > getNodeNetworkCfg ( $ node ) ;
2014-04-17 10:04:54 +00:00
unless ( $ ipaddr ) {
$ callback - > (
{
error = > [
"cannot resolve the ip address of $node"
] ,
errorcode = > [ 1 ]
}
) ;
2014-04-11 09:40:34 +00:00
}
2014-04-17 10:04:54 +00:00
if ( $ gateway eq '<xcatmaster>' ) {
$ gateway = xCAT::NetworkUtils - > my_ip_facing ( $ ipaddr ) ;
}
$ kcmdline . = " hostip=$ipaddr netmask=$netmask gateway=$gateway hostname=$hostname " ;
my % nameservers = % { xCAT::NetworkUtils - > getNodeNameservers ( [ $ node ] ) } ;
my @ nameserverARR = split ( "," , $ nameservers { $ node } ) ;
my @ nameserversIP ;
foreach ( @ nameserverARR )
{
my $ ip ;
if ( $ _ eq '<xcatmaster>' ) {
$ ip = xCAT::NetworkUtils - > my_ip_facing ( $ gateway ) ;
} else {
( undef , $ ip ) = xCAT::NetworkUtils - > gethostnameandip ( $ _ ) ;
}
push @ nameserversIP , $ ip ;
}
2014-04-11 09:40:34 +00:00
if ( scalar @ nameserversIP ) {
2014-05-09 09:02:45 +00:00
$ kcmdline . = " Nameserver=" . join ( "," , @ nameserversIP ) ;
2014-04-11 09:40:34 +00:00
}
2014-05-09 09:02:45 +00:00
my $ nd = xCAT::NetworkUtils - > getNodeDomains ( [ $ node ] ) ;
my % nodedomains = %$ nd ;
my $ domain = $ nodedomains { $ node } ;
$ kcmdline . = " Domain=$domain " ;
2014-06-11 09:53:37 +00:00
$ kcmdline . = " netwait=10 " ;
2014-04-11 09:40:34 +00:00
}
2014-05-09 09:02:45 +00:00
2014-04-11 09:40:34 +00:00
2014-05-09 09:02:45 +00:00
2014-04-11 09:40:34 +00:00
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" ;
}
2012-07-05 14:59:08 +00:00
my $ kernelpath ;
my $ initrdpath ;
2008-03-12 19:16:44 +00:00
if ( $ arch =~ /x86/ )
{
2013-01-10 13:56:49 +00:00
$ kernelpath = "$rtftppath/linux" ;
$ initrdpath = "$rtftppath/initrd" ;
2008-04-25 15:36:56 +00:00
$ bptab - > setNodeAttribs (
2008-03-12 19:16:44 +00:00
$ node ,
{
2012-07-05 14:59:08 +00:00
kernel = > $ kernelpath ,
initrd = > $ initrdpath ,
2008-03-12 19:16:44 +00:00
kcmdline = > $ kcmdline
}
) ;
}
elsif ( $ arch =~ /ppc/ )
{
2013-01-10 13:56:49 +00:00
$ kernelpath = "$rtftppath/inst64" ;
2008-04-25 15:36:56 +00:00
$ bptab - > setNodeAttribs (
2008-03-12 19:16:44 +00:00
$ node ,
{
2012-07-05 14:59:08 +00:00
kernel = > $ kernelpath ,
2008-03-12 19:16:44 +00:00
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
}
2012-08-09 04:07:40 +00:00
#my $rc = xCAT::TableUtils->create_postscripts_tar();
2008-05-01 14:45:30 +00:00
#if ($rc != 0)
#{
# xCAT::MsgUtils->message("S", "Error creating postscripts tar file.");
#}
2007-10-26 22:44:33 +00:00
}
2013-08-23 06:32:02 +00:00
sub mksysclone
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
my @ nodes = @ { $ request - > { node } } ;
my $ osimagetab ;
my % img_hash = ( ) ;
my $ installroot ;
my $ globaltftpdir ;
$ installroot = "/install" ;
$ globaltftpdir = "/tftpboot" ;
my @ ents = xCAT::TableUtils - > get_site_attribute ( "installdir" ) ;
my $ site_ent = $ ents [ 0 ] ;
if ( defined ( $ site_ent ) )
{
$ installroot = $ site_ent ;
}
@ ents = xCAT::TableUtils - > get_site_attribute ( "tftpdir" ) ;
$ site_ent = $ ents [ 0 ] ;
if ( defined ( $ site_ent ) )
{
$ globaltftpdir = $ site_ent ;
}
my $ node ;
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
my $ restab = xCAT::Table - > new ( 'noderes' ) ;
my $ bptab = xCAT::Table - > new ( 'bootparams' , - create = > 1 ) ;
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
my % osents = % { $ ostab - > getNodesAttribs ( \ @ nodes , [ 'os' , 'arch' , 'provmethod' ] ) } ;
my % rents =
% { $ restab - > getNodesAttribs ( \ @ nodes ,
[ 'xcatmaster' , 'nfsserver' , 'tftpdir' , 'primarynic' , 'installnic' ] ) } ;
my % hents =
% { $ hmtab - > getNodesAttribs ( \ @ nodes ,
[ 'serialport' , 'serialspeed' , 'serialflow' ] ) } ;
my $ xcatdport = "3001" ;
my @ entries = xCAT::TableUtils - > get_site_attribute ( "xcatdport" ) ;
if ( defined ( $ entries [ 0 ] ) ) {
$ xcatdport = $ entries [ 0 ] ;
}
my @ entries = xCAT::TableUtils - > get_site_attribute ( "master" ) ;
my $ master_entry = $ entries [ 0 ] ;
require xCAT::Template ;
my $ flag_return = 0 ;
# Warning message for nodeset <noderange> install/netboot/statelite
foreach my $ knode ( keys % osents )
{
my $ ent = $ osents { $ knode } - > [ 0 ] ;
if ( $ ent && $ ent - > { provmethod } && ( $ ent - > { provmethod } eq 'sysclone' ) ) {
$ callback - > ( { error = > [ "$knode: The provmethod \"sysclone\" have been deprecated. use \"nodeset <noderange> osimage=<osimage_name>\" instead." ] ,
errorcode = > [ 1 ] } ) ;
# Do not print this warning message multiple times
$ flag_return = 1 ;
}
}
if ( $ flag_return == 1 ) {
return ;
}
# copy postscripts
my $ pspath = "$installroot/sysclone/scripts/post-install/" ;
my $ clusterfile = "$installroot/sysclone/scripts/cluster.txt" ;
mkpath ( "$pspath" ) ;
2014-08-25 07:15:58 +00:00
copy ( "$installroot/postscripts/replace_byid_device" , "$pspath/11all.replace_byid_device" ) ;
2013-08-23 06:32:02 +00:00
copy ( "$installroot/postscripts/configefi" , "$pspath/15all.configefi" ) ;
copy ( "$installroot/postscripts/updatenetwork" , "$pspath/16all.updatenetwork" ) ;
copy ( "$installroot/postscripts/runxcatpost" , "$pspath/17all.runxcatpost" ) ;
2014-06-19 08:48:08 +00:00
copy ( "$installroot/postscripts/makeinitrd" , "$pspath/20all.makeinitrd" ) ;
2013-08-27 03:51:26 +00:00
copy ( "$installroot/postscripts/killsyslog" , "$pspath/99all.killsyslog" ) ;
2013-08-23 06:32:02 +00:00
unless ( - r "$pspath/10all.fix_swap_uuids" )
{
mkpath ( "$pspath" ) ;
copy ( "/var/lib/systemimager/scripts/post-install/10all.fix_swap_uuids" , "$pspath" ) ;
}
2014-08-25 07:15:58 +00:00
#unless (-r "$pspath/11all.replace_byid_device")
#{
# mkpath("$pspath");
# copy("/var/lib/systemimager/scripts/post-install/11all.replace_byid_device","$pspath");
#}
2013-08-26 07:01:05 +00:00
2013-08-23 06:32:02 +00:00
unless ( - r "$pspath/95all.monitord_rebooted" )
{
mkpath ( "$pspath" ) ;
copy ( "/var/lib/systemimager/scripts/post-install/95all.monitord_rebooted" , "$pspath" ) ;
}
# copy hosts
copy ( "/etc/hosts" , "$installroot/sysclone/scripts/" ) ;
foreach $ node ( @ nodes )
{
my $ os ;
my $ tftpdir ;
my $ arch ;
my $ imagename ; # set it if running of 'nodeset osimage=xxx'
my $ xcatmaster ;
my $ instserver ;
my $ ient = $ rents { $ node } - > [ 0 ] ;
if ( $ ient and $ ient - > { xcatmaster } )
{
$ xcatmaster = $ ient - > { xcatmaster } ;
} else {
$ xcatmaster = $ master_entry ;
}
my $ osinst ;
if ( $ rents { $ node } - > [ 0 ] and $ rents { $ node } - > [ 0 ] - > { tftpdir } ) {
$ tftpdir = $ rents { $ node } - > [ 0 ] - > { tftpdir } ;
} else {
$ tftpdir = $ globaltftpdir ;
}
my $ ent = $ osents { $ node } - > [ 0 ] ;
if ( $ ent and $ ent - > { provmethod } and ( $ ent - > { provmethod } ne 'install' ) and ( $ ent - > { provmethod } ne 'netboot' ) and ( $ ent - > { provmethod } ne 'statelite' ) and ( $ ent - > { provmethod } ne 'sysclone' ) ) {
$ 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 } - > { osarch } = $ ref - > { 'osarch' } ;
} else {
$ callback - > (
{ error = > [ "The os image $imagename does not exists on the osimage table for $node" ] ,
errorcode = > [ 1 ] } ) ;
next ;
}
}
my $ ph = $ img_hash { $ imagename } ;
$ arch = $ ph - > { osarch } ;
}
# copy kernel and initrd from image dir to /tftpboot
my $ ramdisk_size = 200000 ;
2013-08-27 03:51:26 +00:00
if ( - r "$tftpdir/xcat/genesis.kernel.$arch"
and ( - r "$tftpdir/xcat/genesis.fs.$arch.gz"
or - r "$tftpdir/xcat/genesis.fs.$arch.lzma" ) )
2013-08-23 06:32:02 +00:00
{
#We have a shot...
my $ ent = $ rents { $ node } - > [ 0 ] ;
my $ sent = $ hents { $ node } - > [ 0 ] ;
my $ kcmdline = "ramdisk_size=$ramdisk_size" ;
my $ ksdev = "" ;
if ( $ ent - > { installnic } )
{
$ ksdev = $ ent - > { installnic } ;
}
elsif ( $ ent - > { primarynic } )
{
$ ksdev = $ ent - > { primarynic } ;
}
else
{
$ ksdev = "bootif" ; #if not specified, fall back to bootif
}
if ( $ ksdev eq "mac" )
{
my $ mactab = xCAT::Table - > new ( "mac" ) ;
my $ macref = $ mactab - > getNodeAttribs ( $ node , [ 'mac' ] ) ;
$ ksdev = $ macref - > { mac } ;
}
unless ( $ ksdev eq "bootif" ) {
$ kcmdline . = " netdevice=" . $ ksdev ;
}
if ( $ arch =~ /ppc/ ) {
$ kcmdline . = " dhcptimeout=150" ;
}
if ( defined ( $ sent - > { serialport } ) )
{
unless ( $ sent - > { serialspeed } )
{
$ callback - > ( { error = > [ "serialport defined, but no serialspeed for $node in nodehm table" ] ,
errorcode = > [ 1 ] } ) ;
}
else {
#go cmdline if serial console is requested, the shiny ansi is just impractical
$ kcmdline . = " cmdline console=tty0 console=ttyS"
. $ sent - > { serialport } . ","
. $ sent - > { serialspeed } ;
if ( $ sent - > { serialflow } =~ /(hard|cts|ctsrts)/ ) {
$ kcmdline . = "n8r" ;
}
}
}
2013-08-27 03:51:26 +00:00
$ kcmdline . = " XCAT=$xcatmaster:$xcatdport xcatd=$xcatmaster:$xcatdport SCRIPTNAME=$imagename" ;
2013-08-23 06:32:02 +00:00
2014-08-25 07:15:58 +00:00
my $ nodetab = xCAT::Table - > new ( 'nodetype' ) ;
my $ archref = $ nodetab - > getNodeAttribs ( $ node , [ 'arch' ] ) ;
if ( $ archref - > { arch } eq "ppc64" ) {
my $ mactab = xCAT::Table - > new ( 'mac' ) ;
my $ macref = $ mactab - > getNodeAttribs ( $ node , [ 'mac' ] ) ;
my $ formatmac = $ macref - > { mac } ;
$ formatmac =~ s/:/-/g ;
$ formatmac = "01-" . $ formatmac ;
$ kcmdline . = " BOOTIF=$formatmac " ;
}
2013-08-27 03:51:26 +00:00
my $ i = "xcat/genesis.fs.$arch.gz" ;
if ( - r "$tftpdir/xcat/genesis.fs.$arch.lzma" ) {
$ i = "xcat/genesis.fs.$arch.lzma" ;
}
2013-08-23 06:32:02 +00:00
$ bptab - > setNodeAttribs (
$ node ,
{
kernel = > "xcat/genesis.kernel.$arch" ,
2013-08-27 03:51:26 +00:00
initrd = > $ i ,
2013-08-23 06:32:02 +00:00
kcmdline = > $ kcmdline
}
) ;
}
else
{
$ callback - > ( { error = > [ "Kernel and initrd not found in $tftpdir/xcat" ] ,
errorcode = > [ 1 ] } ) ;
}
# assign nodes to an image
if ( - r "$clusterfile" )
{
my $ cmd = qq{ cat $clusterfile | grep "$node" } ;
my $ out = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC == 0 )
{
my $ out = `sed -i /$node./d $clusterfile` ;
}
}
2014-06-19 08:48:08 +00:00
2013-08-23 06:32:02 +00:00
my $ cmd = qq{ echo "$node:compute:$imagename:" >> $clusterfile } ;
2014-06-19 08:48:08 +00:00
my $ rc = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
my $ imagedir ;
my $ osimagetab = xCAT::Table - > new ( 'linuximage' ) ;
my $ osimageentry = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'rootimgdir' ) ;
if ( $ osimageentry ) {
$ imagedir = $ osimageentry - > { rootimgdir } ;
$ imagedir =~ s/^(\/.*)\/.+\/?$/$1/ ;
} else {
$ imagedir = "$installroot/sysclone/images" ;
$ cmd = "chdef -t osimage $imagename rootimgdir=$imagedir/$imagename" ;
$ rc = `$cmd` ;
}
my $ cfgimagedir = `cat /etc/systemimager/rsync_stubs/40$imagename|grep path` ;
chomp ( $ cfgimagedir ) ;
$ cfgimagedir =~ s/^\s+path=(\/.*)\/.+$/$1/g ;
if ( $ imagedir ne $ cfgimagedir ) {
my $ oldstr = `cat /etc/systemimager/rsync_stubs/40$imagename|grep path` ;
chomp ( $ oldstr ) ;
$ oldstr =~ s/\//\\\\\//g ;
my $ targetstr = "\tpath=" . $ imagedir . "/" . $ imagename ;
$ targetstr =~ s/\//\\\\\//g ;
$ cmd = "sed -i \"s/$oldstr/$targetstr/\" /etc/systemimager/rsync_stubs/40$imagename" ;
$ rc = `$cmd` ;
}
$ rc = `export PERL5LIB=/usr/lib/perl5/site_perl/;LANG=C si_mkrsyncd_conf` ;
2013-08-23 06:32:02 +00:00
2014-06-19 08:48:08 +00:00
unless ( - r "$imagedir/$imagename/opt/xcat/xcatdsklspost" )
2013-08-23 06:32:02 +00:00
{
2014-06-19 08:48:08 +00:00
mkpath ( "$imagedir/$imagename/opt/xcat/" ) ;
copy ( "$installroot/postscripts/xcatdsklspost" , "$imagedir/$imagename/opt/xcat/" ) ;
2013-08-23 06:32:02 +00:00
}
}
# check systemimager-server-rsyncd to make sure it's running.
2014-06-10 13:11:07 +00:00
#my $out = xCAT::Utils->runcmd("service systemimager-server-rsyncd status", -1);
#if ($::RUNCMD_RC != 0) { # not running
my $ retcode = xCAT::Utils - > checkservicestatus ( "systemimager-server-rsyncd" ) ;
if ( $ retcode != 0 ) {
my $ rc = xCAT::Utils - > startservice ( "systemimager-server-rsyncd" ) ;
2013-08-23 06:32:02 +00:00
if ( $ rc != 0 ) {
return 1 ;
}
}
}
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 ;
2012-06-08 09:06:09 +00:00
my $ mntpath = undef ;
my $ inspection = undef ;
2012-11-08 07:02:56 +00:00
my $ noosimage = undef ;
2013-01-07 08:39:52 +00:00
my $ nonoverwrite = undef ;
2012-06-08 09:06:09 +00:00
2008-03-12 19:16:44 +00:00
$ installroot = "/install" ;
2012-05-23 05:50:08 +00:00
#my $sitetab = xCAT::Table->new('site');
#if ($sitetab)
#{
#(my $ref) = $sitetab->getAttribs({key => 'installdir'}, 'value');
#print Dumper($ref);
2012-08-09 04:07:40 +00:00
my @ entries = xCAT::TableUtils - > get_site_attribute ( "installdir" ) ;
2012-05-23 05:50:08 +00:00
my $ t_entry = $ entries [ 0 ] ;
if ( defined ( $ t_entry ) ) {
$ installroot = $ t_entry ;
2008-03-12 19:16:44 +00:00
}
2012-05-23 05:50:08 +00:00
#}
2008-03-12 19:16:44 +00:00
@ ARGV = @ { $ request - > { arg } } ;
GetOptions (
'n=s' = > \ $ distname ,
'a=s' = > \ $ arch ,
2012-06-08 09:06:09 +00:00
'm=s' = > \ $ mntpath ,
'i' = > \ $ inspection ,
2012-11-08 07:02:56 +00:00
'p=s' = > \ $ path ,
'o' = > \ $ noosimage ,
2013-01-07 08:39:52 +00:00
'w' = > \ $ nonoverwrite ,
) ;
2012-06-08 09:06:09 +00:00
unless ( $ mntpath )
2008-03-12 19:16:44 +00:00
{
2012-06-08 09:06:09 +00:00
#this plugin needs $mntpath...
2008-03-12 19:16:44 +00:00
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 ;
}
2013-01-07 08:39:52 +00:00
#parse the disc info of the os media to get the distribution, arch of the os
2012-06-08 09:06:09 +00:00
unless ( - r $ mntpath . "/content" )
2008-03-12 19:16:44 +00:00
{
return ;
}
my $ dinfo ;
2012-06-08 09:06:09 +00:00
open ( $ dinfo , $ mntpath . "/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 ;
2012-06-08 09:06:09 +00:00
opendir ( $ dirh , $ mntpath ) ;
2008-03-12 19:16:44 +00:00
my $ discnumber ;
my $ totaldiscnumber ;
while ( my $ pname = readdir ( $ dirh ) )
{
if ( $ pname =~ /media.(\d+)/ )
{
$ discnumber = $ 1 ;
chomp ( $ discnumber ) ;
my $ mfile ;
2012-06-08 09:06:09 +00:00
open ( $ mfile , $ mntpath . "/" . $ pname . "/media" ) ;
2008-03-12 19:16:44 +00:00
<$mfile> ;
<$mfile> ;
$ totaldiscnumber = <$mfile> ;
chomp ( $ totaldiscnumber ) ;
close ( $ mfile ) ;
2012-06-08 09:06:09 +00:00
open ( $ mfile , $ mntpath . "/" . $ pname . "/products" ) ;
2008-03-12 19:16:44 +00:00
my $ prod = <$mfile> ;
close ( $ mfile ) ;
2011-06-27 03:46:29 +00:00
if ( $ prod =~ m/SUSE-Linux-Enterprise-Server/ || $ prod =~ m/SUSE-Linux-Enterprise-Software-Development-Kit/ )
2008-03-12 19:16:44 +00:00
{
2012-06-08 09:06:09 +00:00
if ( - f "$mntpath/content" ) {
2010-05-25 15:29:28 +00:00
my $ content ;
2012-06-08 09:06:09 +00:00
open ( $ content , "<" , "$mntpath/content" ) ;
2010-05-25 15:29:28 +00:00
my @ contents = <$content> ;
close ( $ content ) ;
foreach ( @ contents ) {
if ( /^VERSION/ ) {
2012-11-13 06:34:53 +00:00
my @ verpair = split /\s+|-/ ;
2010-05-25 15:29:28 +00:00
$ 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 ] } ;
}
2011-06-27 03:46:29 +00:00
if ( $ prod =~ m/Software-Development-Kit/ ) {
2013-11-07 18:44:04 +00:00
if ( $ distname eq 'sles11.3' ) {
if ( $ discnumber == 1 and $ totaldiscnumber == 1 ) { #disc 3, aka disc1 of 'debug'
$ discnumber = 3 ;
}
}
2011-06-27 03:46:29 +00:00
$ discnumber = 'sdk' . $ discnumber ;
}
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
}
}
2012-12-04 13:25:52 +00:00
closedir ( $ dirh ) ;
2012-06-08 09:06:09 +00:00
2008-03-12 19:16:44 +00:00
unless ( $ distname and $ discnumber )
{
2013-01-07 08:39:52 +00:00
#failed to parse the disc info
return ;
2008-03-12 19:16:44 +00:00
}
2012-06-08 09:06:09 +00:00
2008-03-12 19:16:44 +00:00
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 ;
}
}
2012-06-08 09:06:09 +00:00
if ( $ inspection )
{
$ callback - > (
{
info = >
"DISTNAME:$distname\n" . "ARCH:$arch\n" . "DISCNO:$discnumber\n"
}
) ;
return ;
}
2008-03-12 19:16:44 +00:00
% { $ request } = ( ) ; #clear request we've got it.
2012-06-08 09:06:09 +00:00
my $ defaultpath = "$installroot/$distname/$arch" ;
unless ( $ path )
{
$ path = $ defaultpath ;
}
2013-04-02 19:19:30 +00:00
my $ osdistroname = $ distname . "-" . $ arch ;
if ( $ ::XCATSITEVALS { osimagerequired } ) {
my ( $ nohaveimages , $ errstr ) = xCAT::SvrUtils - > update_tables_with_templates ( $ distname , $ arch , $ path , $ osdistroname , checkonly = > 1 ) ;
if ( $ nohaveimages ) {
2013-04-03 20:57:18 +00:00
$ callback - > ( { error = > "No Templates found to support $distname($arch)" , errorcode = > 2 } ) ;
2013-04-02 19:19:30 +00:00
return ;
}
}
2012-06-08 09:06:09 +00:00
my $ ospkgpath = "$path/$discnumber" ;
2013-01-07 08:39:52 +00:00
#tranverse the directory structure of the os media and get the fingerprint
my @ filelist = ( ) ;
find (
{
"wanted" = > sub { s/$mntpath/\./ ; push ( @ filelist , $ _ ) ; } ,
"no_chdir" = > 1 ,
"follow" = > 0 ,
} ,
$ mntpath
) ;
my @ sortedfilelist = sort @ filelist ;
my $ fingerprint = md5_hex ( join ( "" , @ sortedfilelist ) ) ;
#check whether the os media has already been copied in
my $ disccopiedin = 0 ;
my $ tabosdistro = xCAT::Table - > new ( 'osdistro' , - create = > 1 ) ;
if ( $ tabosdistro )
{
my % keyhash = ( ) ;
$ keyhash { osdistroname } = $ osdistroname ;
my $ ref = undef ;
$ ref = $ tabosdistro - > getAttribs ( \ % keyhash , 'dirpaths' ) ;
if ( $ ref and $ ref - > { dirpaths } )
{
my @ dirpaths = split ( ',' , $ ref - > { dirpaths } ) ;
foreach ( @ dirpaths )
{
if ( 0 == system ( "grep -E " . "\"\\<$fingerprint\\>\"" . " $_" . "/.fingerprint" ) )
{
$ disccopiedin = 1 ;
if ( $ nonoverwrite )
{
$ callback - > (
{
info = >
[ "The disc iso has already been copied in!" ]
}
) ;
$ tabosdistro - > close ( ) ;
return ;
}
last ;
}
}
}
}
$ tabosdistro - > close ( ) ;
2012-06-08 09:06:09 +00:00
2013-01-07 08:39:52 +00:00
#create the destination directory of the os media copying
2012-06-08 09:06:09 +00:00
if ( - l $ ospkgpath )
{
unlink ( $ ospkgpath ) ;
} elsif ( - d $ ospkgpath )
{
rmtree ( $ ospkgpath ) ;
}
mkpath ( "$ospkgpath" ) ;
2008-03-12 19:16:44 +00:00
my $ omask = umask 0022 ;
umask $ omask ;
2012-06-08 09:06:09 +00:00
$ callback - > (
{ data = > "Copying media to $ospkgpath" } ) ;
2008-04-21 20:43:07 +00:00
my $ rc ;
2012-12-04 13:25:52 +00:00
2013-01-07 08:39:52 +00:00
#the intrupt handler of SIGINT and SIGTERM
2012-12-04 13:25:52 +00:00
$ SIG { INT } = $ SIG { TERM } = sub {
2008-06-02 23:51:40 +00:00
foreach ( @ cpiopid ) {
2012-12-04 13:25:52 +00:00
kill 15 , $ _ ;
use POSIX ":sys_wait_h" ;
my $ kid = 0 ;
do {
$ kid = waitpid ( $ _ , WNOHANG ) ;
} while $ kid != $ _ ;
}
if ( $ mntpath ) {
2008-08-11 18:36:10 +00:00
chdir ( "/" ) ;
2012-10-16 11:22:53 +00:00
system ( "umount $mntpath" ) ;
2012-12-04 13:25:52 +00:00
system ( "rm -rf $mntpath" ) ;
}
exit ;
2008-05-15 15:48:34 +00:00
} ;
2012-12-04 13:25:52 +00:00
2013-01-07 08:39:52 +00:00
#media copy process
2008-04-21 20:43:07 +00:00
my $ kid ;
2012-06-08 09:06:09 +00:00
chdir $ mntpath ;
2013-01-07 08:39:52 +00:00
my $ numFiles = scalar ( @ sortedfilelist ) ;
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 ;
2012-12-04 13:25:52 +00:00
chdir ( "/" ) ;
2013-01-07 08:39:52 +00:00
for ( @ sortedfilelist ) {
print $ kid $ _ . "\n" ;
2008-04-21 20:43:07 +00:00
}
close ( $ kid ) ;
$ rc = $? ;
} else {
2012-06-08 09:06:09 +00:00
my $ c = "nice -n 20 cpio -vdump $ospkgpath" ;
2013-01-07 08:39:52 +00:00
my $ k2 = open ( PIPE , "$c 2>&1 |" ) || exit ( 1 ) ;
2012-12-04 13:25:52 +00:00
chdir ( "/" ) ;
2008-06-02 23:51:40 +00:00
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 ;
}
2013-01-07 08:39:52 +00:00
if ( $ copied == $ numFiles )
{
#media copy success
exit ( 0 ) ;
}
else
{
#media copy failed
exit ( 1 ) ;
}
2008-04-21 20:43:07 +00:00
}
# system(
# "cd $path; find . | nice -n 20 cpio -dump $installroot/$distname/$arch/$discnumber/"
# );
2012-06-08 09:06:09 +00:00
chmod 0755 , "$path" ;
chmod 0755 , "$ospkgpath" ;
2013-01-07 08:39:52 +00:00
#append the fingerprint to the .fingerprint file to indicate that the os media has been copied in
unless ( $ disccopiedin )
{
my $ ret = open ( my $ fpd , ">>" , "$path/.fingerprint" ) ;
if ( $ ret ) {
print $ fpd "$fingerprint," ;
close ( $ fpd ) ;
}
}
#if the destination path is not the default, create a symlink named by the default path to the specified path
2012-06-08 09:06:09 +00:00
unless ( $ path =~ /^($defaultpath)/ )
{
mkpath ( "$defaultpath/$discnumber" ) ;
if ( - d "$defaultpath/$discnumber" )
{
rmtree ( "$defaultpath/$discnumber" ) ;
}
else
{
unlink ( "$defaultpath/$discnumber" ) ;
}
my $ hassymlink = eval { symlink ( "" , "" ) ; 1 } ;
if ( $ hassymlink ) {
symlink ( $ ospkgpath , "$defaultpath/$discnumber" ) ;
} else
{
link ( $ ospkgpath , "$defaultpath/$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" } ) ;
2013-01-07 08:39:52 +00:00
2012-08-30 09:19:27 +00:00
my @ ret = xCAT::SvrUtils - > update_osdistro_table ( $ distname , $ arch , $ path , $ osdistroname ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osdistro tables: " . $ ret [ 1 ] } ) ;
2011-07-21 06:26:13 +00:00
}
2013-01-07 08:39:52 +00:00
#if --noosimage option is not specified, create the relevant osimage and linuximage entris
2012-11-08 07:02:56 +00:00
unless ( $ noosimage ) {
my @ ret = xCAT::SvrUtils - > update_tables_with_templates ( $ distname , $ arch , $ path , $ osdistroname ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables: " . $ ret [ 1 ] } ) ;
}
2013-03-30 07:51:25 +00:00
my @ ret = xCAT::SvrUtils - > update_tables_with_mgt_image ( $ distname , $ arch , $ path , $ osdistroname ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables for management node " . $ ret [ 1 ] } ) ;
}
2012-11-08 07:02:56 +00:00
my @ ret = xCAT::SvrUtils - > update_tables_with_diskless_image ( $ distname , $ arch , undef , "netboot" , $ path , $ osdistroname ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables for stateless: " . $ ret [ 1 ] } ) ;
}
my @ ret = xCAT::SvrUtils - > update_tables_with_diskless_image ( $ distname , $ arch , undef , "statelite" , $ path , $ osdistroname ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables for statelite: " . $ ret [ 1 ] } ) ;
}
}
2008-03-12 19:16:44 +00:00
}
2007-10-26 22:44:33 +00:00
}
2012-07-05 14:59:08 +00:00
# callback subroutine for 'find' command to return the path
my $ driver_name ;
my $ real_path ;
sub get_path ()
{
if ( $ File:: Find:: name =~ /\/$driver_name/ ) {
$ real_path = $ File:: Find:: name ;
}
}
2012-11-28 09:02:39 +00:00
# callback subroutine for 'find' command to return the path for all the matches
my @ all_real_path ;
sub get_all_path ()
{
if ( $ File:: Find:: name =~ /\/$driver_name/ ) {
push @ all_real_path , $ File:: Find:: name ;
}
}
2012-07-05 14:59:08 +00:00
# Get the driver disk or driver rpm from the osimage.driverupdatesrc
# The valid value: dud:/install/dud/dd.img,rpm:/install/rpm/d.rpm, if missing the tag: 'dud'/'rpm'
# the 'rpm' is default.
#
# If cannot find the driver disk from osimage.driverupdatesrc, will try to search driver disk
# from /install/driverdisk/<os>/<arch>
#
# For driver rpm, the driver list will be gotten from osimage.netdrivers. If not set, copy all the drivers from driver
# rpm to the initrd.
#
2010-08-12 09:05:22 +00:00
2012-07-05 14:59:08 +00:00
sub insert_dd () {
2010-08-12 09:05:22 +00:00
my $ callback = shift ;
2013-07-15 03:04:36 +00:00
if ( $ callback eq "xCAT_plugin::sles" ) {
$ callback = shift ;
}
2010-08-12 09:05:22 +00:00
my $ os = shift ;
my $ arch = shift ;
my $ img = shift ;
2013-07-15 03:04:36 +00:00
my $ kernelpath = shift ;
2012-07-05 14:59:08 +00:00
my $ driverupdatesrc = shift ;
my $ drivers = shift ;
2013-07-04 05:06:50 +00:00
my $ osupdirlist = shift ;
2013-11-19 11:27:11 +00:00
my $ ignorekernelchk = shift ;
2010-08-12 09:05:22 +00:00
2012-08-09 04:07:40 +00:00
my $ install_dir = xCAT::TableUtils - > getInstallDir ( ) ;
2010-08-12 09:05:22 +00:00
2012-07-05 14:59:08 +00:00
my $ cmd ;
my @ dd_list ;
my @ rpm_list ;
2013-11-19 11:27:11 +00:00
my @ vendor_rpm ; # the rpms from driverupdatesrc attribute
2012-07-05 14:59:08 +00:00
my @ driver_list ;
2012-10-16 05:58:29 +00:00
my $ Injectalldriver ;
2013-08-16 09:50:59 +00:00
my $ updatealldriver ;
2012-07-05 14:59:08 +00:00
my @ rpm_drivers ;
2013-07-04 05:06:50 +00:00
# since the all rpms for drivers searching will be extracted to one dir, the newer rpm should be
# extracted later so that the newer drivers will overwirte the older one if certain drvier is included
# in multiple rpms
#
# The order of rpm list in the @rpm_list should be: osdistroupdate1, osdistroupdate2, driverupdatesrc
#
# get the kernel-*.rpm from the dirpath of osdistroupdate
if ( $ osupdirlist ) {
my @ osupdirs = split ( /,/ , $ osupdirlist ) ;
foreach my $ osupdir ( @ osupdirs ) {
# find all the rpms start with kernel.*
my @ kernel_rpms = `find $osupdir -name kernel-*.rpm` ;
push @ rpm_list , @ kernel_rpms ;
}
}
2012-07-05 14:59:08 +00:00
# Parse the parameters to the the source of Driver update disk and Driver rpm, and driver list as well
if ( $ driverupdatesrc ) {
my @ srcs = split ( ',' , $ driverupdatesrc ) ;
foreach my $ src ( @ srcs ) {
if ( $ src =~ /dud:(.*)/i ) {
push @ dd_list , $ 1 ;
} elsif ( $ src =~ /rpm:(.*)/i ) {
push @ rpm_list , $ 1 ;
2013-11-19 11:27:11 +00:00
push @ vendor_rpm , $ 1 ;
2012-07-05 14:59:08 +00:00
} else {
push @ rpm_list , $ src ;
2013-11-19 11:27:11 +00:00
push @ vendor_rpm , $ src ;
2012-07-05 14:59:08 +00:00
}
}
}
if ( ! @ dd_list ) {
# get Driver update disk from the default path if not specified in osimage
# check the Driver Update Disk images, it can be .img or .iso
if ( - d "$install_dir/driverdisk/$os/$arch" ) {
$ cmd = "find $install_dir/driverdisk/$os/$arch -type f" ;
@ dd_list = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
}
2010-08-12 09:05:22 +00:00
}
2012-07-05 14:59:08 +00:00
foreach ( split /,/ , $ drivers ) {
2012-10-16 05:58:29 +00:00
if ( /^allupdate$/ ) {
$ Injectalldriver = 1 ;
next ;
2013-08-16 09:50:59 +00:00
} elsif ( /^updateonly$/ ) {
$ updatealldriver = 1 ;
next ;
2012-10-16 05:58:29 +00:00
}
2012-07-05 14:59:08 +00:00
unless ( /\.ko$/ ) {
s/$/.ko/ ;
}
push @ driver_list , $ _ ;
}
2010-08-12 09:05:22 +00:00
chomp ( @ dd_list ) ;
2012-07-05 14:59:08 +00:00
chomp ( @ rpm_list ) ;
2013-11-19 11:27:11 +00:00
chomp ( @ vendor_rpm ) ;
2012-07-05 14:59:08 +00:00
2013-08-16 09:50:59 +00:00
unless ( @ dd_list || ( @ rpm_list && ( $ Injectalldriver || $ updatealldriver || @ driver_list ) ) ) {
2012-10-16 05:58:29 +00:00
return ( ) ;
2010-08-12 09:05:22 +00:00
}
# 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
2012-07-05 14:59:08 +00:00
# This only needs to be done for ppc or handling the driver rpm
# For the driver disk against x86, append the driver disk to initrd directly
2013-08-16 09:50:59 +00:00
if ( $ arch =~ /ppc/ || ( @ rpm_list && ( $ Injectalldriver || $ updatealldriver || @ driver_list ) ) ) {
2012-07-05 14:59:08 +00:00
if ( $ arch =~ /ppc/ ) {
$ cmd = "gunzip --quiet -c $pkgdir/1/suseboot/initrd64 > $dd_dir/initrd" ;
} elsif ( $ arch =~ /x86/ ) {
$ cmd = "gunzip --quiet -c $img > $dd_dir/initrd" ;
}
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update 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 ( ) ;
}
# Start to load the drivers from rpm packages
2013-08-16 09:50:59 +00:00
if ( @ rpm_list && ( $ Injectalldriver || $ updatealldriver || @ driver_list ) ) {
2012-07-05 14:59:08 +00:00
# Extract the files from rpm to the tmp dir
mkpath "$dd_dir/rpm" ;
2013-07-15 03:04:36 +00:00
my $ new_kernel_ver ;
2012-07-05 14:59:08 +00:00
foreach my $ rpm ( @ rpm_list ) {
if ( - r $ rpm ) {
$ cmd = "cd $dd_dir/rpm; rpm2cpio $rpm | cpio -idum" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not extract files from the rpm $rpm." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
} else {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not read the rpm $rpm." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
2012-11-28 09:02:39 +00:00
2013-07-15 03:04:36 +00:00
# get the new kernel if it exists in the update distro
2013-07-31 10:57:34 +00:00
my @ new_kernels = <$dd_dir/rpm/boot/vmlinu*> ;
2013-07-15 03:04:36 +00:00
foreach my $ new_kernel ( @ new_kernels ) {
2013-08-16 09:50:59 +00:00
if ( - r $ new_kernel && $ new_kernel =~ /\/vmlinu[zx]-(.*(x86_64|ppc64|default))$/ ) {
$ new_kernel_ver = $ 1 ;
$ cmd = "/bin/mv -f $new_kernel $dd_dir/rpm/newkernel" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not move $new_kernel to $dd_dir/rpm/newkernel." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
2013-07-15 03:04:36 +00:00
}
2013-11-19 11:27:11 +00:00
}
}
2013-07-15 03:04:36 +00:00
2013-11-19 11:27:11 +00:00
# Extract files from vendor rpm when $ignorekernelchk is specified
if ( $ ignorekernelchk ) {
mkpath "$dd_dir/vendor_rpm" ;
foreach my $ rpm ( @ vendor_rpm ) {
if ( - r $ rpm ) {
$ cmd = "cd $dd_dir/vendor_rpm; rpm2cpio $rpm | cpio -idum" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not extract files from the rpm $rpm." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
} else {
2013-07-04 05:06:50 +00:00
my $ rsp ;
2013-11-19 11:27:11 +00:00
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not read the rpm $rpm." ;
2013-07-04 05:06:50 +00:00
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
2012-11-28 09:02:39 +00:00
}
}
2013-11-19 11:27:11 +00:00
# To skip the conflict of files that some rpm uses the xxx.ko.new as the name of the driver
# Change it back to xxx.ko here
$ driver_name = "\*ko.new" ;
@ all_real_path = ( ) ;
my @ rpmfiles = <$dd_dir/rpm/*> ;
if ( $ ignorekernelchk ) {
push @ rpmfiles , <$dd_dir/vendor_rpm/*> ;
}
find ( \ & get_all_path , @ rpmfiles ) ;
foreach my $ file ( @ all_real_path ) {
my $ newname = $ file ;
$ newname =~ s/\.new$// ;
$ cmd = "mv -f $file $newname" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not rename $file." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
}
2012-07-05 14:59:08 +00:00
# Copy the firmware to the rootimage
if ( - d "$dd_dir/rpm/lib/firmware" ) {
if ( ! - d "$dd_dir/initrd_img/lib" ) {
mkpath "$dd_dir/initrd_img/lib" ;
}
2013-07-04 05:06:50 +00:00
$ cmd = "/bin/cp -rf $dd_dir/rpm/lib/firmware $dd_dir/initrd_img/lib" ;
2012-07-05 14:59:08 +00:00
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not copy firmware to the initrd." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
}
2013-07-15 03:04:36 +00:00
# if the new kernel from update distro is not existed in initrd, create the path for it
if ( ! - r "$dd_dir/initrd_img/lib/modules/$new_kernel_ver/" ) {
mkpath ( "$dd_dir/initrd_img/lib/modules/$new_kernel_ver/" ) ;
2013-08-07 13:59:54 +00:00
# link the /modules to this new kernel dir
unlink "$dd_dir/initrd_img/modules" ;
$ cmd = "/bin/ln -sf lib/modules/$new_kernel_ver/initrd $dd_dir/initrd_img/modules" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not create link to the new kernel dir." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
2013-07-15 03:04:36 +00:00
}
2013-08-16 09:50:59 +00:00
# get the name list for all drivers in the original initrd if 'netdrivers=updateonly'
# then only the drivers in this list will be updated from the drvier rpms
if ( $ updatealldriver ) {
$ driver_name = "\*\.ko" ;
@ all_real_path = ( ) ;
find ( \ & get_all_path , <$dd_dir/initrd_img/lib/modules/*> ) ;
foreach my $ real_path ( @ all_real_path ) {
my $ driver = basename ( $ real_path ) ;
push @ driver_list , $ driver ;
}
}
2012-07-05 14:59:08 +00:00
# Copy the drivers to the rootimage
# Figure out the kernel version
my @ kernelpaths = <$dd_dir/initrd_img/lib/modules/*> ;
my @ kernelvers ;
2013-08-16 09:50:59 +00:00
if ( $ new_kernel_ver ) {
push @ kernelvers , $ new_kernel_ver ;
}
2012-07-05 14:59:08 +00:00
foreach ( @ kernelpaths ) {
2013-08-16 09:50:59 +00:00
my $ kernelv = basename ( $ _ ) ;
if ( $ kernelv =~ /^[\d\.]+/ ) {
if ( $ new_kernel_ver ) {
rmtree ( "$dd_dir/initrd_img/lib/modules/$kernelv" ) ;
} else {
push @ kernelvers , $ kernelv ;
}
}
2012-07-05 14:59:08 +00:00
}
foreach my $ kernelver ( @ kernelvers ) {
2013-11-19 11:27:11 +00:00
# if $ignorekernelchk is specified, copy all files from vendor_rpm dir to target kernel dir
if ( $ ignorekernelchk ) {
my @ kernelpath4vrpm = <$dd_dir/vendor_rpm/lib/modules/*> ;
foreach my $ path ( @ kernelpath4vrpm ) {
unless ( - d "$dd_dir/rpm/lib/modules/$kernelver" ) {
mkpath "$dd_dir/rpm/lib/modules/$kernelver" ;
}
$ cmd = "/bin/cp -rf $path/* $dd_dir/rpm/lib/modules/$kernelver" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not copy driver $path from vendor rpm." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
}
}
2013-07-04 05:06:50 +00:00
unless ( - d "$dd_dir/rpm/lib/modules/$kernelver" ) {
next ;
}
2013-11-19 11:27:11 +00:00
2012-07-05 14:59:08 +00:00
if ( @ driver_list ) {
# copy the specific drivers to initrd
foreach my $ driver ( @ driver_list ) {
$ driver_name = $ driver ;
2013-07-04 05:06:50 +00:00
@ all_real_path = ( ) ;
find ( \ & get_all_path , <$dd_dir/rpm/lib/modules/$kernelver/*> ) ;
2012-11-28 09:02:39 +00:00
# NOTE: for the initrd of sles that the drivers are put in the /lib/modules/$kernelver/initrd/
2013-07-04 05:06:50 +00:00
foreach my $ real_path ( @ all_real_path ) {
if ( $ real_path && $ real_path =~ m !$dd_dir/rpm/lib/modules/$kernelver/! ) {
if ( ! - d "$dd_dir/initrd_img/lib/modules/$kernelver/initrd" ) {
mkpath "$dd_dir/initrd_img/lib/modules/$kernelver/initrd" ;
}
$ cmd = "/bin/cp -rf $real_path $dd_dir/initrd_img/lib/modules/$kernelver/initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not copy driver $driver to the initrd." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
} else {
push @ rpm_drivers , $ driver ;
}
2012-07-05 14:59:08 +00:00
}
}
}
2012-10-16 05:58:29 +00:00
} elsif ( $ Injectalldriver ) {
2012-07-05 14:59:08 +00:00
# copy all the drviers to the initrd
2012-11-28 09:02:39 +00:00
$ driver_name = "\*\.ko" ;
@ all_real_path = ( ) ;
find ( \ & get_all_path , <$dd_dir/rpm/lib/modules/$kernelver/*> ) ;
2013-08-16 09:50:59 +00:00
foreach my $ real_path ( @ all_real_path ) {
2012-11-28 09:02:39 +00:00
# NOTE: for the initrd of sles that the drivers are put in the /lib/modules/$kernelver/initrd/
if ( $ real_path && $ real_path =~ m !$dd_dir/rpm/lib/modules/$kernelver/! ) {
if ( ! - d "$dd_dir/initrd_img/lib/modules/$kernelver/initrd" ) {
mkpath "$dd_dir/initrd_img/lib/modules/$kernelver/initrd" ;
}
2013-07-04 05:06:50 +00:00
$ cmd = "/bin/cp -rf $real_path $dd_dir/initrd_img/lib/modules/$kernelver/initrd" ;
2012-11-28 09:02:39 +00:00
my $ driver = basename ( $ real_path ) ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not copy driver $driver to the initrd." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
} else {
push @ rpm_drivers , $ driver ;
}
}
2012-07-05 14:59:08 +00:00
}
}
2010-08-12 09:05:22 +00:00
2012-07-05 14:59:08 +00:00
# regenerate the modules dependency
foreach my $ kernelver ( @ kernelvers ) {
$ cmd = "cd $dd_dir/initrd_img; depmod -b . $kernelver" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update failed. Could not generate the depdency for the drivers in the initrd." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
}
}
}
} # end of loading drivers from rpm packages
2010-08-12 09:05:22 +00:00
2013-07-31 10:57:34 +00:00
# Create the dir for driver update disk
mkpath ( "$dd_dir/initrd_img/cus_driverdisk" ) ;
2010-08-12 09:05:22 +00:00
2013-07-31 10:57:34 +00:00
# insert the driver update disk into the cus_driverdisk dir
foreach my $ dd ( @ dd_list ) {
copy ( $ dd , "$dd_dir/initrd_img/cus_driverdisk" ) ;
}
2010-08-12 09:05:22 +00:00
2013-07-31 10:57:34 +00:00
# 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 ( ) ;
}
2012-07-05 14:59:08 +00:00
2013-07-31 10:57:34 +00:00
# zip the initrd
#move ("$dd_dir/initrd.new", "$dd_dir/initrd");
$ cmd = "gzip -f $dd_dir/initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
2010-08-12 09:05:22 +00:00
2012-07-05 14:59:08 +00:00
if ( $ arch =~ /ppc/ ) {
2013-07-15 03:04:36 +00:00
if ( - r "$dd_dir/rpm/newkernel" ) {
# if there's new kernel from update distro, then use it
copy ( "$dd_dir/rpm/newkernel" , "$dd_dir/kernel" ) ;
} else {
# make sure the src kernel existed
$ cmd = "gunzip -c $pkgdir/1/suseboot/linux64.gz > $dd_dir/kernel" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
}
2012-07-05 14:59:08 +00:00
# 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 ( ) ;
}
} elsif ( $ arch =~ /x86/ ) {
2013-07-15 03:04:36 +00:00
if ( - r "$dd_dir/rpm/newkernel" ) {
# if there's new kernel from update distro, then use it
copy ( "$dd_dir/rpm/newkernel" , $ kernelpath ) ;
}
2012-07-05 14:59:08 +00:00
copy ( "$dd_dir/initrd.gz" , "$img" ) ;
2010-08-12 09:05:22 +00:00
}
2012-07-05 14:59:08 +00:00
} elsif ( $ arch =~ /x86/ ) {
2013-11-18 21:31:15 +00:00
mkpath ( "$dd_dir/initrd_img/cus_driverdisk" ) ;
# 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 ( ) ;
}
$ cmd = "gzip -f $dd_dir/initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
2012-07-05 14:59:08 +00:00
my $ rdhandle ;
my $ ddhandle ;
open ( $ rdhandle , ">>" , $ img ) ;
open ( $ ddhandle , "<" , "$dd_dir/initrd.gz" ) ;
binmode ( $ rdhandle ) ;
binmode ( $ ddhandle ) ;
{ local $/ = 32768 ; my $ block ; while ( $ block = <$ddhandle> ) { print $ rdhandle $ block ; } }
close ( $ rdhandle ) ;
close ( $ ddhandle ) ;
2010-08-12 09:05:22 +00:00
}
2012-07-05 14:59:08 +00:00
# clean the env
2012-02-25 17:48:11 +00:00
system ( "rm -rf $dd_dir" ) ;
2010-08-12 09:05:22 +00:00
my $ rsp ;
2012-07-05 14:59:08 +00:00
if ( @ dd_list ) {
2013-07-31 10:57:34 +00:00
push @ { $ rsp - > { data } } , "The driver update disk:" . join ( ',' , @ dd_list ) . " have been injected to initrd." ;
}
# remove the duplicated names
my % dnhash ;
foreach ( @ rpm_drivers ) {
$ dnhash { $ _ } = 1 ;
2012-07-05 14:59:08 +00:00
}
2013-07-31 10:57:34 +00:00
@ rpm_drivers = keys % dnhash ;
if ( @ rpm_list ) {
2013-09-25 05:49:56 +00:00
if ( @ rpm_drivers ) {
2013-07-31 10:57:34 +00:00
push @ { $ rsp - > { data } } , "The drivers:" . join ( ',' , sort ( @ rpm_drivers ) ) . " from " . join ( ',' , sort ( @ rpm_list ) ) . " have been injected to initrd." ;
2013-09-25 05:49:56 +00:00
} else {
push @ { $ rsp - > { data } } , "No driver was injected to initrd." ;
2013-07-31 10:57:34 +00:00
}
2012-07-05 14:59:08 +00:00
}
2010-08-12 09:05:22 +00:00
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 ;