mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 11:22:27 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			98 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
| #!/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";
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 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";
 | |
| 
 |