2008-05-19 19:05:54 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
use strict;
|
2013-05-31 10:33:15 +00:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT =
|
|
|
|
$ENV{'XCATROOT'} ? $ENV{'XCATROOT'}
|
|
|
|
: -d '/opt/xcat' ? '/opt/xcat'
|
|
|
|
: '/usr';
|
|
|
|
}
|
|
|
|
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2008-05-19 19:05:54 +00:00
|
|
|
use File::Basename;
|
2013-05-31 10:33:15 +00:00
|
|
|
use Getopt::Long;
|
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::NodeRange;
|
|
|
|
|
2008-05-19 19:05:54 +00:00
|
|
|
sub usage {
|
|
|
|
print basename($0)." usage:\n";
|
2013-05-31 10:33:15 +00:00
|
|
|
print " ".basename($0)." [-o|--osver] [-p|--profile] [-a|--arch] [-O|--osimage] [-c|--console] <noderange>\n"
|
2008-05-19 19:05:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:33:15 +00:00
|
|
|
|
|
|
|
|
2008-05-19 19:05:54 +00:00
|
|
|
my $OSVER;
|
|
|
|
my $PROFILE;
|
|
|
|
my $ARCH;
|
|
|
|
my $CONSOLE;
|
2013-05-31 10:33:15 +00:00
|
|
|
my $OSIMAGE;
|
|
|
|
|
|
|
|
Getopt::Long::Configure("bundling");
|
2008-05-19 19:05:54 +00:00
|
|
|
unless (GetOptions(
|
|
|
|
'o|osver=s' => \$OSVER,
|
|
|
|
'p|profile=s' => \$PROFILE,
|
|
|
|
'a|arch=s' => \$ARCH,
|
2013-05-31 10:33:15 +00:00
|
|
|
'O|osimage=s' => \$OSIMAGE,
|
2008-05-19 19:05:54 +00:00
|
|
|
'c|console' => \$CONSOLE
|
|
|
|
)) {
|
|
|
|
usage;
|
|
|
|
exit 1;
|
|
|
|
}
|
2010-04-26 17:53:32 +00:00
|
|
|
my $arraysize=@ARGV;
|
|
|
|
if ($arraysize > 1) {
|
|
|
|
print "noderange invalid\n";
|
|
|
|
usage;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if ($arraysize == 0) {
|
|
|
|
print "noderange not supplied\n";
|
|
|
|
usage;
|
|
|
|
exit 1;
|
|
|
|
}
|
2013-05-31 10:33:15 +00:00
|
|
|
|
2010-04-26 17:53:32 +00:00
|
|
|
my $noderange=@ARGV[0];
|
2013-05-31 10:33:15 +00:00
|
|
|
my $rc=0;
|
|
|
|
my %pnhash;
|
|
|
|
my @allnodes;
|
|
|
|
#use Data::Dumper;
|
2010-04-26 17:53:32 +00:00
|
|
|
|
2013-05-31 10:33:15 +00:00
|
|
|
sub checkoption{
|
|
|
|
my $optstring=shift;
|
|
|
|
if($OSVER) {print 'warning: "'.$optstring.'" specified, "[-o|--osver] '.$OSVER."\" ignored\n"};
|
|
|
|
if($PROFILE) {print 'warning: "'.$optstring.'" specified, "[-p|--profile] '.$PROFILE."\" ignored\n"};
|
|
|
|
if($ARCH) {print 'warning: "'.$optstring.'" specified, "[-a|--arch] '.$OSVER."\" ignored\n"};
|
2008-05-19 19:05:54 +00:00
|
|
|
}
|
2013-05-31 10:33:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
if($OSIMAGE){
|
|
|
|
&checkoption("[-O|--osimage] $OSIMAGE");
|
|
|
|
$rc=system("nodeset $noderange osimage=$OSIMAGE");
|
|
|
|
if ($rc) { die "nodeset failure" };
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
@allnodes=noderange($noderange);
|
|
|
|
foreach(@allnodes){
|
|
|
|
my $tab=xCAT::Table->new("nodetype");
|
|
|
|
my $nthash=$tab->getNodeAttribs($_,['provmethod']);
|
|
|
|
$tab->close();
|
|
|
|
if(defined($nthash) and defined($nthash->{'provmethod'}))
|
|
|
|
{
|
|
|
|
push(@{$pnhash{$nthash->{'provmethod'}}},$_);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push(@{$pnhash{'BLANK###'}},$_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach my $key (keys %pnhash)
|
|
|
|
{
|
|
|
|
my $rclocal=0;
|
|
|
|
my $nodes=join(',',@{$pnhash{$key}});
|
|
|
|
if($key =~ /^(install|netboot|statelite)$/)
|
|
|
|
{
|
|
|
|
my $nodechline = "";
|
|
|
|
if ($OSVER) {
|
|
|
|
$nodechline = "nodetype.os=$OSVER";
|
|
|
|
}
|
|
|
|
if ($PROFILE) {
|
|
|
|
$nodechline .= " nodetype.profile=$PROFILE";
|
|
|
|
}
|
|
|
|
if ($ARCH) {
|
|
|
|
$nodechline .= " nodetype.arch=$ARCH";
|
|
|
|
}
|
|
|
|
if ($nodechline) {
|
|
|
|
$rclocal=system("nodech $nodes $nodechline");
|
|
|
|
if ($rclocal) {
|
|
|
|
print "nodech failure\n";
|
|
|
|
$rc=$rclocal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unless($rc){
|
|
|
|
$rclocal=system("nodeset $nodes $key");
|
|
|
|
if ($rclocal) {
|
|
|
|
print "nodeset $nodes failure\n";
|
|
|
|
$rc=$rclocal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif($key eq 'BLANK###')
|
|
|
|
{
|
|
|
|
print "nodetype.provmethod must be specified for nodes: $nodes\n";
|
|
|
|
$rc=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&checkoption("nodetype.provmethod=$key");
|
|
|
|
$rclocal=system("nodeset $nodes osimage");
|
|
|
|
if ($rclocal) {
|
|
|
|
print "nodeset $nodes failure\n";
|
|
|
|
$rc=$rclocal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-05-19 19:05:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:33:15 +00:00
|
|
|
if($rc){
|
|
|
|
die "nodeset failure";
|
2008-05-19 19:05:54 +00:00
|
|
|
}
|
2013-05-31 10:33:15 +00:00
|
|
|
|
|
|
|
|
2008-05-19 19:05:54 +00:00
|
|
|
$rc=system("rpower $noderange boot");
|
|
|
|
if ($rc) { die "rpower failure" };
|
2013-05-31 10:33:15 +00:00
|
|
|
|
2008-05-19 19:05:54 +00:00
|
|
|
if (basename($0) =~ /rinstall/) {
|
|
|
|
if ($CONSOLE) {
|
2013-05-31 10:33:15 +00:00
|
|
|
if(scalar @allnodes ne 1){
|
|
|
|
die "rinstall [-c|--console] will only work if there is only one node in the noderange. See winstall(8) for consoles on multiple systems";
|
|
|
|
}
|
2008-05-19 19:05:54 +00:00
|
|
|
exec("rcons $noderange");
|
|
|
|
}
|
|
|
|
} elsif (basename($0) =~ /winstall/) {
|
|
|
|
exec("wcons $noderange");
|
|
|
|
}
|