Change blade console method to avoid direct Table access, to alleviate SQL load and be throttled like other xCAT accesses
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2033 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
e98cd07abe
commit
dfb5424f4c
@ -32,6 +32,7 @@ sub handled_commands {
|
||||
getmacs => 'nodehm:getmac,mgt',
|
||||
rscan => 'nodehm:mgt',
|
||||
rpower => 'nodehm:power,mgt',
|
||||
getbladecons => 'blade',
|
||||
rvitals => 'nodehm:mgt',
|
||||
rinv => 'nodehm:mgt',
|
||||
rbeacon => 'nodehm:mgt',
|
||||
@ -1350,6 +1351,60 @@ sub build_depend {
|
||||
}
|
||||
|
||||
|
||||
sub getbladecons {
|
||||
my $noderange = shift;
|
||||
my $callback=shift;
|
||||
my $mpatab = xCAT::Table->new('mpa');
|
||||
my $passtab = xCAT::Table->new('mpa');
|
||||
my $tmp;
|
||||
my $user="USERID";
|
||||
if ($passtab) {
|
||||
($tmp)=$passtab->getAttribs({'key'=>'blade'},'username');
|
||||
if (defined($tmp)) {
|
||||
$user = $tmp->{username};
|
||||
}
|
||||
}
|
||||
my %mpausers;
|
||||
my %checkedmpas=();
|
||||
my $mptab=xCAT::Table->new('mp');
|
||||
my $mptabhash = $mptab->getNodesAttribs($noderange,['mpa','id']);
|
||||
foreach my $node (@$noderange) {
|
||||
my $rsp = {node=>[{name=>[$node]}]};
|
||||
my $ent=$mptabhash->{$node}->[0]; #$mptab->getNodeAttribs($node,['mpa', 'id']);
|
||||
if (defined($ent->{mpa})) {
|
||||
$rsp->{node}->[0]->{mm}->[0]=$ent->{mpa};
|
||||
if (defined($checkedmpas{$ent->{$mpa}}) or not defined $mpatab) {
|
||||
if (defined($mpausers{$ent->{mpa}})) {
|
||||
$rsp->{node}->[0]->{username}=[$mpausers{$ent->{mpa}}];
|
||||
} else {
|
||||
$rsp->{node}->[0]->{username}=[$user];
|
||||
}
|
||||
} else {
|
||||
$checkedmpas{$ent->{$mpa}}=1;
|
||||
($tmp)=$mpatab->getAttribs({'mpa'=>$mpa},'username');
|
||||
if (defined($tmp) and defined $tmp->{username}) {
|
||||
$mpausers{$ent->{mpa}}=$tmp->{username};
|
||||
$rsp->{node}->[0]->{username}=[$tmp->{username}];
|
||||
} else {
|
||||
$rsp->{node}->[0]->{username}=[$user];
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$rsp->{node}->[0]->{error}=["no mpa defined"];
|
||||
$rsp->{node}->[0]->{errorcode}=[1];
|
||||
$callback->($rsp);
|
||||
next;
|
||||
}
|
||||
if (defined($ent->{id})) {
|
||||
$rsp->{node}->[0]->{slot}=$ent->{id};
|
||||
} else {
|
||||
$rsp->{node}->[0]->{slot}="";
|
||||
}
|
||||
$callback->($rsp);
|
||||
}
|
||||
}
|
||||
|
||||
sub preprocess_request {
|
||||
my $request = shift;
|
||||
if ($request->{_xcatdest}) { return [$request]; } #exit if preprocessed
|
||||
@ -1390,6 +1445,12 @@ sub preprocess_request {
|
||||
}
|
||||
my %mpa_hash=();
|
||||
my $mptabhash = $mptab->getNodesAttribs($noderange,['mpa','id']);
|
||||
if ($request->{command}->[0] eq "getbladecons") { #Can handle it here and now
|
||||
getbladecons($noderange,$callback);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
foreach my $node (@$noderange) {
|
||||
my $ent=$mptabhash->{$node}->[0]; #$mptab->getNodeAttribs($node,['mpa', 'id']);
|
||||
if (defined($ent->{mpa})) { push @{$mpa_hash{$ent->{mpa}}{nodes}}, $node;}
|
||||
|
@ -4,57 +4,78 @@ BEGIN
|
||||
{
|
||||
use Time::HiRes qw(sleep);
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
my $sleepint=int(rand(10));
|
||||
my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd
|
||||
print "Opening console in ".(2+(0.5*$sleepint))." seconds...\n";
|
||||
sleep $sleepint;
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
$ENV{HOME}='/root/';
|
||||
require xCAT::Client;
|
||||
|
||||
require xCAT::Table;
|
||||
require xCAT::Utils;
|
||||
#require xCAT::Table;
|
||||
#require xCAT::Utils;
|
||||
require File::Basename;
|
||||
import File::Basename;
|
||||
my $scriptname = $0;
|
||||
|
||||
$mptab = xCAT::Table->new('mp');
|
||||
unless ($mptab) {
|
||||
#$mptab = xCAT::Table->new('mp');
|
||||
#unless ($mptab) {
|
||||
#sleep 5; #Try not to overwhelm logfiles...
|
||||
die "mp table must be configured";
|
||||
}
|
||||
$mpatab = xCAT::Table->new('mpa');
|
||||
$passtab = xCAT::Table->new('passwd');
|
||||
# die "mp table must be configured";
|
||||
#}
|
||||
#$mpatab = xCAT::Table->new('mpa');
|
||||
#$passtab = xCAT::Table->new('passwd');
|
||||
|
||||
my $username = "USERID";
|
||||
my $passsword = "PASSW0RD";
|
||||
my $mm;
|
||||
my $slot;
|
||||
my $dba;
|
||||
if ($passtab) {
|
||||
($dba) = $passtab->getAttribs({key=>blade},qw(username password));
|
||||
if ($dba->{username}) {
|
||||
$username = $dba->{username};
|
||||
}
|
||||
if ($dba->{password}) {
|
||||
$password = $dba->{password};
|
||||
}
|
||||
}
|
||||
#my $dba;
|
||||
#if ($passtab) {
|
||||
# ($dba) = $passtab->getAttribs({key=>blade},qw(username password));
|
||||
# if ($dba->{username}) {
|
||||
# $username = $dba->{username};
|
||||
# }
|
||||
# if ($dba->{password}) {
|
||||
# $password = $dba->{password};
|
||||
# }
|
||||
#}
|
||||
|
||||
$dba = $mptab->getNodeAttribs($ARGV[0],[qw(mpa id)]);
|
||||
$mm = $dba->{mpa};
|
||||
$slot = $dba->{id};
|
||||
if ($mpatab) {
|
||||
($dba) = $mpatab->getAttribs({mpa=>$mm},qw(username password));
|
||||
if ($dba) {
|
||||
if ($dba->{username}) { $username = $dba->{username}; }
|
||||
if ($dba->{password}) { $password = $dba->{password}; }
|
||||
}
|
||||
}
|
||||
xCAT::Utils::close_all_dbhs;
|
||||
#$dba = $mptab->getNodeAttribs($ARGV[0],[qw(mpa id)]);
|
||||
#$mm = $dba->{mpa};
|
||||
#$slot = $dba->{id};
|
||||
#if ($mpatab) {
|
||||
# ($dba) = $mpatab->getAttribs({mpa=>$mm},qw(username password));
|
||||
# if ($dba) {
|
||||
# if ($dba->{username}) { $username = $dba->{username}; }
|
||||
# if ($dba->{password}) { $password = $dba->{password}; }
|
||||
# }
|
||||
#}
|
||||
#xCAT::Utils::close_all_dbhs;
|
||||
#sleep 5; #Slow start, I know, but with exec, can't return
|
||||
sub getans {
|
||||
my $rsp = shift;
|
||||
if ($rsp->{node}) {
|
||||
$mm = $rsp->{node}->[0]->{mm}->[0];
|
||||
$username = $rsp->{node}->[0]->{username}->[0];
|
||||
$slot = $rsp->{node}->[0]->{slot}->[0];
|
||||
}
|
||||
}
|
||||
my $cmdref={
|
||||
command=>"getbladecons",
|
||||
arg=>"text",
|
||||
noderange=>$ARGV[0]
|
||||
};
|
||||
xCAT::Client::submit_request($cmdref,\&getans);
|
||||
until ($mm and $username and $slot) {
|
||||
print "console not ready\n";
|
||||
sleep 5+int(rand(10));
|
||||
xCAT::Client::submit_request($cmdref,\&getans);
|
||||
}
|
||||
exec "ssh -t $username"."@"."$mm console -o -T blade[$slot]";
|
||||
#my $pathtochild= dirname($scriptname). "/";
|
||||
#exec $pathtochild."blade.expect $mm $slot $username $password";
|
||||
|
||||
|
||||
|
||||
#SECURITY: In this case, the authentication is expected to be done using the script user's ssh keys. As such,
|
||||
#this script does not receive any particularly sensitive data from the xCAT server.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user