xcat-core/xCAT-server/share/xcat/cons/ipmi

123 lines
3.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
use Fcntl qw(:DEFAULT :flock);
sub get_lock {
unless (flock(LOCKHANDLE,LOCK_EX|LOCK_NB)) {
$| = 1;
print "Acquiring startup lock...";
flock(LOCKHANDLE,LOCK_EX) or die "Fatal Error securing startup lock";
print "done\n";
}
truncate(LOCKHANDLE,0);
print LOCKHANDLE $$."\n";
}
sub release_lock {
truncate(LOCKHANDLE,0);
flock(LOCKHANDLE,LOCK_UN);
}
BEGIN
{
use Time::HiRes qw(sleep);
use File::Path;
use Fcntl qw(:DEFAULT :flock);
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
umask 0077;
mkpath("/tmp/xcat/");
unless (sysopen(LOCKHANDLE,"/tmp/xcat/consolelock",O_WRONLY | O_CREAT)) {
sleep 15;
print "Unable to open lock file";
exit 0;
}
get_lock();
#my $sleepint=int(rand(10));
#print "Opening console in ".(2+(0.5*$sleepint))." seconds...\n";
#sleep $sleepint;
}
my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
use lib "$::XCATROOT/lib/perl";
$ENV{HOME}='/root/';
require xCAT::Client;
my $username = 'USERID';
my $password = 'PASSW0RD';
my $node = $ARGV[0];
my $bmc;
sub getans {
my $rsp = shift;
if ($rsp->{node}) {
$bmc = $rsp->{node}->[0]->{bmcaddr}->[0];
$username = $rsp->{node}->[0]->{bmcuser}->[0];
$password = $rsp->{node}->[0]->{bmcpass}->[0];
}
}
my $cmdref={
command=>"getipmicons",
arg=>"text",
noderange=>$ARGV[0]
};
xCAT::Client::submit_request($cmdref,\&getans);
until ($username and $password and $bmc) {
release_lock(); #Let other clients have a go
$sleepint=10+int(rand(10));
print "Console not ready, retrying in $sleepint seconds (Ctrl-e,c,o to skip delay) \n";
sleep $sleepint;
get_lock();
xCAT::Client::submit_request($cmdref,\&getans);
}
release_lock();
#require xCAT::Table;
#require xCAT::Utils;
#my $dba;
#my $ipmitab = xCAT::Table->new('ipmi');
#unless ($ipmitab) { die "Unable to open IPMI table"; }
#my $passtab = xCAT::Table->new('passwd');
#if ($passtab) {
# ($dba) = $passtab->getAttribs({key=>'ipmi'},qw(username password));
# if ($dba) {
# if ($dba->{username}) { $username = $dba->{username}; }
# if ($dba->{password}) { $password = $dba->{password}; }
# }
#}
#$dba = $ipmitab->getNodeAttribs($ARGV[0],[qw(bmc username password)]);
#if ($dba) {
# if ($dba->{bmc}) { $bmc = $dba->{bmc}; }
# if ($dba->{username}) { $username = $dba->{username}; }
# if ($dba->{password}) { $password = $dba->{password}; }
#}
#xCAT::Utils::close_all_dbhs;
#my $isintel = system "ipmitool -I lanplus -U $username -P $password -H $bmc chassis status > /dev/null 2>&1";
my $isintel=0;
my $sleepint;
my $rc;
my @mcinfo=`ipmitool -I lan -U $username -P $password -H $bmc mc info`;#| grep 'Manufacturer ID : 343' > /dev/null 2>&1";
$rc = $?;
while ($rc != 0) {
$sleepint = 10+int(rand(20));
print "Failure to reach IPMI device, retrying in $sleepint seconds (Hit Ctrl-E,c,o to skip)\n";
sleep $sleepint;
@mcinfo=`ipmitool -I lan -U $username -P $password -H $bmc mc info`;#| grep 'Manufacturer ID : 343' > /dev/null 2>&1";
$rc = $?;
}
my $solcom="sol";
my $iface="lanplus";
if (grep /IPMI Version : 1.5/,@mcinfo) {
$solcom="isol";
$iface="lan";
} elsif (grep /Manufacturer ID : 343/,@mcinfo) {
$isintel=1;
}
my $inteloption="";
if ($isintel) {
$inteloption=" -o intelplus";
}
if ($iface eq "lanplus") {
system "ipmitool -I lanplus $inteloption -U $username -P $password -H $bmc $solcom deactivate"; #Stop any active session
}
exec "ipmitool -I $iface $inteloption -U $username -P $password -H $bmc $solcom activate";