/[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 329 by dpavlin, Fri Aug 28 21:55:41 2009 UTC revision 403 by dpavlin, Tue Sep 8 20:38:26 2009 UTC
# Line 5  use strict; Line 5  use strict;
5  use autodie;  use autodie;
6    
7  use File::Slurp;  use File::Slurp;
 use Net::Ping;  
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9    use File::Path;
10    
11  use server;  use server;
12  use format;  use format;
13  use ip;  use ip;
14    use ping;
15    
16  our $debug = $server::debug;  our $debug = $server::debug;
17    
# Line 83  sub next_ip($) { Line 84  sub next_ip($) {
84          my $mac = shift;          my $mac = shift;
85          $mac = format::mac($mac);          $mac = format::mac($mac);
86    
87          my $p = Net::Ping->new;          if ( $server::new_clients-- ) {
88                    warn "# clients left: $server::new_clients\n";
89            } else {
90                    warn "W: no new clients accepted";
91                    return '0.0.0.0';
92            }
93    
94          my $prefix = $server::ip;          my $prefix = $server::ip;
95          $prefix =~ s{\.\d+$}{.};          $prefix =~ s{\.\d+$}{.};
96          my $addr = $server::ip_from || die;          my $addr = $server::ip_from || die;
97          my $ip = $prefix . $addr;          my $ip = $prefix . $addr;
98    
99          while ( -e ip_path($ip) || $p->ping( $ip, 0.7 ) ) {          while ( -e ip_path($ip) || ping::host($ip) ) {
100                  $ip = $prefix . $addr++;                  $ip = $prefix . $addr++;
101                  die "all addresses allocated!" if $addr == $server::ip_to;                  die "all addresses allocated!" if $addr == $server::ip_to;
102                  warn "skip $ip\n";                  warn "skip $ip\n";
# Line 169  sub remove { Line 175  sub remove {
175          if ( my $mac = mac_from_ip $ip ) {          if ( my $mac = mac_from_ip $ip ) {
176                  unlink "$server::conf/mac/$mac";                  unlink "$server::conf/mac/$mac";
177          }          }
178          rmdir "$server::conf/ip/$ip";          rmtree "$server::conf/ip/$ip";
179  }  }
180    
181  sub arp_mac_dev {  sub arp_mac_dev {
# Line 188  sub arp_mac_dev { Line 194  sub arp_mac_dev {
194          return $arp;          return $arp;
195  }  }
196    
197    sub rebuild_mac_links {
198            warn "# rebuild mac links";
199            foreach my $ip ( all_ips ) {
200                    my $mac = ip_path $ip, 'mac';
201                    if ( -e $mac ) {
202                            $mac = read_file $mac;
203                            save_ip_mac( $ip, $mac );
204                            warn "## $ip $mac\n";
205                    }
206            }
207    }
208    
209  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26