=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.40 retrieving revision 1.45 diff -u -r1.40 -r1.45 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/02/06 21:15:28 1.40 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2008/02/08 16:49:09 1.45 @@ -1,6 +1,6 @@ package Net::Telnet::Trango; -# $RedRiver: Trango.pm,v 1.39 2007/02/06 20:41:42 andrew Exp $ +# $RedRiver: Trango.pm,v 1.44 2007/06/05 19:54:05 mike Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -17,7 +17,7 @@ use Net::Telnet::Trango; my $t = new Net::Telnet::Trango ( Timeout => 5 ); - $t->open( Host => $fox ) or die "Error connecting: $!"; + $t->open( Host => $ap ) or die "Error connecting: $!"; $t->login('password') or die "Couldn't log in: $!"; @@ -28,12 +28,12 @@ =head1 DESCRIPTION -Perl access to the telnet interface on Trango Foxes, SUs and APs. +Perl access to the telnet interface on Trango APs and SUs. -Another handy feature is that it will parse the output from certain -commands that is in the format "[key1] value1 [key2] value2" and put -those in a hashref that is returned. This makes using the output from -things like sysinfo very easy to do. +A handy feature is that it will parse the output from certain commands that is +in the format "[key1] value1 [key2] value2" and put those in a hashref that is +returned. This makes using the output from things like sysinfo very easy to +do. =head2 EXPORT @@ -322,6 +322,7 @@ my $success = 'Success\\.'; my %COMMANDS = ( + _clear => { String => "\n" }, tftpd => { decode => 'all', expect => $success }, ver => { decode => 'all' }, sysinfo => { decode => 'all', expect => $success }, @@ -342,6 +343,7 @@ { String => 'su testrflink', decode => 'each', expect => $success }, save_ss => { String => 'save ss', expect => $success }, opmode => { decode => 'all', expect => $success }, + arq => { decode => 'all' }, ); my %ALIASES = ( @@ -892,6 +894,7 @@ $cmd{'String'} .= $SPACE . $cfg{'args'}; } + #print "Running cmd $cmd{String}\n"; my @lines; if ( $cfg{'no_prompt'} ) { $self->print( $cmd{'String'} ); @@ -913,6 +916,9 @@ } elsif ( $cfg{'decode'} eq 'maclist' ) { $vals = _decode_maclist(@lines); + if (! $vals) { + $self->last_error("Error decoding maclist"); + } } else { $vals = _decode_lines(@lines); @@ -941,12 +947,12 @@ my $err; if (grep { /\[ERR\]/ } @lines) { $err = _decode_lines(@lines); - } + } - if (ref $err eq 'HASH' && $err ->{ERR}) { + if (ref $err eq 'HASH' && $err->{ERR}) { $self->last_error($err->{ERR} ); } else { - $self->last_error("Error with command ($cfg{'String'}): $last"); + $self->last_error("Error with command ($cmd{'String'}): $last"); } return; } @@ -1061,6 +1067,32 @@ return \@decoded; } +#=item _decode_linktest + +sub _decode_linktest { + my @lines = @_; + my %decoded; + foreach my $line (@lines) { + + if ($line =~ s/^(\d+) \s*//xms) { + my $line_id = $1; + my $d = _decode_lines($line . "\n"); + $decoded{tests}[$line_id] = $d; + } + + else { + my $d = _decode_lines($line . "\n"); + if ($d) { + while (my ($k, $v) = each %{ $d }) { + $decoded{$k} = $v; + } + } + } + + } + return \%decoded; +} + #=item _decode_sulog sub _decode_sulog { @@ -1135,8 +1167,6 @@ return \@decoded; } else { - - # XXX we should have a way to set last error, not sure why we don't return; } }