/[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 220 by dpavlin, Sat Aug 15 13:47:37 2009 UTC revision 305 by dpavlin, Thu Aug 27 14:30:55 2009 UTC
# Line 6  use autodie; Line 6  use autodie;
6    
7  use File::Slurp;  use File::Slurp;
8  use Net::Ping;  use Net::Ping;
 use Carp qw/confess/;  
9    
10  use server;  use server;
11  use format;  use format;
# Line 31  sub conf_value { Line 30  sub conf_value {
30          } elsif ( -f $path ) {          } elsif ( -f $path ) {
31                  $value = read_file $path;                  $value = read_file $path;
32          } else {          } else {
33                  confess "$path not file or symlink";                  warn "W: $path not file or symlink\n";
34          }          }
35          return $value;          return $value;
36  }  }
# Line 67  sub conf { Line 66  sub conf {
66          return $value;          return $value;
67  }  }
68    
69    sub all_conf {
70            my $ip = shift;
71            my $path = ip_path $ip || return;
72            my $conf;
73            foreach my $file ( glob("$path/*") ) {
74                    my $name = $file;
75                    $name =~ s{^.+/([^/]+)$}{$1};
76                    $conf->{ $name } = read_file $file;
77            }
78            return $conf;
79    }
80  sub next_ip($) {  sub next_ip($) {
81          my $mac = shift;          my $mac = shift;
82    
# Line 85  sub next_ip($) { Line 95  sub next_ip($) {
95    
96          warn "next_ip $ip\n";          warn "next_ip $ip\n";
97    
98          mkdir ip_path($ip);          save_ip_mac( $ip, $mac );
99    
100            return $ip;
101    }
102    
103    sub save_ip_mac {
104            my ($ip,$mac) = @_;
105    
106            mkdir ip_path($ip) unless -e ip_path($ip);
107    
108          my $mac_path = mac_path($mac);          my $mac_path = mac_path($mac);
109          unlink $mac_path if -e $mac_path;       # XXX audit?          unlink $mac_path if -l $mac_path;       # XXX audit?
110          symlink ip_path($ip), $mac_path;          symlink ip_path($ip), $mac_path;
111          write_file ip_path($ip,'mac'), $mac;          write_file ip_path($ip,'mac'), $mac;
   
         return $ip;  
   
112  }  }
113    
114  sub ip_from_mac($) {  sub ip_from_mac($) {

Legend:
Removed from v.220  
changed lines
  Added in v.305

  ViewVC Help
Powered by ViewVC 1.1.26