=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/scripts/update_trango.pl,v retrieving revision 1.27 retrieving revision 1.30 diff -u -r1.27 -r1.30 --- trango/Net-Telnet-Trango/scripts/update_trango.pl 2007/02/02 21:36:00 1.27 +++ trango/Net-Telnet-Trango/scripts/update_trango.pl 2007/02/06 23:00:31 1.30 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $RedRiver: update_trango.pl,v 1.25 2007/02/02 17:50:09 andrew Exp $ +# $RedRiver: update_trango.pl,v 1.29 2007/02/05 16:37:20 mike Exp $ ######################################################################## # update_trango.pl *** Updates trango hosts with a new firmware # @@ -10,9 +10,7 @@ use YAML qw/ LoadFile /; use Net::TFTP; -use lib '.'; use Net::Telnet::Trango; -use RedRiver::Wireless; my $config_file = shift || 'update_trango.yaml'; my $max_tries = 3; @@ -24,10 +22,9 @@ my $hosts; if (@ARGV) { - @{ $hosts } = map { { name => $_, group => 'Trango-Client' } } @ARGV + @{ $hosts } = map { { name => $_, group => 'Trango-Client' } } @ARGV } else { - $l->sp("Reading hosts"); - $hosts = RedRiver::Wireless::Read_Hosts(); + $hosts = parse_hosts($conf->{hosts}); } #@{ $hosts } = grep { $_->{name} eq '10.100.7.2' } @{ $hosts }; @@ -39,7 +36,6 @@ foreach my $host (@{ $hosts }) { - next if $host->{group} !~ /^Trango/; if (! exists $host->{retry}) { $host->{tries} = 0; @@ -74,46 +70,38 @@ my $password = $host->{Telnet_Password} || $conf->{general}->{password}; - # XXX I am not sure this is the best way to check if we should look for - # XXX associated stations. - if ($host->{group} !~ /Client$/) { - $l->p("Logging in"); - $t->login($password); - unless ($t->logged_in) { - $l->p('Failed!'); - $t->close; - next; - } + $l->p("Logging in"); + $t->login($password); + unless ($t->logged_in) { + $l->p('Failed!'); + $t->close; + next; + } - $l->sp("Getting sudb"); - my $sudb = $t->sudb_view; - if ($sudb) { - foreach my $su (@{ $sudb }) { - $l->p("Getting su info $su->{suid}"); - my $su_info = $t->su_info( $su->{suid} ); - if ($su_info->{ip}) { - if (grep { $_->{name} eq $su_info->{'ip'} } @{ $hosts }) { - $l->p("Already have $su_info->{ip}"); - next; - } - $l->sp("Adding host $su_info->{ip}"); - my $new_host = { - Telnet_Password => $host->{Telnet_Password}, - group => $host->{group} . '-Client', - name => $su_info->{ip}, - remarks => $su_info->{remarks}, - }; - push @{ $hosts }, $new_host; - } else { - $l->sp("Couldn't get su info for $su->{suid}"); - if ($su_info->{ERR}) { - $l->sp("ERR: $su_info->{ERR}"); - } + $l->sp("Getting sudb"); + my $sudb = $t->sudb_view; + if ($sudb) { + foreach my $su (@{ $sudb }) { + $l->p("Getting su info $su->{suid}"); + my $su_info = $t->su_info( $su->{suid} ); + if ($su_info->{ip}) { + if (grep { $_->{name} eq $su_info->{'ip'} } @{ $hosts }) { + $l->p("Already have $su_info->{ip}"); next; } + $l->sp("Adding host $su_info->{ip}"); + my $new_host = { + password => $host->{password}, + name => $su_info->{ip}, + remarks => $su_info->{remarks}, + }; + push @{ $hosts }, $new_host; + } else { + $l->sp("Couldn't get su info for $su->{suid}"); + $l->sp("ERR: " . $t->last_error); } } - } + } foreach my $firmware_type ('Firmware', 'FPGA') { @@ -134,6 +122,14 @@ next; } + if ($firmware_type eq 'Firmware' && + $t->firmware_version eq + $conf->{$firmware_type}->{$host_type}->{ver} + ) { + $l->sp("Firmware already up to date"); + next; + } + if (! $t->logged_in) { $l->p("Logging in"); $t->login($password); @@ -308,6 +304,31 @@ return 1; } +} + +sub parse_hosts +{ + my $src = shift; + + my @hosts; + foreach my $h (@{ $src }) { + if ($h->{name} =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.)(\d{1,3})-(\d{1,3})/) { + for ($2..$3) { + my %cur_host; + foreach my $k (keys %{ $h }) { + $cur_host{$k} = $h->{$k}; + } + $cur_host{name} = $1 . $_; + if (! grep { $cur_host{name} eq $h->{name} } @hosts) { + push @hosts, \%cur_host; + } + } + } else { + push @hosts, $h; + } + } + + return \@hosts; } package Mylogger;