pf-tools commit: r556 [ccaillet-guest] - in /trunk: debian/changelog sbin/mk_pxelinuxcfg sbin/pxe_linuxcfg
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Fri Jan 18 11:32:07 UTC 2008
Author: ccaillet-guest
Date: Fri Jan 18 11:32:07 2008
New Revision: 556
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=556
Log:
* extracting Mk_pxelinuxcfg from Net.pm to mk_pxelinuxcfg tool and exporting some
functions which are needed for mk_pxelinuxcfg
*
Removed:
trunk/sbin/pxe_linuxcfg
Modified:
trunk/debian/changelog
trunk/sbin/mk_pxelinuxcfg
Modified: trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/trunk/debian/changelog?rev=556&op=diff
==============================================================================
--- trunk/debian/changelog (original)
+++ trunk/debian/changelog Fri Jan 18 11:32:07 2008
@@ -9,8 +9,8 @@
Update.pm to update-config script (right place)
* exporting some logging functions needed by update-config from Conf.pm
* creating pxe_linuxcfg tool which is a rewrite of mk_pxelinuxcfg
- * extracting Mk_pxelinuxcfg from Net.pm to pxe_linuxcfg and exporting some
- functions which are needed for pxe_linuxcfg
+ * extracting Mk_pxelinuxcfg from Net.pm to mk_pxelinuxcfg tool and exporting some
+ functions which are needed for mk_pxelinuxcfg
* function Load_conf from Conf.pm now supports "use strict"
[ Thomas Parmelan ]
@@ -22,7 +22,10 @@
made mistakes...
* Update my email address.
- -- Christophe Caillet <quadchris at free.fr> Fri, 18 Jan 2008 12:18:36 +0100
+ [ Christophe Caillet ]
+ *
+
+ -- Christophe Caillet <tof at sitadelle.com> Fri, 18 Jan 2008 12:31:13 +0100
pf-tools (0.32.46-1) unstable; urgency=low
Modified: trunk/sbin/mk_pxelinuxcfg
URL: http://svn.debian.org/wsvn/pf-tools/trunk/sbin/mk_pxelinuxcfg?rev=556&op=diff
==============================================================================
--- trunk/sbin/mk_pxelinuxcfg (original)
+++ trunk/sbin/mk_pxelinuxcfg Fri Jan 18 11:32:07 2008
@@ -2,6 +2,7 @@
##
## $Id$
##
+## Copyright (C) 2007-2008 Christophe Caillet <quadchris at free.fr>
## Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
## Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
##
@@ -20,17 +21,111 @@
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
##
-use strict;
+# use strict;
use warnings;
use PFTools::Net;
use PFTools::Update;
+use Data::Dumper ;
-my ($SRC, $TEMPLATE) = @ARGV;
-unless ($SRC and $TEMPLATE) {
+sub Mk_pxe_bootfile ($;$) {
+ my ( $Z, $template ) = @_;
+ my $oldout;
+ my $s;
+ my $hash_tpl = {} ;
+
+ my $pxelinuxconfdir = dirname ( $template ) ;
+ unless ( open ( TPL, $template ) ) {
+ die "Unable to open file ".$template.": ".$!."\n" ;
+ }
+ @{$hash_tpl->{'default'}} = <TPL> ;
+ close ( TPL ) ;
+
+ my $dhcpvlanregex
+ = '^([^.]+)\.('
+ . join( '|', @{ $Z->{'SOA'}->{'dhcpvlan'} } )
+ . ')(\.*)?$';
+
+ foreach $s ( sort ( keys %{ $Z->{'SERVERS'}->{'BY_ADDR'} } ) ) {
+ my $m;
+ my $N = $Z->{'SERVERS'}->{'BY_ADDR'}->{$s};
+
+ foreach $m ( sort ( keys %{ $N->{'SRVLIST'} } ) ) {
+ my $nam;
+ my $M = $N->{'SRVLIST'}->{$m};
+
+ foreach $nam ( sort ( keys %{ $M->{'zone'} } ) ) {
+ if ( $nam =~ /$dhcpvlanregex/ ) {
+ my $nam2 = $1;
+
+ #my $vlan2 = $2;
+ if ( defined( $M->{'zone'}->{$nam}->{'ether'} )
+ && defined( $M->{'filename'} )
+ && defined( $M->{'pxefilename'} ) )
+ {
+ if ( $M->{'filename'} ne 'pxelinux.0' ) {
+ Warn( $ERR_SYNTAX,
+ "Mk_pxelinuxconf["
+ . $nam2
+ . "]: pxefilename exists but filename is not pxelinux.0!"
+ );
+ }
+ my $addr = Resolv( $nam . '.' . $Z->{'SOA'}->{'name'}, $Z );
+ if ( defined $addr
+ && $addr ne $nam . '.' . $Z->{'SOA'}->{'name'} )
+ {
+ my $hexaddr = sprintf( '%02X%02X%02X%02X',
+ split( '\.', $addr ) );
+
+ if ( -e $pxelinuxconfdir . "/" . $hexaddr ) {
+ unlink( $pxelinuxconfdir . "/" . $hexaddr );
+ }
+
+ open( PXELINUXCFG,
+ ">" . $pxelinuxconfdir . "/" . $hexaddr )
+ || die "impossible d'ecrire "
+ . $pxelinuxconfdir . "/"
+ . $hexaddr . ": "
+ . $!;
+
+ my $temptemplatecontent ;
+ if ( ! defined ( $M->{'pxetemplate'} ) ) {
+ $temptemplatecontent = join ( "", @{$hash_tpl->{'default'}} ) ;
+ } else {
+ my $tpl_name ;
+ $tpl_name = $M->{'pxetemplate'} ;
+ $tpl_name =~ s%.*/%%;
+ if ( ! defined ( $hash_tpl->{$tpl_name} ) ) {
+ my $tpl ;
+ ( $M->{'pxetemplate'} =~ /^\// ) ? $tpl = $M->{'pxetemplate'} : $tpl = $pxelinuxconfdir."/".$M->{'pxetemplate'};
+ print "Need to open ".$tpl."\n" ;
+ open ( TPL, $tpl ) || die "impossible d'ouvrir " . $tpl . ": " . $!;
+ @{$hash_tpl->{$tpl_name}} = <TPL> ;
+ close ( TPL ) ;
+ }
+ $temptemplatecontent = join ( "", @{$hash_tpl->{$tpl_name}} ) ;
+ }
+ $temptemplatecontent =~ s/%KERNEL%/$M->{pxefilename}/gs;
+ $temptemplatecontent =~ s/%INITRD%/$M->{initrd}/gs;
+# my $ramdisk_size = Get_Ramdisk_size_from_Initrd($M->{'initrd'} );
+ my $ramdisk_size = 4096 ;
+ $temptemplatecontent =~ s/%RAMDISK_SIZE%/$ramdisk_size/gs;
+ my $cmdline = $M->{'cmdline'} || '';
+ $temptemplatecontent =~ s/%CMDLINE%/$cmdline/gs;
+ print PXELINUXCFG $temptemplatecontent;
+ close(PXELINUXCFG);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+my ( $SRC, $TEMPLATE ) = @ARGV ;
+unless ( $SRC && $TEMPLATE ) {
warn "Usage: $0 src template\n";
die "\t(confs will be written do template's dirname)\n";
}
-Mk_pxelinuxcfg( Get_source($TEMPLATE), Init_lib_net( Get_source($SRC) ) );
-
+Mk_pxe_bootfile ( Init_lib_net ( Get_source ( $SRC ) ), Get_source ( $TEMPLATE ) ) ;
More information about the pf-tools-commits
mailing list