/[pxelator]/lib/PXElator/client.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

Diff of /lib/PXElator/client.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 322 by dpavlin, Fri Aug 28 16:41:46 2009 UTC revision 329 by dpavlin, Fri Aug 28 21:55:41 2009 UTC
# Line 6  use autodie; Line 6  use autodie;
6    
7  use File::Slurp;  use File::Slurp;
8  use Net::Ping;  use Net::Ping;
9    use Data::Dump qw/dump/;
10    
11  use server;  use server;
12  use format;  use format;
# Line 105  sub next_ip($) { Line 106  sub next_ip($) {
106  sub save_ip_mac {  sub save_ip_mac {
107          my ($ip,$mac) = @_;          my ($ip,$mac) = @_;
108          $mac = format::mac($mac);          $mac = format::mac($mac);
109            return if $mac eq '00:00:00:00:00:00';
110    
111          mkdir ip_path($ip) unless -e ip_path($ip);          mkdir ip_path($ip) unless -e ip_path($ip);
112    
113          my $mac_path = mac_path($mac);          my $mac_path = mac_path($mac);
114          unlink $mac_path if -l $mac_path;       # XXX audit?          unlink $mac_path if -l $mac_path;       # XXX audit?
115          symlink ip_path($ip), $mac_path;          symlink ip_path($ip), $mac_path;
116          write_file ip_path($ip,'mac'), $mac;          write_file( ip_path($ip,'mac'), $mac );
117  }  }
118    
119  sub ip_from_mac($) {  sub ip_from_mac($) {
# Line 144  sub mac_from_ip($) { Line 146  sub mac_from_ip($) {
146    
147  sub change_ip($$) {  sub change_ip($$) {
148          my ($old, $new) = @_;          my ($old, $new) = @_;
149          my $mac = mac_from_ip($old);          return if $old eq $new;
150            my $mac = mac_from_ip($old) || die "no mac for $old";
151          rename ip_path($old), ip_path($new);          rename ip_path($old), ip_path($new);
152          unlink mac_path($mac);          unlink mac_path($mac);
153          symlink ip_path($new), mac_path($mac);          symlink ip_path($new), mac_path($mac);
154            return $new;
155  }  }
156    
157  sub all_ips {  sub all_ips {
# Line 159  sub all_ips { Line 163  sub all_ips {
163          } glob("$server::conf/ip/*")          } glob("$server::conf/ip/*")
164  }  }
165    
166    sub remove {
167            my $ip = shift;
168            unlink $_ foreach grep { -e $_ } ( glob "$server::conf/ip/$ip/*" );
169            if ( my $mac = mac_from_ip $ip ) {
170                    unlink "$server::conf/mac/$mac";
171            }
172            rmdir "$server::conf/ip/$ip";
173    }
174    
175    sub arp_mac_dev {
176            my $arp = {
177                    map {
178                            my @c = split(/\s+/,$_);
179                            if ( $#c == 5 ) {
180                                    client::save_ip_mac( $c[0], $c[3] );
181                                    ( uc $c[3] => $c[5] )
182                            } else {
183                            }
184                    } read_file('/proc/net/arp')
185            };
186    
187            warn "# arp ",dump( $arp );
188            return $arp;
189    }
190    
191  1;  1;

Legend:
Removed from v.322  
changed lines
  Added in v.329

  ViewVC Help
Powered by ViewVC 1.1.26