2008-02-18 15:57:25 +00:00
|
|
|
#!/usr/bin/perl
|
2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2007-12-11 19:15:28 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
2008-01-14 17:04:41 +00:00
|
|
|
$::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
|
|
|
|
2010-01-20 07:47:07 +00:00
|
|
|
use Cwd;
|
2007-10-26 22:44:33 +00:00
|
|
|
use File::Basename;
|
2007-11-26 19:59:04 +00:00
|
|
|
use xCAT::MsgUtils;
|
2008-02-21 21:10:35 +00:00
|
|
|
use xCAT::Client;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-09-10 14:32:19 +00:00
|
|
|
use Getopt::Std;
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
my $bname = basename($0);
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Main
|
|
|
|
#
|
|
|
|
# xcatDBcmds
|
|
|
|
#
|
2007-11-26 19:59:04 +00:00
|
|
|
# Build hash and submit request
|
2007-10-26 22:44:33 +00:00
|
|
|
#
|
2008-09-10 14:32:19 +00:00
|
|
|
# Handles: mkdef, chdef, lsdef, rmdef, mknimimage, rmnimimage,
|
|
|
|
# nimnodeset, mkdsklsnode, rmdsklsnode, and xcat2nim commands
|
2007-10-26 22:44:33 +00:00
|
|
|
#
|
2007-11-26 19:59:04 +00:00
|
|
|
# Note: The subroutines that implement these commands
|
2008-02-18 20:44:29 +00:00
|
|
|
# are, for the most part, in:
|
|
|
|
# /opt/xcat/lib/perl/xCAT_plugin/DBobjectdefs.pm
|
|
|
|
# /opt/xcat/lib/perl/xCAT_plugin/xcat2nim.pm
|
2008-09-10 14:32:19 +00:00
|
|
|
# /opt/xcat/lib/perl/xCAT_plugin/aixinstall.pm
|
2008-02-21 21:10:35 +00:00
|
|
|
# /opt/xcat/lib/perl/xCAT/DBobjUtils.pm
|
2007-10-26 22:44:33 +00:00
|
|
|
#
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
my $cmdref;
|
|
|
|
|
|
|
|
# set the command name to pass to the plugin
|
|
|
|
if ($bname =~ /xcatDBcmds/)
|
|
|
|
{
|
|
|
|
$cmdref->{command}->[0] = shift @ARGV;
|
|
|
|
}
|
|
|
|
elsif ($bname =~ /^(.*$)/)
|
|
|
|
{
|
|
|
|
$cmdref->{command}->[0] = $1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Bad usage\n");
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2010-01-20 07:47:07 +00:00
|
|
|
$cmdref->{cwd}->[0] = cwd();
|
2007-11-26 19:59:04 +00:00
|
|
|
# get info from files piped in as stdin
|
2010-11-18 09:11:14 +00:00
|
|
|
my $data;
|
|
|
|
if (($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/))
|
|
|
|
{
|
|
|
|
my $rin="";
|
|
|
|
vec($rin,fileno(STDIN),1)=1;
|
|
|
|
my $nfound=select($rout=$rin,"","",1);
|
|
|
|
if ($nfound)
|
|
|
|
{
|
|
|
|
while ( <STDIN> ) { $data.=$_; }
|
|
|
|
$cmdref->{stdin}->[0]=$data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (-p STDIN) {
|
|
|
|
while ( <STDIN> ) { $data.=$_; }
|
|
|
|
$cmdref->{stdin}->[0]=$data;
|
|
|
|
}
|
|
|
|
}
|
2007-11-26 19:59:04 +00:00
|
|
|
}
|
2010-01-20 07:47:07 +00:00
|
|
|
# The noderange can be specified through a noderange file
|
|
|
|
# the noderange file can be a relative path,
|
|
|
|
# convert the relative path to a full path.
|
|
|
|
my @tmpargv = ();
|
|
|
|
my @tmpv = @ARGV;
|
|
|
|
foreach my $a (@tmpv)
|
|
|
|
{
|
|
|
|
if (!($a =~ /=/) && !($a =~ /^-/)) {
|
|
|
|
my @tempnr = ();
|
|
|
|
foreach my $nr (split(/,/, $a)) {
|
|
|
|
if ($nr =~ /^\^(.*)$/) {
|
|
|
|
my $nrf = $1;
|
|
|
|
if ($nrf !~ /^\//) { #relative path
|
|
|
|
$nrf = Cwd::abs_path($nrf);
|
|
|
|
}
|
|
|
|
$nrf = "\^" . $nrf;
|
|
|
|
push @tempnr, $nrf;
|
|
|
|
} else {
|
|
|
|
push @tempnr, $nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$a = join(',',@tempnr);
|
|
|
|
}
|
|
|
|
push @tmpargv, $a;
|
|
|
|
}
|
|
|
|
@ARGV = @tmpargv;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
# add all the cmd line args to the hash - to pass to the plugin subroutine
|
2008-09-10 14:32:19 +00:00
|
|
|
foreach my $a (@ARGV)
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2008-09-10 14:32:19 +00:00
|
|
|
push(@{$cmdref->{arg}}, $a);
|
|
|
|
}
|
|
|
|
|
|
|
|
# For some commands we need to set the noderange value
|
|
|
|
# - don't want to depend on the order of args so need to pick
|
|
|
|
# the operand that doesn't have an "=" sign ( ie. attr=val format)
|
2008-09-24 18:14:11 +00:00
|
|
|
my @checkcmds = ("nimnodeset", "mkdsklsnode", "rmdsklsnode", "xcat2nim", "nimnodecust");
|
2008-09-10 14:32:19 +00:00
|
|
|
if (grep(/^$bname$/, @checkcmds) ) {
|
|
|
|
# strip off all options
|
2010-07-23 09:09:38 +00:00
|
|
|
# use getopt instead of getopts to let long options pass through
|
2010-07-30 08:35:44 +00:00
|
|
|
getopt('bdismotp');
|
2008-09-10 14:32:19 +00:00
|
|
|
# check the operands for a noderange
|
|
|
|
while (my $a = shift(@ARGV)) {
|
2009-10-10 17:12:05 +00:00
|
|
|
if (!($a =~ /=/) && !($a =~ /^-/)) {
|
2008-09-10 14:32:19 +00:00
|
|
|
$cmdref->{noderange}->[0]=$a;
|
2009-10-10 17:12:05 +00:00
|
|
|
last;
|
2008-09-10 14:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response);
|
|
|
|
exit $xCAT::Client::EXITCODE;
|