/[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 51 by dpavlin, Fri Nov 16 17:03:33 2007 UTC revision 79 by dpavlin, Sun Nov 18 16:25:26 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.242',          'CP0636JT3SH' => '192.168.1.242;10.0.0.1',
11          'CP0644JTHJ4' => '192.168.1.243;10.0.0.243',          'CP0644JTHJ4' => '192.168.1.243;10.0.0.2',
12          'CP0624BH55U' => '192.168.1.244;10.0.0.244',          'CP0624BH55U' => '192.168.1.244;10.0.0.3',
13  };  };
14    
15  sub check {  sub check {
16          my ( $self, $h ) = @_;          my ( $self, $h ) = @_;
         warn "## ",__PACKAGE__,"check(",dump($h),")" if $debug;  
17    
18          my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?";          my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?";
   
19          my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST";          my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST";
20    
21          if ( my $ip = $serial2ip->{$serial} ) {          if ( my $ip = $serial2ip->{$serial} ) {
22                  if ( $ip eq $ip_list ) {                  if ( $ip eq $ip_list ) {
23                          warn "OK ",__PACKAGE__," $serial $ip_list\n" if $verbose;                          once "OK ",__PACKAGE__," $serial $ip_list";
24                          return;                          return;
25                  }                  }
26    
# Line 33  sub check { Line 28  sub check {
28                          $h->{'_VARIANT_FRIENDLY_NAME'}, " ",                          $h->{'_VARIANT_FRIENDLY_NAME'}, " ",
29                          $h->{'_BOARD_NAME'}, " ",                          $h->{'_BOARD_NAME'}, " ",
30                          $h->{'_BUILD'}, " ",                          $h->{'_BUILD'}, " ",
31                          "IP $ip_list -> $ip\n" if $verbose;                          "IP $ip_list -> $ip\n" if $debug;
32    
33                  my $ip_status;                  my $ip_status;
34                  $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) );                  $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) );
35                  $ip_status->{$_}++ foreach ( split(/;/, $ip ) );                  $ip_status->{$_}++ foreach ( split(/;/, $ip ) );
36                  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";  
37                          if ( $ip_status->{$current_ip} < 0 ) {                          if ( $ip_status->{$current_ip} < 0 ) {
38                                  warn "-- remove IP $current_ip\n";                                  warn "-- remove IP $current_ip\n" if $debug;
39                                  return "ip ipdelete addr=$current_ip";                                  return "ip ipdelete addr=$current_ip";
40                          } elsif ( $ip_status->{$current_ip} > 0 ) {                          } elsif ( $ip_status->{$current_ip} > 0 ) {
41                                  warn "-- add IP $current_ip\n";                                  my $mask = '';
42                                  return "ip ipadd intf=LocalNetwork addr=$current_ip";                                  $mask = '/8'  if $current_ip =~ m/^10\./;
43                                    $mask = '/24' if $current_ip =~ m/^192\.168\./;
44                                    warn "++ add IP $current_ip$mask\n" if $debug;
45                                    return "ip ipadd intf=LocalNetwork addr=$current_ip$mask";
46                          }                          }
47                  }                  }
48                  return;                  return;
49          } else {          } else {
50                  warn "!! can't find serial2ip mapping for $serial IP $ip_list\n";                  once "ERROR: can't find serial2ip mapping for $serial IP $ip_list";
51                  return;                  return;
52          }          }
53  }  }

Legend:
Removed from v.51  
changed lines
  Added in v.79

  ViewVC Help
Powered by ViewVC 1.1.26