#!/usr/local/bin/perl -w
# Add some code in here to tell if is begin
# run as a .cgi program, and if so, emit some headers...
use strict;
my (%PARTITION_HOSTS);
my (%HOST_PARTITIONS);
my ($rsh_pid);
my (@ALL_HOSTS) = ("angelou", "brecht", "gibson", "vertov", "hooks", "godard",
"benjamin", "jarry", "stein", "keaton", "ronell", "haraway",
"barthes", "melies");
my (@foo, $i);
foreach $i (@ALL_HOSTS) {
&get_host_partition_info ($i);
}
foreach $i (&all_hosts) {
@foo = &partitions ($i);
print "$i: @foo\n";
}
print "\n\n";
foreach $i (&all_partitions) {
@foo = &hosts ($i);
print "$i: @foo\n";
}
#
# HTML version of the above.
&report_by_partition;
&report_by_host;
sub report_by_partition {
my($i, @hosts);
print "
\n";
print " | Depot Partitions by Package Name |
\n";
foreach $i (&all_partitions) {
@hosts = &hosts($i);
print "| $i | @hosts |
\n";
}
print "
\n";
}
sub report_by_host {
my($i, @partitions);
print "\n";
print " | Depot Partitions by Hostname |
\n";
foreach $i (&all_hosts) {
@partitions = &partitions($i);
print "| $i | @partitions |
\n";
}
print "
\n";
}
sub get_host_partition_info {
my($host) = @_;
my($date, $partition);
$date = localtime();
$SIG{ 'ALRM' } = "rsh_timeout";
$rsh_pid = open (DF, "/bin/rsh $host -n /bin/ls -lF /exp/depot/ 2>&1 |");
alarm (30);
while () {
if (m{^d.*\s(\w+)/$}) {
$partition = $1;
&add_partition ($host, $partition);
&add_host ($host, $partition);
}
}
close(DF);
}
sub rsh_timeout
{
kill 9, $rsh_pid;
close ();
}
sub unpack_data {
my($packed) = @_;
my(@unpacked);
if ($packed) {
@unpacked = split /:/, $packed;
return @unpacked;
} else {
return ();
}
}
sub pack_data {
my(@unpacked) = @_;
my($packed);
if (@unpacked) {
$packed = join ':', @unpacked;
return $packed;
} else {
return ()
}
}
# Add a host to a partition key in a database.
sub add_partition {
my ($host, $partition) = @_;
my (@entries) = unpack_data ($PARTITION_HOSTS{$partition});
my ($i);
foreach $i (@entries) {
if ($host eq $i) {
return;
}
}
$PARTITION_HOSTS{$partition} = pack_data ($host, @entries);
}
# Add a partition to a host key in a database.
sub add_host {
my ($host, $partition) = @_;
my (@entries) = unpack_data ($HOST_PARTITIONS{$host});
my ($i);
foreach $i (@entries) {
if ($partition eq $i) {
return;
}
}
$HOST_PARTITIONS{$host} = pack_data ($partition, @entries);
}
sub all_partitions {
my(@keys);
@keys = sort keys(%PARTITION_HOSTS);
return @keys;
}
sub all_hosts {
my(@keys);
@keys = sort keys(%HOST_PARTITIONS);
return @keys;
}
sub partitions {
my ($host) = @_;
my (@entries) = unpack_data ($HOST_PARTITIONS{$host});
@entries = sort (@entries);
return @entries;
}
sub hosts {
my ($partition) = @_;
my (@entries) = unpack_data ($PARTITION_HOSTS{$partition});
@entries = sort (@entries);
return @entries;
}