/[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 396 by dpavlin, Tue Sep 8 17:30:14 2009 UTC revision 457 by dpavlin, Sat Jan 2 17:20:40 2010 UTC
# Line 3  package server; Line 3  package server;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6    use Data::Dump qw(dump);
7    use YAML qw();
8    
9  our $base_dir = '/srv/pxelator';  our $base_dir = '/srv/pxelator';
10    
11  tie our $ip,      'server::tie', 'server_ip' => '172.16.10.1';  use ties;
12  tie our $netmask, 'server::tie', 'natmask'   => '255.255.255.0';  
13  tie our $bcast,   'server::tie', 'bcast'     => '172.16.10.254';  tie our $ip,      'ties', 'server_ip' => '172.16.10.1';
14  tie our $ip_from, 'server::tie', 'ip_from'   => 10;  tie our $netmask, 'ties', 'netmask'   => '255.255.255.0';
15  tie our $ip_to,   'server::tie', 'ip_to'     => 100;  tie our $bcast,   'ties', 'bcast'     => '172.16.10.254';
16  tie our $domain,  'server::tie', 'domain'    => 'pxelator.lan';  tie our $ip_from, 'ties', 'ip_from'   => 10;
17  tie our $new_clients, 'server::tie', 'new_clients' => $ip_to - $ip_from;  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";  warn "DEV $ip $bcast $netmask";
22    
# Line 54  sub conf_default { shared($_[0]) || $_[1 Line 59  sub conf_default { shared($_[0]) || $_[1
59    
60  sub debug { shared('debug', @_) || 0 }  sub debug { shared('debug', @_) || 0 }
61    
62  warn "loaded";  sub as_hash_for {
63            my $ip = shift;
   
 package server::tie;  
   
 use File::Slurp;  
 use Data::Dump qw/dump/;  
   
 use server;  
   
 sub TIESCALAR {  
         warn dump @_;  
         my ($class,$name,$default) = @_;  
64    
65          my $path = $server::base_dir . '/conf/' . $name;          my $server;
66            map { $server->{ $_ } = eval '$server::' . $_ } ( 'ip', 'netmask', 'bcast', 'domain' );
67    
68          my $o = {          my $server_path = "$server::conf/ip/$ip/server.yaml";
69                  path => $path,          $server =  YAML::LoadFile $server_path if -e $server_path;
         };  
         write_file $o->{path}, $default unless -f $o->{path};  
70    
71  warn "TIESCALAR $name ", $o->{path}, " [$default]";          return $server;
   
         bless \$o,$class;  
72  }  }
73    
74  sub STORE {  warn "loaded";
         warn dump @_;  
         my ( $self, $value ) = @_;  
         write_file $$self->{path}, $value;  
 }  
   
 sub FETCH {  
         warn dump @_;  
         my $self = shift;  
         read_file $$self->{path};  
 }  
75    
76  3;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26