/[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 54 - (show annotations)
Fri Nov 16 17:45:22 2007 UTC (11 years, 8 months ago) by dpavlin
File size: 1446 byte(s)
 r68@brr:  dpavlin | 2007-11-16 18:45:16 +0100
 move tweaks of addressing

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

  ViewVC Help
Powered by ViewVC 1.1.26