From: <sis...@sy...> - 2007-01-27 15:49:02
|
Author: arighi Date: 2007-01-27 09:48:53 -0600 (Sat, 27 Jan 2007) New Revision: 3878 Modified: trunk/lib/SystemImager/HostRange.pm trunk/sbin/si_pcp trunk/sbin/si_psh Log: si_psh and si_pcp support host ranges also in the input host file Modified: trunk/lib/SystemImager/HostRange.pm =================================================================== --- trunk/lib/SystemImager/HostRange.pm 2007-01-26 21:57:02 UTC (rev 3877) +++ trunk/lib/SystemImager/HostRange.pm 2007-01-27 15:48:53 UTC (rev 3878) @@ -24,6 +24,25 @@ use strict; # Usage: +# my @hosts = expand_range_list($range_string) +# Description: +# Expand host ranges identified by the $range_string into the +# @hosts list. +sub expand_range_list { + my $clients = shift; + my @hosts = split(/,| |\n/, $clients); + + # Expand host or IP ranges. + my %expanded_hosts = (); + foreach my $range (@hosts) { + expand_range(\%expanded_hosts, $range); + } + + # Convert into a list. + return sort(keys(%expanded_hosts)); +} + +# Usage: # expand_range(\%expanded_hosts, $range_string) # Description: # Expand host ranges identified by the $range_string into the Modified: trunk/sbin/si_pcp =================================================================== --- trunk/sbin/si_pcp 2007-01-26 21:57:02 UTC (rev 3877) +++ trunk/sbin/si_pcp 2007-01-27 15:48:53 UTC (rev 3878) @@ -40,8 +40,9 @@ comma, spaces or new line and can include ranges (e.g. "node001-node256,node300 node400"). - --hosts-file, -f=FILE File that contains the list of the target hosts - (one host per line). + --hosts-file, -f=FILE File that contains the list of the target host. + Every line can include one or more ranges + (e.g. "node001-node256,node300 node400"). --timeout, -t=NUM Set the timeout of the sessions. @@ -96,18 +97,24 @@ my @hosts = (); if ($hostlist) { - @hosts = split(/,| |\n/, $hostlist); - # Expand host ranges. - my %expanded_hosts = (); - foreach my $range (@hosts) { - SystemImager::HostRange::expand_range(\%expanded_hosts, $range); - } - @hosts = keys(%expanded_hosts); + # Expand host ranges. + @hosts = SystemImager::HostRange::expand_range_list($hostlist); } elsif ($hostlist_file) { + # Read input file. open(IN, "<$hostlist_file") || die("error: could't read $hostlist_file!\n"); chomp(@hosts = <IN>); close(IN); + # Expand host ranges. + my %expanded_hosts = (); + foreach my $line (@hosts) { + my @list = split(/,| |\n/, $line); + foreach my $range (@list) { + SystemImager::HostRange::expand_range(\%expanded_hosts, $range); + } + } + # Convert hosts hash into a list. + @hosts = sort(keys(%expanded_hosts)); } elsif (!-t) { chomp(@hosts = <STDIN>); } else { @@ -226,7 +233,8 @@ =item B<--hosts-file | -f FILE> -File that contains the list of the target hosts (one host per line). +File that contains the list of the target hosts. +Every line can include one or more ranges (e.g. "node001-node256,node300 node400"). =item B<--timeout | -t NUM> Modified: trunk/sbin/si_psh =================================================================== --- trunk/sbin/si_psh 2007-01-26 21:57:02 UTC (rev 3877) +++ trunk/sbin/si_psh 2007-01-27 15:48:53 UTC (rev 3878) @@ -38,8 +38,9 @@ comma, spaces or new line and can include ranges (e.g. "node001-node256,node300 node400"). - --hosts-file, -f=FILE File that contains the list of the target hosts - (one host per line). + --hosts-file, -f=FILE File that contains the list of the target host. + Every line can include one or more ranges + (e.g. "node001-node256,node300 node400"). --timeout, -t=NUM Set the timeout of the ssh sessions. @@ -80,18 +81,24 @@ my @hosts = (); if ($hostlist) { - @hosts = split(/,| |\n/, $hostlist); # Expand host ranges. - my %expanded_hosts = (); - foreach my $range (@hosts) { - SystemImager::HostRange::expand_range(\%expanded_hosts, $range); - } - @hosts = keys(%expanded_hosts); + @hosts = SystemImager::HostRange::expand_range_list($hostlist); } elsif ($hostlist_file) { + # Read input file. open(IN, "<$hostlist_file") || die("error: could't read $hostlist_file!\n"); chomp(@hosts = <IN>); close(IN); + # Expand host ranges. + my %expanded_hosts = (); + foreach my $line (@hosts) { + my @list = split(/,| |\n/, $line); + foreach my $range (@list) { + SystemImager::HostRange::expand_range(\%expanded_hosts, $range); + } + } + # Convert hosts hash into a list. + @hosts = sort(keys(%expanded_hosts)); } else { die("error: no host defined!\nTry \"--help\" for more options.\n"); } @@ -225,7 +232,8 @@ =item B<--hosts-file | -f FILE> -File that contains the list of the target hosts (one host per line). +File that contains the list of the target hosts. +Every line can include one or more ranges (e.g. "node001-node256,node300 node400"). =item B<--timeout | -t NUM> |