Expand uses of ranges

Ranges can now be used on:

Ports:
        cssh localhost:{22001..22008}

FQDN's:
        cssh host{10..20}.domain.name

IP's:
        cssh 192.168.10.{10..20}
This commit is contained in:
Duncan Ferguson 2017-05-17 22:35:46 +01:00
parent 34f6c3e77d
commit f1446f9be3
3 changed files with 18 additions and 3 deletions

View file

@ -2,6 +2,7 @@
- Include coverage tests in the resources
- Include the version of cssh in the utility documentation and README
- Fix dashes (-) not being accepted in hostname range expansion (Github issue #89)
- Amend ranges to work on ports, FQDN's and IP addresses
4.10_01 2017-04-12 Duncan Ferguson <duncan_ferguson@user.sf.net>
- Allow 'include' directives when reading SSH configuration files (Github issue #77) (thanks to Azenet)

View file

@ -54,7 +54,7 @@ Ranges are of the form:
sub expand {
my ( $self, @items ) = @_;
my $range_regexp = qr/^[\w-]+\{[\w\.,]+\}$/;
my $range_regexp = qr/[\w-]*:?\{[\w\.,]+\}/;
my @newlist;
foreach my $item (@items) {
if ( $item !~ m/$range_regexp/ ) {
@ -62,7 +62,7 @@ sub expand {
next;
}
my ( $base, $spec ) = $item =~ m/^(.*)?\{(.*)\}$/;
my ( $base, $spec ) = $item =~ m/^(.*?\{(.*)\}.*?)$/;
for my $section ( split( /,/, $spec ) ) {
my ( $start, $end );
@ -75,7 +75,8 @@ sub expand {
$end = $start if ( !defined($end) );
foreach my $number ( $start .. $end ) {
push( @newlist, "$base$number" );
( my $changed = $base ) =~ s/\{$spec\}/$number/;
push( @newlist, $changed );
}
}
}

View file

@ -33,6 +33,19 @@ my %tests = (
# Reported as bug in github issue #89
'q-0{0,1}' => 'q-00 q-01',
'q-0{0..1}' => 'q-00 q-01',
# expand pure ranges
'{10..12}' => '10 11 12',
# expand ports
'lh:{22001..22003}' => 'lh:22001 lh:22002 lh:22003',
# FQDN's
'lh{1..3}.dot.com' => 'lh1.dot.com lh2.dot.com lh3.dot.com',
# IP addresses
'127.0.0.{10..12}' => '127.0.0.10 127.0.0.11 127.0.0.12',
'127.0.{20..22}.1' => '127.0.20.1 127.0.21.1 127.0.22.1',
);
my $range = App::ClusterSSH::Range->new();