/[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

Annotation of /lib/MDAP/ChangeIP.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (hide annotations)
Fri Nov 16 19:12:08 2007 UTC (12 years, 10 months ago) by dpavlin
File size: 1322 byte(s)
 r78@brr:  dpavlin | 2007-11-16 20:12:03 +0100
 cleanup messages and plugins

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

  ViewVC Help
Powered by ViewVC 1.1.26