X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FH1%2FZTEMSAN.pm;h=85c81bb1443018a53e98fa59cde82e08d2be7dfa;hb=5e876ece6477bcff745dee98b19309c88d9a890e;hp=316acadf73b9ef3d67d92bad637d8089b287a61b;hpb=355b54702c3ee12c0284a6d1f17220bff4e9daf2;p=APKPM.git diff --git a/lib/H1/ZTEMSAN.pm b/lib/H1/ZTEMSAN.pm old mode 100755 new mode 100644 index 316acad..85c81bb --- a/lib/H1/ZTEMSAN.pm +++ b/lib/H1/ZTEMSAN.pm @@ -1,98 +1,80 @@ package H1::ZTEMSAN; -use warnings; -use strict; +use Moose; -use Net::Telnet; +with 'H1::ZTE'; use Data::Dump qw(dump); -sub hash { - my $self = shift; - my $args = {@_}; +sub connect { + my ( $self,$ip ) = @_; - warn "# info ", dump($args); + my $t = Net::Telnet->new( Timeout => 20, Port => 1123, Prompt => '/#/' ); -my $t = Net::Telnet->new( Timeout => 20, Port => 1123, Prompt => '/#/' ); + $t->dump_log('/tmp/log') if $ENV{DEBUG}; -$t->dump_log('/tmp/log') if $ENV{DEBUG}; + warn "open"; + $t->open( $ip ); -warn "open"; -$t->open( $args->{ip} ); + $t->waitfor('/Login:/'); + $t->print('root'); + $t->waitfor('/Password:/'); + $t->print('root'); + $t->waitfor('/#/'); -$t->waitfor('/Login:/'); -$t->print('root'); -$t->waitfor('/Password:/'); -$t->print('root'); -#$t->waitfor('/>/'); -#$t->print('en'); -#$t->waitfor('/Please input password:/'); -#$t->print('admin'); -$t->waitfor('/#/'); + warn "login OK"; -warn "login OK"; - -my $port = "$args->{shelf}/$args->{slot}/$args->{port}"; - -sub command { - my $command = shift; - - warn "# command $command\n"; - $t->print($command); - - my $out; - while (1) { - warn "waitfor"; - my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/'); - $out .= $prematch; - last if $match eq '#'; - $t->put(" "); - } + return $t; +} - warn "## out = [$out]"; +sub parse { + my ( $self, $out ) = @_; my $hash; + my $section = ''; + my $last_line; foreach my $line ( split(/[\n\r]+/, $out) ) { warn "# $line\n"; - if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) { + if ( $line =~ m/^(\S+.*?)\s*:+\s+(\S+.*?)\s*$/ ) { my ($n,$v) = ($1,$2); $n =~ s/\(.+\)//; - $hash->{$n} = $v; + if ( $v =~ s/\s+(\S+)\s*:\s+(\S+.+)// ) { + # strip second column + my ($n2,$v2) = ($1,$2); + $n2 =~ s/\(.+\)//; + $hash->{ $section . $n2 } = $v2; + warn "## $n2 = $v2\n"; + } + $hash->{ $section . $n } = $v; warn "## $n = $v\n"; + } elsif ( $line =~ m/^-+$/ ) { + $section = $last_line . '_'; } - + $last_line = $line; } - warn dump $hash; + warn "## hash = ",dump $hash; return $hash; } -our ( $row, $hash ); -sub copy { - my @what = @_ ? @_ : keys %$hash; - foreach my $name (@what) { - warn "# copy $name ", dump( $hash->{$name} ),$/; - $row->{$name} = $hash->{$name}; +sub commands {{ + 'show adsl port %s' => [], + 'show adsl port %s line-config' => [], + 'show adsl port %s physical-table' => [], +}} + +sub fixup_row { + my ( $self, $row ) = @_; + # cleanup column names + foreach my $n ( grep { m/[:\s]/ } keys %$row ) { + my $v = delete $row->{$n}; + $n =~ s/\s+/_/g; + $n =~ s/:$// && $v =~ s/\skbps$//; # special case + $row->{$n} = $v; } -} - -$hash = command "show adsl port $port"; -copy; - -$hash = command "show adsl port $port line-config"; -copy; - -$hash = command "show adsl port $port physical-table"; -copy; - -warn "# row = ",dump $row; - -warn "logout"; -$t->print('logout'); -$t->waitfor('/:/'); -$t->print('y'); + return $row; +} -} # sub 1;