200 lines
5.8 KiB
Perl
200 lines
5.8 KiB
Perl
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||
|
package xCAT_plugin::rhel;
|
||
|
use Storable qw(dclone);
|
||
|
use Sys::Syslog;
|
||
|
use xCAT::Table;
|
||
|
use xCAT::Template;
|
||
|
use xCAT::Postage;
|
||
|
use Data::Dumper;
|
||
|
use Getopt::Long;
|
||
|
Getopt::Long::Configure("bundling");
|
||
|
Getopt::Long::Configure("pass_through");
|
||
|
use File::Path;
|
||
|
use File::Copy;
|
||
|
|
||
|
my %discids = (
|
||
|
"1170973598.629055" => "rhelc5",
|
||
|
"1170978545.752040" => "rhels5"
|
||
|
);
|
||
|
|
||
|
sub handled_commands {
|
||
|
return {
|
||
|
copycd => "rhel",
|
||
|
mkinstall => "nodetype:os=rh.*"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub process_request {
|
||
|
my $request = shift;
|
||
|
my $callback = shift;
|
||
|
my $doreq = shift;
|
||
|
my $distname = undef;
|
||
|
my $arch = undef;
|
||
|
my $path = undef;
|
||
|
if ($request->{command}->[0] eq 'copycd') {
|
||
|
return copycd($request,$callback,$doreq);
|
||
|
} elsif ($request->{command}->[0] eq 'mkinstall') {
|
||
|
return mkinstall($request,$callback,$doreq);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub mkinstall {
|
||
|
my $request = shift;
|
||
|
my $callback = shift;
|
||
|
my $doreq = shift;
|
||
|
my @nodes = @{$request->{node}};
|
||
|
my $node;
|
||
|
my $ostab = xCAT::Table->new('nodetype');
|
||
|
my %doneimgs;
|
||
|
foreach $node (@nodes) {
|
||
|
my $osinst;
|
||
|
my $ent = $ostab->getNodeAttribs($node,['profile','os','arch']);
|
||
|
unless ($ent->{os} and $ent->{arch} and $ent->{profile}) {
|
||
|
$callback->({error=>["No profile defined in nodetype for $node"],errorcode=>[1]});
|
||
|
next; #No profile
|
||
|
}
|
||
|
my $os = $ent->{os};
|
||
|
my $arch = $ent->{arch};
|
||
|
my $profile = $ent->{profile};
|
||
|
unless (-r "/usr/share/xcat/install/rh/".$ent->{profile}.".tmpl") {
|
||
|
$callback->({error=>["No kickstart template exists for ".$ent->{profile}],errorcode=>[1]});
|
||
|
next;
|
||
|
}
|
||
|
#Call the Template class to do substitution to produce a kickstart file in the autoinst dir
|
||
|
xCAT::Template->subvars("/usr/share/xcat/install/rh/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node);
|
||
|
mkpath "/install/postscripts/";
|
||
|
xCAT::Postage->writescript($node,"/install/postscripts/".$node);
|
||
|
if (-r "/install/$os/$arch/images/pxeboot/vmlinuz"
|
||
|
and -r "/install/$os/$arch/images/pxeboot/initrd.img") {
|
||
|
unless ($doneimgs{"$os|$arch"}) {
|
||
|
#TODO: driver slipstream, targetted for network.
|
||
|
mkpath("/tftpboot/xcat/$os/$arch");
|
||
|
copy("/install/$os/$arch/images/pxeboot/vmlinuz","/tftpboot/xcat/$os/$arch/");
|
||
|
copy("/install/$os/$arch/images/pxeboot/initrd.img","/tftpboot/xcat/$os/$arch/");
|
||
|
$doneimgs{"$os|$arch"}=1;
|
||
|
}
|
||
|
#We have a shot...
|
||
|
my $restab = xCAT::Table->new('noderes');
|
||
|
my $ent = $restab->getNodeAttribs($node,['nfsserver','serialport','primarynic','installnic']);
|
||
|
my $hmtab = xCAT::Table->new('nodehm');
|
||
|
my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']);
|
||
|
unless ($ent and $ent->{nfsserver}) {
|
||
|
$callback->({error=>["No noderes.nfsserver defined for ".$ent->{profile}],errorcode=>[1]});
|
||
|
next;
|
||
|
}
|
||
|
my $kcmdline="nofb utf8 ks=http://".$ent->{nfsserver}."/install/autoinst/".$node;
|
||
|
if ($ent->{installnic}) {
|
||
|
$kcmdline.=" ksdevice=".$ent->{installnic};
|
||
|
} elsif ($ent->{primarynic}) {
|
||
|
$kcmdline.=" ksdevice=".$ent->{primarynic};
|
||
|
} else {
|
||
|
$kcmdline .= " ksdevice=eth0";
|
||
|
}
|
||
|
|
||
|
#TODO: dd=<url> for driver disks
|
||
|
if (defined $ent->{serialport}) {
|
||
|
unless ($sent->{serialspeed}) {
|
||
|
$callback->({error=>["serialport defined, but no serialspeed for $node in nodehm table"],errorcode=>[1]});
|
||
|
next;
|
||
|
}
|
||
|
$kcmdline.=" console=ttyS".$ent->{serialport}.",".$sent->{serialspeed};
|
||
|
if ($sent->{serialflow} =~ /(ctsrts|cts|hard)/) {
|
||
|
$kcmdline .= "n8r";
|
||
|
}
|
||
|
}
|
||
|
$kcmdline .= " noipv6";
|
||
|
|
||
|
$restab->setNodeAttribs($node,{
|
||
|
kernel=>"xcat/$os/$arch/vmlinuz",
|
||
|
initrd=>"xcat/$os/$arch/initrd.img",
|
||
|
kcmdline=>$kcmdline
|
||
|
});
|
||
|
} else {
|
||
|
$callback->({error=>["Install image not found in /install/$os/$arch"],errorcode=>[1]});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub copycd {
|
||
|
my $request = shift;
|
||
|
my $callback = shift;
|
||
|
my $doreq = shift;
|
||
|
my $installroot;
|
||
|
my $sitetab = xCAT::Table->new('site');
|
||
|
if ($sitetab) {
|
||
|
(my $ref) = $sitetab->getAttribs({key=>installdir},value);
|
||
|
print Dumper($ref);
|
||
|
if ($ref and $ref->{value}) {
|
||
|
$installroot = $ref->{value};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@ARGV= @{$request->{arg}};
|
||
|
GetOptions(
|
||
|
'n=s' => \$distname,
|
||
|
'a=s' => \$arch,
|
||
|
'p=s' => \$path
|
||
|
);
|
||
|
unless ($path) {
|
||
|
#this plugin needs $path...
|
||
|
return;
|
||
|
}
|
||
|
if ($distname and $distname !~ /^rh/) {
|
||
|
#If they say to call it something other than RH, give up?
|
||
|
return;
|
||
|
}
|
||
|
unless (-r $path."/.discinfo") {
|
||
|
return;
|
||
|
}
|
||
|
my $dinfo;
|
||
|
open($dinfo,$path."/.discinfo");
|
||
|
my $did = <$dinfo>;
|
||
|
chomp($did);
|
||
|
my $desc = <$dinfo>;
|
||
|
chomp($desc);
|
||
|
my $darch = <$dinfo>;
|
||
|
chomp($darch);
|
||
|
if ($darch and $darch =~ /i.86/) {
|
||
|
$darch = "x86";
|
||
|
}
|
||
|
close($dinfo);
|
||
|
if ($desc =~ /^Red Hat Enterprise Linux Client 5$/) {
|
||
|
unless ($distname) {
|
||
|
$distname = "rhelc5";
|
||
|
}
|
||
|
} elsif ($desc =~ /^Red Hat Enterprise Linux Server 5$/) {
|
||
|
unless ($distname) {
|
||
|
$distname = "rhels5";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
print $desc;
|
||
|
unless ($distname) {
|
||
|
return; #Do nothing, not ours..
|
||
|
}
|
||
|
if ($darch) {
|
||
|
unless ($arch) {
|
||
|
$arch = $darch;
|
||
|
}
|
||
|
if ($arch and $arch ne $darch) {
|
||
|
$callback->({error=>"Requested RedHat architecture $arch, but media is $darch"});
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
%{$request} = (); #clear request we've got it.
|
||
|
|
||
|
$callback->({data=>"Copying media to $installroot/$distname/$arch/"});
|
||
|
my $omask=umask 0022;
|
||
|
mkpath("$installroot/$distname/$arch");
|
||
|
umask $omask;
|
||
|
my $rc = system("cd $path; find . | cpio -dump $installroot/$distname/$arch");
|
||
|
chmod 0755,"$installroot/$distname/$arch";
|
||
|
if ($rc != 0) {
|
||
|
$callback->({error=>"Media copy operation failed, status $rc"});
|
||
|
} else {
|
||
|
$callback->({data=>"Media copy operation successful"});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
1;
|