added pxelinux::config_ip_boot
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 3 Jan 2010 01:19:50 +0000 (01:19 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 3 Jan 2010 01:19:50 +0000 (01:19 +0000)
which can look up in boot/ directory and create pxelinux selection
of kernels and initrd.img

lib/PXElator/config.pm
lib/PXElator/pxelinux.pm
lib/PXElator/t/pxelinux.t [new file with mode: 0755]

index 4daafaf..a9e44e2 100644 (file)
@@ -205,18 +205,8 @@ iface eth0 inet dhcp
                file::append "$export/etc/rc.local", $_;
        } ( '/srv/sysadmin-cookbook/recepies/amt/serial-console.sh' );
 
-       pxelinux::config_for_ip( $ip, qq{
-
-default nfsroot
-label nfsroot
-       kernel $ip/vmlinuz
-       append initrd=$ip/initrd.img root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp
+       pxelinux::config_ip_boot( $ip, "$export/boot", "root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp" );
 
-label old
-       kernel $ip/vmlinuz.old
-       append initrd=$ip/initrd.img.old root=/dev/nfs nfsroot=$server->{ip}:$export ro ip=dhcp
-
-       });
 }
 
 sub openvz {
index c9b88bf..e94acfb 100644 (file)
@@ -19,7 +19,8 @@ sub config_for_ip {
        confess "$ip not IP" unless $ip =~ m{^\d+\.\d+\.\d+\.\d+$};
 
        $path_prefix = (caller(1))[3];
-       $path_prefix =~ s{config::}{} || die "caller isn't package config !";
+       $path_prefix = (caller(2))[3] unless $path_prefix =~ m{config::};
+       $path_prefix =~ s{config::}{} || warn "# caller isn't package config !";
        $path_prefix .= '/';
 
        warn "# $ip $path_prefix";
@@ -44,4 +45,34 @@ sub config_for_ip {
        return $config;
 }
 
+sub config_ip_boot {
+       my ( $ip, $boot, $append ) = @_;
+
+       my $default;
+       my $config;
+
+       foreach my $kernel ( glob "$boot/vmlinuz*" ) {
+               my $ver = $1 if $kernel =~ m{vmlinuz(.+)};
+               $default ||= $ver;
+
+               $config .= qq{
+
+label boot$ver
+       kernel $ip/boot/vmlinuz$ver
+       append initrd=$ip/boot/initrd.img$ver $append
+
+               };
+       }
+
+       config_for_ip( $ip, qq{
+
+default boot$default
+prompt 5
+
+$config
+
+       });
+
+}
+
 1;
diff --git a/lib/PXElator/t/pxelinux.t b/lib/PXElator/t/pxelinux.t
new file mode 100755 (executable)
index 0000000..4530056
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 2;
+
+use_ok 'pxelinux';
+
+ok( my $config = pxelinux::config_ip_boot( '127.0.0.1', '/boot', 'fake' ), 'file' );
+diag $config;