/[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 64 - (show annotations)
Sun Nov 18 00:55:43 2007 UTC (16 years, 5 months ago) by dpavlin
File size: 1306 byte(s)
 r89@brr:  root | 2007-11-18 01:51:20 +0100
 - move $debug into MDAP and export it
 - iterate plugins correctly

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 sub check {
16 my ( $self, $h ) = @_;
17
18 my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?";
19 my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST";
20
21 if ( my $ip = $serial2ip->{$serial} ) {
22 if ( $ip eq $ip_list ) {
23 once "OK ",__PACKAGE__," $serial $ip_list";
24 return;
25 }
26
27 warn "## change_ip $serial ",
28 $h->{'_VARIANT_FRIENDLY_NAME'}, " ",
29 $h->{'_BOARD_NAME'}, " ",
30 $h->{'_BUILD'}, " ",
31 "IP $ip_list -> $ip\n" if $debug;
32
33 my $ip_status;
34 $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) );
35 $ip_status->{$_}++ foreach ( split(/;/, $ip ) );
36 foreach my $current_ip ( sort { $ip_status->{$b} <=> $ip_status->{$a} } keys %$ip_status ) {
37 if ( $ip_status->{$current_ip} < 0 ) {
38 warn "-- remove IP $current_ip\n" if $debug;
39 return "ip ipdelete addr=$current_ip";
40 } elsif ( $ip_status->{$current_ip} > 0 ) {
41 warn "++ add IP $current_ip\n" if $debug;
42 return "ip ipadd intf=LocalNetwork addr=$current_ip";
43 }
44 }
45 return;
46 } else {
47 once "ERROR: can't find serial2ip mapping for $serial IP $ip_list";
48 return;
49 }
50 }
51
52 1;

  ViewVC Help
Powered by ViewVC 1.1.26