mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-12 17:30:19 +00:00
remove configssh routine
This commit is contained in:
@ -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;
|
||||
|
@ -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";
|
||||
|
Reference in New Issue
Block a user