From: Dobrica Pavlinusic Date: Sun, 3 Jan 2010 01:19:50 +0000 (+0000) Subject: added pxelinux::config_ip_boot X-Git-Url: http://git.rot13.org/?p=pxelator;a=commitdiff_plain;h=b1156f05f84531b1ea9044fed9129ebec027e867 added pxelinux::config_ip_boot which can look up in boot/ directory and create pxelinux selection of kernels and initrd.img --- diff --git a/lib/PXElator/config.pm b/lib/PXElator/config.pm index 4daafaf..a9e44e2 100644 --- a/lib/PXElator/config.pm +++ b/lib/PXElator/config.pm @@ -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 { diff --git a/lib/PXElator/pxelinux.pm b/lib/PXElator/pxelinux.pm index c9b88bf..e94acfb 100644 --- a/lib/PXElator/pxelinux.pm +++ b/lib/PXElator/pxelinux.pm @@ -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 index 0000000..4530056 --- /dev/null +++ b/lib/PXElator/t/pxelinux.t @@ -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;