From 6913b1107ecd2068d33e071202c4618f55b980af Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 6 Oct 2009 14:25:05 +0000 Subject: [PATCH] add new groupfiles4dsh git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4307 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-client/share/xcat/tools/groupfiles4dsh | 124 ++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100755 xCAT-client/share/xcat/tools/groupfiles4dsh diff --git a/xCAT-client/share/xcat/tools/groupfiles4dsh b/xCAT-client/share/xcat/tools/groupfiles4dsh new file mode 100755 index 000000000..2e103b436 --- /dev/null +++ b/xCAT-client/share/xcat/tools/groupfiles4dsh @@ -0,0 +1,124 @@ +#!/usr/bin/perl +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#(C)IBM Corp +# + +BEGIN +{ + $::XCATROOT = + $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} + : -d '/opt/xcat' ? '/opt/xcat' + : '/usr'; +} +use lib "$::XCATROOT/lib/perl"; +use Getopt::Long; +use xCAT::MsgUtils; +use xCAT::Utils; + +#----------------------------------------------------------------------------- + +=head1 groupfiles4dsh + + + This tool will build a directory of files for each defined + nodegroup in xCAT. The file will be named the nodegroup name and + contain a list of nodes that belong to the nodegroup. + The file can be used as input to the AIX dsh command run in the DSH + context. + The purpose of this tool is to allow backward compatiblity with scripts + that were created using the AIX or CSM dsh command. + + + groupfiles4dsh -p + example: groupfiles4dsh -p /tmp/dshnodegrpfiles + + Use: export DSH_CONTEXT=DSH ( default unless CSM is installed) + export DSH_NODE_RSH=/bin/ssh (default is rsh) + export DSH_NODEGROUP_PATH= /tmp/dshnodegrpfiles + + dsh -N all date ( all is a group in xCAT) + dsh -a date ( see man dsh, DSH context) + +=cut + +#----------------------------------------------------------------------------- +# Main +my $rc = 0; +&parse_args; +my $cmd = "lsdef -t group"; +my @grpoutput = xCAT::Utils->runcmd($cmd, 0); +if ($::RUNCMD_RC != 0) +{ # error + xCAT::MsgUtils->message("E", "Error running $cmd"); + exit 1; +} +foreach my $group (@grpoutput) +{ + my $cmd = "nodels $group > $::PATH/$group"; + xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC != 0) + { # error + xCAT::MsgUtils->message("E", "Error running $cmd\n"); + exit 1; + } + +} +exit $rc; + +#----------------------------------------------------------------------------- + +=head3 parse_args + + Parses for input + +=cut + +#----------------------------------------------------------------------------- +sub parse_args +{ + my $msg; + my $usagemsg; + $usagemsg = + "groupfiles4dsh -h \ngroupfiles4dsh -v \ngroupfiles4dsh [-p] [path to group files directory]"; + Getopt::Long::Configure("posix_default"); + Getopt::Long::Configure("no_gnu_compat"); + Getopt::Long::Configure("bundling"); + if ( + !GetOptions( + 'p|path=s' => \$::PATH, + 'h|help' => \$::HELP, + 'v|version' => \$::VERSION + + ) + ) + { + xCAT::MsgUtils->message("E", $usagemsg); + exit 1; + } + if ($::HELP) + { + xCAT::MsgUtils->message("I", $usagemsg); + exit 0; + } + if ($::VERSION) + { + my $version = xCAT::Utils->Version(); + xCAT::MsgUtils->message("I", $version); + exit 0; + } + if (!($::PATH)) + { + my $msg = + "Requires -p with path to existing directory to hold group files."; + xCAT::MsgUtils->message("E", $msg); + exit 1; + } + if (!(-d $::PATH)) + { + my $msg = " Input directory must exist."; + xCAT::MsgUtils->message("E", $msg); + exit 1; + } + +} +