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

Contents of /lib/PXElator/pxelinux.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 463 - (show annotations)
Sun Jan 3 01:19:50 2010 UTC (14 years, 3 months ago) by dpavlin
File size: 1472 byte(s)
added pxelinux::config_ip_boot

which can look up in boot/ directory and create pxelinux selection
of kernels and initrd.img

1 package pxelinux;
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 our $magic = 0xF100747E;
8
9 our $config_file; #= 'pxelinux.cfg/default';
10 our $path_prefix;
11 our $reboot_time; # 300 s
12
13 use server;
14 use File::Slurp;
15 use Carp qw/confess/;
16
17 sub config_for_ip {
18 my ($ip,$config) = @_;
19 confess "$ip not IP" unless $ip =~ m{^\d+\.\d+\.\d+\.\d+$};
20
21 $path_prefix = (caller(1))[3];
22 $path_prefix = (caller(2))[3] unless $path_prefix =~ m{config::};
23 $path_prefix =~ s{config::}{} || warn "# caller isn't package config !";
24 $path_prefix .= '/';
25
26 warn "# $ip $path_prefix";
27
28 my $dir = "$server::base_dir/tftp";
29 $dhcpd::file = 'pxelinux.0';
30 symlink "/usr/lib/syslinux/pxelinux.0", "$dir/$dhcpd::file" unless -e "$dir/$dhcpd::file";
31
32 $dir .= "/$path_prefix";
33 mkdir $dir unless -d $dir;
34
35 mkdir "$dir/pxelinux.cfg" unless -e "$dir/pxelinux.cfg";
36
37 $config_file = 'pxelinux.cfg/' . uc sprintf "%02x%02x%02x%02x", split(/\./, $ip, 4);
38 warn "$ip config_file $config_file";
39
40 my $path = "$dir/$config_file";
41 write_file $path, $config;
42
43 warn "# config: $path ", -s $path;
44
45 return $config;
46 }
47
48 sub config_ip_boot {
49 my ( $ip, $boot, $append ) = @_;
50
51 my $default;
52 my $config;
53
54 foreach my $kernel ( glob "$boot/vmlinuz*" ) {
55 my $ver = $1 if $kernel =~ m{vmlinuz(.+)};
56 $default ||= $ver;
57
58 $config .= qq{
59
60 label boot$ver
61 kernel $ip/boot/vmlinuz$ver
62 append initrd=$ip/boot/initrd.img$ver $append
63
64 };
65 }
66
67 config_for_ip( $ip, qq{
68
69 default boot$default
70 prompt 5
71
72 $config
73
74 });
75
76 }
77
78 1;

  ViewVC Help
Powered by ViewVC 1.1.26