Enhance blade.pm in preparation for deeper CMM support
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12096 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		@@ -8,9 +8,11 @@ use IO::Pty;
 | 
			
		||||
use POSIX;
 | 
			
		||||
 | 
			
		||||
sub _startssh {
 | 
			
		||||
	my $self = shift;
 | 
			
		||||
	my $pty = shift;
 | 
			
		||||
	my $name = shift;
 | 
			
		||||
	my $dest = shift;
 | 
			
		||||
	my %args=@_;
 | 
			
		||||
	my $tty;
 | 
			
		||||
	my $tty_fd;
 | 
			
		||||
	my $pid = fork();
 | 
			
		||||
@@ -25,7 +27,12 @@ sub _startssh {
 | 
			
		||||
	open STDOUT,">&",$tty_fd;
 | 
			
		||||
	$pty->make_slave_controlling_terminal();
 | 
			
		||||
	close($tty);
 | 
			
		||||
	exec ("ssh","-o","StrictHostKeyChecking=no","-l",$name,$dest);
 | 
			
		||||
	my @cmd =  ("ssh","-o","StrictHostKeyChecking=no");
 | 
			
		||||
	if ($args{"-nokeycheck"}) {
 | 
			
		||||
		push @cmd,("-o","UserKnownHostsFile=/dev/null");
 | 
			
		||||
	}
 | 
			
		||||
	push @cmd,("-l",$name,$dest);
 | 
			
		||||
	exec @cmd;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub new {
 | 
			
		||||
@@ -42,8 +49,10 @@ sub new {
 | 
			
		||||
	delete $args{"-host"};
 | 
			
		||||
	delete $args{"-username"};
 | 
			
		||||
	delete $args{"-password"};
 | 
			
		||||
	my $nokeycheck = $args{"-nokeycheck"};
 | 
			
		||||
	if ($nokeycheck) { delete $args{"-nokeycheck"}; }
 | 
			
		||||
	my $self = Net::Telnet->new(%args);
 | 
			
		||||
	_startssh($pty,$username,$host);
 | 
			
		||||
	_startssh($self,$pty,$username,$host,"-nokeycheck"=>$nokeycheck);
 | 
			
		||||
	$self->waitfor("-match" => '/password:/i', -errmode => "return") or die "Unable to reach host ",$self->lastline;
 | 
			
		||||
	$self->print($password);
 | 
			
		||||
	my $nextline = $self->getline();
 | 
			
		||||
 
 | 
			
		||||
@@ -3972,6 +3972,7 @@ sub clicmds {
 | 
			
		||||
  my $pass=shift;
 | 
			
		||||
  my $node=shift;
 | 
			
		||||
  my $nodeid=shift;
 | 
			
		||||
  my %args=@_;
 | 
			
		||||
  my $value;
 | 
			
		||||
  my @unhandled;
 | 
			
		||||
  my %handled = ();
 | 
			
		||||
@@ -3999,31 +4000,51 @@ sub clicmds {
 | 
			
		||||
  unless (%handled) {
 | 
			
		||||
    return([0,\@unhandled]);
 | 
			
		||||
  }
 | 
			
		||||
  require Net::Telnet;
 | 
			
		||||
  my $t = new Net::Telnet(
 | 
			
		||||
                Timeout=>15, 
 | 
			
		||||
                Errmode=>'return',
 | 
			
		||||
                Prompt=>'/system> $/'
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  my $Rc;
 | 
			
		||||
  if (defined($handled{'initnetwork'})) {
 | 
			
		||||
  my $curruser = $user;
 | 
			
		||||
  my $currpass = $pass;
 | 
			
		||||
  my $nokeycheck=0; #default to checking ssh key
 | 
			
		||||
  if ($args{defaultcfg}) {
 | 
			
		||||
    $curruser="USERID";
 | 
			
		||||
    $currpass = "PASSW0RD";
 | 
			
		||||
    $nokeycheck=1;
 | 
			
		||||
  }
 | 
			
		||||
  my $curraddr = $mpa;
 | 
			
		||||
  if ($args{curraddr}) {
 | 
			
		||||
	$curraddr = $args{curraddr};
 | 
			
		||||
  } elsif (defined($handled{'initnetwork'})) {
 | 
			
		||||
    # get the IP of mpa from the hosts.otherinterfaces
 | 
			
		||||
    my $hoststab = xCAT::Table->new('hosts');
 | 
			
		||||
    if ($hoststab) {
 | 
			
		||||
      my $hostdata = $hoststab->getNodeAttribs($node, ['otherinterfaces']);
 | 
			
		||||
      if (!$hostdata->{'otherinterfaces'}) {
 | 
			
		||||
      return ([1,\@unhandled,"Cannot find the temporary IP from the hosts.otherinterfaces"]);
 | 
			
		||||
         return ([1,\@unhandled,"Cannot find the temporary IP from the hosts.otherinterfaces"]);
 | 
			
		||||
      } else {
 | 
			
		||||
        $Rc = $t->open($hostdata->{'otherinterfaces'});
 | 
			
		||||
        ## TRACE_LINE print "Telnet to $hostdata->{'otherinterfaces'} for the initnetwork command.\n";
 | 
			
		||||
      	$curraddr = $hostdata->{'otherinterfaces'};
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    $Rc = $t->open($mpa);
 | 
			
		||||
  }
 | 
			
		||||
  if ($Rc) {
 | 
			
		||||
    $Rc = $t->login($user,$pass); 
 | 
			
		||||
  } 
 | 
			
		||||
  require xCAT::SSHInteract;
 | 
			
		||||
  my $t = new  xCAT::SSHInteract(
 | 
			
		||||
		-username=>$curruser,
 | 
			
		||||
		-password=>$currpass,
 | 
			
		||||
		-host=>$curraddr,
 | 
			
		||||
		-nokeycheck=>$nokeycheck,
 | 
			
		||||
                Timeout=>15, 
 | 
			
		||||
                Errmode=>'return',
 | 
			
		||||
                Prompt=>'/system> $/'
 | 
			
		||||
		);
 | 
			
		||||
  my $Rc=1;
 | 
			
		||||
  unless ($t) { #ssh failed.. fallback to a telnet attempt for older AMMs with telnet disabled by default
 | 
			
		||||
     require Net::Telnet;
 | 
			
		||||
     $t = new Net::Telnet(
 | 
			
		||||
                   Timeout=>15, 
 | 
			
		||||
                   Errmode=>'return',
 | 
			
		||||
                   Prompt=>'/system> $/'
 | 
			
		||||
     );
 | 
			
		||||
     $Rc = $t->open($curraddr);
 | 
			
		||||
     if ($Rc) {
 | 
			
		||||
       $Rc = $t->login($user,$pass); 
 | 
			
		||||
     }
 | 
			
		||||
  }
 | 
			
		||||
  if (!$Rc) {
 | 
			
		||||
    push @cfgtext,$t->errmsg;
 | 
			
		||||
@@ -4187,6 +4208,7 @@ sub mmtextid {
 | 
			
		||||
  if (!grep(/OK/i,@data)) {
 | 
			
		||||
    return([1,@data]);
 | 
			
		||||
  }
 | 
			
		||||
  my @data = $t->cmd("config -name \"$value\" -T system"); #on cmms, this identifier is frequently relevant...
 | 
			
		||||
  return([0,"textid: $value"]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user