From 5793009eab6a2d51e356aafa0fad67bc596d79cf Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Mon, 20 Feb 2017 20:29:23 -0500 Subject: [PATCH 1/8] Support ssh based console in rcons for openbmc --- xCAT-server/lib/xcat/plugins/openbmc.pm | 65 ++++++++++++++- xCAT-server/share/xcat/cons/openbmc | 100 ++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) create mode 100755 xCAT-server/share/xcat/cons/openbmc diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 4ba2c2e82..fc4fb6678 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1,11 +1,21 @@ #!/usr/bin/perl -## IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +#------------------------------------------------------- +=head1 + xCAT plugin package to handle openbmc + + Supported command: + getopenbmccons + +=cut + +#------------------------------------------------------- package xCAT_plugin::openbmc; BEGIN { - $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; } use lib "$::XCATROOT/lib/perl"; use strict; @@ -24,6 +34,10 @@ use JSON; $::OPENBMC_DEVEL = $ENV{'OPENBMC_DEVEL'}; +my $VERBOSE = 0; +my %allerrornodes = (); +my $callback; + #------------------------------------------------------- =head3 handled_commands @@ -37,6 +51,7 @@ sub handled_commands { return { rpower => 'nodehm:mgt', rinv => 'nodehm:mgt', + getopenbmccons => 'nodehm:cons', }; } @@ -233,6 +248,33 @@ sub process_request { } } + + #Assume the openbmc user/password is defined in the passwd + my $passtab = xCAT::Table->new('passwd'); + if ($passtab) { + ($dba) = $passtab->getAttribs({key=>'openbmc'},qw(username password)); + if ($dba) { + if ($dba->{username}) { $username = $dba->{username}; } + if ($dba->{password}) { $password = $dba->{password}; } + } + } + + + foreach (@$noderange) { + my $node = $_; + my $nodeip = $node; + push @donargs, [ $node,$nodeip,$username, $password]; + my $output = "openbmc, get $username and $password from passwd table for $nodeip"; + xCAT::SvrUtils::sendmsg($output, $callback, $node, %allerrornodes); + } + + + if ($request->{command}->[0] eq "getopenbmccons") { + foreach (@donargs) { + getopenbmccons($_, $callback); + } + return; + } return; } @@ -625,4 +667,23 @@ sub rinv_response { } +sub getopenbmccons { + my $argr = shift; + + #$argr is [$node,$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]->{nodeip}->[0] = $argr->[1]; + $rsp->{node}->[0]->{username}->[0] = $argr->[2]; + $rsp->{node}->[0]->{passwd}->[0] = $argr->[3]; + $callback->($rsp); + return $rsp; +} + 1; diff --git a/xCAT-server/share/xcat/cons/openbmc b/xCAT-server/share/xcat/cons/openbmc new file mode 100755 index 000000000..a83038a81 --- /dev/null +++ b/xCAT-server/share/xcat/cons/openbmc @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +# IBM(c) 2007 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, $nodeip); +my $username = 'UESRID'; +my $password = 'PASSWD'; +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}) { + $nodeip = $rsp->{node}->[0]->{nodeip}->[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"; + } + } +} +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 $nodeip ) { + #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}; +} + +#sshpass command needs to install before can run that +if (-x '/usr/bin/sshpass') { + exec "/usr/bin/sshpass -p $password ssh -p $sshport -l $username $nodeip"; +} else { + print "Please install sshpass first. \n"; +} + From 8a8c5a943ded374787e1f874d0fce59bc24e6e2a Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 28 Feb 2017 17:08:05 -0500 Subject: [PATCH 2/8] use mgt=ipmi instead of openbmc --- xCAT-server/lib/xcat/plugins/openbmc.pm | 35 ++++++++++++++++--------- xCAT-server/share/xcat/cons/openbmc | 7 +---- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index fc4fb6678..84b32ab3c 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -31,6 +31,16 @@ use xCAT::SvrUtils; use File::Basename; use Data::Dumper; use JSON; +use Getopt::Long; +use File::Path; +use Term::ANSIColor; +use Time::Local; +use strict; +use Class::Struct; +use XML::Simple; +use Storable qw(dclone); +use SNMP; +use xCAT::PasswordUtils; $::OPENBMC_DEVEL = $ENV{'OPENBMC_DEVEL'}; @@ -249,22 +259,23 @@ sub process_request { } - #Assume the openbmc user/password is defined in the passwd - my $passtab = xCAT::Table->new('passwd'); - if ($passtab) { - ($dba) = $passtab->getAttribs({key=>'openbmc'},qw(username password)); - if ($dba) { - if ($dba->{username}) { $username = $dba->{username}; } - if ($dba->{password}) { $password = $dba->{password}; } - } - } - + my $ipmitab = xCAT::Table->new('ipmi'); + my $ipmihash = $ipmitab->getNodesAttribs($noderange, [ 'bmc', 'username', 'password' ]); + my $authdata = xCAT::PasswordUtils::getIPMIAuth(noderange => $noderange, ipmihash => $ipmihash); foreach (@$noderange) { my $node = $_; my $nodeip = $node; - push @donargs, [ $node,$nodeip,$username, $password]; - my $output = "openbmc, get $username and $password from passwd table for $nodeip"; + my $nodeuser = $authdata->{$node}->{username}; + my $nodepass = $authdata->{$node}->{password}; + my $nodeip = $node; + my $ent; + if (defined($ipmitab)) { + $ent = $ipmihash->{$node}->[0]; + if (ref($ent) and defined $ent->{bmc}) { $nodeip = $ent->{bmc}; } + } + push @donargs, [ $node,$nodeip,$nodeuser, $nodepass]; + my $output = "openbmc, get $username and $password from ipmi table for $nodeip"; xCAT::SvrUtils::sendmsg($output, $callback, $node, %allerrornodes); } diff --git a/xCAT-server/share/xcat/cons/openbmc b/xCAT-server/share/xcat/cons/openbmc index a83038a81..87a2a7a7b 100755 --- a/xCAT-server/share/xcat/cons/openbmc +++ b/xCAT-server/share/xcat/cons/openbmc @@ -91,10 +91,5 @@ if ($ENV{SSHCONSOLEPORT}) { $sshport= $ENV{SSHCONSOLEPORT}; } -#sshpass command needs to install before can run that -if (-x '/usr/bin/sshpass') { - exec "/usr/bin/sshpass -p $password ssh -p $sshport -l $username $nodeip"; -} else { - print "Please install sshpass first. \n"; -} +exec "ssh -p $sshport -l $username $nodeip"; From 20b71f888bf1fd87003853bd521cb52856a47cda Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 3 Mar 2017 14:26:42 -0500 Subject: [PATCH 3/8] Add support to config passwordless for openbmc --- xCAT-server/lib/xcat/plugins/openbmc.pm | 103 +++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 84b32ab3c..f99e3808b 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -41,6 +41,7 @@ use XML::Simple; use Storable qw(dclone); use SNMP; use xCAT::PasswordUtils; +use Expect; $::OPENBMC_DEVEL = $ENV{'OPENBMC_DEVEL'}; @@ -282,6 +283,7 @@ sub process_request { if ($request->{command}->[0] eq "getopenbmccons") { foreach (@donargs) { + configssh($_, $callback); getopenbmccons($_, $callback); } return; @@ -688,7 +690,7 @@ sub getopenbmccons { my $node=$argr->[0]; my $output = "openbmc, getopenbmccoms"; xCAT::SvrUtils::sendmsg($output, $callback, $argr->[0], %allerrornodes); - + $rsp = { node => [ { name => [ $argr->[0] ] } ] }; $rsp->{node}->[0]->{nodeip}->[0] = $argr->[1]; $rsp->{node}->[0]->{username}->[0] = $argr->[2]; @@ -697,4 +699,103 @@ sub getopenbmccons { return $rsp; } +#------------------------------------------------------- + +=head3 configssh + + config passwordless for openbmc + +=cut + +#------------------------------------------------------- +sub configssh { + my $argr = shift; + my $callback = shift; + + my $rsp; + my $node=$argr->[0]; + my $bmcip = $argr->[1]; + my $bmcuser = $argr->[2]; + my $bmcpass = $argr->[3]; + my $timeout = 10; + + my $output = "openbmc, configssh "; + xCAT::SvrUtils::sendmsg($output, $callback, $argr->[0], %allerrornodes); + + my $rootkey = `cat /root/.ssh/id_rsa.pub`; + + # remove old host key from /root/.ssh/known_hosts + my $cmd = `ssh-keygen -R $bmcip`; + + my ($exp, $errstr) = openbmc_connect($bmcip, $bmcuser, $bmcpass, $timeout); + if (!defined $exp) { + print ("connect failed $errstr\n"); + next; + } + + my $ret; + my $err; + + ($ret, $err) = openbmc_exec($exp, "mkdir -p /home/root/.ssh"); + ($ret, $err) = openbmc_exec($exp, "chmod 700 /home/root/.ssh"); + ($ret, $err) = openbmc_exec($exp, "echo \"$rootkey\" >/home/root/.ssh/authorized_keys"); + ($ret, $err) = openbmc_exec($exp, "chmod 644 /home/root/.ssh/authorized_keys"); + + $exp->hard_close(); +} + +sub openbmc_connect { + my $server = shift; + my $userid = shift; + my $password = shift; + my $timeout = shift; + + my $ssh = Expect->new; + my $command = 'ssh'; + my @parameters = ($userid . "@" . $server); + + $ssh->debug(0); + $ssh->log_stdout(0); # suppress stdout output.. + $ssh->slave->stty(qw(sane -echo)); + + unless ($ssh->spawn($command, @parameters)) + { + my $err = $!; + $ssh->soft_close(); + my $rsp; + return(undef, "unable to run command $command $err\n"); + } + + $ssh->expect($timeout, + [ "-re", qr/WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED/, sub {die "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!\n"; } ], + [ "-re", qr/\(yes\/no\)\?\s*$/, sub { $ssh->send("yes\n"); exp_continue; } ], + [ "-re", qr/ password:/, sub { $ssh->send("$password\n"); exp_continue; } ], + [ "-re", qr/:~\#/, sub { $ssh->clear_accum(); } ], + [ timeout => sub { die "No login.\n"; } ] + ); + $ssh->clear_accum(); + return ($ssh); +} + +sub openbmc_exec { + my $exp = shift; + my $cmd = shift; + my $timeout = shift; + my $prompt = shift; + + $timeout = 10 unless defined $timeout; + $prompt = qr/:~\#/ unless defined $prompt; + + $exp->clear_accum(); + $exp->send("$cmd\n"); + my ($mpos, $merr, $mstr, $mbmatch, $mamatch) = $exp->expect(6, "-re", $prompt); + + if (defined $merr) { + return(undef,$merr); + } + return($mbmatch); +} + + + 1; From 6112875d5d2ce3b7a5dbb68ccef5177548b7c128 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Tue, 7 Mar 2017 11:31:51 -0500 Subject: [PATCH 4/8] disable configssh routine --- xCAT-server/lib/xcat/plugins/openbmc.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index f99e3808b..72337c133 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -283,7 +283,7 @@ sub process_request { if ($request->{command}->[0] eq "getopenbmccons") { foreach (@donargs) { - configssh($_, $callback); + #configssh($_, $callback); getopenbmccons($_, $callback); } return; From a924cfffe50531680cf5f8af903df1bbf49bb5c5 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Thu, 9 Mar 2017 13:19:52 -0500 Subject: [PATCH 5/8] remove configssh routine --- xCAT-server/lib/xcat/plugins/openbmc.pm | 106 +----------------------- xCAT-server/share/xcat/cons/openbmc | 6 +- 2 files changed, 4 insertions(+), 108 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 72337c133..531bf70ba 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1,5 +1,5 @@ #!/usr/bin/perl -# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +# IBM(c) 2017 EPL license http://www.eclipse.org/legal/epl-v10.html #------------------------------------------------------- =head1 @@ -37,11 +37,7 @@ use Term::ANSIColor; use Time::Local; use strict; use Class::Struct; -use XML::Simple; -use Storable qw(dclone); -use SNMP; use xCAT::PasswordUtils; -use Expect; $::OPENBMC_DEVEL = $ENV{'OPENBMC_DEVEL'}; @@ -283,7 +279,6 @@ sub process_request { if ($request->{command}->[0] eq "getopenbmccons") { foreach (@donargs) { - #configssh($_, $callback); getopenbmccons($_, $callback); } return; @@ -699,103 +694,4 @@ sub getopenbmccons { return $rsp; } -#------------------------------------------------------- - -=head3 configssh - - config passwordless for openbmc - -=cut - -#------------------------------------------------------- -sub configssh { - my $argr = shift; - my $callback = shift; - - my $rsp; - my $node=$argr->[0]; - my $bmcip = $argr->[1]; - my $bmcuser = $argr->[2]; - my $bmcpass = $argr->[3]; - my $timeout = 10; - - my $output = "openbmc, configssh "; - xCAT::SvrUtils::sendmsg($output, $callback, $argr->[0], %allerrornodes); - - my $rootkey = `cat /root/.ssh/id_rsa.pub`; - - # remove old host key from /root/.ssh/known_hosts - my $cmd = `ssh-keygen -R $bmcip`; - - my ($exp, $errstr) = openbmc_connect($bmcip, $bmcuser, $bmcpass, $timeout); - if (!defined $exp) { - print ("connect failed $errstr\n"); - next; - } - - my $ret; - my $err; - - ($ret, $err) = openbmc_exec($exp, "mkdir -p /home/root/.ssh"); - ($ret, $err) = openbmc_exec($exp, "chmod 700 /home/root/.ssh"); - ($ret, $err) = openbmc_exec($exp, "echo \"$rootkey\" >/home/root/.ssh/authorized_keys"); - ($ret, $err) = openbmc_exec($exp, "chmod 644 /home/root/.ssh/authorized_keys"); - - $exp->hard_close(); -} - -sub openbmc_connect { - my $server = shift; - my $userid = shift; - my $password = shift; - my $timeout = shift; - - my $ssh = Expect->new; - my $command = 'ssh'; - my @parameters = ($userid . "@" . $server); - - $ssh->debug(0); - $ssh->log_stdout(0); # suppress stdout output.. - $ssh->slave->stty(qw(sane -echo)); - - unless ($ssh->spawn($command, @parameters)) - { - my $err = $!; - $ssh->soft_close(); - my $rsp; - return(undef, "unable to run command $command $err\n"); - } - - $ssh->expect($timeout, - [ "-re", qr/WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED/, sub {die "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!\n"; } ], - [ "-re", qr/\(yes\/no\)\?\s*$/, sub { $ssh->send("yes\n"); exp_continue; } ], - [ "-re", qr/ password:/, sub { $ssh->send("$password\n"); exp_continue; } ], - [ "-re", qr/:~\#/, sub { $ssh->clear_accum(); } ], - [ timeout => sub { die "No login.\n"; } ] - ); - $ssh->clear_accum(); - return ($ssh); -} - -sub openbmc_exec { - my $exp = shift; - my $cmd = shift; - my $timeout = shift; - my $prompt = shift; - - $timeout = 10 unless defined $timeout; - $prompt = qr/:~\#/ unless defined $prompt; - - $exp->clear_accum(); - $exp->send("$cmd\n"); - my ($mpos, $merr, $mstr, $mbmatch, $mamatch) = $exp->expect(6, "-re", $prompt); - - if (defined $merr) { - return(undef,$merr); - } - return($mbmatch); -} - - - 1; diff --git a/xCAT-server/share/xcat/cons/openbmc b/xCAT-server/share/xcat/cons/openbmc index 87a2a7a7b..e309357df 100755 --- a/xCAT-server/share/xcat/cons/openbmc +++ b/xCAT-server/share/xcat/cons/openbmc @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html +# 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; @@ -8,8 +8,8 @@ BEGIN { } my $sleepint = int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd my ($lockfd, $nodeip); -my $username = 'UESRID'; -my $password = 'PASSWD'; +my $username = 'root'; +my $password = '0penBmc'; my $node = $ARGV[0]; use constant CONSOLE_LOCK_FILE => "/tmp/xcat/consolelock"; From 4fa11191789fc5c7113191ceecb8be53e015ac93 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 10 Mar 2017 14:23:46 -0500 Subject: [PATCH 6/8] change nodeip to bmcip --- xCAT-server/lib/xcat/plugins/openbmc.pm | 13 ++++++------- xCAT-server/share/xcat/cons/openbmc | 11 +++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 531bf70ba..6c19cb4f4 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -262,17 +262,16 @@ sub process_request { foreach (@$noderange) { my $node = $_; - my $nodeip = $node; + my $bmcip; my $nodeuser = $authdata->{$node}->{username}; my $nodepass = $authdata->{$node}->{password}; - my $nodeip = $node; my $ent; if (defined($ipmitab)) { $ent = $ipmihash->{$node}->[0]; - if (ref($ent) and defined $ent->{bmc}) { $nodeip = $ent->{bmc}; } + if (ref($ent) and defined $ent->{bmc}) { $bmcip = $ent->{bmc}; } } - push @donargs, [ $node,$nodeip,$nodeuser, $nodepass]; - my $output = "openbmc, get $username and $password from ipmi table for $nodeip"; + push @donargs, [ $node,$bmcip,$nodeuser, $nodepass]; + my $output = "openbmc, get $username and $password from ipmi table for $bmcip"; xCAT::SvrUtils::sendmsg($output, $callback, $node, %allerrornodes); } @@ -678,7 +677,7 @@ sub rinv_response { sub getopenbmccons { my $argr = shift; - #$argr is [$node,$nodeuser,$nodepass]; + #$argr is [$node,$bmcip,$nodeuser,$nodepass]; my $callback = shift; my $rsp; @@ -687,7 +686,7 @@ sub getopenbmccons { xCAT::SvrUtils::sendmsg($output, $callback, $argr->[0], %allerrornodes); $rsp = { node => [ { name => [ $argr->[0] ] } ] }; - $rsp->{node}->[0]->{nodeip}->[0] = $argr->[1]; + $rsp->{node}->[0]->{bmcip}->[0] = $argr->[1]; $rsp->{node}->[0]->{username}->[0] = $argr->[2]; $rsp->{node}->[0]->{passwd}->[0] = $argr->[3]; $callback->($rsp); diff --git a/xCAT-server/share/xcat/cons/openbmc b/xCAT-server/share/xcat/cons/openbmc index e309357df..172bb272e 100755 --- a/xCAT-server/share/xcat/cons/openbmc +++ b/xCAT-server/share/xcat/cons/openbmc @@ -7,7 +7,7 @@ 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, $nodeip); +my ($lockfd, $bmcip); my $username = 'root'; my $password = '0penBmc'; my $node = $ARGV[0]; @@ -51,13 +51,14 @@ require xCAT::Client; sub getans { my $rsp = shift; if ($rsp->{node}) { - $nodeip = $rsp->{node}->[0]->{nodeip}->[0]; + $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 = { @@ -71,7 +72,7 @@ sleep(0.1); release_lock(); xCAT::Client::submit_request($cmdref, \&getans); -until (($username or $password) and $nodeip ) { +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"; @@ -91,5 +92,7 @@ if ($ENV{SSHCONSOLEPORT}) { $sshport= $ENV{SSHCONSOLEPORT}; } -exec "ssh -p $sshport -l $username $nodeip"; +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"; From 033fa4fb41433812185964f03b6a5fb520f54312 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 15 Mar 2017 15:49:42 -0400 Subject: [PATCH 7/8] fix process_request routine after merge --- xCAT-server/lib/xcat/plugins/openbmc.pm | 77 +++++++++---------------- 1 file changed, 26 insertions(+), 51 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index 6c19cb4f4..c89e0605a 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -1,21 +1,11 @@ #!/usr/bin/perl -# IBM(c) 2017 EPL license http://www.eclipse.org/legal/epl-v10.html -#------------------------------------------------------- +## IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html -=head1 - xCAT plugin package to handle openbmc - - Supported command: - getopenbmccons - -=cut - -#------------------------------------------------------- package xCAT_plugin::openbmc; BEGIN { - $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; } use lib "$::XCATROOT/lib/perl"; use strict; @@ -31,20 +21,9 @@ use xCAT::SvrUtils; use File::Basename; use Data::Dumper; use JSON; -use Getopt::Long; -use File::Path; -use Term::ANSIColor; -use Time::Local; -use strict; -use Class::Struct; -use xCAT::PasswordUtils; $::OPENBMC_DEVEL = $ENV{'OPENBMC_DEVEL'}; -my $VERBOSE = 0; -my %allerrornodes = (); -my $callback; - #------------------------------------------------------- =head3 handled_commands @@ -154,6 +133,7 @@ my $async; my $cookie_jar; my $callback; +my %allerrornodes = (); #------------------------------------------------------- @@ -237,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}; @@ -246,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) { @@ -255,33 +246,6 @@ sub process_request { } } - - my $ipmitab = xCAT::Table->new('ipmi'); - my $ipmihash = $ipmitab->getNodesAttribs($noderange, [ 'bmc', 'username', 'password' ]); - my $authdata = xCAT::PasswordUtils::getIPMIAuth(noderange => $noderange, ipmihash => $ipmihash); - - foreach (@$noderange) { - my $node = $_; - my $bmcip; - my $nodeuser = $authdata->{$node}->{username}; - my $nodepass = $authdata->{$node}->{password}; - my $ent; - if (defined($ipmitab)) { - $ent = $ipmihash->{$node}->[0]; - if (ref($ent) and defined $ent->{bmc}) { $bmcip = $ent->{bmc}; } - } - push @donargs, [ $node,$bmcip,$nodeuser, $nodepass]; - my $output = "openbmc, get $username and $password from ipmi table for $bmcip"; - xCAT::SvrUtils::sendmsg($output, $callback, $node, %allerrornodes); - } - - - if ($request->{command}->[0] eq "getopenbmccons") { - foreach (@donargs) { - getopenbmccons($_, $callback); - } - return; - } return; } @@ -330,6 +294,7 @@ sub parse_args { sub unsupported { my $callback = shift; + xCAT::SvrUtils::sendmsg("ENV: OPENBMC_DEVEL=$ENV{OPENBMC_DEVEL},$ENV{'OPENBMC_DEVEL'}\n", $callback); if ($::OPENBMC_DEVEL ne "YES") { return ([ 1, "This function is currently not supported" ]); } else { @@ -673,7 +638,15 @@ sub rinv_response { return; } +#------------------------------------------------------- +=head3 getopenbmccons + + Process getopenbmccons + +=cut + +#------------------------------------------------------- sub getopenbmccons { my $argr = shift; @@ -684,7 +657,7 @@ sub getopenbmccons { 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]; @@ -693,4 +666,6 @@ sub getopenbmccons { return $rsp; } + + 1; From c66aadb0b79db3a12be8585b7eb4587dd4f862a6 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Wed, 15 Mar 2017 15:52:30 -0400 Subject: [PATCH 8/8] remove a debug message --- xCAT-server/lib/xcat/plugins/openbmc.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/openbmc.pm b/xCAT-server/lib/xcat/plugins/openbmc.pm index c89e0605a..1bea4b1a5 100644 --- a/xCAT-server/lib/xcat/plugins/openbmc.pm +++ b/xCAT-server/lib/xcat/plugins/openbmc.pm @@ -294,7 +294,6 @@ sub parse_args { sub unsupported { my $callback = shift; - xCAT::SvrUtils::sendmsg("ENV: OPENBMC_DEVEL=$ENV{OPENBMC_DEVEL},$ENV{'OPENBMC_DEVEL'}\n", $callback); if ($::OPENBMC_DEVEL ne "YES") { return ([ 1, "This function is currently not supported" ]); } else {