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

Contents of /lib/MDAP/ChangeIP.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 package MDAP::ChangeIP;
2
3 use strict;
4 use warnings;
5
6 use Module::Pluggable;
7 use MDAP;
8
9 my $serial2ip = {
10 '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 };
14
15 my $debug = 1;
16
17 sub check {
18 my ( $self, $h ) = @_;
19
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 if ( $ip eq $ip_list ) {
25 once "OK ",__PACKAGE__," $serial $ip_list";
26 return;
27 }
28
29 warn "## change_ip $serial ",
30 $h->{'_VARIANT_FRIENDLY_NAME'}, " ",
31 $h->{'_BOARD_NAME'}, " ",
32 $h->{'_BUILD'}, " ",
33 "IP $ip_list -> $ip\n" if $debug;
34
35 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 warn "-- remove IP $current_ip\n" if $debug;
41 return "ip ipdelete addr=$current_ip";
42 } elsif ( $ip_status->{$current_ip} > 0 ) {
43 warn "++ add IP $current_ip\n" if $debug;
44 return "ip ipadd intf=LocalNetwork addr=$current_ip";
45 }
46 }
47 return;
48 } else {
49 once "ERROR: can't find serial2ip mapping for $serial IP $ip_list";
50 return;
51 }
52 }
53
54 1;

  ViewVC Help
Powered by ViewVC 1.1.26