From df449fdcf95d94d28fa13dc77cdffb0533ff3cf2 Mon Sep 17 00:00:00 2001 From: lissav Date: Wed, 12 Mar 2008 19:16:44 +0000 Subject: [PATCH] Add code for tarring /install/postscripts and wget to nodes on install git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@769 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/Utils.pm | 27 + xCAT-server-2.0/lib/xcat/plugins/fedora.pm | 841 +++++++++++------- xCAT-server-2.0/lib/xcat/plugins/rhel.pm | 775 ++++++++++------ xCAT-server-2.0/lib/xcat/plugins/sles.pm | 605 ++++++++----- .../share/xcat/install/scripts/post.rh | 5 +- 5 files changed, 1456 insertions(+), 797 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index d8793b289..86f50130d 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -1599,5 +1599,32 @@ sub gethost_ips } return @ipaddress; } +#----------------------------------------------------------------------------- +=head3 create_postscripts_tar + + This routine will tar and compress the /install/postscripts directory + and place in /install/autoinst/xcat_postscripts.Z + + input: none + output: + example: $rc=xCAT::create_postscripts_tar(); + +=cut + +#----------------------------------------------------------------------------- +sub create_postscripts_tar +{ + my ($class) = @_; + my $cmd; + $cmd="cd /install/postscripts;tar -cjf /install/autoinst/xcatpost.tar.bz2 *"; + my @result = xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) + { + xCAT::MsgUtils->message("S", "Error from $cmd\n"); + return $::RUNCMD_RC; + } + return 0; + +} 1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/fedora.pm b/xCAT-server-2.0/lib/xcat/plugins/fedora.pm index 2235d630b..2ad4c6492 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/fedora.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/fedora.pm @@ -3,6 +3,8 @@ package xCAT_plugin::fedora; use Storable qw(dclone); use Sys::Syslog; use DBI; +use xCAT::Utils; +use xCAT::MsgUtils; use xCAT::Yum; use xCAT::Table; use xCAT::Template; @@ -14,350 +16,585 @@ Getopt::Long::Configure("pass_through"); use File::Path; use File::Copy; -my %discids = ( - "1194015916.783841" => "fedora8", - ); +my %discids = ("1194015916.783841" => "fedora8",); -sub handled_commands { - return { - copycd => "fedora", - mkinstall => "nodetype:os=fedora.*", - mknetboot => "nodetype:os=fedora.*" - } -} - -sub preprocess_request { - my $req = shift; - my $callback = shift; - if ($req->{command}->[0] eq 'copycd') { #don't farm out copycd - return [$req]; - } - my %localnodehash; - my %dispatchhash; - my $nrtab = xCAT::Table->new('noderes'); - foreach my $node (@{$req->{node}}) { - my $nodeserver; - my $tent = $nrtab->getNodeAttribs($node,['tftpserver']); - if ($tent) { $nodeserver = $tent->{tftpserver} } - unless ($tent and $tent->{tftpserver}) { - $tent = $nrtab->getNodeAttribs($node,['servicenode']); - if ($tent) { $nodeserver = $tent->{servicenode} } - } - if ($nodeserver) { - $dispatchhash{$nodeserver}->{$node} = 1; - } else { - $localnodehash{$node} = 1; - } - } - my @requests; - my $reqc = {%$req}; - $reqc->{node} = [ keys %localnodehash ]; - if (scalar(@{$reqc->{node}})) { push @requests,$reqc } - - foreach my $dtarg (keys %dispatchhash) { #iterate dispatch targets - my $reqcopy = {%$req}; #deep copy - $reqcopy->{'_xcatdest'} = $dtarg; - $reqcopy->{node} = [ keys %{$dispatchhash{$dtarg}}]; - push @requests,$reqcopy; - } - return \@requests; -} - - -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); - } elsif ($request->{command}->[0] eq 'mknetboot') { - return mknetboot($request,$callback,$doreq); - } elsif ($request->{command}->[0] eq 'packimage') { - packimage($request,$callback,$doreq); - } #$osver,$arch,$profile,$installroot,$callback); +sub handled_commands +{ + return { + copycd => "fedora", + mkinstall => "nodetype:os=fedora.*", + mknetboot => "nodetype:os=fedora.*" + }; } -sub mknetboot { - my $req = shift; +sub preprocess_request +{ + my $req = shift; my $callback = shift; - my $doreq = shift; - my $tftpdir = "/tftpboot"; - my $nodes = @{$request->{node}}; - my @args=@{$req->{arg}}; - my @nodes = @{$req->{node}}; - my $ostab = xCAT::Table->new('nodetype'); - my $sitetab = xCAT::Table->new('site'); - (my $sent) = $sitetab->getAttribs({key=>master},value); + if ($req->{command}->[0] eq 'copycd') + { #don't farm out copycd + return [$req]; + } + my %localnodehash; + my %dispatchhash; + my $nrtab = xCAT::Table->new('noderes'); + foreach my $node (@{$req->{node}}) + { + my $nodeserver; + my $tent = $nrtab->getNodeAttribs($node, ['tftpserver']); + if ($tent) { $nodeserver = $tent->{tftpserver} } + unless ($tent and $tent->{tftpserver}) + { + $tent = $nrtab->getNodeAttribs($node, ['servicenode']); + if ($tent) { $nodeserver = $tent->{servicenode} } + } + if ($nodeserver) + { + $dispatchhash{$nodeserver}->{$node} = 1; + } + else + { + $localnodehash{$node} = 1; + } + } + my @requests; + my $reqc = {%$req}; + $reqc->{node} = [keys %localnodehash]; + if (scalar(@{$reqc->{node}})) { push @requests, $reqc } + + foreach my $dtarg (keys %dispatchhash) + { #iterate dispatch targets + my $reqcopy = {%$req}; #deep copy + $reqcopy->{'_xcatdest'} = $dtarg; + $reqcopy->{node} = [keys %{$dispatchhash{$dtarg}}]; + push @requests, $reqcopy; + } + return \@requests; +} + +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); + } + elsif ($request->{command}->[0] eq 'mknetboot') + { + return mknetboot($request, $callback, $doreq); + } + elsif ($request->{command}->[0] eq 'packimage') + { + packimage($request, $callback, $doreq); + } #$osver,$arch,$profile,$installroot,$callback); +} + +sub mknetboot +{ + my $req = shift; + my $callback = shift; + my $doreq = shift; + my $tftpdir = "/tftpboot"; + my $nodes = @{$request->{node}}; + my @args = @{$req->{arg}}; + my @nodes = @{$req->{node}}; + my $ostab = xCAT::Table->new('nodetype'); + my $sitetab = xCAT::Table->new('site'); + (my $sent) = $sitetab->getAttribs({key => master}, value); my $imgsrv; - if ($sent and $sent->{value}) { - $imgsrv = $sent->{value}; + + if ($sent and $sent->{value}) + { + $imgsrv = $sent->{value}; } my $installroot; $installroot = "/install"; - if ($sitetab) { - (my $ref) = $sitetab->getAttribs({key=>installdir},value); - if ($ref and $ref->{value}) { + if ($sitetab) + { + (my $ref) = $sitetab->getAttribs({key => installdir}, value); + if ($ref and $ref->{value}) + { $installroot = $ref->{value}; } } - foreach $node (@nodes) { - my $ent = $ostab->getNodeAttribs($node,['os','arch','profile']); - unless ($ent->{os} and $ent->{arch} and $ent->{profile}) { - $callback->({error=>["Insufficient nodetype entry for $node"],errorcode=>[1]}); + foreach $node (@nodes) + { + my $ent = $ostab->getNodeAttribs($node, ['os', 'arch', 'profile']); + unless ($ent->{os} and $ent->{arch} and $ent->{profile}) + { + $callback->( + { + error => ["Insufficient nodetype entry for $node"], + errorcode => [1] + } + ); next; } - my $osver = $ent->{os}; - my $arch = $ent->{arch}; + my $osver = $ent->{os}; + my $arch = $ent->{arch}; my $profile = $ent->{profile}; - #packimage($osver,$arch,$profile,$installroot,$callback); - my $suffix = 'gz'; - if (-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") { + + #packimage($osver,$arch,$profile,$installroot,$callback); + my $suffix = 'gz'; + if (-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") + { $suffix = 'sfs'; - } - unless ((-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.gz" or - -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") and - -r "/$installroot/netboot/$osver/$arch/$profile/kernel" and - -r "/$installroot/netboot/$osver/$arch/$profile/initrd.gz") { - $callback->({error=>["No packed image for platform $osver, architecture $arch, profile $profile, please run packimage -o $osver -p $profile -a $arch"],errorcode=>[1]}); + } + unless ( + ( + -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.gz" + or -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs" + ) + and -r "/$installroot/netboot/$osver/$arch/$profile/kernel" + and -r "/$installroot/netboot/$osver/$arch/$profile/initrd.gz" + ) + { + $callback->( + { + error => [ + "No packed image for platform $osver, architecture $arch, profile $profile, please run packimage -o $osver -p $profile -a $arch" + ], + errorcode => [1] + } + ); next; - } - mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - #TODO: only copy if newer.. - copy("/$installroot/netboot/$osver/$arch/$profile/kernel","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - copy("/$installroot/netboot/$osver/$arch/$profile/initrd.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - #copy("/$installroot/netboot/$osver/$arch/$profile/rootimg.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - unless (-r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel" and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd.gz") { - $callback->({error=>["Copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed"],errorcode=>[1]}); + } + mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + + #TODO: only copy if newer.. + copy("/$installroot/netboot/$osver/$arch/$profile/kernel", + "/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + copy("/$installroot/netboot/$osver/$arch/$profile/initrd.gz", + "/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + + #copy("/$installroot/netboot/$osver/$arch/$profile/rootimg.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + unless ( -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel" + and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd.gz") + { + $callback->( + { + error => [ + "Copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed" + ], + errorcode => [1] + } + ); next; + #mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); #copy("/$installroot/netboot/$osver/$arch/$profile/kernel","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); #copy("/$installroot/netboot/$osver/$arch/$profile/rootimg.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); } my $restab = xCAT::Table->new('noderes'); - my $hmtab = xCAT::Table->new('nodehm'); - my $ent = $restab->getNodeAttribs($node,['serialport','primarynic']); - my $ient = $restab->getNodeAttribs($node,['servicenode']); - if ($ient and $ient->{servicenode}) { - $imgsrv = $ient->{servicenode}; + my $hmtab = xCAT::Table->new('nodehm'); + my $ent = $restab->getNodeAttribs($node, ['serialport', 'primarynic']); + my $ient = $restab->getNodeAttribs($node, ['servicenode']); + if ($ient and $ient->{servicenode}) + { + $imgsrv = $ient->{servicenode}; } - unless ($imgsrv) { - $callback->({error=>["Unable to determine image server for $node"]}); - next; + unless ($imgsrv) + { + $callback->( + {error => ["Unable to determine image server for $node"]}); + next; } - my $kcmdline = "imgurl=http://$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.$suffix "; - if (defined $ent->{serialport}) { - my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']); - unless ($sent->{serialspeed}) { - $callback->({error=>["serialport defined, but no serialspeed for $node in nodehm table"],errorcode=>[1]}); + my $kcmdline = + "imgurl=http://$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.$suffix "; + if (defined $ent->{serialport}) + { + my $sent = + $hmtab->getNodeAttribs($node, ['serialspeed', 'serialflow']); + unless ($sent->{serialspeed}) + { + $callback->( + { + error => [ + "serialport defined, but no serialspeed for $node in nodehm table" + ], + errorcode => [1] + } + ); next; } - $kcmdline .= "console=ttyS".$ent->{serialport}.",".$sent->{serialspeed}; - if ($sent->{serialflow} =~ /(hard|tcs|ctsrts)/) { + $kcmdline .= + "console=ttyS" . $ent->{serialport} . "," . $sent->{serialspeed}; + if ($sent->{serialflow} =~ /(hard|tcs|ctsrts)/) + { $kcmdline .= "n8r"; } } - $restab->setNodeAttribs($node,{ - kernel=>"xcat/netboot/$osver/$arch/$profile/kernel", - initrd=>"xcat/netboot/$osver/$arch/$profile/initrd.gz", - kcmdline=>$kcmdline - }); + $restab->setNodeAttribs( + $node, + { + kernel => "xcat/netboot/$osver/$arch/$profile/kernel", + initrd => "xcat/netboot/$osver/$arch/$profile/initrd.gz", + kcmdline => $kcmdline + } + ); } } -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 $::XCATROOT."/share/xcat/install/fedora/".$ent->{profile}.".tmpl" or - -r $::XCATROOT."/share/xcat/install/fedora/$profile.$arch.tmpl" or - -r $::XCATROOT."/share/xcat/install/fedora/$profile.$os.tmpl" or - -r $::XCATROOT."/share/xcat/install/fedora/$profile.$os.$arch.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 - - my $tmperr; - if ( -r $::XCATROOT."/share/xcat/install/fedora/$profile.$os.$arch.tmpl" ) { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$os.$arch.tmpl","/install/autoinst/".$node,$node); - } elsif ( -r $::XCATROOT."/share/xcat/install/fedora/$profile.$arch.tmpl" ) { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$arch.tmpl","/install/autoinst/".$node,$node); - } elsif ( -r $::XCATROOT."/share/xcat/install/fedora/$profile.$os.tmpl" ) { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/$profile.$os.tmpl","/install/autoinst/".$node,$node); - } else { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/fedora/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); - } - if ($tmperr) { - $callback->({ - node => [ { - name=> [ $node ], - error=> [ $tmperr ], - errorcode => [ 1 ] - } ]}); - next; - } - mkpath "/install/postscripts/"; - xCAT::Postage->writescript($node,"/install/postscripts/".$node); - if (($arch =~ /x86/ and - (-r "/install/$os/$arch/images/pxeboot/vmlinuz" and -r "/install/$os/$arch/images/pxeboot/initrd.img")) - or $arch =~ /ppc/ and - (-r "/install/$os/$arch/ppc/ppc64/vmlinuz" and -r "/install/$os/$arch/ppc/ppc64/ramdisk.image.gz")) { - unless ($doneimgs{"$os|$arch"}) { - #TODO: driver slipstream, targetted for network. - mkpath("/tftpboot/xcat/$os/$arch"); - if ($arch =~ /x86/) { - copy("/install/$os/$arch/images/pxeboot/vmlinuz","/tftpboot/xcat/$os/$arch/"); - copy("/install/$os/$arch/images/pxeboot/initrd.img","/tftpboot/xcat/$os/$arch/"); - } elsif ($arch =~ /ppc/) { - copy("/install/$os/$arch/ppc/ppc64/vmlinuz","/tftpboot/xcat/$os/$arch/"); - copy("/install/$os/$arch/ppc/ppc64/ramdisk.image.gz","/tftpboot/xcat/$os/$arch/initrd.img"); - } else { - $callback->({error=>["Plugin doesn't know how to handle architecture $arch"],errorcode=>[1]}); + +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 $::XCATROOT + . "/share/xcat/install/fedora/" + . $ent->{profile} . ".tmpl" + or -r $::XCATROOT . "/share/xcat/install/fedora/$profile.$arch.tmpl" + or -r $::XCATROOT . "/share/xcat/install/fedora/$profile.$os.tmpl" + or -r $::XCATROOT + . "/share/xcat/install/fedora/$profile.$os.$arch.tmpl") + { + $callback->( + { + error => + ["No kickstart template exists for " . $ent->{profile}], + errorcode => [1] + } + ); next; } - $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 ".$node],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= 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; + #Call the Template class to do substitution to produce a kickstart file in the autoinst dir + + my $tmperr; + if (-r $::XCATROOT + . "/share/xcat/install/fedora/$profile.$os.$arch.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT + . "/share/xcat/install/fedora/$profile.$os.$arch.tmpl", + "/install/autoinst/" . $node, + $node + ); } - $kcmdline.=" console=ttyS".$ent->{serialport}.",".$sent->{serialspeed}; - if ($sent->{serialflow} =~ /(ctsrts|cts|hard)/) { - $kcmdline .= "n8r"; + elsif ( + -r $::XCATROOT . "/share/xcat/install/fedora/$profile.$arch.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT + . "/share/xcat/install/fedora/$profile.$arch.tmpl", + "/install/autoinst/" . $node, + $node + ); + } + elsif (-r $::XCATROOT . "/share/xcat/install/fedora/$profile.$os.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT . "/share/xcat/install/fedora/$profile.$os.tmpl", + "/install/autoinst/" . $node, $node); + } + else + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT + . "/share/xcat/install/fedora/" + . $ent->{profile} . ".tmpl", + "/install/autoinst/" . $node, + $node + ); + } + if ($tmperr) + { + $callback->( + { + node => [ + { + name => [$node], + error => [$tmperr], + errorcode => [1] + } + ] + } + ); + next; + } + mkpath "/install/postscripts/"; + xCAT::Postage->writescript($node, "/install/postscripts/" . $node); + if ( + ( + $arch =~ /x86/ + and ( -r "/install/$os/$arch/images/pxeboot/vmlinuz" + and -r "/install/$os/$arch/images/pxeboot/initrd.img") + ) + or $arch =~ /ppc/ + and ( -r "/install/$os/$arch/ppc/ppc64/vmlinuz" + and -r "/install/$os/$arch/ppc/ppc64/ramdisk.image.gz") + ) + { + unless ($doneimgs{"$os|$arch"}) + { + + #TODO: driver slipstream, targetted for network. + mkpath("/tftpboot/xcat/$os/$arch"); + if ($arch =~ /x86/) + { + copy("/install/$os/$arch/images/pxeboot/vmlinuz", + "/tftpboot/xcat/$os/$arch/"); + copy("/install/$os/$arch/images/pxeboot/initrd.img", + "/tftpboot/xcat/$os/$arch/"); + } + elsif ($arch =~ /ppc/) + { + copy("/install/$os/$arch/ppc/ppc64/vmlinuz", + "/tftpboot/xcat/$os/$arch/"); + copy("/install/$os/$arch/ppc/ppc64/ramdisk.image.gz", + "/tftpboot/xcat/$os/$arch/initrd.img"); + } + else + { + $callback->( + { + error => [ + "Plugin doesn't know how to handle architecture $arch" + ], + errorcode => [1] + } + ); + next; + } + $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 " . $node], + 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= 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 + { + print + "$arch is arch and /install/$os/$arch/images/pxeboot/vmlinuz and /install/$os/$arch/images/pxeboot/initrd.img\n"; + $callback->( + { + error => ["Install image not found in /install/$os/$arch"], + errorcode => [1] + } + ); } - } - $kcmdline .= " noipv6"; - - $restab->setNodeAttribs($node,{ - kernel=>"xcat/$os/$arch/vmlinuz", - initrd=>"xcat/$os/$arch/initrd.img", - kcmdline=>$kcmdline - }); - } else { - print "$arch is arch and /install/$os/$arch/images/pxeboot/vmlinuz and /install/$os/$arch/images/pxeboot/initrd.img\n"; - $callback->({error=>["Install image not found in /install/$os/$arch"],errorcode=>[1]}); } - } + my $rc = xCAT::Utils->create_postscripts_tar(); + if ($rc != 0) + { + xCAT::MsgUtils->message("S", "Error creating postscripts tar file."); + } } -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); - if ($ref and $ref->{value}) { - $installroot = $ref->{value}; +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); + 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 !~ /^fedora/) { - #If they say to call it something other than Fedora, 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 ($discids{$did}) { - unless ($distname) { - $distname = $discids{$did}; - } - } - if ($desc =~ /^Fedora 8$/) { - unless ($distname) { - $distname = "fedora8"; - } - } - unless ($distname) { - return; #Do nothing, not ours.. - } - if ($darch) { - unless ($arch) { - $arch = $darch; - } - if ($arch and $arch ne $darch) { - $callback->({error=>"Requested Fedora architecture $arch, but media is $darch"}); - return; - } - if ($arch =~ /ppc/) { $arch = "ppc64" }; - } - %{$request} = (); #clear request we've got it. + @ARGV = @{$request->{arg}}; + GetOptions( + 'n=s' => \$distname, + 'a=s' => \$arch, + 'p=s' => \$path + ); + unless ($path) + { - $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"); - my $rc = system("cd $path;rsync -a . $installroot/$distname/$arch/"); - chmod 0755,"$installroot/$distname/$arch"; - xCAT::Yum->localize_yumrepo($installroot,$distname,$arch); - if ($rc != 0) { - $callback->({error=>"Media copy operation failed, status $rc"}); - } else { - $callback->({data=>"Media copy operation successful"}); - } + #this plugin needs $path... + return; + } + if ($distname and $distname !~ /^fedora/) + { + + #If they say to call it something other than Fedora, 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 ($discids{$did}) + { + unless ($distname) + { + $distname = $discids{$did}; + } + } + if ($desc =~ /^Fedora 8$/) + { + unless ($distname) + { + $distname = "fedora8"; + } + } + unless ($distname) + { + return; #Do nothing, not ours.. + } + if ($darch) + { + unless ($arch) + { + $arch = $darch; + } + if ($arch and $arch ne $darch) + { + $callback->( + { + error => + "Requested Fedora architecture $arch, but media is $darch" + } + ); + return; + } + if ($arch =~ /ppc/) { $arch = "ppc64" } + } + %{$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"); + my $rc = system("cd $path;rsync -a . $installroot/$distname/$arch/"); + chmod 0755, "$installroot/$distname/$arch"; + xCAT::Yum->localize_yumrepo($installroot, $distname, $arch); + if ($rc != 0) + { + $callback->({error => "Media copy operation failed, status $rc"}); + } + else + { + $callback->({data => "Media copy operation successful"}); + } } 1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/rhel.pm b/xCAT-server-2.0/lib/xcat/plugins/rhel.pm index 0ac38dab8..69f6e1d12 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/rhel.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/rhel.pm @@ -3,6 +3,8 @@ package xCAT_plugin::rhel; use Storable qw(dclone); use Sys::Syslog; use xCAT::Table; +use xCAT::Utils; +use xCAT::MsgUtils; use xCAT::Template; use xCAT::Postage; use Data::Dumper; @@ -13,316 +15,545 @@ use File::Path; use File::Copy; my %discids = ( - "1170973598.629055" => "rhelc5", - "1170978545.752040" => "rhels5", - "1192660014.052098" => "rhels5.1", - "1192663619.181374" => "rhels5.1", - ); + "1170973598.629055" => "rhelc5", + "1170978545.752040" => "rhels5", + "1192660014.052098" => "rhels5.1", + "1192663619.181374" => "rhels5.1", + ); -sub handled_commands { - return { - copycd => "rhel", - mkinstall => "nodetype:os=rh.*", - mknetboot => "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); - } elsif ($request->{command}->[0] eq 'mknetboot') { - return mknetboot($request,$callback,$doreq); - } +sub handled_commands +{ + return { + copycd => "rhel", + mkinstall => "nodetype:os=rh.*", + mknetboot => "nodetype:os=rh.*" + }; } -sub mknetboot { - my $req = shift; +sub process_request +{ + my $request = shift; my $callback = shift; - my $doreq = shift; - my $tftpdir = "/tftpboot"; - my $nodes = @{$request->{node}}; - my @args=@{$req->{arg}}; - my @nodes = @{$req->{node}}; - my $ostab = xCAT::Table->new('nodetype'); - my $sitetab = xCAT::Table->new('site'); - (my $sent) = $sitetab->getAttribs({key=>master},value); + 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); + } + elsif ($request->{command}->[0] eq 'mknetboot') + { + return mknetboot($request, $callback, $doreq); + } +} + +sub mknetboot +{ + my $req = shift; + my $callback = shift; + my $doreq = shift; + my $tftpdir = "/tftpboot"; + my $nodes = @{$request->{node}}; + my @args = @{$req->{arg}}; + my @nodes = @{$req->{node}}; + my $ostab = xCAT::Table->new('nodetype'); + my $sitetab = xCAT::Table->new('site'); + (my $sent) = $sitetab->getAttribs({key => master}, value); my $imgsrv; - if ($sent and $sent->{value}) { - $imgsrv = $sent->{value}; + + if ($sent and $sent->{value}) + { + $imgsrv = $sent->{value}; } my $installroot; - $installroot="/install"; - if ($sitetab) { - (my $ref) = $sitetab->getAttribs({key=>installdir},value); + $installroot = "/install"; + if ($sitetab) + { + (my $ref) = $sitetab->getAttribs({key => installdir}, value); print Dumper($ref); - if ($ref and $ref->{value}) { + if ($ref and $ref->{value}) + { $installroot = $ref->{value}; } } - foreach $node (@nodes) { - my $ent = $ostab->getNodeAttribs($node,['os','arch','profile']); - unless ($ent->{os} and $ent->{arch} and $ent->{profile}) { - $callback->({error=>["Insufficient nodetype entry for $node"],errorcode=>[1]}); + foreach $node (@nodes) + { + my $ent = $ostab->getNodeAttribs($node, ['os', 'arch', 'profile']); + unless ($ent->{os} and $ent->{arch} and $ent->{profile}) + { + $callback->( + { + error => ["Insufficient nodetype entry for $node"], + errorcode => [1] + } + ); next; } - my $osver = $ent->{os}; - my $arch = $ent->{arch}; + my $osver = $ent->{os}; + my $arch = $ent->{arch}; my $profile = $ent->{profile}; - my $suffix = 'gz'; - if (-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") { - $suffix = 'sfs'; + my $suffix = 'gz'; + if (-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") + { + $suffix = 'sfs'; } - unless ((-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.gz" or - -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") and - -r "/$installroot/netboot/$osver/$arch/$profile/kernel" and - -r "/$installroot/netboot/$osver/$arch/$profile/initrd.gz") { - $callback->({error=>["No packed image for platform $osver, architecture $arch, and profile $profile, please run packimage (i.e. packimage -o $osver -p $profile -a $arch"],errorcode=>[1]}); - next; + unless ( + ( + -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.gz" + or -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs" + ) + and -r "/$installroot/netboot/$osver/$arch/$profile/kernel" + and -r "/$installroot/netboot/$osver/$arch/$profile/initrd.gz" + ) + { + $callback->( + { + error => [ + "No packed image for platform $osver, architecture $arch, and profile $profile, please run packimage (i.e. packimage -o $osver -p $profile -a $arch" + ], + errorcode => [1] + } + ); + next; } mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + #TODO: only copy if newer... - copy("/$installroot/netboot/$osver/$arch/$profile/kernel","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - copy("/$installroot/netboot/$osver/$arch/$profile/initrd.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - unless (-r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel" and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd.gz") { - $callback->({error=>["Copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed"],errorcode=>[1]}); - next; + copy("/$installroot/netboot/$osver/$arch/$profile/kernel", + "/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + copy("/$installroot/netboot/$osver/$arch/$profile/initrd.gz", + "/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + unless ( -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel" + and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd.gz") + { + $callback->( + { + error => [ + "Copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed" + ], + errorcode => [1] + } + ); + next; } my $restab = xCAT::Table->new('noderes'); - my $hmtab = xCAT::Table->new('nodehm'); - my $ent = $restab->getNodeAttribs($node,['serialport','primarynic']); - my $ient = $restab->getNodeAttribs($node,['servicenode']); + my $hmtab = xCAT::Table->new('nodehm'); + my $ent = $restab->getNodeAttribs($node, ['serialport', 'primarynic']); + my $ient = $restab->getNodeAttribs($node, ['servicenode']); my $ipfn = xCAT::Utils->my_ip_facing($node); - if ($ient and $ient->{servicenode}) { #Servicenode attribute overrides - $imgsrv = $ient->{servicenode}; - } elsif ($ipfn) { - $imgsrv = $ipfn; #guessing self is second best - } # resort to master value in site table only if not local to node... - unless ($imgsrv) { - $callback->({error=>["Unable to determine or reasonably guess the image server for $node"],errorcode=>[1]}); - next; + if ($ient and $ient->{servicenode}) + { #Servicenode attribute overrides + $imgsrv = $ient->{servicenode}; } - my $kcmdline = "imgurl=http://$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.$suffix "; - if (defined $ent->{serialport}) { - my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']); - unless ($sent->{serialspeed}) { - $callback->({error=>["serialport defined, but no serialspeed for $node in nodehm table"],errorcode=>[1]}); + elsif ($ipfn) + { + $imgsrv = $ipfn; #guessing self is second best + } # resort to master value in site table only if not local to node... + unless ($imgsrv) + { + $callback->( + { + error => [ + "Unable to determine or reasonably guess the image server for $node" + ], + errorcode => [1] + } + ); next; - } - $kcmdline .= "console=ttyS".$ent->{serialport}.",".$sent->{serialspeed}; - if ($sent->{serialflow} =~ /(hard|tcs|ctsrts)/) { - $kcmdline .= "n8r"; - } } - $restab->setNodeAttribs($node,{ - kernel=>"xcat/netboot/$osver/$arch/$profile/kernel", - initrd=>"xcat/netboot/$osver/$arch/$profile/initrd.gz", - kcmdline=>$kcmdline - }); + my $kcmdline = + "imgurl=http://$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.$suffix "; + if (defined $ent->{serialport}) + { + my $sent = + $hmtab->getNodeAttribs($node, ['serialspeed', 'serialflow']); + unless ($sent->{serialspeed}) + { + $callback->( + { + error => [ + "serialport defined, but no serialspeed for $node in nodehm table" + ], + errorcode => [1] + } + ); + next; + } + $kcmdline .= + "console=ttyS" . $ent->{serialport} . "," . $sent->{serialspeed}; + if ($sent->{serialflow} =~ /(hard|tcs|ctsrts)/) + { + $kcmdline .= "n8r"; + } + } + $restab->setNodeAttribs( + $node, + { + kernel => "xcat/netboot/$osver/$arch/$profile/kernel", + initrd => "xcat/netboot/$osver/$arch/$profile/initrd.gz", + kcmdline => $kcmdline + } + ); } } -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 $::XCATROOT."/share/xcat/install/rh/".$ent->{profile}.".tmpl" or - -r $::XCATROOT."/share/xcat/install/rh/$profile.$arch.tmpl" or - -r $::XCATROOT."/share/xcat/install/rh/$profile.$os.tmpl" or - -r $::XCATROOT."/share/xcat/install/rh/$profile.$os.$arch.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 - - my $tmperr; - if ( -r $::XCATROOT."/share/xcat/install/rh/$profile.$os.$arch.tmpl" ) { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$os.$arch.tmpl","/install/autoinst/".$node,$node); - } elsif ( -r $::XCATROOT."/share/xcat/install/rh/$profile.$arch.tmpl" ) { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$arch.tmpl","/install/autoinst/".$node,$node); - } elsif ( -r $::XCATROOT."/share/xcat/install/rh/$profile.$os.tmpl" ) { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/$profile.$os.tmpl","/install/autoinst/".$node,$node); - } else { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/rh/".$ent->{profile}.".tmpl","/install/autoinst/".$node,$node); - } - if ($tmperr) { - $callback->({ - node => [ { - name=> [ $node ], - error=> [ $tmperr ], - errorcode => [ 1 ] - } ]}); - next; - } - mkpath "/install/postscripts/"; - xCAT::Postage->writescript($node,"/install/postscripts/".$node); - if (($arch =~ /x86/ and - (-r "/install/$os/$arch/images/pxeboot/vmlinuz" and -r "/install/$os/$arch/images/pxeboot/initrd.img")) - or $arch =~ /ppc/ and - (-r "/install/$os/$arch/ppc/ppc64/vmlinuz" and -r "/install/$os/$arch/ppc/ppc64/ramdisk.image.gz")) { - unless ($doneimgs{"$os|$arch"}) { - #TODO: driver slipstream, targetted for network. - mkpath("/tftpboot/xcat/$os/$arch"); - if ($arch =~ /x86/) { - copy("/install/$os/$arch/images/pxeboot/vmlinuz","/tftpboot/xcat/$os/$arch/"); - copy("/install/$os/$arch/images/pxeboot/initrd.img","/tftpboot/xcat/$os/$arch/"); - } elsif ($arch =~ /ppc/) { - copy("/install/$os/$arch/ppc/ppc64/vmlinuz","/tftpboot/xcat/$os/$arch/"); - copy("/install/$os/$arch/ppc/ppc64/ramdisk.image.gz","/tftpboot/xcat/$os/$arch/initrd.img"); - } else { - $callback->({error=>["Plugin doesn't know how to handle architecture $arch"],errorcode=>[1]}); +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 $::XCATROOT + . "/share/xcat/install/rh/" + . $ent->{profile} . ".tmpl" + or -r $::XCATROOT . "/share/xcat/install/rh/$profile.$arch.tmpl" + or -r $::XCATROOT . "/share/xcat/install/rh/$profile.$os.tmpl" + or -r $::XCATROOT + . "/share/xcat/install/rh/$profile.$os.$arch.tmpl") + { + $callback->( + { + error => + ["No kickstart template exists for " . $ent->{profile}], + errorcode => [1] + } + ); next; } - $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 ".$node],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= 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; + #Call the Template class to do substitution to produce a kickstart file in the autoinst dir + + my $tmperr; + if (-r $::XCATROOT . "/share/xcat/install/rh/$profile.$os.$arch.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT + . "/share/xcat/install/rh/$profile.$os.$arch.tmpl", + "/install/autoinst/" . $node, + $node + ); } - $kcmdline.=" console=ttyS".$ent->{serialport}.",".$sent->{serialspeed}; - if ($sent->{serialflow} =~ /(ctsrts|cts|hard)/) { - $kcmdline .= "n8r"; + elsif (-r $::XCATROOT . "/share/xcat/install/rh/$profile.$arch.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT . "/share/xcat/install/rh/$profile.$arch.tmpl", + "/install/autoinst/" . $node, $node); + } + elsif (-r $::XCATROOT . "/share/xcat/install/rh/$profile.$os.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT . "/share/xcat/install/rh/$profile.$os.tmpl", + "/install/autoinst/" . $node, $node); + } + else + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT + . "/share/xcat/install/rh/" + . $ent->{profile} . ".tmpl", + "/install/autoinst/" . $node, + $node + ); + } + if ($tmperr) + { + $callback->( + { + node => [ + { + name => [$node], + error => [$tmperr], + errorcode => [1] + } + ] + } + ); + next; + } + mkpath "/install/postscripts/"; + xCAT::Postage->writescript($node, "/install/postscripts/" . $node); + if ( + ( + $arch =~ /x86/ + and ( -r "/install/$os/$arch/images/pxeboot/vmlinuz" + and -r "/install/$os/$arch/images/pxeboot/initrd.img") + ) + or $arch =~ /ppc/ + and ( -r "/install/$os/$arch/ppc/ppc64/vmlinuz" + and -r "/install/$os/$arch/ppc/ppc64/ramdisk.image.gz") + ) + { + unless ($doneimgs{"$os|$arch"}) + { + + #TODO: driver slipstream, targetted for network. + mkpath("/tftpboot/xcat/$os/$arch"); + if ($arch =~ /x86/) + { + copy("/install/$os/$arch/images/pxeboot/vmlinuz", + "/tftpboot/xcat/$os/$arch/"); + copy("/install/$os/$arch/images/pxeboot/initrd.img", + "/tftpboot/xcat/$os/$arch/"); + } + elsif ($arch =~ /ppc/) + { + copy("/install/$os/$arch/ppc/ppc64/vmlinuz", + "/tftpboot/xcat/$os/$arch/"); + copy("/install/$os/$arch/ppc/ppc64/ramdisk.image.gz", + "/tftpboot/xcat/$os/$arch/initrd.img"); + } + else + { + $callback->( + { + error => [ + "Plugin doesn't know how to handle architecture $arch" + ], + errorcode => [1] + } + ); + next; + } + $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 " . $node], + 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= 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] + } + ); } - } - $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]}); } - } + my $rc = xCAT::Utils->create_postscripts_tar(); + if ($rc != 0) + { + xCAT::MsgUtils->message("S", "Error creating postscripts tar file."); + } } -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}; +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 ($discids{$did}) { - unless ($distname) { - $distname = $discids{$did}; - } - } - 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; - } - if ($arch =~ /ppc/) { $arch = "ppc64" }; - } - %{$request} = (); #clear request we've got it. + @ARGV = @{$request->{arg}}; + GetOptions( + 'n=s' => \$distname, + 'a=s' => \$arch, + 'p=s' => \$path + ); + unless ($path) + { - $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"; - xCAT::Yum->localize_yumrepo($installroot,$distname,$arch); - if ($rc != 0) { - $callback->({error=>"Media copy operation failed, status $rc"}); - } else { - $callback->({data=>"Media copy operation successful"}); - } + #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 ($discids{$did}) + { + unless ($distname) + { + $distname = $discids{$did}; + } + } + 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; + } + if ($arch =~ /ppc/) { $arch = "ppc64" } + } + %{$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"; + xCAT::Yum->localize_yumrepo($installroot, $distname, $arch); + if ($rc != 0) + { + $callback->({error => "Media copy operation failed, status $rc"}); + } + else + { + $callback->({data => "Media copy operation successful"}); + } } 1; diff --git a/xCAT-server-2.0/lib/xcat/plugins/sles.pm b/xCAT-server-2.0/lib/xcat/plugins/sles.pm index 98ae4e592..c77a10787 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/sles.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/sles.pm @@ -3,6 +3,8 @@ package xCAT_plugin::sles; use Storable qw(dclone); use Sys::Syslog; use xCAT::Table; +use xCAT::Utils; +use xCAT::MsgUtils; use xCAT::Template; use xCAT::Postage; use Data::Dumper; @@ -12,242 +14,401 @@ Getopt::Long::Configure("pass_through"); use File::Path; use File::Copy; - -sub handled_commands { - return { - copycd => "sles", - mkinstall => "nodetype:os=sles.*" - } -} - -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 handled_commands +{ + return { + copycd => "sles", + mkinstall => "nodetype:os=sles.*" + }; } -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 +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); } - my $os = $ent->{os}; - my $arch = $ent->{arch}; - my $profile = $ent->{profile}; - unless ( - -r $::XCATROOT."/share/xcat/install/sles/$profile.tmpl" or - -r $::XCATROOT."/share/xcat/install/sles/$profile.$arch.tmpl" or - -r $::XCATROOT."/share/xcat/install/sles/$profile.$os.tmpl" or - -r $::XCATROOT."/share/xcat/install/sles/$profile.$os.$arch.tmpl" - ) { - $callback->({error=>["No AutoYaST template exists for ".$ent->{profile}],errorcode=>[1]}); - next; + elsif ($request->{command}->[0] eq 'mkinstall') + { + return mkinstall($request, $callback, $doreq); } - #Call the Template class to do substitution to produce a kickstart file in the autoinst dir - my $tmperr; - if (-r $::XCATROOT."/share/xcat/install/sles/$profile.$os.$arch.tmpl") { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$os.$arch.tmpl","/install/autoinst/$node",$node); - } elsif (-r $::XCATROOT."/share/xcat/install/sles/$profile.$arch.tmpl") { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$arch.tmpl","/install/autoinst/$node",$node); - } elsif (-r $::XCATROOT."/share/xcat/install/sles/$profile.$os.tmpl") { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.$os.tmpl","/install/autoinst/$node",$node); - } elsif (-r $::XCATROOT."/share/xcat/install/sles/$profile.tmpl") { - $tmperr=xCAT::Template->subvars($::XCATROOT."/share/xcat/install/sles/$profile.tmpl","/install/autoinst/$node",$node); - } - if ($tmperr) { - $callback->({ - node => [ { - name=> [ $node ], - error=> [ $tmperr ], - errorcode => [ 1 ] - } ]}); - next; - } - mkpath "/install/postscripts/"; - xCAT::Postage->writescript($node,"/install/postscripts/".$node); - if (($arch =~ /x86/ and -r "/install/$os/$arch/1/boot/$arch/loader/linux" - and -r "/install/$os/$arch/1/boot/$arch/loader/initrd") or - ($arch =~ /ppc/ and -r "/install/$os/$arch/1/suseboot/inst64")) { - #TODO: driver slipstream, targetted for network. - unless ($doneimgs{"$os|$arch"}) { - mkpath("/tftpboot/xcat/$os/$arch"); - if ($arch =~ /x86/) { - copy("/install/$os/$arch/1/boot/$arch/loader/linux","/tftpboot/xcat/$os/$arch/"); - copy("/install/$os/$arch/1/boot/$arch/loader/initrd","/tftpboot/xcat/$os/$arch/"); - } elsif ($arch =~ /ppc/) { - copy("/install/$os/$arch/1/suseboot/inst64","/tftpboot/xcat/$os/$arch"); - } - $doneimgs{"$os|$arch"}=1; - } - #We have a shot... - my $restab = xCAT::Table->new('noderes'); - my $hmtab = xCAT::Table->new('nodehm'); - my $ent = $restab->getNodeAttribs($node,['nfsserver','serialport','primarynic','installnic']); - my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']); - unless ($ent and $ent->{nfsserver}) { - $callback->({error=>["No noderes.nfsserver for $node defined"],errorcode=>[1]}); - next; - } - my $kcmdline="autoyast=http://".$ent->{nfsserver}."/install/autoinst/".$node." install=http://".$ent->{nfsserver}."/install/$os/$arch/1"; - if ($ent->{installnic}) { - $kcmdline.=" netdevice=".$ent->{installnic}; - } elsif ($ent->{primarynic}) { - $kcmdline.=" netdevice=".$ent->{primarynic}; - } else { - $kcmdline .= " netdevice=eth0"; - } +} - #TODO: driver disk handling should in SLES case be a mod of the install source, nothing to see here - if (defined $ent->{serialport}) { - unless ($sent->{serialspeed}) { - $callback->({error=>["serialport defined, but no serialspeed for $node in nodehm table"],errorcode=>[1]}); - next; +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 } - $kcmdline.=" console=ttyS".$ent->{serialport}.",".$sent->{serialspeed}; - if ($sent and ($sent->{serialflow} =~ /(ctsrts|cts|hard)/)) { - $kcmdline .= "n8r"; + my $os = $ent->{os}; + my $arch = $ent->{arch}; + my $profile = $ent->{profile}; + unless ( -r $::XCATROOT . "/share/xcat/install/sles/$profile.tmpl" + or -r $::XCATROOT . "/share/xcat/install/sles/$profile.$arch.tmpl" + or -r $::XCATROOT . "/share/xcat/install/sles/$profile.$os.tmpl" + or -r $::XCATROOT + . "/share/xcat/install/sles/$profile.$os.$arch.tmpl") + { + $callback->( + { + error => + ["No AutoYaST template exists for " . $ent->{profile}], + errorcode => [1] + } + ); + next; } - } - - if ($arch =~ /x86/) { - $restab->setNodeAttribs($node,{ - kernel=>"xcat/$os/$arch/linux", - initrd=>"xcat/$os/$arch/initrd", - kcmdline=>$kcmdline - }); - } elsif ($arch =~ /ppc/) { - $restab->setNodeAttribs($node,{ - kernel=>"xcat/$os/$arch/inst64", - initrd=>"", - kcmdline=>$kcmdline - }); - } - } else { - $callback->({error=>["Failed to detect copycd configured install source at /install/$os/$arch"],errorcode=>[1]}); + #Call the Template class to do substitution to produce a kickstart file in the autoinst dir + my $tmperr; + if (-r $::XCATROOT . "/share/xcat/install/sles/$profile.$os.$arch.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT + . "/share/xcat/install/sles/$profile.$os.$arch.tmpl", + "/install/autoinst/$node", + $node + ); + } + elsif (-r $::XCATROOT . "/share/xcat/install/sles/$profile.$arch.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT . "/share/xcat/install/sles/$profile.$arch.tmpl", + "/install/autoinst/$node", $node); + } + elsif (-r $::XCATROOT . "/share/xcat/install/sles/$profile.$os.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT . "/share/xcat/install/sles/$profile.$os.tmpl", + "/install/autoinst/$node", $node); + } + elsif (-r $::XCATROOT . "/share/xcat/install/sles/$profile.tmpl") + { + $tmperr = + xCAT::Template->subvars( + $::XCATROOT . "/share/xcat/install/sles/$profile.tmpl", + "/install/autoinst/$node", $node); + } + if ($tmperr) + { + $callback->( + { + node => [ + { + name => [$node], + error => [$tmperr], + errorcode => [1] + } + ] + } + ); + next; + } + mkpath "/install/postscripts/"; + xCAT::Postage->writescript($node, "/install/postscripts/" . $node); + if ( + ( + $arch =~ /x86/ + and -r "/install/$os/$arch/1/boot/$arch/loader/linux" + and -r "/install/$os/$arch/1/boot/$arch/loader/initrd" + ) + or ($arch =~ /ppc/ and -r "/install/$os/$arch/1/suseboot/inst64") + ) + { + + #TODO: driver slipstream, targetted for network. + unless ($doneimgs{"$os|$arch"}) + { + mkpath("/tftpboot/xcat/$os/$arch"); + if ($arch =~ /x86/) + { + copy("/install/$os/$arch/1/boot/$arch/loader/linux", + "/tftpboot/xcat/$os/$arch/"); + copy("/install/$os/$arch/1/boot/$arch/loader/initrd", + "/tftpboot/xcat/$os/$arch/"); + } + elsif ($arch =~ /ppc/) + { + copy("/install/$os/$arch/1/suseboot/inst64", + "/tftpboot/xcat/$os/$arch"); + } + $doneimgs{"$os|$arch"} = 1; + } + + #We have a shot... + my $restab = xCAT::Table->new('noderes'); + my $hmtab = xCAT::Table->new('nodehm'); + my $ent = + $restab->getNodeAttribs( + $node, + [ + 'nfsserver', 'serialport', + 'primarynic', 'installnic' + ] + ); + my $sent = + $hmtab->getNodeAttribs($node, ['serialspeed', 'serialflow']); + unless ($ent and $ent->{nfsserver}) + { + $callback->( + { + error => ["No noderes.nfsserver for $node defined"], + errorcode => [1] + } + ); + next; + } + my $kcmdline = + "autoyast=http://" + . $ent->{nfsserver} + . "/install/autoinst/" + . $node + . " install=http://" + . $ent->{nfsserver} + . "/install/$os/$arch/1"; + if ($ent->{installnic}) + { + $kcmdline .= " netdevice=" . $ent->{installnic}; + } + elsif ($ent->{primarynic}) + { + $kcmdline .= " netdevice=" . $ent->{primarynic}; + } + else + { + $kcmdline .= " netdevice=eth0"; + } + + #TODO: driver disk handling should in SLES case be a mod of the install source, nothing to see here + 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 and ($sent->{serialflow} =~ /(ctsrts|cts|hard)/)) + { + $kcmdline .= "n8r"; + } + } + + if ($arch =~ /x86/) + { + $restab->setNodeAttribs( + $node, + { + kernel => "xcat/$os/$arch/linux", + initrd => "xcat/$os/$arch/initrd", + kcmdline => $kcmdline + } + ); + } + elsif ($arch =~ /ppc/) + { + $restab->setNodeAttribs( + $node, + { + kernel => "xcat/$os/$arch/inst64", + initrd => "", + kcmdline => $kcmdline + } + ); + } + + } + else + { + $callback->( + { + error => [ + "Failed to detect copycd configured install source at /install/$os/$arch" + ], + errorcode => [1] + } + ); + } + } + my $rc = xCAT::Utils->create_postscripts_tar(); + if ($rc != 0) + { + xCAT::MsgUtils->message("S", "Error creating postscripts tar file."); } - } } -sub copycd { - my $request = shift; - my $callback = shift; - my $doreq = shift; - my $installroot; - $installroot="/install"; - 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}; +sub copycd +{ + my $request = shift; + my $callback = shift; + my $doreq = shift; + my $installroot; + $installroot = "/install"; + 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 !~ /^sles/) { - #If they say to call it something other than SLES, give up? - return; - } - unless (-r $path."/content") { - return; - } - my $dinfo; - open($dinfo,$path."/content"); - while (<$dinfo>) { - if (m/^DEFAULTBASE\s+(\S+)/) { - $darch = $1; - chomp($darch); - last; - } - } - close($dinfo); - unless ($darch) { - return; - } - my $dirh; - opendir($dirh,$path); - my $discnumber; - my $totaldiscnumber; - while (my $pname = readdir($dirh)) { - if ($pname =~ /media.(\d+)/) { - $discnumber=$1; - chomp($discnumber); - my $mfile; - open($mfile,$path."/".$pname."/media"); - <$mfile>; - <$mfile>; - $totaldiscnumber=<$mfile>; - chomp($totaldiscnumber); - close($mfile); - open($mfile,$path."/".$pname."/products"); - my $prod = <$mfile>; - close($mfile); - if ($prod =~ m/SUSE-Linux-Enterprise-Server/) { - my @parts = split /\s+/,$prod; - my @subparts = split /-/,$parts[2]; - $distname="sles".$subparts[0]; - } - } - } - unless ($distname and $discnumber) { - return; - } - if ($darch and $darch =~ /i.86/) { - $darch = "x86"; - } elsif ($darch and $darch =~ /ppc/) { - $darch = "ppc64"; - } - if ($darch) { - unless ($arch) { - $arch = $darch; - } - if ($arch and $arch ne $darch) { - $callback->({error=>"Requested SLES architecture $arch, but media is $darch"}); - return; - } - } - %{$request} = (); #clear request we've got it. + @ARGV = @{$request->{arg}}; + GetOptions( + 'n=s' => \$distname, + 'a=s' => \$arch, + 'p=s' => \$path + ); + unless ($path) + { - $callback->({data=>"Copying media to $installroot/$distname/$arch/$discnumber"}); - my $omask=umask 0022; - mkpath("$installroot/$distname/$arch/$discnumber"); - umask $omask; - my $rc = system("cd $path; find . | nice -n 20 cpio -dump $installroot/$distname/$arch/$discnumber/"); - chmod 0755,"$installroot/$distname/$arch"; - chmod 0755,"$installroot/$distname/$arch/$discnumber"; - if ($rc != 0) { - $callback->({error=>"Media copy operation failed, status $rc"}); - } else { - $callback->({data=>"Media copy operation successful"}); - } + #this plugin needs $path... + return; + } + if ($distname and $distname !~ /^sles/) + { + + #If they say to call it something other than SLES, give up? + return; + } + unless (-r $path . "/content") + { + return; + } + my $dinfo; + open($dinfo, $path . "/content"); + while (<$dinfo>) + { + if (m/^DEFAULTBASE\s+(\S+)/) + { + $darch = $1; + chomp($darch); + last; + } + } + close($dinfo); + unless ($darch) + { + return; + } + my $dirh; + opendir($dirh, $path); + my $discnumber; + my $totaldiscnumber; + while (my $pname = readdir($dirh)) + { + if ($pname =~ /media.(\d+)/) + { + $discnumber = $1; + chomp($discnumber); + my $mfile; + open($mfile, $path . "/" . $pname . "/media"); + <$mfile>; + <$mfile>; + $totaldiscnumber = <$mfile>; + chomp($totaldiscnumber); + close($mfile); + open($mfile, $path . "/" . $pname . "/products"); + my $prod = <$mfile>; + close($mfile); + + if ($prod =~ m/SUSE-Linux-Enterprise-Server/) + { + my @parts = split /\s+/, $prod; + my @subparts = split /-/, $parts[2]; + $distname = "sles" . $subparts[0]; + } + } + } + unless ($distname and $discnumber) + { + return; + } + if ($darch and $darch =~ /i.86/) + { + $darch = "x86"; + } + elsif ($darch and $darch =~ /ppc/) + { + $darch = "ppc64"; + } + if ($darch) + { + unless ($arch) + { + $arch = $darch; + } + if ($arch and $arch ne $darch) + { + $callback->( + { + error => + "Requested SLES architecture $arch, but media is $darch" + } + ); + return; + } + } + %{$request} = (); #clear request we've got it. + + $callback->( + {data => "Copying media to $installroot/$distname/$arch/$discnumber"}); + my $omask = umask 0022; + mkpath("$installroot/$distname/$arch/$discnumber"); + umask $omask; + my $rc = + system( + "cd $path; find . | nice -n 20 cpio -dump $installroot/$distname/$arch/$discnumber/" + ); + chmod 0755, "$installroot/$distname/$arch"; + chmod 0755, "$installroot/$distname/$arch/$discnumber"; + + if ($rc != 0) + { + $callback->({error => "Media copy operation failed, status $rc"}); + } + else + { + $callback->({data => "Media copy operation successful"}); + } } 1; diff --git a/xCAT-server-2.0/share/xcat/install/scripts/post.rh b/xCAT-server-2.0/share/xcat/install/scripts/post.rh index d833da66f..b1c40533a 100644 --- a/xCAT-server-2.0/share/xcat/install/scripts/post.rh +++ b/xCAT-server-2.0/share/xcat/install/scripts/post.rh @@ -26,6 +26,7 @@ hostname $HOSTNAME export MASTER_IP="#XCATVAR:XCATMASTER#" export MASTER_IPS="#XCATVAR:XCATMASTER#" mkdir -p /xcatpost +cd /xcatpost RAND=$(perl -e 'print int(rand(50)). "\n"') sleep $RAND for i in $(seq 1 20) @@ -34,7 +35,8 @@ do for i in $MASTER_IPS do # mount -r $i:$XCATROOT $XCATROOT - mount -o ro,nolock $i:/install/postscripts /xcatpost +# mount -o ro,nolock $i:/install/postscripts /xcatpost + wget http://$i/install/autoinst/xcatpost.tar.bz2 if [ "$?" = "0" ] then GOTIT=1 @@ -51,6 +53,7 @@ done #mount -r #XCATVAR:MASTER_IP#:$XCATROOT $XCATROOT #mount -o ro,nolock #XCATVAR:MASTER_IP#:$XCATROOT $XCATROOT #$XCATROOT/bin/postage +tar -xvf xcatpost.tar.bz2 /xcatpost/#TABLE:nodelist:THISNODE:node# cd / umount /xcatpost