/[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 322 by dpavlin, Fri Aug 28 16:41:46 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    use ip;
13    
14    our $debug = $server::debug;
15    
16  sub mkbasedir {  sub mkbasedir {
17          my $path = shift;          my $path = shift;
# Line 29  sub conf_value { Line 31  sub conf_value {
31          } elsif ( -f $path ) {          } elsif ( -f $path ) {
32                  $value = read_file $path;                  $value = read_file $path;
33          } else {          } else {
34                  confess "$path not file or symlink";                  warn "W: $path not file or symlink\n";
35          }          }
36          return $value;          return $value;
37  }  }
# Line 60  sub conf { Line 62  sub conf {
62          } elsif ( -f $path ) {          } elsif ( -f $path ) {
63                  $value = read_file $path;                  $value = read_file $path;
64          } else {          } else {
65                  confess "conf $name";                  warn "# $name missing $path\n" if $debug;
66          }          }
67          return $value;          return $value;
68  }  }
69    
70    sub all_conf {
71            my $ip = shift;
72            my $path = ip_path $ip || return;
73            my $conf;
74            foreach my $file ( glob("$path/*") ) {
75                    my $name = $file;
76                    $name =~ s{^.+/([^/]+)$}{$1};
77                    $conf->{ $name } = read_file $file;
78            }
79            return $conf;
80    }
81  sub next_ip($) {  sub next_ip($) {
82          my $mac = shift;          my $mac = shift;
83            $mac = format::mac($mac);
84    
85          my $p = Net::Ping->new;          my $p = Net::Ping->new;
86    
# Line 83  sub next_ip($) { Line 97  sub next_ip($) {
97    
98          warn "next_ip $ip\n";          warn "next_ip $ip\n";
99    
100          mkdir ip_path($ip);          save_ip_mac( $ip, $mac );
101    
102            return $ip;
103    }
104    
105    sub save_ip_mac {
106            my ($ip,$mac) = @_;
107            $mac = format::mac($mac);
108    
109            mkdir ip_path($ip) unless -e ip_path($ip);
110    
111          my $mac_path = mac_path($mac);          my $mac_path = mac_path($mac);
112          unlink $mac_path if -e $mac_path;       # XXX audit?          unlink $mac_path if -l $mac_path;       # XXX audit?
113          symlink ip_path($ip), $mac_path;          symlink ip_path($ip), $mac_path;
114          write_file ip_path($ip,'mac'), $mac;          write_file ip_path($ip,'mac'), $mac;
   
         return $ip;  
   
115  }  }
116    
117  sub ip_from_mac($) {  sub ip_from_mac($) {
118          my $mac = shift;          my $mac = shift;
119            $mac = format::mac($mac);
         $mac = lc $mac;  
         $mac =~ s{:}{}g;  
120    
121          my $mac_path = mac_path $mac;          my $mac_path = mac_path $mac;
122          return unless -e $mac_path;          return unless -e $mac_path;
# Line 132  sub change_ip($$) { Line 150  sub change_ip($$) {
150          symlink ip_path($new), mac_path($mac);          symlink ip_path($new), mac_path($mac);
151  }  }
152    
153    sub all_ips {
154            sort { ip::to_int($a) cmp ip::to_int($b) }
155            map {
156                    my $ip = $_;
157                    $ip =~ s{^.+/ip/}{};
158                    $ip;
159            } glob("$server::conf/ip/*")
160    }
161    
162  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26