--- lib/MDAP/ChangeIP.pm 2007/11/16 17:45:22 54 +++ lib/MDAP/ChangeIP.pm 2007/11/23 00:48:49 82 @@ -4,28 +4,24 @@ use warnings; use Module::Pluggable; -use Data::Dump qw/dump/; - -my $debug = 0; -my $verbose = 1; +use MDAP; my $serial2ip = { 'CP0636JT3SH' => '192.168.1.242;10.0.0.1', 'CP0644JTHJ4' => '192.168.1.243;10.0.0.2', 'CP0624BH55U' => '192.168.1.244;10.0.0.3', + 'CP0703KT3PP' => '10.0.0.4', }; sub check { my ( $self, $h ) = @_; - warn "## ",__PACKAGE__,"check(",dump($h),")" if $debug; my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?"; - my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST"; if ( my $ip = $serial2ip->{$serial} ) { if ( $ip eq $ip_list ) { - warn "OK ",__PACKAGE__," $serial $ip_list\n" if $verbose; + once "OK ",__PACKAGE__," $serial $ip_list"; return; } @@ -33,23 +29,26 @@ $h->{'_VARIANT_FRIENDLY_NAME'}, " ", $h->{'_BOARD_NAME'}, " ", $h->{'_BUILD'}, " ", - "IP $ip_list -> $ip\n" if $verbose; + "IP $ip_list -> $ip\n" if $debug; + my $ip_status; $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) ); $ip_status->{$_}++ foreach ( split(/;/, $ip ) ); foreach my $current_ip ( sort { $ip_status->{$b} <=> $ip_status->{$a} } keys %$ip_status ) { - warn "## current_ip = $current_ip\n"; if ( $ip_status->{$current_ip} < 0 ) { - warn "-- remove IP $current_ip\n"; + warn "-- remove IP $current_ip\n" if $debug; return "ip ipdelete addr=$current_ip"; } elsif ( $ip_status->{$current_ip} > 0 ) { - warn "-- add IP $current_ip\n"; - return "ip ipadd intf=LocalNetwork addr=$current_ip"; + my $mask = ''; + $mask = '/8' if $current_ip =~ m/^10\./; + $mask = '/24' if $current_ip =~ m/^192\.168\./; + warn "++ add IP $current_ip$mask\n" if $debug; + return "ip ipadd intf=LocalNetwork addr=$current_ip$mask"; } } return; } else { - warn "!! can't find serial2ip mapping for $serial IP $ip_list\n"; + once "ERROR: can't find serial2ip mapping for $serial IP $ip_list"; return; } }