diff options
| author | Paul Buetow (mars) <paul@buetow.org> | 2011-12-26 15:18:08 +0100 |
|---|---|---|
| committer | Paul Buetow (mars) <paul@buetow.org> | 2011-12-26 15:18:08 +0100 |
| commit | 7749c8604f72b3b4cd62a9cfa16142c685d449cd (patch) | |
| tree | 982b168c6a5a4ef58f3cc47233a9addf633bab50 | |
| parent | 2e4329ceec29f9ca1ad9347268a0d76f1446a260 (diff) | |
Support for aliases in /etc/clusters. E.g. clusters of clusters
| -rwxr-xr-x | loadbars | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -28,6 +28,8 @@ use constant { DEPTH => 8, VERSION => 'loadbars v0.3.1-devel', Copyright => '2010-2011 (c) Paul Buetow <loadbars@mx.buetow.org>', + CSSH_CONFFILE => '/etc/clusters', + CSSH_MAX_RECURSION => 10, BLACK => SDL::Color->new(-r => 0x00, -g => 0x00, -b => 0x00), BLUE => SDL::Color->new(-r => 0x00, -g => 0x00, -b => 0xff), GREEN => SDL::Color->new(-r => 0x00, -g => 0x90, -b => 0x00), @@ -686,11 +688,19 @@ END return (\$hosts, $closure); } -sub get_cluster_hosts ($) { - my $cluster = shift; - my $confile = '/etc/clusters'; +# Recursuve function +sub get_cluster_hosts ($;$); +sub get_cluster_hosts ($;$) { + my ($cluster, $recursion) = @_; - open my $fh, $confile or error "$!: $confile"; + unless (defined $recursion) { + $recursion = 1; + + } elsif ($recursion > CSSH_MAX_RECURSION) { + error "CSSH_MAX_RECURSION reached. Infinite circle loop in " . CSSH_CONFFILE . "?"; + } + + open my $fh, CSSH_CONFFILE or error "$!: " . CSSH_CONFFILE; my $hosts; while (<$fh>) { @@ -702,9 +712,16 @@ sub get_cluster_hosts ($) { close $fh; - error "No such cluster in $confile: $cluster" unless defined $hosts; + unless (defined $hosts) { + error "No such cluster in " . CSSH_CONFFILE . ": $cluster" + unless defined $recursion; + + return ($cluster); + } - return split /\s+/, $hosts; + my @hosts; + push @hosts, get_cluster_hosts $_, ($recursion + 1) for (split /\s+/, $hosts); + return @hosts; } sub main () { |
