/[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 403 by dpavlin, Tue Sep 8 20:38:26 2009 UTC revision 541 by dpavlin, Sat Oct 9 12:28:01 2010 UTC
# Line 12  use server; Line 12  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 49  sub conf { Line 50  sub conf {
50          }          }
51    
52          my $path = ip_path $ip;          my $path = ip_path $ip;
53          mkdir $path unless -d $path;          mkdir $path unless -e $path;
54            warn "WARNING: $path not directory" unless -d $path;
55          $path .= '/' . $name;          $path .= '/' . $name;
56    
57          if ( defined $value ) {          if ( defined $value ) {
# Line 61  sub conf { Line 63  sub conf {
63                  write_file $path, $default;                  write_file $path, $default;
64                  warn "default $path = $default";                  warn "default $path = $default";
65                  $value = $default;                  $value = $default;
66            } elsif ( -l $path ) {
67                    $value = readlink $path;
68          } elsif ( -f $path ) {          } elsif ( -f $path ) {
69                  $value = read_file $path;                  $value = read_file $path;
70                    chomp $value;
71          } else {          } else {
72                  warn "# $name missing $path\n" if $debug;                  warn "# $name missing $path\n" if $debug;
73          }          }
# Line 73  sub all_conf { Line 78  sub all_conf {
78          my $ip = shift;          my $ip = shift;
79          my $path = ip_path $ip || return;          my $path = ip_path $ip || return;
80          my $conf;          my $conf;
81          foreach my $file ( glob("$path/*") ) {          foreach my $file ( glob("$path/*"), glob("$path/*/*") ) {
82                  my $name = $file;                  my $name = $file;
83                  $name =~ s{^.+/([^/]+)$}{$1};                  $name =~ s{^$path/+}{} || die "can't remove $path from $name";
84                  $conf->{ $name } = read_file $file;                  next if -d $file;
85                    $conf->{ $name } =
86                            -l $file ? readlink  $file :
87                            -f $file ? read_file $file :
88                            '?';
89          }          }
90          return $conf;          return $conf;
91  }  }
# Line 84  sub next_ip($) { Line 93  sub next_ip($) {
93          my $mac = shift;          my $mac = shift;
94          $mac = format::mac($mac);          $mac = format::mac($mac);
95    
96          if ( $server::new_clients-- ) {          if ( $server::new_clients > 0 ) {
97                  warn "# clients left: $server::new_clients\n";                  warn "# clients left: ", --$server::new_clients;
98          } else {          } else {
99                  warn "W: no new clients accepted";                  warn "W: no new clients accepted";
100                  return '0.0.0.0';                  return '0.0.0.0';
# Line 112  sub next_ip($) { Line 121  sub next_ip($) {
121  sub save_ip_mac {  sub save_ip_mac {
122          my ($ip,$mac) = @_;          my ($ip,$mac) = @_;
123          $mac = format::mac($mac);          $mac = format::mac($mac);
124          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';
125    
126          mkdir ip_path($ip) unless -e ip_path($ip);          mkdir ip_path($ip) unless -e ip_path($ip);
127    
# Line 165  sub all_ips { Line 174  sub all_ips {
174          map {          map {
175                  my $ip = $_;                  my $ip = $_;
176                  $ip =~ s{^.+/ip/}{};                  $ip =~ s{^.+/ip/}{};
177                    autocreate_params( $ip );
178                  $ip;                  $ip;
179          } glob("$server::conf/ip/*")          } glob("$server::conf/ip/*")
180  }  }
181    
182  sub remove {  sub remove {
183          my $ip = shift;          my $ip = shift;
         unlink $_ foreach grep { -e $_ } ( glob "$server::conf/ip/$ip/*" );  
184          if ( my $mac = mac_from_ip $ip ) {          if ( my $mac = mac_from_ip $ip ) {
185                  unlink "$server::conf/mac/$mac";                  unlink "$server::conf/mac/$mac";
186          }          }
# Line 200  sub rebuild_mac_links { Line 209  sub rebuild_mac_links {
209                  my $mac = ip_path $ip, 'mac';                  my $mac = ip_path $ip, 'mac';
210                  if ( -e $mac ) {                  if ( -e $mac ) {
211                          $mac = read_file $mac;                          $mac = read_file $mac;
212                            chomp $mac;
213                          save_ip_mac( $ip, $mac );                          save_ip_mac( $ip, $mac );
214                          warn "## $ip $mac\n";                          warn "## $ip $mac\n";
215                  }                  }
216          }          }
217  }  }
218    
219    sub autocreate_params {
220            my $ip = shift;
221            my $mac = mac_from_ip $ip;
222            if ( $mac =~ m{^AC:DE:48:00:00} && ! defined conf( $ip, 'kvm' ) ) {
223                    conf( $ip, 'kvm', default => kvm::nr_from_mac( $mac ) );
224                    warn "# create kvm for $ip";
225            }
226    }
227    
228  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26