2008-02-07 21:48:21 +00:00
#!/usr/bin/env perl
2008-01-10 01:59:16 +00:00
#A placeholder wcons, a fuller port from 1.3 is needed
2008-02-08 22:02:43 +00:00
use Getopt::Long qw(:config getopt_compat pass_through);
2008-02-07 21:48:21 +00:00
use File::Basename;
2013-04-11 18:01:37 +00:00
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
2014-11-12 21:48:44 +00:00
use IO::Socket::UNIX;
use Time::HiRes qw/sleep/;
2013-04-11 18:01:37 +00:00
use lib "$::XCATROOT/lib/perl";
use xCAT::Client;
2011-04-11 16:17:08 +00:00
#use Data::Dumper;
2008-02-08 15:45:13 +00:00
use strict;
2008-02-07 21:48:21 +00:00
unless ($ENV{DISPLAY}) {
print '$DISPLAY not set';
exit 1;
}
my $mydir = dirname($0);
my $sb;
my $tilefact;
2008-07-01 15:33:41 +00:00
my $xrm="-xrm xterm.mainMenu.*.font:fixed -xrm xterm.vtMenu.*.font:fixed -xrm xterm.fontMenu.*.font:fixed -xrm xterm -xrm xterm.vt100.font6:grvga.737";
2008-02-08 22:02:43 +00:00
my $font = "5x7";
2015-01-30 21:57:32 +00:00
my $sizegeometry;
2008-02-07 21:48:21 +00:00
GetOptions(
2008-02-08 22:02:43 +00:00
#'sb' => \$sb,
2008-02-07 21:48:21 +00:00
'tile|t:i' => \$tilefact,
2015-01-30 21:57:32 +00:00
'geometry|g:s' => \$sizegeometry,
2008-02-08 22:02:43 +00:00
#'font|f=s' => \$font
2008-02-07 21:48:21 +00:00
);
2013-04-11 18:01:37 +00:00
my $noderange = $ARGV[$#ARGV];
my %conserverref = (command => 'nodels', noderange => $noderange, arg => ['nodehm.conserver']);
2013-04-11 18:01:45 +00:00
my @nodes;
my %conservers;
sub getconserver {
my $rsp = shift;
foreach (@{$rsp->{node}}) {
my $node = $_->{name};
if (ref $node) { $node = $node->[0]; }
push @nodes,$node;
if ($_->{data}->[0]->{contents}) {
$conservers{$node}=$_->{data}->[0]->{contents};
if (ref $conservers{$node}) { $conservers{$node} = $conservers{$node}->[0] };
}
}
}
xCAT::Client::submit_request(\%conserverref,\&getconserver);
2013-04-11 18:01:37 +00:00
2008-02-08 22:07:09 +00:00
unless ($ARGV[$#ARGV]) {
print "Usage: wcons <options> <noderange>\n";
exit 1;
}
2008-02-08 22:02:43 +00:00
pop @ARGV;
2008-02-08 21:12:56 +00:00
foreach (@nodes) {
if ($conservers{$_}) {
next;
}
if ($ENV{XCATHOST}) {
$conservers{$_} = $ENV{XCATHOST};
$conservers{$_} =~ s/:.*//;
next;
}
}
2008-02-07 21:48:21 +00:00
my $firstnode = shift @nodes;
2008-05-07 17:27:59 +00:00
unless ($firstnode) {
exit 1;
}
2008-02-08 15:45:13 +00:00
my $currx;
my $curry;
my $wmxo;
my $wmyo;
my $currx;
my $screenwidth;
my $screenheight;
my $window_width;
my $window_height;
2008-02-08 19:13:10 +00:00
my $panel_pad=0;
my $top_pad;
2008-02-07 21:48:21 +00:00
if (defined($tilefact)) {
2008-02-08 15:45:13 +00:00
my $rootinf = `xwininfo -root`;
foreach (split /\n/,$rootinf) {
if (/.*Width:\s+([0-9]*).*/) {
$screenwidth=$1;
} elsif (/.*Height:\s+([0-9]*).*/) {
$screenheight=$1;
}
}
2014-11-12 21:48:44 +00:00
$rootinf = `xwininfo -name "Top Panel" 2> /dev/null`;
2008-02-08 19:13:10 +00:00
foreach (split /\n/,$rootinf) {
if (/-geometry\s+([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)/) {
if ($1 > 640 and $2 < 480 and $3 == 0 and $4 == 0) {
$panel_pad=$2;
}
}
}
2010-04-09 20:58:12 +00:00
if ($panel_pad == 0) {
2014-11-12 21:48:44 +00:00
$rootinf = `xwininfo -name "Top Expanded Edge Panel" 2> /dev/null`;
2010-04-09 20:58:12 +00:00
foreach (split /\n/,$rootinf) {
if (/-geometry\s+([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)/) {
if ($1 > 640 and $2 < 480 and $3 == 0 and $4 == 0) {
$panel_pad=$2;
}
}
}
}
2008-02-08 19:13:10 +00:00
2014-11-12 21:48:44 +00:00
$ENV{CONSCONTROLPATH} = "/tmp/wconscontrol.$firstnode.$$";
2015-01-30 21:57:32 +00:00
system("xterm $xrm -bg black -fg white -title $firstnode -n $firstnode -geometry $sizegeometry+0+0 ".join(" ",@ARGV)." -e /bin/bash -c \"/bin/true ".$ENV{DISPLAY}." $firstnode $firstnode & let SDATE=`date +%s`+5; $mydir/rcons $firstnode ".$conservers{$firstnode}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi \" &");
2015-01-30 19:25:08 +00:00
$ENV{CONSCONTROLPATH} = "";
2014-11-12 21:48:44 +00:00
my $remainwait = 2;
2015-03-20 15:00:10 +00:00
if (-x "/opt/confluent/bin/confetty" or -x "/usr/bin/confetty" or -x "/usr/local/bin/confetty" ) {
$remainwait = 10;
}
2014-11-12 21:48:44 +00:00
while (not -S "/tmp/wconscontrol.$firstnode.$$" and $remainwait > 0) {
sleep(0.1);
$remainwait -= 0.1;
}
my $xinfo;
if (-S "/tmp/wconscontrol.$firstnode.$$") { # confluent mode
my $controlchannel = IO::Socket::UNIX->new(Type=>SOCK_STREAM(), Peer => "/tmp/wconscontrol.$firstnode.$$");
print $controlchannel "GETWINID\n";
my $winid = <$controlchannel>;
$winid = <$controlchannel>;
$xinfo = `xwininfo -id $winid`;
} else {
$xinfo = `xwininfo -name $firstnode`;
}
2008-02-08 15:45:13 +00:00
my @xinfl = split(/\n/,$xinfo);
my $side_pad;
my $wmxo;
my $wmyo;
foreach (@xinfl) {
if (/.*Absolute upper-left X:\s*([0-9]*).*/) {
$side_pad = $1;
} elsif (/.*Absolute upper-left Y:\s*([0-9]*).*/) {
2008-02-08 19:13:10 +00:00
$top_pad = $1-$panel_pad;
2008-02-08 15:45:13 +00:00
} elsif (/.*Width:\s*([0-9]*).*/) {
$window_width = $1;
} elsif (/.*Height:\s*([0-9]*).*/) {
$window_height = $1;
} elsif (/.*-gemotery \d+x\d+\+(\d+)(\d+)/) {
$wmxo=$1;
$wmyo=$2;
}
}
$window_width += $side_pad*2; #add the side border, assuming symmetric left and right borders
$window_height += $side_pad+$top_pad; #Add the titlebar and bottom border, which is guessed to probably be equal to the sides, doesn't hold true in all cases, i.e. window maker, but it's the currently best approximation
$screenwidth-=$wmxo; #Subtract a factor that 1.3 did, not sure why precisely
$screenheight-=$wmyo;
$currx=$window_width;
2008-02-08 19:13:10 +00:00
$curry=$panel_pad; #+$top_pad;
2008-02-08 15:45:13 +00:00
my $maxcol = int($screenwidth/$window_width);
unless ($tilefact or $tilefact > $maxcol) {
$tilefact=$maxcol;
}
if ($tilefact==1) {
$curry+=$window_height;
2008-02-08 19:13:10 +00:00
$currx=0;
2008-02-08 15:45:13 +00:00
}
2008-02-07 21:48:21 +00:00
} else {
2015-01-30 21:57:32 +00:00
my $geo;
if ($sizegeometry) {
$geo = "-g $sizegeometry ";
}
system("xterm $xrm $geo-bg black -fg white -title $firstnode -n $firstnode ".join(" ",@ARGV)." -e /bin/bash -c \"$mydir/xtcd.pl ".$ENV{DISPLAY}." $firstnode $firstnode & let SDATE=`date +%s`+5; $mydir/rcons $firstnode ".$conservers{$firstnode}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi\" &");
2008-02-07 21:48:21 +00:00
}
2008-02-08 15:45:13 +00:00
my $geometry="";
2008-02-07 21:48:21 +00:00
foreach (@nodes) {
2008-02-08 15:45:13 +00:00
if ($tilefact) {
my $corrected_x=$currx+$wmxo;
my $corrected_y=$curry+$wmyo;
2015-01-30 21:57:32 +00:00
$geometry="-geometry $sizegeometry+$corrected_x+$corrected_y";
2008-02-08 15:45:13 +00:00
$currx+=$window_width;
if ($currx >= ($tilefact * $window_width)) {
$currx=0;
$curry+=$window_height;
2008-02-08 22:02:43 +00:00
if (($curry+$window_height) > $screenheight) {
2008-02-08 19:13:10 +00:00
$curry = $panel_pad; #+$top_pad;
2008-02-08 15:45:13 +00:00
}
}
2015-01-30 21:57:32 +00:00
} elsif ($sizegeometry) {
$geometry = "-geometry $sizegeometry";
2008-02-08 15:45:13 +00:00
}
2010-04-09 20:58:12 +00:00
system("xterm $xrm -bg black -fg white ".join(" ",@ARGV)." -title $_ -n $_ $geometry -e /bin/bash -c \"$mydir/xtcd.pl .".$ENV{DISPLAY}." $_ $_ & let SDATE=`date +%s`+5; $mydir/rcons $_ ".$conservers{$_}."; if [ \\\$SDATE -gt \\`date +%s\\` ]; then echo Press enter to close; read SDATE; fi\" &");
2008-02-07 21:48:21 +00:00
}
#print Dumper(\@ARGV);
#MYDIR=`dirname $0`
#for n in $NODES
#do
2008-07-01 15:33:41 +00:00
# xterm -bg black -fg white ".join(" ",@ARGV)." -T $n -n $n -e $MYDIR/rcons $n &
2008-02-07 21:48:21 +00:00
#done