/[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 330 by dpavlin, Fri Aug 28 22:29:08 2009 UTC revision 455 by dpavlin, Sat Jan 2 15:47:39 2010 UTC
# Line 6  use autodie; Line 6  use autodie;
6    
7  use File::Slurp;  use File::Slurp;
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;  use ping;
15    use kvm;
16    
17  our $debug = $server::debug;  our $debug = $server::debug;
18    
# Line 62  sub conf { Line 64  sub conf {
64                  $value = $default;                  $value = $default;
65          } elsif ( -f $path ) {          } elsif ( -f $path ) {
66                  $value = read_file $path;                  $value = read_file $path;
67                    chomp $value;
68          } else {          } else {
69                  warn "# $name missing $path\n" if $debug;                  warn "# $name missing $path\n" if $debug;
70          }          }
# Line 72  sub all_conf { Line 75  sub all_conf {
75          my $ip = shift;          my $ip = shift;
76          my $path = ip_path $ip || return;          my $path = ip_path $ip || return;
77          my $conf;          my $conf;
78          foreach my $file ( glob("$path/*") ) {          foreach my $file ( glob("$path/*"), glob("$path/*/*") ) {
79                  my $name = $file;                  my $name = $file;
80                  $name =~ s{^.+/([^/]+)$}{$1};                  $name =~ s{^$path/+}{} || die "can't remove $path from $name";
81                  $conf->{ $name } = read_file $file;                  $conf->{ $name } = read_file $file if -f $file;
82          }          }
83          return $conf;          return $conf;
84  }  }
# Line 83  sub next_ip($) { Line 86  sub next_ip($) {
86          my $mac = shift;          my $mac = shift;
87          $mac = format::mac($mac);          $mac = format::mac($mac);
88    
89            if ( $server::new_clients > 0 ) {
90                    warn "# clients left: ", --$server::new_clients;
91            } else {
92                    warn "W: no new clients accepted";
93                    return '0.0.0.0';
94            }
95    
96          my $prefix = $server::ip;          my $prefix = $server::ip;
97          $prefix =~ s{\.\d+$}{.};          $prefix =~ s{\.\d+$}{.};
98          my $addr = $server::ip_from || die;          my $addr = $server::ip_from || die;
# Line 104  sub next_ip($) { Line 114  sub next_ip($) {
114  sub save_ip_mac {  sub save_ip_mac {
115          my ($ip,$mac) = @_;          my ($ip,$mac) = @_;
116          $mac = format::mac($mac);          $mac = format::mac($mac);
117          return if $mac eq '00:00:00:00:00:00';          return if $mac eq '00:00:00:00:00:00' || $ip eq '0.0.0.0';
118    
119          mkdir ip_path($ip) unless -e ip_path($ip);          mkdir ip_path($ip) unless -e ip_path($ip);
120    
# Line 157  sub all_ips { Line 167  sub all_ips {
167          map {          map {
168                  my $ip = $_;                  my $ip = $_;
169                  $ip =~ s{^.+/ip/}{};                  $ip =~ s{^.+/ip/}{};
170                    autocreate_params( $ip );
171                  $ip;                  $ip;
172          } glob("$server::conf/ip/*")          } glob("$server::conf/ip/*")
173  }  }
174    
175  sub remove {  sub remove {
176          my $ip = shift;          my $ip = shift;
         unlink $_ foreach grep { -e $_ } ( glob "$server::conf/ip/$ip/*" );  
177          if ( my $mac = mac_from_ip $ip ) {          if ( my $mac = mac_from_ip $ip ) {
178                  unlink "$server::conf/mac/$mac";                  unlink "$server::conf/mac/$mac";
179          }          }
180          rmdir "$server::conf/ip/$ip";          rmtree "$server::conf/ip/$ip";
181  }  }
182    
183  sub arp_mac_dev {  sub arp_mac_dev {
# Line 186  sub arp_mac_dev { Line 196  sub arp_mac_dev {
196          return $arp;          return $arp;
197  }  }
198    
199    sub rebuild_mac_links {
200            warn "# rebuild mac links";
201            foreach my $ip ( all_ips ) {
202                    my $mac = ip_path $ip, 'mac';
203                    if ( -e $mac ) {
204                            $mac = read_file $mac;
205                            chomp $mac;
206                            save_ip_mac( $ip, $mac );
207                            warn "## $ip $mac\n";
208                    }
209            }
210    }
211    
212    sub autocreate_params {
213            my $ip = shift;
214            my $mac = mac_from_ip $ip;
215            if ( $mac =~ m{^AC:DE:48:00:00} && ! defined conf( $ip, 'kvm' ) ) {
216                    conf( $ip, 'kvm', default => kvm::nr_from_mac( $mac ) );
217                    warn "# create kvm for $ip";
218            }
219    }
220    
221  1;  1;

Legend:
Removed from v.330  
changed lines
  Added in v.455

  ViewVC Help
Powered by ViewVC 1.1.26