2007-10-26 22:44:33 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2008-02-14 14:25:49 +00:00
|
|
|
|
|
|
|
# Just like xcatclient, but needs to read a file in and pass it as $request->data
|
|
|
|
|
|
|
|
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
|
2007-12-11 19:15:28 +00:00
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2007-10-26 22:44:33 +00:00
|
|
|
use File::Basename;
|
2008-02-14 14:25:49 +00:00
|
|
|
use xCAT::Client;
|
|
|
|
use Getopt::Long;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
sub usage {
|
|
|
|
print "Usage: tabrestore <tablename>.csv\n";
|
|
|
|
print " tabrestore [-?|-h|--help]\n";
|
|
|
|
exit $_[0];
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
#my $bname = basename($0);
|
2007-10-26 22:44:33 +00:00
|
|
|
my $cmdref;
|
|
|
|
$cmdref->{command}->[0] = "tabrestore";
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
# Get the options
|
|
|
|
my $HELP;
|
|
|
|
if (!GetOptions('h|?|help' => \$HELP)) { usage(1); }
|
2007-10-26 22:44:33 +00:00
|
|
|
my $arg=shift(@ARGV);
|
|
|
|
while ($arg =~ /^-/) {
|
|
|
|
push (@{$cmdref->{arg}}, $arg);
|
|
|
|
$arg=shift(@ARGV);
|
|
|
|
}
|
2008-02-14 14:25:49 +00:00
|
|
|
unless ($arg) { usage(2); } # no filename specified
|
|
|
|
|
|
|
|
# Open the specified table file and put its contents in the data key
|
2007-10-26 22:44:33 +00:00
|
|
|
my $filename = $arg;
|
|
|
|
my $tabname = basename($filename);
|
|
|
|
$tabname =~ s/\..*//;
|
|
|
|
$cmdref->{table}->[0] = $tabname;
|
|
|
|
my $fh;
|
2008-02-14 14:25:49 +00:00
|
|
|
unless (open($fh,$filename)) { print "Error: Unable to open $arg for reading.\n"; exit 3; }
|
2007-10-26 22:44:33 +00:00
|
|
|
while (<$fh>) {
|
|
|
|
push @{$cmdref->{data}},$_;
|
|
|
|
}
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
push (@{$cmdref->{arg}}, @ARGV); # get the rest of the arguments
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response);
|
|
|
|
exit $xCAT::Client::EXITCODE;
|