2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::copycds;
|
|
|
|
use Storable qw(dclone);
|
|
|
|
use xCAT::Table;
|
|
|
|
use Data::Dumper;
|
|
|
|
use Getopt::Long;
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
Getopt::Long::Configure("pass_through");
|
|
|
|
|
|
|
|
my $processed = 0;
|
|
|
|
my $callback;
|
|
|
|
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
|
|
|
copycds => "copycds",
|
|
|
|
}
|
|
|
|
}
|
2008-04-29 17:39:28 +00:00
|
|
|
|
|
|
|
my $identified;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
sub take_answer {
|
|
|
|
#TODO: Intelligently filter and decide things
|
|
|
|
my $resp = shift;
|
|
|
|
$callback->($resp);
|
2008-04-29 17:39:28 +00:00
|
|
|
$identified=1;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub process_request {
|
|
|
|
my $request = shift;
|
|
|
|
$callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my $distname = undef;
|
|
|
|
my $arch = undef;
|
2008-04-29 17:39:28 +00:00
|
|
|
$identified=0;
|
2008-05-15 15:48:34 +00:00
|
|
|
$::CDMOUNTPATH="/mnt/xcat";
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
@ARGV = @{$request->{arg}};
|
|
|
|
GetOptions(
|
|
|
|
'n|name|osver=s' => \$distname,
|
|
|
|
'a|arch=s' => \$arch
|
|
|
|
);
|
|
|
|
if ($arch and $arch =~ /i.86/) {
|
|
|
|
$arch = x86;
|
|
|
|
}
|
|
|
|
my @args = @ARGV; #copy ARGV
|
|
|
|
unless ($#args >= 0) {
|
|
|
|
$callback->({error=>"copycds needs at least one full path to ISO currently."});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach (@args) {
|
2008-01-10 13:41:31 +00:00
|
|
|
unless (/^\//) { #If not an absolute path, concatenate with client specified cwd
|
|
|
|
s/^/$request->{cwd}->[0]\//;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
unless (-r $_ and -f $_) {
|
2008-01-10 13:41:31 +00:00
|
|
|
$callback->({error=>"The management server was unable to find/read $_, ensure that file exists on the server at specified location"});
|
2007-10-26 22:44:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mkdir "/mnt/xcat";
|
2008-01-13 16:56:23 +00:00
|
|
|
if (system("mount -o loop,ro $_ /mnt/xcat")) {
|
2007-10-26 22:44:33 +00:00
|
|
|
$callback->({error=>"copycds was unable to examine $_ as an install image"});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $newreq = dclone($request);
|
|
|
|
$newreq->{command}= [ 'copycd' ]; #Note the singular, it's different
|
|
|
|
$newreq->{arg} = ["-p","/mnt/xcat"];
|
|
|
|
if ($distname) {
|
|
|
|
push @{$newreq->{arg}},("-n",$distname);
|
|
|
|
}
|
|
|
|
if ($arch) {
|
|
|
|
push @{$newreq->{arg}},("-a",$arch);
|
|
|
|
}
|
|
|
|
$doreq->($newreq,\&take_answer);
|
2008-05-15 15:48:34 +00:00
|
|
|
$::CDMOUNTPATH="";
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
system("umount /mnt/xcat");
|
2008-04-29 17:39:28 +00:00
|
|
|
unless ($identified) {
|
|
|
|
$callback->({error=>["copycds could not identify the ISO supplied, you may wish to try -n <osver>"],errorcode=>[1]});
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|