/[mdap]/lib/MDAP/ChangeIP.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/MDAP/ChangeIP.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 57 by dpavlin, Fri Nov 16 17:45:22 2007 UTC revision 58 by dpavlin, Fri Nov 16 19:12:08 2007 UTC
# Line 4  use strict; Line 4  use strict;
4  use warnings;  use warnings;
5    
6  use Module::Pluggable;  use Module::Pluggable;
7  use Data::Dump qw/dump/;  use MDAP;
   
 my $debug = 0;  
 my $verbose = 1;  
8    
9  my $serial2ip = {  my $serial2ip = {
10          'CP0636JT3SH' => '192.168.1.242;10.0.0.1',          'CP0636JT3SH' => '192.168.1.242;10.0.0.1',
# Line 15  my $serial2ip = { Line 12  my $serial2ip = {
12          'CP0624BH55U' => '192.168.1.244;10.0.0.3',          'CP0624BH55U' => '192.168.1.244;10.0.0.3',
13  };  };
14    
15    my $debug = 1;
16    
17  sub check {  sub check {
18          my ( $self, $h ) = @_;          my ( $self, $h ) = @_;
         warn "## ",__PACKAGE__,"check(",dump($h),")" if $debug;  
19    
20          my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?";          my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?";
   
21          my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST";          my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST";
22    
23          if ( my $ip = $serial2ip->{$serial} ) {          if ( my $ip = $serial2ip->{$serial} ) {
24                  if ( $ip eq $ip_list ) {                  if ( $ip eq $ip_list ) {
25                          warn "OK ",__PACKAGE__," $serial $ip_list\n" if $verbose;                          once "OK ",__PACKAGE__," $serial $ip_list";
26                          return;                          return;
27                  }                  }
28    
# Line 33  sub check { Line 30  sub check {
30                          $h->{'_VARIANT_FRIENDLY_NAME'}, " ",                          $h->{'_VARIANT_FRIENDLY_NAME'}, " ",
31                          $h->{'_BOARD_NAME'}, " ",                          $h->{'_BOARD_NAME'}, " ",
32                          $h->{'_BUILD'}, " ",                          $h->{'_BUILD'}, " ",
33                          "IP $ip_list -> $ip\n" if $verbose;                          "IP $ip_list -> $ip\n" if $debug;
34    
35                  my $ip_status;                  my $ip_status;
36                  $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) );                  $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) );
37                  $ip_status->{$_}++ foreach ( split(/;/, $ip ) );                  $ip_status->{$_}++ foreach ( split(/;/, $ip ) );
38                  foreach my $current_ip ( sort { $ip_status->{$b} <=> $ip_status->{$a} } keys %$ip_status ) {                  foreach my $current_ip ( sort { $ip_status->{$b} <=> $ip_status->{$a} } keys %$ip_status ) {
                         warn "## current_ip = $current_ip\n";  
39                          if ( $ip_status->{$current_ip} < 0 ) {                          if ( $ip_status->{$current_ip} < 0 ) {
40                                  warn "-- remove IP $current_ip\n";                                  warn "-- remove IP $current_ip\n" if $debug;
41                                  return "ip ipdelete addr=$current_ip";                                  return "ip ipdelete addr=$current_ip";
42                          } elsif ( $ip_status->{$current_ip} > 0 ) {                          } elsif ( $ip_status->{$current_ip} > 0 ) {
43                                  warn "-- add IP $current_ip\n";                                  warn "++ add IP $current_ip\n" if $debug;
44                                  return "ip ipadd intf=LocalNetwork addr=$current_ip";                                  return "ip ipadd intf=LocalNetwork addr=$current_ip";
45                          }                          }
46                  }                  }
47                  return;                  return;
48          } else {          } else {
49                  warn "!! can't find serial2ip mapping for $serial IP $ip_list\n";                  once "ERROR: can't find serial2ip mapping for $serial IP $ip_list";
50                  return;                  return;
51          }          }
52  }  }

Legend:
Removed from v.57  
changed lines
  Added in v.58

  ViewVC Help
Powered by ViewVC 1.1.26