[BACK]Return to update_trango.pl CVS log [TXT][DIR] Up to [local] / trango / Net-Telnet-Trango / scripts

Diff for /trango/Net-Telnet-Trango/scripts/update_trango.pl between version 1.29 and 1.30

version 1.29, 2007/02/05 16:37:20 version 1.30, 2007/02/06 23:00:31
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver: update_trango.pl,v 1.28 2007/02/02 22:37:24 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
 #  #
Line 10 
Line 10 
   
 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;
Line 24 
Line 22 
   
 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 };
Line 39 
Line 36 
   
   
 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;
Line 74 
Line 70 
   
   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) {
       $t->su_password($password);      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;
             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("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') {
   
Line 316 
Line 304 
   
     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;

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>