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

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

revision 67 by dpavlin, Thu Jul 30 21:31:30 2009 UTC revision 457 by dpavlin, Sat Jan 2 17:20:40 2010 UTC
# Line 2  package server; Line 2  package server;
2    
3  use warnings;  use warnings;
4  use strict;  use strict;
 use File::Slurp;  
5    
6  our $ip      = '172.16.10.1';  use Data::Dump qw(dump);
7  our $netmask = '255.255.255.0';  use YAML qw();
8    
9    our $base_dir = '/srv/pxelator';
10    
11    use ties;
12    
13    tie our $ip,      'ties', 'server_ip' => '172.16.10.1';
14    tie our $netmask, 'ties', 'netmask'   => '255.255.255.0';
15    tie our $bcast,   'ties', 'bcast'     => '172.16.10.254';
16    tie our $ip_from, 'ties', 'ip_from'   => 10;
17    tie our $ip_to,   'ties', 'ip_to'     => 100;
18    tie our $domain,  'ties', 'domain'    => 'pxelator.lan';
19    tie our $new_clients, 'ties', 'new_clients' => $ip_to - $ip_from;
20    
21    warn "DEV $ip $bcast $netmask";
22    
23    our $conf = "$base_dir/conf";
24    mkdir $conf unless -e $conf;
25    
26    sub conf {
27            warn "## conf $conf";
28            $conf;
29    }
30    
31    use Module::Refresh qw//;
32    sub refresh {
33            Module::Refresh->refresh;
34            my $from = (caller(1))[3];
35            $from =~ s{^(\w+)::.+$}{$1};
36            my $eval = '$' . $from . '::debug = server::debug();';
37            warn "refresh $eval\n";
38            eval $eval;
39            warn $@ if $@;
40    };
41    
42  our ( $ip_from, $ip_to ) = ( 10, 100 );  mkdir $_ foreach grep { ! -d $_ } map { "$conf/$_" } ( 'ip', 'mac' );
43    
44  our $base_dir = '/home/dpavlin/llin/pxelator';  use File::Slurp;
45    sub shared {
46            my ($name, $value) = @_;
47    
48  our $debug = 0;          my $path ="$conf/$name";
49  sub debug {          if ( defined $value ) {
50          my $new = shift;                  write_file $path, $value;
51          my $path ="$base_dir/conf/debug";                  warn "update $path = $value";
         if ( defined $new ) {  
                 write_file $path, $debug = $new;  
52          } else {          } else {
53                  $debug = read_file $path if -e $path;                  $value = read_file $path if -e $path;
54          }          }
55          return $debug;          return $value;
56    }
57    
58    sub conf_default { shared($_[0]) || $_[1] }
59    
60    sub debug { shared('debug', @_) || 0 }
61    
62    sub as_hash_for {
63            my $ip = shift;
64    
65            my $server;
66            map { $server->{ $_ } = eval '$server::' . $_ } ( 'ip', 'netmask', 'bcast', 'domain' );
67    
68            my $server_path = "$server::conf/ip/$ip/server.yaml";
69            $server =  YAML::LoadFile $server_path if -e $server_path;
70    
71            return $server;
72  }  }
73    
74  warn "loaded";  warn "loaded";
75    
76    1;

Legend:
Removed from v.67  
changed lines
  Added in v.457

  ViewVC Help
Powered by ViewVC 1.1.26