/[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 219 by dpavlin, Sat Aug 15 13:44:13 2009 UTC revision 313 by dpavlin, Thu Aug 27 18:59:12 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;
12    
13    our $debug = $server::debug;
14    
15  sub mkbasedir {  sub mkbasedir {
16          my $path = shift;          my $path = shift;
17          $path =~ s{(^.*)/[^/]+$}{$1};          $path =~ s{(^.*)/[^/]+$}{$1};
# Line 29  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 60  sub conf { Line 61  sub conf {
61          } elsif ( -f $path ) {          } elsif ( -f $path ) {
62                  $value = read_file $path;                  $value = read_file $path;
63          } else {          } else {
64                  confess "conf $name";                  warn "# $name missing $path\n" if $debug;
65          }          }
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            $mac = format::mac($mac);
83    
84          my $p = Net::Ping->new;          my $p = Net::Ping->new;
85    
# Line 83  sub next_ip($) { Line 96  sub next_ip($) {
96    
97          warn "next_ip $ip\n";          warn "next_ip $ip\n";
98    
99          mkdir ip_path($ip);          save_ip_mac( $ip, $mac );
100    
101            return $ip;
102    }
103    
104    sub save_ip_mac {
105            my ($ip,$mac) = @_;
106            $mac = format::mac($mac);
107    
108            mkdir ip_path($ip) unless -e ip_path($ip);
109    
110          my $mac_path = mac_path($mac);          my $mac_path = mac_path($mac);
111          unlink $mac_path if -e $mac_path;       # XXX audit?          unlink $mac_path if -l $mac_path;       # XXX audit?
112          symlink ip_path($ip), $mac_path;          symlink ip_path($ip), $mac_path;
113          write_file ip_path($ip,'mac'), $mac;          write_file ip_path($ip,'mac'), $mac;
   
         return $ip;  
   
114  }  }
115    
116  sub ip_from_mac($) {  sub ip_from_mac($) {
117          my $mac = shift;          my $mac = shift;
118            $mac = format::mac($mac);
         $mac = lc $mac;  
         $mac =~ s{:}{}g;  
119    
120          my $mac_path = mac_path $mac;          my $mac_path = mac_path $mac;
121          return unless -e $mac_path;          return unless -e $mac_path;

Legend:
Removed from v.219  
changed lines
  Added in v.313

  ViewVC Help
Powered by ViewVC 1.1.26