version 1.27, 2007/02/02 21:36:00 |
version 1.30, 2007/02/06 23:00:31 |
|
|
#!/usr/bin/perl |
#!/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 |
# update_trango.pl *** Updates trango hosts with a new firmware |
# |
# |
|
|
|
|
use YAML qw/ LoadFile /; |
use YAML qw/ LoadFile /; |
use Net::TFTP; |
use Net::TFTP; |
use lib '.'; |
|
use Net::Telnet::Trango; |
use Net::Telnet::Trango; |
use RedRiver::Wireless; |
|
|
|
my $config_file = shift || 'update_trango.yaml'; |
my $config_file = shift || 'update_trango.yaml'; |
my $max_tries = 3; |
my $max_tries = 3; |
|
|
|
|
my $hosts; |
my $hosts; |
if (@ARGV) { |
if (@ARGV) { |
@{ $hosts } = map { { name => $_, group => 'Trango-Client' } } @ARGV |
@{ $hosts } = map { { name => $_, group => 'Trango-Client' } } @ARGV |
} else { |
} else { |
$l->sp("Reading hosts"); |
$hosts = parse_hosts($conf->{hosts}); |
$hosts = RedRiver::Wireless::Read_Hosts(); |
|
} |
} |
|
|
#@{ $hosts } = grep { $_->{name} eq '10.100.7.2' } @{ $hosts }; |
#@{ $hosts } = grep { $_->{name} eq '10.100.7.2' } @{ $hosts }; |
|
|
|
|
|
|
foreach my $host (@{ $hosts }) { |
foreach my $host (@{ $hosts }) { |
next if $host->{group} !~ /^Trango/; |
|
|
|
if (! exists $host->{retry}) { |
if (! exists $host->{retry}) { |
$host->{tries} = 0; |
$host->{tries} = 0; |
|
|
|
|
my $password = $host->{Telnet_Password} || $conf->{general}->{password}; |
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 |
$l->p("Logging in"); |
# XXX associated stations. |
$t->login($password); |
if ($host->{group} !~ /Client$/) { |
unless ($t->logged_in) { |
$l->p("Logging in"); |
$l->p('Failed!'); |
$t->login($password); |
$t->close; |
unless ($t->logged_in) { |
next; |
$l->p('Failed!'); |
} |
$t->close; |
|
next; |
|
} |
|
|
|
$l->sp("Getting sudb"); |
$l->sp("Getting sudb"); |
my $sudb = $t->sudb_view; |
my $sudb = $t->sudb_view; |
if ($sudb) { |
if ($sudb) { |
foreach my $su (@{ $sudb }) { |
foreach my $su (@{ $sudb }) { |
$l->p("Getting su info $su->{suid}"); |
$l->p("Getting su info $su->{suid}"); |
my $su_info = $t->su_info( $su->{suid} ); |
my $su_info = $t->su_info( $su->{suid} ); |
if ($su_info->{ip}) { |
if ($su_info->{ip}) { |
if (grep { $_->{name} eq $su_info->{'ip'} } @{ $hosts }) { |
if (grep { $_->{name} eq $su_info->{'ip'} } @{ $hosts }) { |
$l->p("Already have $su_info->{ip}"); |
$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}"); |
|
} |
|
next; |
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') { |
foreach my $firmware_type ('Firmware', 'FPGA') { |
|
|
|
|
next; |
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) { |
if (! $t->logged_in) { |
$l->p("Logging in"); |
$l->p("Logging in"); |
$t->login($password); |
$t->login($password); |
|
|
|
|
return 1; |
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; |
package Mylogger; |