/[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 47 - (show annotations)
Fri Nov 16 14:59:30 2007 UTC (16 years, 5 months ago) by dpavlin
File size: 1313 byte(s)
 r56@brr:  dpavlin | 2007-11-16 15:59:26 +0100
 - more strict parsing of SEQ-NR (which can contain " OK" at end)
 - call new ChangeIP plugin which sorts out IP addressing issues
 - report EXEC-CLI failures

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

  ViewVC Help
Powered by ViewVC 1.1.26