2011-04-15 20:05:58 +00:00
|
|
|
# IBM(c) 2011 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2009-06-15 11:23:10 +00:00
|
|
|
#-------------------------------------------------------
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2009-06-15 11:23:10 +00:00
|
|
|
=head 1
|
2011-04-15 20:05:58 +00:00
|
|
|
|
|
|
|
xCAT plugin to handle xCAT UI commands
|
2009-06-15 11:23:10 +00:00
|
|
|
|
|
|
|
=cut
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2009-06-15 11:23:10 +00:00
|
|
|
#-------------------------------------------------------
|
|
|
|
|
|
|
|
package xCAT_plugin::web;
|
|
|
|
use strict;
|
|
|
|
require xCAT::Utils;
|
|
|
|
require xCAT::MsgUtils;
|
|
|
|
use Getopt::Long;
|
|
|
|
use Data::Dumper;
|
2010-07-01 10:40:39 +00:00
|
|
|
use LWP::Simple;
|
2010-08-26 05:16:31 +00:00
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::NodeRange;
|
2009-06-15 11:23:10 +00:00
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
sub handled_commands {
|
|
|
|
return { webrun => "web", };
|
2009-06-15 11:23:10 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
sub process_request {
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $sub_req = shift;
|
|
|
|
my %authorized_cmds = (
|
|
|
|
'update' => \&web_update,
|
|
|
|
'lscondition' => \&web_lscond,
|
|
|
|
'lsresponse' => \&web_lsresp,
|
|
|
|
'lscondresp' => \&web_lscondresp,
|
|
|
|
'mkcondresp' => \&web_mkcondresp,
|
|
|
|
'startcondresp' => \&web_startcondresp,
|
|
|
|
'stopcondresp' => \&web_stopcondresp,
|
|
|
|
'lsevent' => \&web_lsevent,
|
|
|
|
'unlock' => \&web_unlock,
|
|
|
|
'rmcstart' => \&web_rmcmonStart,
|
|
|
|
'rmcshow' => \&web_rmcmonShow,
|
|
|
|
'gangliastart' => \&web_gangliastart,
|
2010-11-09 05:03:33 +00:00
|
|
|
'gangliastop' => \&web_gangliastop,
|
2010-11-05 22:51:12 +00:00
|
|
|
'gangliastatus' => \&web_gangliastatus,
|
2011-03-08 13:34:42 +00:00
|
|
|
'gangliacheck' => \&web_gangliacheck,
|
2011-04-22 21:02:51 +00:00
|
|
|
'installganglia'=> \&web_installganglia,
|
2010-12-23 03:03:19 +00:00
|
|
|
'mkcondition' => \&web_mkcondition,
|
2011-01-12 10:43:45 +00:00
|
|
|
'monls' => \&web_monls,
|
2011-03-16 09:19:02 +00:00
|
|
|
'discover' => \&web_discover,
|
|
|
|
'updatevpd' => \&web_updatevpd,
|
2011-06-28 08:37:16 +00:00
|
|
|
'createimage' => \&web_createimage,
|
|
|
|
'provision' => \&web_provision
|
2010-11-05 22:51:12 +00:00
|
|
|
);
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
#check whether the request is authorized or not
|
2010-11-05 22:51:12 +00:00
|
|
|
split ' ', $request->{arg}->[0];
|
|
|
|
my $cmd = $_[0];
|
|
|
|
if ( grep { $_ eq $cmd } keys %authorized_cmds ) {
|
|
|
|
my $func = $authorized_cmds{$cmd};
|
|
|
|
$func->( $request, $callback, $sub_req );
|
2011-04-15 20:05:58 +00:00
|
|
|
} else {
|
2010-11-05 22:51:12 +00:00
|
|
|
$callback->( { error => "$cmd is not authorized!\n", errorcode => [1] } );
|
|
|
|
}
|
2009-06-15 11:23:10 +00:00
|
|
|
}
|
|
|
|
|
2009-09-10 07:34:11 +00:00
|
|
|
sub web_lsevent {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my @ret = `$request->{arg}->[0]`;
|
2009-09-10 07:34:11 +00:00
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
#please refer the manpage for the output format of "lsevent"
|
2011-04-15 20:05:58 +00:00
|
|
|
my $data = [];
|
2010-12-13 10:17:24 +00:00
|
|
|
my $record = '';
|
2011-04-15 20:05:58 +00:00
|
|
|
my $i = 0;
|
|
|
|
my $j = 0;
|
2009-09-10 07:34:11 +00:00
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
foreach my $item (@ret) {
|
|
|
|
if ( $item ne "\n" ) {
|
|
|
|
chomp $item;
|
|
|
|
my ( $key, $value ) = split( "=", $item );
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( $j < 2 ) {
|
2010-12-13 10:17:24 +00:00
|
|
|
$record .= $value . ';';
|
2011-04-15 20:05:58 +00:00
|
|
|
} else {
|
2010-12-13 10:17:24 +00:00
|
|
|
$record .= $value;
|
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
$j++;
|
|
|
|
if ( $j == 3 ) {
|
|
|
|
$i++;
|
|
|
|
$j = 0;
|
2011-04-15 20:05:58 +00:00
|
|
|
push( @$data, $record );
|
2010-12-13 10:17:24 +00:00
|
|
|
$record = '';
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-13 10:17:24 +00:00
|
|
|
$callback->( { data => $data } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
sub web_mkcondresp {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2010-12-27 09:02:40 +00:00
|
|
|
my $conditionName = $request->{arg}->[1];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $temp = $request->{arg}->[2];
|
|
|
|
my $cmd = '';
|
|
|
|
my @resp = split( ':', $temp );
|
2010-12-27 09:02:40 +00:00
|
|
|
|
|
|
|
#create new associations
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( 1 < length( @resp[0] ) ) {
|
|
|
|
$cmd = substr( @resp[0], 1 );
|
2010-12-27 09:02:40 +00:00
|
|
|
$cmd =~ s/,/ /;
|
|
|
|
$cmd = 'mkcondresp ' . $conditionName . ' ' . $cmd;
|
2011-04-15 20:05:58 +00:00
|
|
|
my $retInfo = xCAT::Utils->runcmd( $cmd, -1, 1 );
|
2010-12-27 09:02:40 +00:00
|
|
|
}
|
2009-09-10 07:34:11 +00:00
|
|
|
|
2010-12-27 09:02:40 +00:00
|
|
|
#delete old associations
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( 1 < length( @resp[1] ) ) {
|
|
|
|
$cmd = substr( @resp[1], 1 );
|
2010-12-27 09:02:40 +00:00
|
|
|
$cmd =~ s/,/ /;
|
|
|
|
$cmd = 'rmcondresp ' . $conditionName . ' ' . $cmd;
|
2011-04-15 20:05:58 +00:00
|
|
|
my $retInfo = xCAT::Utils->runcmd( $cmd, -1, 1 );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
2010-12-27 09:02:40 +00:00
|
|
|
#there's no output for "mkcondresp"
|
2011-01-12 05:54:46 +00:00
|
|
|
$cmd = 'startcondresp ' . $conditionName;
|
2011-04-15 20:05:58 +00:00
|
|
|
my $refInfo = xCAT::Utils->runcmd( $cmd, -1, 1 );
|
|
|
|
$callback->( { data => "Success." } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub web_startcondresp {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2010-12-28 09:34:44 +00:00
|
|
|
my $conditionName = $request->{arg}->[1];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $cmd = 'startcondresp "' . $conditionName . '"';
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( $cmd, -1, 1 );
|
|
|
|
$callback->( { data => 'start monitor "' . $conditionName . '" Successful.' } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub web_stopcondresp {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2010-12-28 09:34:44 +00:00
|
|
|
my $conditionName = $request->{arg}->[1];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $cmd = 'stopcondresp "' . $conditionName . '"';
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( $cmd, -1, 1 );
|
|
|
|
$callback->( { data => 'stop monitor "' . $conditionName . '" Successful.' } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub web_lscond {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2010-12-23 03:03:19 +00:00
|
|
|
my $nodeRange = $request->{arg}->[1];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $names = '';
|
2010-12-23 03:03:19 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
#list all the conditions on all lpars in this group
|
|
|
|
if ($nodeRange) {
|
2010-12-23 03:03:19 +00:00
|
|
|
my @nodes = xCAT::NodeRange::noderange($nodeRange);
|
|
|
|
my %tempHash;
|
|
|
|
my $nodeCount = @nodes;
|
2011-04-15 20:05:58 +00:00
|
|
|
|
2010-12-23 03:03:19 +00:00
|
|
|
#no node in this group
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( 1 > $nodeCount ) {
|
2010-12-23 03:03:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2010-12-23 03:03:19 +00:00
|
|
|
#no conditions return
|
2011-04-15 20:05:58 +00:00
|
|
|
my $tempCmd = 'lscondition -d :' . join( ',', @nodes );
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( $tempCmd, -1, 1 );
|
|
|
|
if ( 1 > @$retInfo ) {
|
2010-12-23 03:03:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shift @$retInfo;
|
|
|
|
shift @$retInfo;
|
2011-04-15 20:05:58 +00:00
|
|
|
foreach my $line (@$retInfo) {
|
|
|
|
my @temp = split( ':', $line );
|
|
|
|
$tempHash{ @temp[0] }++;
|
2010-12-23 03:03:19 +00:00
|
|
|
}
|
2009-09-10 07:34:11 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
foreach my $name ( keys(%tempHash) ) {
|
|
|
|
if ( $nodeCount == $tempHash{$name} ) {
|
2010-12-23 03:03:19 +00:00
|
|
|
$names = $names . $name . ';';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
#only list the conditions on local.
|
|
|
|
else {
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( 'lscondition -d', -1, 1 );
|
|
|
|
if ( 2 > @$retInfo ) {
|
2010-12-28 09:34:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
2010-12-23 03:03:19 +00:00
|
|
|
shift @$retInfo;
|
|
|
|
shift @$retInfo;
|
|
|
|
foreach my $line (@$retInfo) {
|
2011-04-15 20:05:58 +00:00
|
|
|
my @temp = split( ':', $line );
|
|
|
|
$names = $names . @temp[0] . ':' . substr( @temp[2], 1, 3 ) . ';';
|
|
|
|
}
|
2010-12-23 03:03:19 +00:00
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
|
|
|
if ( '' eq $names ) {
|
2010-12-23 03:03:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
|
|
|
$names = substr( $names, 0, ( length($names) - 1 ) );
|
2010-12-23 03:03:19 +00:00
|
|
|
$callback->( { data => $names } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_mkcondition {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2009-09-10 07:34:11 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( 'change' eq $request->{arg}->[1] ) {
|
2010-12-23 03:03:19 +00:00
|
|
|
my @nodes;
|
|
|
|
my $conditionName = $request->{arg}->[2];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $groupName = $request->{arg}->[3];
|
2010-12-23 03:03:19 +00:00
|
|
|
|
2011-07-06 07:59:41 +00:00
|
|
|
my $retInfo = xCAT::Utils->runcmd( 'nodels ' . $groupName . " ppc.nodetype", -1, 1 );
|
2011-04-15 20:05:58 +00:00
|
|
|
foreach my $line (@$retInfo) {
|
|
|
|
my @temp = split( ':', $line );
|
|
|
|
if ( @temp[1] !~ /lpar/ ) {
|
2010-12-23 03:03:19 +00:00
|
|
|
$callback->( { data => 'Error : only the compute nodes\' group could select.' } );
|
|
|
|
return;
|
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
|
|
|
push( @nodes, @temp[0] );
|
2010-12-23 03:03:19 +00:00
|
|
|
}
|
2009-09-10 07:34:11 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
xCAT::Utils->runcmd( 'chcondition -n ' + join( ',', @nodes ) + '-m m ' + $conditionName );
|
2010-12-23 03:03:19 +00:00
|
|
|
$callback->( { data => 'Change scope success.' } );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
|
2010-12-23 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub web_lsresp {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $names = '';
|
2010-12-25 02:17:00 +00:00
|
|
|
my @temp;
|
2011-04-15 20:05:58 +00:00
|
|
|
my $retInfo = xCAT::Utils->runcmd( 'lsresponse -d', -1, 1 );
|
2010-12-23 03:03:19 +00:00
|
|
|
|
|
|
|
shift @$retInfo;
|
|
|
|
shift @$retInfo;
|
|
|
|
foreach my $line (@$retInfo) {
|
2011-04-15 20:05:58 +00:00
|
|
|
@temp = split( ':', $line );
|
2010-12-23 03:03:19 +00:00
|
|
|
$names = $names . @temp[0] . ';';
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
$names = substr( $names, 0, ( length($names) - 1 ) );
|
2010-12-23 03:03:19 +00:00
|
|
|
$callback->( { data => $names } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub web_lscondresp {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2011-04-15 20:05:58 +00:00
|
|
|
my $names = '';
|
2010-12-25 02:17:00 +00:00
|
|
|
my @temp;
|
2011-04-15 20:05:58 +00:00
|
|
|
|
2010-12-25 02:17:00 +00:00
|
|
|
#if there is condition name, then we only show the condition linked associations.
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( $request->{arg}->[1] ) {
|
2010-12-25 02:17:00 +00:00
|
|
|
my $cmd = 'lscondresp -d ' . $request->{arg}->[1];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $retInfo = xCAT::Utils->runcmd( $cmd, -1, 1 );
|
|
|
|
if ( 2 > @$retInfo ) {
|
2010-12-25 02:17:00 +00:00
|
|
|
$callback->( { data => '' } );
|
|
|
|
return;
|
|
|
|
}
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2010-12-25 02:17:00 +00:00
|
|
|
shift @$retInfo;
|
|
|
|
shift @$retInfo;
|
2011-04-15 20:05:58 +00:00
|
|
|
for my $line (@$retInfo) {
|
|
|
|
@temp = split( ':', $line );
|
2010-12-25 02:17:00 +00:00
|
|
|
$names = $names . @temp[1] . ';';
|
|
|
|
}
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
2010-12-25 02:17:00 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
$names = substr( $names, 0, ( length($names) - 1 ) );
|
2010-12-25 02:17:00 +00:00
|
|
|
$callback->( { data => $names } );
|
2009-09-10 07:34:11 +00:00
|
|
|
}
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2009-06-15 11:23:10 +00:00
|
|
|
sub web_update {
|
2010-11-05 22:51:12 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $os = "unknow";
|
|
|
|
my $RpmNames = $request->{arg}->[1];
|
|
|
|
my $repository = $request->{arg}->[2];
|
|
|
|
my $FileHandle;
|
|
|
|
my $cmd;
|
|
|
|
my $ReturnInfo;
|
|
|
|
my $WebpageContent = undef;
|
|
|
|
my $RemoteRpmFilePath = undef;
|
|
|
|
my $LocalRpmFilePath = undef;
|
|
|
|
|
|
|
|
if ( xCAT::Utils->isLinux() ) {
|
|
|
|
$os = xCAT::Utils->osver();
|
|
|
|
|
|
|
|
#suse linux
|
|
|
|
if ( $os =~ /sles.*/ ) {
|
|
|
|
$RpmNames =~ s/,/ /g;
|
|
|
|
|
|
|
|
#create zypper command
|
|
|
|
$cmd = "zypper -n -p " . $repository . " update " . $RpmNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
#redhat
|
|
|
|
else {
|
|
|
|
|
|
|
|
#check the yum config file, and delect it if exist.
|
|
|
|
if ( -e "/tmp/xCAT_update.yum.conf" ) {
|
|
|
|
unlink("/tmp/xCAT_update.yum.conf");
|
|
|
|
}
|
|
|
|
|
|
|
|
#create file, return error if failed.
|
|
|
|
unless ( open( $FileHandle, '>>', "/tmp/xCAT_update.yum.conf" ) ) {
|
|
|
|
$callback->( { error => "Create temp file error!\n", errorcode => [1] } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#write the rpm path into config file.
|
|
|
|
print $FileHandle "[xcat_temp_update]\n";
|
|
|
|
print $FileHandle "name=temp prepository\n";
|
|
|
|
$repository = "baseurl=" . $repository . "\n";
|
|
|
|
print $FileHandle $repository;
|
|
|
|
print $FileHandle "enabled=1\n";
|
|
|
|
print $FileHandle "gpgcheck=0\n";
|
|
|
|
close($FileHandle);
|
|
|
|
|
|
|
|
#use system to run the cmd "yum -y -c config-file update rpm-names"
|
|
|
|
$RpmNames =~ s/,/ /g;
|
|
|
|
$cmd = "yum -y -c /tmp/xCAT_update.yum.conf update " . $RpmNames . " 2>&1";
|
|
|
|
}
|
|
|
|
|
|
|
|
#run the command and return the result
|
|
|
|
$ReturnInfo = readpipe($cmd);
|
|
|
|
$callback->( { info => $ReturnInfo } );
|
|
|
|
}
|
|
|
|
|
|
|
|
#AIX
|
|
|
|
else {
|
|
|
|
|
|
|
|
#open the rpmpath(may be error), and read the page's content
|
|
|
|
$WebpageContent = LWP::Simple::get($repository);
|
|
|
|
unless ( defined($WebpageContent) ) {
|
|
|
|
$callback->( { error => "open $repository error, please check!!", errorcode => [1] } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#must support for updating several rpms.
|
|
|
|
foreach ( split( /,/, $RpmNames ) ) {
|
|
|
|
|
|
|
|
#find out rpms' corresponding rpm href on the web page
|
|
|
|
$WebpageContent =~ m/href="($_-.*?[ppc64|noarch].rpm)/i;
|
|
|
|
unless ( defined($1) ) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$RemoteRpmFilePath = $repository . $1;
|
|
|
|
$LocalRpmFilePath = '/tmp/' . $1;
|
|
|
|
|
|
|
|
#download rpm package to temp
|
|
|
|
unless ( -e $LocalRpmFilePath ) {
|
|
|
|
$cmd = "wget -O " . $LocalRpmFilePath . " " . $RemoteRpmFilePath;
|
|
|
|
if ( 0 != system($cmd) ) {
|
2011-04-15 20:05:58 +00:00
|
|
|
$ReturnInfo =
|
|
|
|
$ReturnInfo . "update " . $_ . " failed: can not download the rpm\n";
|
2010-11-05 22:51:12 +00:00
|
|
|
$callback->( { error => $ReturnInfo, errorcode => [1] } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#update rpm by rpm packages.
|
|
|
|
$cmd = "rpm -U " . $LocalRpmFilePath . " 2>&1";
|
|
|
|
$ReturnInfo = $ReturnInfo . readpipe($cmd);
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
$callback->( { info => $ReturnInfo } );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
2009-06-15 11:23:10 +00:00
|
|
|
}
|
2010-06-15 21:09:35 +00:00
|
|
|
|
|
|
|
sub web_unlock {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $node = $request->{arg}->[1];
|
|
|
|
my $password = $request->{arg}->[2];
|
2011-04-15 20:05:58 +00:00
|
|
|
|
|
|
|
# Unlock a node by setting up the SSH keys
|
|
|
|
my $out = `DSH_REMOTE_PASSWORD=$password xdsh $node -K`;
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2010-06-15 21:09:35 +00:00
|
|
|
$callback->( { data => $out } );
|
2010-08-26 05:16:31 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
sub web_gangliastatus {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
|
|
|
|
# Get node range
|
2010-11-09 05:03:33 +00:00
|
|
|
my $nr = $request->{arg}->[1];
|
|
|
|
my $out = `xdsh $nr "service gmond status"`;
|
2010-11-05 22:51:12 +00:00
|
|
|
|
|
|
|
# Parse output, and use $callback to send back to the web interface
|
|
|
|
# Output looks like:
|
|
|
|
# node_1: Checking for gmond: ..running
|
|
|
|
# node_2: Checking for gmond: ..running
|
|
|
|
my @lines = split( '\n', $out );
|
|
|
|
my $line;
|
|
|
|
my $status;
|
|
|
|
foreach $line (@lines) {
|
|
|
|
if ( $line =~ m/running/i ) {
|
|
|
|
$status = 'on';
|
2011-04-15 20:05:58 +00:00
|
|
|
} else {
|
2010-11-05 22:51:12 +00:00
|
|
|
$status = 'off';
|
|
|
|
}
|
|
|
|
|
|
|
|
split( ': ', $line );
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
node => [
|
|
|
|
{
|
|
|
|
name => [ $_[0] ], # Node name
|
|
|
|
data => [$status] # Output
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub web_gangliastart() {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2010-11-09 05:03:33 +00:00
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
# Get node range
|
|
|
|
my $nr = $request->{arg}->[1];
|
2010-11-09 05:03:33 +00:00
|
|
|
if ( !$nr ) {
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
# If no node range is given, then assume all nodes
|
|
|
|
$nr = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add gangliamon to the monitoring table
|
|
|
|
my $info;
|
|
|
|
my $output = `monadd gangliamon`;
|
2010-11-09 05:03:33 +00:00
|
|
|
my @lines = split( '\n', $output );
|
|
|
|
foreach (@lines) {
|
2010-11-05 22:51:12 +00:00
|
|
|
if ($_) {
|
2010-11-09 05:03:33 +00:00
|
|
|
$info .= ( $_ . "\n" );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run the ganglia configuration script on node
|
|
|
|
$output = `moncfg gangliamon $nr -r`;
|
2010-11-09 05:03:33 +00:00
|
|
|
@lines = split( '\n', $output );
|
|
|
|
foreach (@lines) {
|
2010-11-05 22:51:12 +00:00
|
|
|
if ($_) {
|
2010-11-09 05:03:33 +00:00
|
|
|
$info .= ( $_ . "\n" );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start the gmond daemon on node
|
|
|
|
$output = `monstart gangliamon $nr -r`;
|
2010-11-09 05:03:33 +00:00
|
|
|
@lines = split( '\n', $output );
|
|
|
|
foreach (@lines) {
|
2010-11-05 22:51:12 +00:00
|
|
|
if ($_) {
|
2010-11-09 05:03:33 +00:00
|
|
|
$info .= ( $_ . "\n" );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$callback->( { info => $info } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub web_gangliastop() {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
2010-11-09 05:03:33 +00:00
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
# Get node range
|
|
|
|
my $nr = $request->{arg}->[1];
|
2010-11-09 05:03:33 +00:00
|
|
|
if ( !$nr ) {
|
2010-11-05 22:51:12 +00:00
|
|
|
$nr = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start the gmond daemon on node
|
|
|
|
my $info;
|
|
|
|
my $output = `monstop gangliamon $nr -r`;
|
2010-11-09 05:03:33 +00:00
|
|
|
my @lines = split( '\n', $output );
|
|
|
|
foreach (@lines) {
|
2010-11-05 22:51:12 +00:00
|
|
|
if ($_) {
|
2010-11-09 05:03:33 +00:00
|
|
|
$info .= ( $_ . "\n" );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$callback->( { info => $info } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-19 20:31:00 +00:00
|
|
|
sub web_gangliacheck() {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
|
|
|
|
# Get node range
|
|
|
|
my $nr = $request->{arg}->[1];
|
|
|
|
if ( !$nr ) {
|
|
|
|
$nr = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if ganglia RPMs are installed
|
|
|
|
my $info;
|
|
|
|
my $info = `xdsh $nr "rpm -q ganglia-gmond libganglia libconfuse"`;
|
|
|
|
$callback->( { info => $info } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-22 21:02:51 +00:00
|
|
|
sub web_installganglia() {
|
2011-04-22 15:58:37 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
|
2011-04-22 21:02:51 +00:00
|
|
|
# Get node range
|
|
|
|
my $nr = $request->{arg}->[1];
|
|
|
|
my @nodes = split( ',', $nr );
|
|
|
|
|
2011-04-28 20:24:10 +00:00
|
|
|
# Loop through each node
|
2011-04-22 21:02:51 +00:00
|
|
|
my $info;
|
|
|
|
my $tab;
|
|
|
|
my $attrs;
|
2011-04-28 20:24:10 +00:00
|
|
|
my $osType;
|
|
|
|
my $dir;
|
|
|
|
my $pkglist;
|
|
|
|
my $defaultDir;
|
2011-04-22 21:02:51 +00:00
|
|
|
foreach (@nodes) {
|
2011-04-28 20:24:10 +00:00
|
|
|
# Get os, arch, profile, and provmethod
|
2011-04-22 21:02:51 +00:00
|
|
|
$tab = xCAT::Table->new('nodetype');
|
2011-04-28 20:24:10 +00:00
|
|
|
$attrs = $tab->getNodeAttribs( $_, ['os', 'arch', 'profile', 'provmethod'] );
|
|
|
|
|
|
|
|
# If any attributes are missing, skip
|
|
|
|
if (!$attrs->{'os'} || !$attrs->{'arch'} || !$attrs->{'profile'} || !$attrs->{'provmethod'}) {
|
|
|
|
$callback->( { info => "$_: (Error) Missing attribute (os, arch, profile, or provmethod) in nodetype table" } );
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the right OS type
|
|
|
|
if ($attrs->{'os'} =~ /fedora/) {
|
|
|
|
$osType = 'fedora';
|
|
|
|
} elsif ($attrs->{'os'} =~ /rh/ || $attrs->{'os'} =~ /rhel/ || $attrs->{'os'} =~ /rhels/) {
|
|
|
|
$osType = 'rh';
|
|
|
|
} elsif ($attrs->{'os'} =~ /sles/) {
|
|
|
|
$osType = 'sles';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Assume /install/post/otherpkgs/<os>/<arch>/ directory is created
|
|
|
|
# If Ganglia RPMs (ganglia-gmond-*, libconfuse-*, and libganglia-*) are not in directory
|
|
|
|
$dir = "/install/post/otherpkgs/$attrs->{'os'}/$attrs->{'arch'}/";
|
|
|
|
if (!(`test -e $dir/ganglia-gmond-* && echo 'File exists'` &&
|
|
|
|
`test -e $dir/libconfuse-* && echo 'File exists'` &&
|
|
|
|
`test -e $dir/libganglia-* && echo 'File exists'`)) {
|
|
|
|
# Skip
|
|
|
|
$callback->( { info => "$_: (Error) Missing Ganglia RPMs under $dir" } );
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find pkglist directory
|
|
|
|
$dir = "/install/custom/$attrs->{'provmethod'}/$osType";
|
|
|
|
if (!(`test -d $dir && echo 'Directory exists'`)) {
|
|
|
|
# Create pkglist directory
|
|
|
|
`mkdir -p $dir`;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find pkglist file
|
|
|
|
# Ganglia RPM names should be added to /install/custom/<inst_type>/<ostype>/<profile>.<os>.<arch>.otherpkgs.pkglist
|
|
|
|
$pkglist = "$attrs->{'profile'}.$attrs->{'os'}.$attrs->{'arch'}.otherpkgs.pkglist";
|
|
|
|
if (!(`test -e $dir/$pkglist && echo 'File exists'`)) {
|
|
|
|
# Copy default otherpkgs.pkglist
|
|
|
|
$defaultDir = "/opt/xcat/share/xcat/$attrs->{'provmethod'}/$osType";
|
|
|
|
if (`test -e $defaultDir/$pkglist && echo 'File exists'`) {
|
|
|
|
# Copy default pkglist
|
|
|
|
`cp $defaultDir/$pkglist $dir/$pkglist`;
|
|
|
|
} else {
|
|
|
|
# Create pkglist
|
|
|
|
`touch $dir/$pkglist`;
|
2011-04-22 21:02:51 +00:00
|
|
|
}
|
|
|
|
|
2011-04-28 20:24:10 +00:00
|
|
|
# Add Ganglia RPMs to pkglist
|
|
|
|
`echo ganglia-gmond >> $dir/$pkglist`;
|
|
|
|
`echo libconfuse >> $dir/$pkglist`;
|
|
|
|
`echo libganglia >> $dir/$pkglist`;
|
2011-04-22 21:02:51 +00:00
|
|
|
}
|
2011-04-28 20:24:10 +00:00
|
|
|
|
2011-04-22 21:02:51 +00:00
|
|
|
# Check if libapr1 is installed
|
|
|
|
$info = `xdsh $_ "rpm -qa libapr1"`;
|
|
|
|
if (!($info =~ /libapr1/)) {
|
2011-04-28 20:24:10 +00:00
|
|
|
$callback->( { info => "$_: (Error) libapr1 package not installed" } );
|
|
|
|
next;
|
2011-04-22 21:02:51 +00:00
|
|
|
}
|
2011-04-22 15:58:37 +00:00
|
|
|
|
2011-04-28 20:24:10 +00:00
|
|
|
# Install Ganglia RPMs using updatenode
|
|
|
|
$callback->( { info => "$_: Installing Ganglia..." } );
|
|
|
|
$info = `updatenode $_ -S`;
|
|
|
|
$callback->( { info => "$info" } );
|
2011-04-22 21:02:51 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 15:58:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
sub web_rmcmonStart {
|
2010-08-26 05:16:31 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $nodeRange = $request->{arg}->[1];
|
|
|
|
my $table;
|
|
|
|
my $retData = "";
|
|
|
|
my $output;
|
|
|
|
|
|
|
|
#check the running status
|
|
|
|
$table = xCAT::Table->new('monitoring');
|
2010-11-05 22:51:12 +00:00
|
|
|
my $rmcWorkingStatus = $table->getAttribs( { name => 'rmcmon' }, 'disable' );
|
|
|
|
$table . close();
|
|
|
|
|
2010-08-26 05:16:31 +00:00
|
|
|
#the rmc monitoring is running so return directly
|
2010-11-05 22:51:12 +00:00
|
|
|
if ($rmcWorkingStatus) {
|
|
|
|
if ( $rmcWorkingStatus->{disable} =~ /0|No|no|NO|N|n/ ) {
|
|
|
|
$callback->( { info => 'RMC Monitoring is running now.' } );
|
2010-08-26 05:16:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-09-17 08:39:17 +00:00
|
|
|
}
|
2010-08-26 05:16:31 +00:00
|
|
|
|
|
|
|
$retData .= "RMC is not running, start it now.\n";
|
|
|
|
|
|
|
|
#check the monsetting table rmc's montype contains "performance"
|
|
|
|
$table = xCAT::Table->new('monsetting');
|
2010-11-05 22:51:12 +00:00
|
|
|
my $rmcmonType = $table->getAttribs( { name => 'rmcmon', key => 'montype' }, 'value' );
|
|
|
|
$table . close();
|
|
|
|
|
2010-08-26 05:16:31 +00:00
|
|
|
#the rmc monitoring is not configure right we should configure it again
|
|
|
|
#there is no rmcmon in monsetting table
|
2010-11-05 22:51:12 +00:00
|
|
|
if ( !$rmcmonType ) {
|
|
|
|
$output = xCAT::Utils->runcmd( 'monadd rmcmon -s [montype=perf]', -1, 1 );
|
|
|
|
foreach (@$output) {
|
|
|
|
$retData .= ( $_ . "\n" );
|
|
|
|
}
|
2010-08-26 05:16:31 +00:00
|
|
|
$retData .= "Add the rmcmon to monsetting table complete.\n";
|
|
|
|
}
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2010-08-26 05:16:31 +00:00
|
|
|
#configure before but there is not performance monitoring, so change the table
|
|
|
|
else {
|
2010-11-05 22:51:12 +00:00
|
|
|
if ( !( $rmcmonType->{value} =~ /perf/ ) ) {
|
2011-04-15 20:05:58 +00:00
|
|
|
$output =
|
|
|
|
xCAT::Utils->runcmd( 'chtab name=rmcmon,key=montype monsetting.value=perf', -1, 1 );
|
2010-11-05 22:51:12 +00:00
|
|
|
foreach (@$output) {
|
|
|
|
$retData .= ( $_ . "\n" );
|
|
|
|
}
|
2010-08-26 05:16:31 +00:00
|
|
|
$retData .= "Change the rmcmon configure in monsetting table finish.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#run the rmccfg command to add all nodes into local RMC configuration
|
2010-11-05 22:51:12 +00:00
|
|
|
$output = xCAT::Utils->runcmd( "moncfg rmcmon $nodeRange", -1, 1 );
|
|
|
|
foreach (@$output) {
|
|
|
|
$retData .= ( $_ . "\n" );
|
|
|
|
}
|
|
|
|
|
2010-08-26 05:16:31 +00:00
|
|
|
#run the rmccfg command to add all nodes into remote RMC configuration
|
2010-11-05 22:51:12 +00:00
|
|
|
$output = xCAT::Utils->runcmd( "moncfg rmcmon $nodeRange -r", -1, 1 );
|
|
|
|
foreach (@$output) {
|
|
|
|
$retData .= ( $_ . "\n" );
|
|
|
|
}
|
2010-08-26 05:16:31 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
#check the monfiguration
|
|
|
|
#use lsrsrc -a IBM.Host Name. compare the command's return and the noderange, then decide witch node should be refrsrc
|
2010-08-26 05:16:31 +00:00
|
|
|
|
|
|
|
#start the rmc monitor
|
2010-11-05 22:51:12 +00:00
|
|
|
$output = xCAT::Utils->runcmd( "monstart rmcmon", -1, 1 );
|
|
|
|
foreach (@$output) {
|
|
|
|
$retData .= ( $_ . "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
$callback->( { info => $retData } );
|
2010-08-26 05:16:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
sub web_rmcmonShow() {
|
2010-08-26 05:16:31 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $nodeRange = $request->{arg}->[1];
|
2011-04-15 20:05:58 +00:00
|
|
|
my $attr = $request->{arg}->[2];
|
2010-08-26 05:16:31 +00:00
|
|
|
my @nodes;
|
|
|
|
my $retInfo;
|
|
|
|
my $retHash = {};
|
|
|
|
my $output;
|
|
|
|
my $temp = "";
|
|
|
|
|
|
|
|
#only get the system rmc info
|
|
|
|
#like this PctTotalTimeIdle=>"10.0000, 20.0000, 12.0000, 30.0000"
|
2010-11-05 22:51:12 +00:00
|
|
|
if ( 'summary' eq $nodeRange ) {
|
2011-05-23 09:45:02 +00:00
|
|
|
$output = xCAT::Utils->runcmd( "monshow rmcmon -s -t 60 -o p -a " . $attr, -1, 1 );
|
2010-11-05 22:51:12 +00:00
|
|
|
foreach $temp (@$output) {
|
|
|
|
|
2010-08-26 05:16:31 +00:00
|
|
|
#the attribute name
|
2010-11-05 22:51:12 +00:00
|
|
|
if ( $temp =~ /Pct/ ) {
|
2010-08-26 05:16:31 +00:00
|
|
|
$temp =~ s/ //g;
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2010-08-26 05:16:31 +00:00
|
|
|
#the first one
|
2010-11-05 22:51:12 +00:00
|
|
|
if ( "" eq $retInfo ) {
|
|
|
|
$retInfo .= ( $temp . ':' );
|
2011-04-15 20:05:58 +00:00
|
|
|
} else {
|
2010-08-26 05:16:31 +00:00
|
|
|
$retInfo =~ s/,$/;/;
|
2010-11-05 22:51:12 +00:00
|
|
|
$retInfo .= ( $temp . ':' );
|
2010-08-26 05:16:31 +00:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
#the content of the attribute
|
|
|
|
$temp =~ m/\s+(\d+\.\d{4})/;
|
2010-11-05 22:51:12 +00:00
|
|
|
if ( defined($1) ) {
|
|
|
|
$retInfo .= ( $1 . ',' );
|
2010-08-26 05:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-05 22:51:12 +00:00
|
|
|
#return the rmc info
|
2010-08-26 05:16:31 +00:00
|
|
|
$retInfo =~ s/,$//;
|
2010-11-05 22:51:12 +00:00
|
|
|
$callback->( { info => $retInfo } );
|
2010-08-26 05:16:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-23 09:45:02 +00:00
|
|
|
if ( 'compute' eq $nodeRange ) {
|
|
|
|
my $node;
|
2010-08-26 05:16:31 +00:00
|
|
|
#get nodes detail containt
|
|
|
|
@nodes = xCAT::NodeRange::noderange($nodeRange);
|
2011-05-23 09:45:02 +00:00
|
|
|
for $node (@nodes){
|
|
|
|
if (-e "/var/rrd/$node"){
|
|
|
|
push( @{ $retHash->{node} }, { name => $node, data => 'OK' } );
|
2010-11-05 22:51:12 +00:00
|
|
|
}
|
2011-05-23 09:45:02 +00:00
|
|
|
else{
|
2011-05-24 06:40:15 +00:00
|
|
|
push( @{ $retHash->{node} }, { name => $node, data => 'UNKNOWN' } );
|
2010-08-26 05:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$callback->($retHash);
|
|
|
|
return;
|
|
|
|
}
|
2010-11-05 22:51:12 +00:00
|
|
|
|
2011-05-24 06:40:15 +00:00
|
|
|
my $attrName = "";
|
|
|
|
my @attrs = split(/,/, $attr);
|
|
|
|
for $attrName (@attrs){
|
|
|
|
my @attrValue = ();
|
|
|
|
$output = xCAT::Utils->runcmd( "rrdtool fetch /var/rrd/${nodeRange}/${attrName}.rrd -r 60 -s e-1h AVERAGE", -1, 1 );
|
|
|
|
foreach(@$output){
|
|
|
|
$temp = $_;
|
|
|
|
if ($temp eq ''){
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($temp =~ /[NaNQ|nan]/){
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($temp =~ /^(\d+): (\S+) (\S+)/){
|
|
|
|
push( @attrValue, (sprintf "%.2f", $2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(scalar(@attrValue) > 1){
|
|
|
|
push(@{$retHash->{node}}, { name => $attrName, data => join( ',', @attrValue )});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$retHash->{node}= { name => $attrName, data => ''};
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$callback->($retHash);
|
2010-09-17 08:39:17 +00:00
|
|
|
}
|
2011-01-12 10:43:45 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_monls() {
|
2011-01-12 10:43:45 +00:00
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( "monls", -1, 1 );
|
|
|
|
my $ret = '';
|
2011-04-15 20:05:58 +00:00
|
|
|
foreach my $line (@$retInfo) {
|
|
|
|
my @temp = split( /\s+/, $line );
|
2011-01-12 10:43:45 +00:00
|
|
|
$ret .= @temp[0];
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( 'not-monitored' eq @temp[1] ) {
|
2011-04-14 00:07:05 +00:00
|
|
|
$ret .= ':Off;';
|
2011-04-15 20:05:58 +00:00
|
|
|
} else {
|
2011-04-14 00:07:05 +00:00
|
|
|
$ret .= ':On;';
|
2011-01-12 10:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
if ( '' eq $ret ) {
|
2011-01-12 10:43:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
$ret = substr( $ret, 0, length($ret) - 1 );
|
|
|
|
$callback->( { data => $ret } );
|
2011-03-08 13:34:42 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_discover {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $type1 = '';
|
|
|
|
my $type2 = uc( $request->{arg}->[1] );
|
|
|
|
|
|
|
|
if ( 'FRAME' eq $type1 ) {
|
|
|
|
$type1 = 'BPA';
|
|
|
|
} elsif ( 'CEC' eq $request->{arg}->[1] ) {
|
|
|
|
$type1 = 'FSP';
|
|
|
|
} elsif ( 'HMC' eq $request->{arg}->[1] ) {
|
|
|
|
$type1 = 'HMC';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $retStr = '';
|
|
|
|
my $retInfo =
|
|
|
|
xCAT::Utils->runcmd( "lsslp -s $type1 2>null | grep $type2 | awk '{print \$2\"-\"\$3}'",
|
|
|
|
-1, 1 );
|
|
|
|
if ( scalar(@$retInfo) < 1 ) {
|
|
|
|
$retStr = 'Error: Can not discover frames in cluster!';
|
|
|
|
} else {
|
|
|
|
foreach my $line (@$retInfo) {
|
|
|
|
$retStr .= $line . ';';
|
|
|
|
}
|
|
|
|
$retStr = substr( $retStr, 0, -1 );
|
|
|
|
}
|
|
|
|
$callback->( { data => $retStr } );
|
2011-03-10 07:12:00 +00:00
|
|
|
}
|
2011-03-16 09:19:02 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_updatevpd {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $harwareMtmsPair = $request->{arg}->[1];
|
|
|
|
my @hardware = split( /:/, $harwareMtmsPair );
|
|
|
|
|
|
|
|
my $vpdtab = xCAT::Table->new('vpd');
|
|
|
|
unless ($vpdtab) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach my $hard (@hardware) {
|
|
|
|
|
|
|
|
#the sequence must be object name, mtm, serial
|
|
|
|
my @temp = split( /,/, $hard );
|
|
|
|
$vpdtab->setAttribs( { 'node' => @temp[0] }, { 'serial' => @temp[2], 'mtm' => @temp[1] } );
|
|
|
|
}
|
|
|
|
|
|
|
|
$vpdtab->close();
|
2011-03-16 09:19:02 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_createimage {
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $ostype = $request->{arg}->[1];
|
|
|
|
my $osarch = lc( $request->{arg}->[2] );
|
|
|
|
my $profile = $request->{arg}->[3];
|
|
|
|
my $bootif = $request->{arg}->[4];
|
|
|
|
my $imagetype = lc( $request->{arg}->[5] );
|
|
|
|
my @softArray;
|
|
|
|
my $netdriver = '';
|
|
|
|
my $installdir = xCAT::Utils->getInstallDir();
|
|
|
|
my $tempos = $ostype;
|
|
|
|
$tempos =~ s/[0-9]//;
|
|
|
|
my $CONFILE;
|
|
|
|
my $archFlag = 0;
|
|
|
|
my $ret = '';
|
|
|
|
my $cmdPath = '';
|
|
|
|
|
|
|
|
if ( $request->{arg}->[6] ) {
|
|
|
|
@softArray = split( ',', $request->{arg}->[6] );
|
|
|
|
|
|
|
|
#check the arch
|
|
|
|
if ( 'ppc64' ne $osarch ) {
|
|
|
|
$callback->( { data => 'Error: only support PPC64!' } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#check the osver
|
|
|
|
unless ( -e "/opt/xcat/share/xcat/IBMhpc/IBMhpc.$ostype.ppc64.pkglist" ) {
|
|
|
|
$callback->( { data => 'Error: only support rhels6 and sles11!' } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#check the custom package, if the path is not exist, must create the dir first
|
|
|
|
if ( -e "$installdir/custom/netboot/$ostype/" ) {
|
|
|
|
|
|
|
|
#the path is exist, so archive all file under this path.
|
|
|
|
opendir( TEMPDIR, "$installdir/custom/netboot/$ostype/" );
|
|
|
|
my @fileArray = readdir(TEMPDIR);
|
|
|
|
closedir(TEMPDIR);
|
|
|
|
if ( 2 < scalar(@fileArray) ) {
|
|
|
|
$archFlag = 1;
|
|
|
|
unless ( -e "/tmp/webImageArch/" ) {
|
|
|
|
system("mkdir -p /tmp/webImageArch/");
|
|
|
|
}
|
|
|
|
system("mv $installdir/custom/netboot/$ostype/*.* /tmp/webImageArch/");
|
|
|
|
} else {
|
|
|
|
$archFlag = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
#do not need to archive
|
|
|
|
$archFlag = 0;
|
|
|
|
system("mkdir -p $installdir/custom/netboot/$ostype/");
|
|
|
|
}
|
|
|
|
|
|
|
|
#write pkglist
|
|
|
|
open( $CONFILE, ">$installdir/custom/netboot/$ostype/$profile.pkglist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/IBMhpc.$ostype.ppc64.pkglist# \n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#write otherpkglist
|
|
|
|
open( $CONFILE, ">$installdir/custom/netboot/$ostype/$profile.otherpkgs.pkglist" );
|
|
|
|
print $CONFILE "\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#write exlist for stateless
|
|
|
|
open( $CONFILE, ">$installdir/custom/netboot/$ostype/$profile.exlist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/IBMhpc.$ostype.$osarch.exlist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#write postinstall
|
|
|
|
open( $CONFILE, ">$installdir/custom/netboot/$ostype/$profile.postinstall" );
|
|
|
|
print $CONFILE
|
|
|
|
"/opt/xcat/share/xcat/IBMhpc/IBMhpc.$tempos.postinstall \$1 \$2 \$3 \$4 \$5 \n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
for my $soft (@softArray) {
|
|
|
|
$soft = lc($soft);
|
|
|
|
if ( 'gpfs' eq $soft ) {
|
|
|
|
web_gpfsConfigure( $ostype, $profile, $osarch, $installdir );
|
|
|
|
} elsif ( 'rsct' eq $soft ) {
|
|
|
|
web_rsctConfigure( $ostype, $profile, $osarch, $installdir );
|
|
|
|
} elsif ( 'pe' eq $soft ) {
|
|
|
|
web_peConfigure( $ostype, $profile, $osarch, $installdir );
|
|
|
|
} elsif ( 'essl' eq $soft ) {
|
|
|
|
web_esslConfigure( $ostype, $profile, $osarch, $installdir );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#chmod
|
|
|
|
system("chmod 755 $installdir/custom/netboot/$ostype/*.*");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $bootif =~ /hf/i ) {
|
|
|
|
$netdriver = 'hf_if';
|
|
|
|
} else {
|
|
|
|
$netdriver = 'ibmveth';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $tempos =~ /rh/i ) {
|
|
|
|
$cmdPath = "/opt/xcat/share/xcat/netboot/rh";
|
|
|
|
} else {
|
|
|
|
$cmdPath = "/opt/xcat/share/xcat/netboot/sles";
|
|
|
|
}
|
|
|
|
|
|
|
|
#for stateless only run packimage is ok
|
|
|
|
if ( 'stateless' eq $imagetype ) {
|
|
|
|
my $retInfo =
|
|
|
|
xCAT::Utils->runcmd(
|
|
|
|
"${cmdPath}/genimage -i $bootif -n $netdriver -o $ostype -p $profile",
|
|
|
|
-1, 1 );
|
|
|
|
$ret = join( "\n", @$retInfo );
|
|
|
|
|
|
|
|
if ($::RUNCMD_RC) {
|
|
|
|
web_restoreChange( $request->{arg}->[6], $archFlag, $imagetype, $ostype, $installdir );
|
|
|
|
$callback->( { data => $ret } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$ret .= "\n";
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( "packimage -o $ostype -p $profile -a $osarch", -1, 1 );
|
|
|
|
$ret .= join( "\n", @$retInfo );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
#for statelist we should check the litefile table
|
|
|
|
#step1 save the old litefile table content into litefilearchive.csv
|
|
|
|
system('tabdump litefile > /tmp/litefilearchive.csv');
|
|
|
|
|
|
|
|
#step2 write the new litefile.csv for this lite image
|
|
|
|
open( $CONFILE, ">/tmp/litefile.csv" );
|
|
|
|
print $CONFILE "#image,file,options,comments,disable\n";
|
|
|
|
print $CONFILE '"ALL","/etc/lvm/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/ntp.conf","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/resolv.conf","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/sysconfig/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/yp.conf","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/ssh/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/var/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/tmp/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/root/.ssh/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/opt/xcat/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/xcatpost/","tmpfs",,' . "\n";
|
|
|
|
|
|
|
|
if ( 'rhels' eq $tempos ) {
|
|
|
|
print $CONFILE '"ALL","/etc/adjtime","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/securetty","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/rsyslog.conf","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/rsyslog.conf.XCATORIG","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/udev/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/ntp.conf.predhclient","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/resolv.conf.predhclient","tmpfs",,' . "\n";
|
|
|
|
} else {
|
|
|
|
print $CONFILE '"ALL","/etc/ntp.conf.org","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/syslog-ng/","tmpfs",,' . "\n";
|
|
|
|
print $CONFILE '"ALL","/etc/fstab","tmpfs",,' . "\n";
|
|
|
|
}
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#write the hpc software litefile into temp litefile.csv
|
|
|
|
for my $soft (@softArray) {
|
|
|
|
$soft = lc($soft);
|
|
|
|
if ( -e "/opt/xcat/share/xcat/IBMhpc/$soft/litefile.csv" ) {
|
|
|
|
system(
|
|
|
|
"grep '^[^#]' /opt/xcat/share/xcat/IBMhpc/$soft/litefile.csv >> /tmp/litefile.csv"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
system("tabrestore /tmp/litefile.csv");
|
|
|
|
|
|
|
|
#create the image
|
|
|
|
my $retInfo =
|
|
|
|
xCAT::Utils->runcmd(
|
|
|
|
"${cmdPath}/genimage -i $bootif -n $netdriver -o $ostype -p $profile",
|
|
|
|
-1, 1 );
|
|
|
|
$ret = join( "\n", @$retInfo );
|
|
|
|
if ($::RUNCMD_RC) {
|
|
|
|
web_restoreChange( $request->{arg}->[6], $archFlag, $imagetype, $ostype, $installdir );
|
|
|
|
$callback->( { data => $ret } );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$ret .= "\n";
|
|
|
|
my $retInfo = xCAT::Utils->runcmd( "liteimg -o $ostype -p $profile -a $osarch", -1, 1 );
|
|
|
|
$ret .= join( "\n", @$retInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
web_restoreChange( $request->{arg}->[6], $archFlag, $imagetype, $ostype, $installdir );
|
|
|
|
$callback->( { data => $ret } );
|
|
|
|
return;
|
2011-03-28 09:02:54 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_gpfsConfigure {
|
|
|
|
my ( $ostype, $profile, $osarch, $installdir ) = @_;
|
|
|
|
my $CONFILE;
|
|
|
|
|
|
|
|
#createrepo
|
|
|
|
system('createrepo $installdir/post/otherpkgs/$ostype/$osarch/gpfs');
|
|
|
|
|
|
|
|
#other pakgs
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.otherpkgs.pkglist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/gpfs/gpfs.otherpkgs.pkglist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#exlist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.exlist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/gpfs/gpfs.exlist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#postinstall
|
|
|
|
system('cp /opt/xcat/share/xcat/IBMhpc/gpfs/gpfs_mmsdrfs $installdir/postscripts/gpfs_mmsdrfs');
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.postinstall" );
|
|
|
|
print $CONFILE
|
|
|
|
"NODESETSTATE=genimage installroot=\$1 /opt/xcat/share/xcat/IBMhpc/gpfs/gpfs_updates\n";
|
|
|
|
print $CONFILE "installroot=\$1 $installdir/postscripts/gpfs_mmsdrfs\n";
|
|
|
|
close($CONFILE);
|
2011-03-28 09:02:54 +00:00
|
|
|
}
|
2011-04-06 02:23:43 +00:00
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_rsctConfigure {
|
|
|
|
my ( $ostype, $profile, $osarch, $installdir ) = @_;
|
|
|
|
my $CONFILE;
|
|
|
|
|
|
|
|
#createrepo
|
|
|
|
system('createrepo $installdir/post/otherpkgs/$ostype/$osarch/rsct');
|
|
|
|
|
|
|
|
#packagelist for sles11
|
|
|
|
if ( $ostype =~ /sles/i ) {
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.pkglist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/rsct/rsct.pkglist# \n";
|
|
|
|
close($CONFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
#exlist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.exlist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/rsct/rsct.exlist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#postinstall
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.postinstall" );
|
|
|
|
print $CONFILE
|
|
|
|
"installroot=\$1 rsctdir=$installdir/post/otherpkgs/rhels6/ppc64/rsct NODESETSTATE=genimage /opt/xcat/share/xcat/IBMhpc/rsct/rsct_install\n";
|
|
|
|
close($CONFILE);
|
2011-04-06 02:23:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_peConfigure {
|
|
|
|
my ( $ostype, $profile, $osarch, $installdir ) = @_;
|
|
|
|
my $CONFILE;
|
|
|
|
|
|
|
|
#createrepo
|
|
|
|
system('createrepo $installdir/post/otherpkgs/$ostype/$osarch/pe');
|
|
|
|
system('createrepo $installdir/post/otherpkgs/$ostype/$osarch/compilers');
|
|
|
|
|
|
|
|
#pkglist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.pkglist" );
|
|
|
|
if ( $ostype =~ /rh/i ) {
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/pe/pe.$ostype.pkglist#\n";
|
|
|
|
} else {
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/compilers/compilers.pkglist#\n";
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/pe/pe.pkglist#\n";
|
|
|
|
}
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#otherpaglist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.otherpkgs.pkglist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/pe/pe.otherpkgs.pkglist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#exlist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.exlist" );
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/compilers/compilers.exlist#\n";
|
|
|
|
print $CONFILE "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/pe/pe.exlist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#postinstall
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.postinstall" );
|
|
|
|
print $CONFILE
|
|
|
|
"installroot=\$1 NODESETSTATE=genimage /opt/xcat/share/xcat/IBMhpc/compilers/compilers_license";
|
|
|
|
print $CONFILE
|
|
|
|
"installroot=\$1 pedir=$installdir/post/otherpkgs/rhels6/ppc64/pe NODESETSTATE=genimage /opt/xcat/share/xcat/IBMhpc/pe/pe_install";
|
|
|
|
close($CONFILE);
|
2011-04-06 02:23:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_esslConfigure {
|
|
|
|
my ( $ostype, $profile, $osarch, $installdir ) = @_;
|
|
|
|
my $CONFILE;
|
|
|
|
|
|
|
|
#reaterepo
|
|
|
|
system('createrepo $installdir/post/otherpkgs/$ostype/$osarch/essl');
|
|
|
|
|
|
|
|
#pkglist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.pkglist" );
|
|
|
|
if ( $ostype =~ /rh/i ) {
|
|
|
|
print $CONFILE,
|
|
|
|
"#INCLUDE:/opt/xcat/share/xcat/IBMhpc/compilers/compilers.rhels6.pkglist#\n";
|
|
|
|
} else {
|
|
|
|
print $CONFILE, "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/essl/essl.pkglist#\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#otherpkgs
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.otherpkgs.pkglist" );
|
|
|
|
print $CONFILE, "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/essl/essl.otherpkgs.pkglist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#exlist
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.exlist" );
|
|
|
|
print $CONFILE, "#INCLUDE:/opt/xcat/share/xcat/IBMhpc/essl/essl.exlist#\n";
|
|
|
|
close($CONFILE);
|
|
|
|
|
|
|
|
#postinstall
|
|
|
|
open( $CONFILE, ">>$installdir/custom/netboot/$ostype/$profile.postinstall" );
|
|
|
|
print $CONFILE,
|
|
|
|
"installroot=\$1 essldir=$installdir/post/otherpkgs/rhels6/ppc64/essl NODESETSTATE=genimage /opt/xcat/share/xcat/IBMhpc/essl/essl_install";
|
|
|
|
close($CONFILE);
|
2011-04-12 07:11:30 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:05:58 +00:00
|
|
|
sub web_restoreChange {
|
|
|
|
my ( $software, $archFlag, $imagetype, $ostype, $installdir ) = @_;
|
|
|
|
|
|
|
|
#recover all file in the $installdir/custom/netboot/$ostype/
|
|
|
|
if ($software) {
|
|
|
|
system("rm -f $installdir/custom/netboot/$ostype/*.*");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($archFlag) {
|
|
|
|
system("mv /tmp/webImageArch/*.* $installdir/custom/netboot/$ostype/");
|
|
|
|
}
|
|
|
|
|
|
|
|
#recover the litefile table for statelite image
|
|
|
|
if ( 'statelite' == $imagetype ) {
|
|
|
|
system(
|
|
|
|
"rm -r /tmp/litefile.csv ; mv /tmp/litefilearchive.csv /tmp/litefile.csv ; tabrestore /tmp/litefile.csv"
|
|
|
|
);
|
|
|
|
}
|
2011-04-06 02:23:43 +00:00
|
|
|
}
|
2011-06-28 08:37:16 +00:00
|
|
|
|
|
|
|
sub web_provision{
|
|
|
|
my ( $request, $callback, $sub_req ) = @_;
|
|
|
|
my $nodes = $request->{arg}->[1];
|
2011-07-06 07:59:41 +00:00
|
|
|
my $imageName = $request->{arg}->[2];
|
|
|
|
my ($arch, $inic, $pnic, $master, $tftp, $nfs) = split(/,/,$request->{arg}->[3]);
|
|
|
|
my $line = '';
|
|
|
|
my %imageattr;
|
|
|
|
my $retinfo = xCAT::Utils->runcmd("lsdef -t osimage -l $imageName", -1, 1);
|
|
|
|
#parse output, get the os name, type
|
|
|
|
foreach $line(@$retinfo){
|
|
|
|
if ($line =~ /(\w+)=(\S*)/){
|
|
|
|
$imageattr{$1} = $2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#check the output
|
|
|
|
unless($imageattr{'osname'}){
|
|
|
|
web_infomsg("Image infomation error. Check the image first.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($imageattr{'osname'} =~ /aix/i){
|
|
|
|
web_provisionaix($nodes, $imageName, $imageattr{'nimtype'}, $inic, $pnic, $master, $tftp, $nfs, $callback);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
web_provisionlinux($nodes, $arch, $imageattr{'osvers'}, $imageattr{'provmethod'}, $imageattr{'profile'}, $inic, $pnic, $master, $tftp, $nfs, $callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub web_provisionlinux{
|
|
|
|
my ($nodes, $arch, $os, $provmethod, $profile, $inic, $pnic, $master, $tftp, $nfs, $callback) = @_;
|
2011-06-28 08:37:16 +00:00
|
|
|
my $outputMessage = '';
|
|
|
|
my $retvalue = 0;
|
|
|
|
my $netboot = '';
|
|
|
|
if ($arch =~ /ppc/i){
|
|
|
|
$netboot = 'yaboot';
|
|
|
|
}
|
|
|
|
elsif($arch =~ /x.*86/i){
|
|
|
|
$netboot = 'xnba';
|
|
|
|
}
|
|
|
|
$outputMessage = "Do provison : $nodes \n".
|
|
|
|
" Arch:$arch\n OS:$os\n Provision:$provmethod\n Profile:$profile\n Install NIC:$inic\n Primary NIC:$pnic\n" .
|
|
|
|
" xCAT Master:$master\n TFTP Server:$tftp\n NFS Server:$nfs\n Netboot:$netboot\n";
|
|
|
|
|
|
|
|
web_infomsg($outputMessage, $callback);
|
|
|
|
|
|
|
|
#change the nodes attribute
|
|
|
|
my $cmd = "chdef -t node -o $nodes arch=$arch os=$os provmethod=$provmethod profile=$profile installnic=$inic tftpserver=$tftp nfsserver=$nfs netboot=$netboot" .
|
|
|
|
" xcatmaster=$master primarynic=$pnic";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
#error return
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Configure nodes' attributes error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#dhcp
|
|
|
|
$cmd = "makedhcp $nodes";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Make DHCP error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#restart dhcp
|
|
|
|
$cmd = "service dhcpd restart";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
#conserver
|
2011-07-06 07:59:41 +00:00
|
|
|
$cmd = "makeconservercf $nodes";
|
2011-06-28 08:37:16 +00:00
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Configure conserver error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#for system x, should configure boot sequence first.
|
|
|
|
if ($arch =~ /x.*86/i){
|
|
|
|
$cmd = "rbootseq $nodes net,hd";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if($::RUNCMD_RC){
|
|
|
|
web_infomsg("Set boot sequence error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#nodeset
|
|
|
|
$cmd = "nodeset $nodes $provmethod";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Set nodes provision method error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#reboot the node fro provision
|
|
|
|
if($arch =~ /ppc/i){
|
|
|
|
$cmd = "rnetboot $nodes";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cmd = "rpower $nodes boot";
|
|
|
|
}
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Boot nodes error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#provision complete
|
|
|
|
web_infomsg("Provision on $nodes success.\nprovision stop.");
|
|
|
|
}
|
|
|
|
|
2011-07-06 07:59:41 +00:00
|
|
|
sub web_provisionaix{
|
|
|
|
my ($nodes, $imagename, $nimtype, $inic, $pnic, $master, $tftp, $nfs, $callback) = @_;
|
|
|
|
my $outputMessage = '';
|
|
|
|
my $retinfo;
|
|
|
|
my %nimhash;
|
|
|
|
my $line;
|
|
|
|
my @updatenodes;
|
|
|
|
my @addnodes;
|
|
|
|
my $cmd = '';
|
|
|
|
#set attibutes
|
|
|
|
$cmd = "chdef -t node -o $nodes installnic=$inic tftpserver=$tftp nfsserver=$nfs xcatmaster=$master primarynic=$pnic";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Change nodes' attributes error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#get all nim resource to filter nodes
|
|
|
|
$retinfo = xCAT::Utils->runcmd("lsnim -c machines", -1, 1);
|
|
|
|
foreach $line (@$retinfo){
|
|
|
|
if($line =~ /(\S+)\s+\S+/){
|
|
|
|
$nimhash{$1} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $node(split(/,/, $nodes)){
|
|
|
|
if ($nimhash{$node}){
|
|
|
|
push(@updatenodes, $node);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
push(@addnodes, $node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#xcat2nim
|
|
|
|
if(0 < scalar(@addnodes)){
|
|
|
|
$cmd = "xcat2nim -t node -o " . join(",", @addnodes);
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("xcat2nim command error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#update nimnode
|
|
|
|
if(0 < scalar(@updatenodes)){
|
|
|
|
$cmd = "xcat2nim -u -t node -o " . join(",", @updatenodes);
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("xcat2nim command error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#make con server
|
|
|
|
$cmd = "makeconservercf $nodes";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Configure conserver error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#nodeset
|
|
|
|
if ($nimtype =~ /diskless/){
|
|
|
|
$cmd = "mkdsklsnode -i $imagename $nodes";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$cmd = "nimnodeset -i $imagename $nodes";
|
|
|
|
}
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Set node install method error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#reboot nodes
|
|
|
|
$cmd = "rnetboot $nodes";
|
|
|
|
web_runcmd($cmd, $callback);
|
|
|
|
if ($::RUNCMD_RC){
|
|
|
|
web_infomsg("Reboot nodes error.\nprovision stop.", $callback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
web_infomsg("Provision on $nodes success.\nprovision stop.");
|
|
|
|
}
|
|
|
|
|
2011-06-28 08:37:16 +00:00
|
|
|
#run the cmd by xCAT::Utils->runcmd and show information.
|
|
|
|
sub web_runcmd{
|
|
|
|
my $cmd = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $showstr = "\n" . $cmd . "\n";
|
|
|
|
web_infomsg($showstr, $callback);
|
|
|
|
my $retvalue = xCAT::Utils->runcmd($cmd, -1, 1);
|
|
|
|
$showstr = join("\n", @$retvalue);
|
|
|
|
$showstr .= "\n";
|
|
|
|
web_infomsg($showstr, $callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub web_infomsg {
|
|
|
|
my $msg = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{info}}, $msg;
|
|
|
|
xCAT::MsgUtils->message('I', \%rsp, $callback);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-15 20:05:58 +00:00
|
|
|
1;
|