2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-31 10:06:39 +00:00

Merge pull request #2511 from cxhong/2499

[Dev] Support rcons command for openbmc
This commit is contained in:
Victor Hu 2017-03-16 15:28:36 -04:00 committed by GitHub
commit cbb27ed281
2 changed files with 140 additions and 0 deletions

View File

@ -37,6 +37,7 @@ sub handled_commands {
return {
rpower => 'nodehm:mgt',
rinv => 'nodehm:mgt',
getopenbmccons => 'nodehm:cons',
};
}
@ -132,6 +133,7 @@ my $async;
my $cookie_jar;
my $callback;
my %allerrornodes = ();
#-------------------------------------------------------
@ -215,6 +217,7 @@ sub process_request {
my $handle_id;
my $content;
$wait_node_num = keys %node_info;
my @donargs = ();
foreach my $node (keys %node_info) {
$bmcip = $node_info{$node}{bmc};
@ -224,8 +227,18 @@ sub process_request {
$handle_id_node{$handle_id} = $node;
$node_info{$node}{cur_status} = $next_status{ $node_info{$node}{cur_status} };
print "$node: DEBUG POST $login_url -d $content\n";
push @donargs, [ $node,$bmcip,$node_info{$node}{username}, $node_info{$node}{password}];
}
#process rcons
if ($request->{command}->[0] eq "getopenbmccons") {
foreach (@donargs) {
getopenbmccons($_, $callback);
}
return;
}
while (1) {
last unless ($wait_node_num);
while (my ($response, $handle_id) = $async->wait_for_next_response) {
@ -624,5 +637,34 @@ sub rinv_response {
return;
}
#-------------------------------------------------------
=head3 getopenbmccons
Process getopenbmccons
=cut
#-------------------------------------------------------
sub getopenbmccons {
my $argr = shift;
#$argr is [$node,$bmcip,$nodeuser,$nodepass];
my $callback = shift;
my $rsp;
my $node=$argr->[0];
my $output = "openbmc, getopenbmccoms";
xCAT::SvrUtils::sendmsg($output, $callback, $argr->[0], %allerrornodes);
$rsp = { node => [ { name => [ $argr->[0] ] } ] };
$rsp->{node}->[0]->{bmcip}->[0] = $argr->[1];
$rsp->{node}->[0]->{username}->[0] = $argr->[2];
$rsp->{node}->[0]->{passwd}->[0] = $argr->[3];
$callback->($rsp);
return $rsp;
}
1;

View File

@ -0,0 +1,98 @@
#!/usr/bin/env perl
# IBM(c) 2017 EPL license http://www.eclipse.org/legal/epl-v10.html
use Fcntl qw(:DEFAULT :flock);
use Time::HiRes qw(sleep);
use File::Path;
BEGIN {
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr';
}
my $sleepint = int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd
my ($lockfd, $bmcip);
my $username = 'root';
my $password = '0penBmc';
my $node = $ARGV[0];
use constant CONSOLE_LOCK_FILE => "/tmp/xcat/consolelock";
use constant CONSOLE_LOCK_DIR => "/tmp/xcat";
sub acquire_lock {
umask 0077;
mkpath(CONSOLE_LOCK_DIR);
print "Acquiring startup lock...";
unless (sysopen($lockfd, CONSOLE_LOCK_FILE, O_WRONLY | O_CREAT)) {
print "Unable to open file ".CONSOLE_LOCK_FILE."\n";
sleep(15);
exit 1;
}
unless (flock($lockfd, LOCK_EX)) {
print "Unable to lock file ".CONSOLE_LOCK_FILE."\n";
close($lockfd);
sleep(15);
exit 1;
}
print "done\n";
unless (syswrite($lockfd, $$, length($$))) {
print "Unable to write file ".CONSOLE_LOCK_FILE."\n";
close($lockfd);
sleep(15);
exit 1;
}
}
sub release_lock {
flock($lockfd, LOCK_UN);
close($lockfd);
}
use lib "$::XCATROOT/lib/perl";
require xCAT::Client;
sub getans {
my $rsp = shift;
if ($rsp->{node}) {
$bmcip = $rsp->{node}->[0]->{bmcip}->[0];
$username = $rsp->{node}->[0]->{username}->[0];
$password = $rsp->{node}->[0]->{passwd}->[0];
if (exists $rsp->{node}->[0]->{error}) {
my $error = $rsp->{node}->[0]->{error}->[0];
print "$error\n";
}
print "$bmcip, $username, $password\n";
}
}
my $cmdref = {
command => ["getopenbmccons"],
arg => ["text"],
noderange => [ $ARGV[0] ]
};
acquire_lock();
# avoid of congestion
sleep(0.1);
release_lock();
xCAT::Client::submit_request($cmdref, \&getans);
until (($username or $password) and $bmcip ) {
#Let other clients have a go
$sleepint = 10 + int(rand(20));
print "Console not ready, retrying in $sleepint seconds (Ctrl-e,c,o to skip delay) \n";
sleep ($sleepint);
acquire_lock();
sleep(0.1);
release_lock();
xCAT::Client::submit_request($cmdref, \&getans);
}
my $isintel = 0;
my $sleepint;
my $rc;
my $sshport = 2200;
if ($ENV{SSHCONSOLEPORT}) {
$sshport= $ENV{SSHCONSOLEPORT};
}
print "If the console cannot connect, please verify whether ssh keys has been configured on the bmc for $username user\n";
exec "ssh -p $sshport -l $username $bmcip";