diff --git a/xCAT-server/share/xcat/cons/hpblade b/xCAT-server/share/xcat/cons/hpblade new file mode 100755 index 000000000..eb572075d --- /dev/null +++ b/xCAT-server/share/xcat/cons/hpblade @@ -0,0 +1,118 @@ +#!/usr/bin/env perl +# +# © Copyright 2009 Hewlett-Packard Development Company, L.P. +# EPL license http://www.eclipse.org/legal/epl-v10.html +# +# Revision history: +# August, 2009 blade adapted to generate hpblade +# +use Fcntl qw(:DEFAULT :flock); +sub get_lock { + unless (flock(LOCKHANDLE,LOCK_EX|LOCK_NB)) { + $| = 1; + print "Acquiring startup lock..."; + flock(LOCKHANDLE,LOCK_EX) or die "Error trying to secure a startup lock"; + print "done\n"; + } + truncate(LOCKHANDLE,0); + print LOCKHANDLE $$."\n"; +} + +sub release_lock { + truncate(LOCKHANDLE,0); + flock(LOCKHANDLE,LOCK_UN); +} + +BEGIN +{ + use Time::HiRes qw(sleep); + use File::Path; + use Fcntl qw(:DEFAULT :flock); + $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; + umask 0077; + mkpath("/tmp/xcat/"); + unless (sysopen(LOCKHANDLE,"/tmp/xcat/consolelock",O_WRONLY | O_CREAT)) { + sleep 15; + print "Unable to open lock file"; + exit 0; + } + get_lock(); + #my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd + #print "Opening console in ".(2+(0.5*$sleepint))." seconds...\n"; + #sleep $sleepint; +} +my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd +use lib "$::XCATROOT/lib/perl"; +$ENV{HOME}='/root/'; +require xCAT::Client; + +require File::Basename; +import File::Basename; +my $scriptname = $0; + +#$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'); + +my $username = "admin"; +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}; +# } +#} + +#$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=>"gethpbladecons", + arg=>"text", + noderange=>$ARGV[0] +}; +xCAT::Client::submit_request($cmdref,\&getans); +until ($mm and $username and $slot) { + release_lock(); #Let other clients have a go + $sleepint=10+int(rand(20)); #Stagger to minimize lock collisions, but no big deal when it does happen + print "Console not ready, retrying in $sleepint seconds (Hit Ctrl-E,c,o to skip delay)\n"; + sleep $sleepint; + get_lock(); + xCAT::Client::submit_request($cmdref,\&getans); +} +release_lock(); #done with xcatd, can run with near impunity +$sleepint=10+int(rand(30)); #Stagger sleep to take it easy on AMM/hosting server +exec "ssh -t $username"."@"."$mm"; +my $pathtochild= dirname($scriptname). "/"; +#exec $pathtochild."hpblade.expect"; + +#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. + diff --git a/xCAT-server/share/xcat/cons/hpblade.expect b/xCAT-server/share/xcat/cons/hpblade.expect new file mode 100755 index 000000000..99ff947bb --- /dev/null +++ b/xCAT-server/share/xcat/cons/hpblade.expect @@ -0,0 +1,17 @@ +#!/usr/bin/expect -f +# +# © Copyright 2009 Hewlett-Packard Development Company, L.P. +# EPL license http://www.eclipse.org/legal/epl-v10.html +# + +set send_slow {1 0.02} + +expect "" +sleep 5 + +send -s "vsp" +sleep 1 + +send "\r" + +exit 0