pf-tools commit: r788 [ccaillet-guest] - in /branches/next-gen: debian/ lib/PFTools/ sbin/ templates/

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Jul 29 09:11:53 UTC 2010


Author: ccaillet-guest
Date: Thu Jul 29 09:11:52 2010
New Revision: 788

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=788
Log:
* sbin/mk_pxelinuxcfg : rewrite according to new global structure, using
Getopt::Long for handling command line option(s) and Template::Tiny for
handling templates
  - deps update according to usage of NetAddr::IP, Net::DNS, Template::Tiny

Removed:
    branches/next-gen/templates/pf-tools
Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/lib/PFTools/Conf.pm
    branches/next-gen/lib/PFTools/Host.pm
    branches/next-gen/lib/PFTools/Logger.pm
    branches/next-gen/sbin/mk_pxelinuxcfg
    branches/next-gen/templates/sources.list.tpl
    branches/next-gen/templates/standard-installer
    branches/next-gen/templates/standard-preseed.tpl
    branches/next-gen/templates/ubuntu-installer
    branches/next-gen/templates/ubuntu-preseed.tpl
    branches/next-gen/templates/ubuntu-sources.list.tpl

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=788&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Jul 29 09:11:52 2010
@@ -51,13 +51,16 @@
   and site definition, using Getopt::Long for handling command line option(s)
   * sbin/mk_dhcp : rewrite according to new global structure, using
   Getopt::Long for handling command line option(s)
+  * sbin/mk_pxelinuxcfg : rewrite according to new global structure, using
+  Getopt::Long for handling command line option(s) and Template::Tiny for
+  handling templates
   * debian/control
-    - deps update according to usage of NetAddr::IP and Net::DNS
+    - deps update according to usage of NetAddr::IP, Net::DNS, Template::Tiny
     - uploaders and maintainers update
   * debian/compat
     - update level for avoiding warning during package build
 
- -- Christophe Caillet <quadchris at free.fr>  Wed, 28 Jul 2010 11:29:53 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Thu, 29 Jul 2010 11:09:46 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=788&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Thu Jul 29 09:11:52 2010
@@ -30,6 +30,7 @@
 use PFTools::Host;
 use PFTools::Parser;
 use PFTools::Logger;
+use Fcntl ':mode';
 use Data::Dumper;
 use Storable;
 
@@ -124,7 +125,7 @@
 $DEF_SECTIONS->{'host'}->{'deployment'} = {
 	'MANDATORY_KEYS'	=> [ 'arch','mode','distrib' ],
 	'arch'				=> 'i386|amd64',
-	'mode'				=> '(debian|ubuntu)(-installer)?',
+	'mode'				=> '(debian|ubuntu)',
 	'distrib'			=> '[a-z]+',
 	'dhcpvlan'			=> '\w+'
 };
@@ -273,10 +274,14 @@
 ### Default value for configuration with new method
 our $PF_CONFIG	= {};
 $PF_CONFIG->{'path'} = {
-	'status_dir'	=> '/var/lib/pftools',
-	'distrib_dir'	=> '/distrib',
-	'tftp_dir'		=> '/distrib/tftpboot',
-	'global_struct'	=> '/var/lib/pf-tools/global_struct.stor'
+	'status_dir'		=> '/var/lib/pftools',
+	'distrib_dir'		=> '/distrib',
+	'tftp_dir'			=> '/distrib/tftpboot',
+	'pxefiles_dir'		=> '/distrib/tftpboot/pxelinux.cfg',
+	'global_struct'		=> '/var/lib/pf-tools/global_struct.stor',
+	'deploy_docroot'	=> '/var/www',
+	'preseed_dir'		=> '/var/www/preseed',
+	'templates_dir'		=> '/usr/share/pf-tools/templates'
 };
 $PF_CONFIG->{'features'} = {
 	'ipv4'			=> 1,
@@ -292,6 +297,12 @@
 	'command'	=> '',
 	'branche'	=> ''
 };
+$PF_CONFIG->{'templates'} = {
+	'debian_preseed'	=> 'standard-preseed',
+	'ubuntu_preseed'	=> 'ubuntu-preseed',
+	'debian_pxe'		=> 'standard-installer',
+	'ubuntu_pxe'		=> 'ubuntu-installer'
+};
 $PF_CONFIG->{'regex'} = {
 	'hostname'	=> $HOST_CONFIG_REGEX,
 	'hosttype'	=> $HOSTTYPE_CONFIG_REGEX
@@ -300,13 +311,16 @@
 sub Init_PF_CONFIG (;$) {
 	my ( $config_file ) = @_;
 
-# 		my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
-# 		$size, $atime, $mtime, $ctime, $blksize, $blocks
-# 		) = lstat($PFTOOLSCONF);
-	if ( -r $PFTOOLSCONF ) {
-		my ( $dev, $ino, $mode, $nlink, $uid, $gid, @lstat_vars ) = lstat($PFTOOLSCONF);
-		unless ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) ) {
-			Abort ( $CODE->{'RIGHTS'}, "Ignoring weak config (check owner/group/mode)" );
+	if ( defined $config_file && ! -e $config_file ) {
+		Abort ( $CODE->{'UNDEF_KEY'},
+			"Unable to proceed with configuration file ".$config_file." : no such file or directory" );
+	}
+	elsif ( -r $config_file ) {
+		my ( $dev, $ino, $mode, $nlink, $uid, $gid, @lstat_vars ) = lstat($config_file);
+# 		unless ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) ) {
+		unless ( S_IMODE($mode) == 0600 && S_ISREG($mode) ) {
+			Abort ( $CODE->{'RIGHTS'},
+				"Ignoring weak rights for configuration file ".$config_file." (check owner/group/mode)" );
 		}
 	}
 	return $PF_CONFIG if ( ! defined $config_file );

Modified: branches/next-gen/lib/PFTools/Host.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Host.pm?rev=788&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Host.pm Thu Jul 29 09:11:52 2010
@@ -29,6 +29,7 @@
 our @EXPORT = qw(
 	Get_site_from_hostname
 	Get_hosttype_from_hostname
+	Get_iface_vlan_from_hostname
 	Add_server
 	Add_host
 );
@@ -223,6 +224,27 @@
 				return $hostclass if ( $host eq $hostname );
 			}
 		}
+	}
+	return undef;
+}
+
+#########################################################################
+#
+# STR Get_iface_vlan_from_hostname ( STR, HASHREF )
+#
+# This function returns the interface for a given vlan
+# Inputs :
+#  - $vlan		: string containing the vlan name
+#  - $ref_host	: hashref containing the host properties from global configuration
+#
+# Output :
+#  Returns a string containing the interface or undef
+#
+sub Get_iface_vlan_from_hostname ($$) {
+	my ( $vlan, $ref_host ) = @_;
+	
+	foreach my $iface ( keys %{$ref_host->{'interfaces'}} ) {
+		return $iface if ( $ref_host->{'interfaces'}->{$iface}->{'vlan'} eq $vlan );
 	}
 	return undef;
 }
@@ -590,7 +612,8 @@
 				"Interface ".$if." cannot be enslaved by ".$iface." : already in use for "
 				.$hostname ) if ( grep ( /$if/, @{$ref_if_list} ) );
 		}
-		$add_if->{'slaves'} = join ( " ", @slaves );
+		$add_if->{'slaves'}		= join ( " ", @slaves );
+		$add_if->{'options'}	= $ref_host->{$iface_section}->{'options.'.$host_number} || $ref_host->{$iface_section}->{'options'};
 	}
 	# Check vlan
 	if ( ! defined $network_site->{'BY_NAME'}->{$vlan} ) {
@@ -715,6 +738,7 @@
 		my $site_part	= $global_config->{'SITE'}->{'BY_NAME'}->{$site};
 		if ( ! defined $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} ) {
 			$site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} = {};
+			push ( @{$site_part->{'HOST'}->{'__hostclass_pxe'}}, $hostclass );
 		}
 		my $host_part	= $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass};
 		my $zone		= $site_part->{'zone'};
@@ -806,6 +830,7 @@
 						}
 						my $resolver = $host2add->{'dns'}->{'resolver.'.$host_number} || $host2add->{'dns'}->{'resolver'};
 						if ( $if2add->{'vlan'} eq $dhcpvlan ) {
+							$host_part->{$hostname}->{'deployment'}->{'dhcpvlan'} = $dhcpvlan;
 							if ( ! defined $dhcp_part->{$dhcpvlan} ) {
 								$dhcp_part->{$dhcpvlan} = {};
 								$dhcp_part->{$dhcpvlan}->{'subnet'}		= $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan}->{'network'.$suffix};

Modified: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=788&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (original)
+++ branches/next-gen/lib/PFTools/Logger.pm Thu Jul 29 09:11:52 2010
@@ -54,10 +54,13 @@
 $CODE->{'WARNING'}			= 1;
 $CODE->{'OPEN'}				= 2;
 $CODE->{'SYNTAX'}			= 3;
+$CODE->{'RIGHTS'}			= 4;
+$CODE->{'UNLINK'}			= 5;
 
 $CODE->{'INVALID_CONTEXT'}	= 10;
 $CODE->{'INVALID_SECTNAME'}	= 11;
 $CODE->{'INVALID_VALUE'}	= 12;
+
 $CODE->{'UNDEF_KEY'}		= 20;
 $CODE->{'DUPLICATE_VALUE'}	= 21;
 

Modified: branches/next-gen/sbin/mk_pxelinuxcfg
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_pxelinuxcfg?rev=788&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_pxelinuxcfg (original)
+++ branches/next-gen/sbin/mk_pxelinuxcfg Thu Jul 29 09:11:52 2010
@@ -24,28 +24,55 @@
 use strict;
 use warnings;
 
+use Getopt::Long qw( :config ignore_case_always bundling );
 use Digest::MD5;
-use PFTools::Net;
-use PFTools::Update;
+use PFTools::Conf;
+use PFTools::Host;
+use PFTools::Logger;
 use File::Compare ;
 use File::Copy ;
-
-my $DEPLOY_DOCROOT	= "/var/www";
-my $PRESEED_REPOS	= $DEPLOY_DOCROOT."/preseed" ;
-
-if ( ! -e $PRESEED_REPOS ) {
-	mkdir $PRESEED_REPOS ;
-	my ($login,$pass,$uid,$gid) = getpwnam ( 'www-data' ) ;
-	chown $uid, $gid, $PRESEED_REPOS ;
-	my $mode = '2750' ;
-	chmod ( oct ( $mode ), $PRESEED_REPOS ) ;
-}
-
-my $TPL_PRESEED			= "/usr/share/pf-tools/templates/standard-preseed.tpl" ;
-my $TPL_UBUNTU_PRESEED	= "/usr/share/pf-tools/templates/ubuntu-preseed.tpl" ;
-my $DEFAULT_PRESEED	= $PRESEED_REPOS."/default_preseed.txt" ;
-
-sub Get_kpkg_from_pxefilename ($$) {
+use Template::Tiny;
+use Data::Dumper;
+
+
+############################################
+# Vars
+
+my $DEPLOY_DOCROOT		= "/var/www";
+my $HELP				= 0;
+my $PF_SCRIPT			= 'pf-tools-config.sh';
+my $PXE_TPL				= '';
+my $PRESEED_TPL			= '';
+my $SITE				= '';
+my $GLOBAL_STORE_FILE	= '';
+my $PF_CONFIG_FILE		= '';
+my $PF_CONFIG			= {};
+my $GLOBAL_STRUCT		= {};
+my $DEFAULT_PRESEED		= '';
+
+my $program = $0;
+$program =~ s%.*/%%; # cheap basename
+
+my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
+
+############################################
+# Functions
+
+sub Do_help {
+    print STDERR << "# ENDHELP";
+    $program - version $version
+
+Usage:	$0 [options]
+	--help		: print help and exit
+	-s --site	: site for which you want to build PXE and preseed files
+	--script	: script which is "wgotten" and executed as post-install preseed default value is pf-tools-config.sh
+	--store		: file where global structure datas are in storable format (optional)
+	-c --config	: pf-tools config file (optional)
+    
+# ENDHELP
+}
+
+sub Get_kpkg_from_kernel ($$) {
 	my ( $pxefilename, $deploymode ) = @_ ;
 	
 	if ( $deploymode =~ /^ubuntu/ ) {
@@ -65,202 +92,179 @@
 }
 
 sub Build_preseed_filename ($$$) {
-	my ( $srv_name, $preseed_tpl, $ref_srv ) = @_ ;
+	my ( $srv_name, $preseed_tpl, $host_props ) = @_ ;
 
 	if ( ! open ( PRESEED_TPL, $preseed_tpl ) ) {
-		warn "Unable to get preseed template from file ".$preseed_tpl."\n" ;
+		Warn ( $CODE->{'OPEN'},
+			"Unable to get preseed template from file ".$preseed_tpl );
 		return $DEFAULT_PRESEED ;
 	}
 	my $preseed_content = join '', <PRESEED_TPL> ;
 	close ( PRESEED_TPL ) ;
-	my $deb_kernel = Get_kpkg_from_pxefilename ( $ref_srv->{'pxefilename'}, $ref_srv->{'deploymode'} ) ;
-	$preseed_content =~ s/%KERNELPKG%/$deb_kernel/gs ;
-	
-	my $distrib	= $ref_srv->{'distrib'} ;
-	my $dist_src	= $ref_srv->{'deploymode'} ;
-	$dist_src	=~ s/^(debian|ubuntu)-installer/$1/ ;
-	
-	$preseed_content =~ s/%DISTSRC%/$dist_src/gs ;
-	$preseed_content =~ s/%DISTRIB%/$distrib/gs ;
+	my $kernel_pkg		= Get_kpkg_from_kernel ( $host_props->{'boot'}->{'kernel'}, $host_props->{'deployment'}->{'mode'} );
+	my $tpl				= Template::Tiny->new ( TRIM => 1 );
+	my $preseed_subst	= {
+		'kernelpkg' 	=> $kernel_pkg,
+		'mode'			=> $host_props->{'deployment'}->{'mode'},
+		'distrib'		=> $host_props->{'deployment'}->{'distrib'},
+		'config_script'	=> $PF_SCRIPT
+	};
+	$preseed_content = $tpl->process ( \$preseed_content, $preseed_subst );
 	
 	if ( ! open ( DST_PRESEED, ">/tmp/tmp_preseed" ) ) {
-		warn "Unable to create preseed file /tmp_preseed\n" ;
+		Warn ( $CODE->{'OPEN'},
+			"Unable to create preseed file /tmp_preseed" );
 		return $DEFAULT_PRESEED ;
 	}
 	print DST_PRESEED $preseed_content ;
 	close ( DST_PRESEED ) ;
 	my $src = "/tmp/tmp_preseed" ;
-	my $dst = $PRESEED_REPOS."/preseed_".$srv_name ;
+	my $dst = $PF_CONFIG->{'path'}->{'preseed_dir'}."/preseed_".$srv_name ;
 	if ( compare ( $src, $dst ) ) {
 		move ($src, $dst) ;
 	} else {
 		if ( ! unlink ( $src ) ) {
-			warn "Unable to unlink source file ".$src."\n" ;
+			Warn ( $CODE->{'UNLINK'},
+				"Unable to unlink source file ".$src );
 		}
 	}
 	return "preseed_".$srv_name ;
 }
 
-sub Get_MD5SUM_from_preseedfilename ($) {
+sub Get_MD5SUM_for_preseedfile ($) {
 	my ( $filename ) = @_;
 	my ( $md5, $hdl );
 	
 	$md5 = Digest::MD5->new;
-	open $hdl, $PRESEED_REPOS."/".$filename || return undef;
+	open $hdl, $PF_CONFIG->{'path'}->{'preseed_dir'}."/".$filename || return undef;
 	$md5->addfile ( $hdl );
-	return $md5->hexdigest;
-}
-
-sub Mk_pxe_bootfile ($;$$) {
-	my ( $Z, $default_template, $tftp_dir ) = @_;
-	my $oldout;
-	my $s;
-	my $templates = {};
-
-	my $pxelinuxconfdir = dirname ( $default_template );
-	my $pxetftpdir = $tftp_dir || dirname ( $default_template );
-	open TPL, $default_template
-	    or die "Unable to open $default_template: $!\n";
-	@{ $templates->{$default_template} } = <TPL>;
-	close TPL;
-
-	my $dhcpvlanregex
-		= '^([^.]+)\.('
-		. join( '|', @{ $Z->{'SOA'}->{'dhcpvlan'} } )
-		. ')(\.*)?$';
-
-	foreach $s ( sort ( keys %{ $Z->{'SERVERS'}->{'BY_ADDR'} } ) ) {
-		foreach my $host ( @{$Z->{'SERVERS'}->{'BY_ADDR'}->{$s}}  ) {
-	
-			foreach my $m ( sort ( keys %{ $host->{'SRVLIST'} } ) ) {
-				my $nam;
-				my $M = $host->{'SRVLIST'}->{$m};
-				my $debian_installer = 0 ;
-				$debian_installer = 1 if ( defined $M->{'deploymode'} && $M->{'deploymode'} =~ /^(debian|ubuntu)-installer/ ) ;
-				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 $pxetftpdir . "/" . $hexaddr ) {
-									unlink( $pxetftpdir . "/" . $hexaddr );
-								}
-	
-								open( PXELINUXCFG,
-									">" . $pxetftpdir . "/" . $hexaddr )
-									|| die "impossible d'ecrire "
-										. $pxelinuxconfdir . "/"
-										. $hexaddr . ": "
-										. $!;
-
-								my $template_name ;
-								if ( $debian_installer ) {
-									if ( $M->{'deploymode'} =~ /^ubuntu/ ) {
-										$template_name = 'ubuntu-installer' ;
-									}
-									else {
-										$template_name = 'standard-installer' ;
-									}
-								}
-								else {
-									$template_name = $M->{'pxetemplate'} ? $M->{'pxetemplate'} : $default_template;
-								}
-
-								unless (defined $templates->{$template_name}) {
-									my $tpl = ( ($template_name =~ m/^\//) ? '' : "$pxelinuxconfdir/" )
-										. $template_name;
-									open PXETEMPLATE, $tpl or die "Impossible d'ouvrir $tpl : . $!\n";
-									@{ $templates->{$template_name} } = <PXETEMPLATE>;
-									close PXETEMPLATE;
-								}
-	
-								my $temptemplatecontent = join '', @{ $templates->{$template_name} };
-								my $kernel_filename	= Get_PXE_Filename ( $Z, $m ) ;
-								if ( ! defined $kernel_filename ) {
-									warn "Unable to retrieve kernel filename for host ".$m."\n" ;
-								}
-								$temptemplatecontent =~ s/%KERNEL%/$kernel_filename/gs;
-
-								if ( $debian_installer ) {
-									# Building preseed file
-									$temptemplatecontent =~ s/%DEPLOYMODE%/$M->{'deploymode'}/gs ;
-									$temptemplatecontent =~ s/%DISTRIB%/$M->{'distrib'}/gs ;
-									if ( defined $M->{'initrd'} ) {
-										$temptemplatecontent =~ s/%INITRD%/$M->{'initrd'}/gs ;
-									}
-									else {
-										$temptemplatecontent =~ s/initrd=([^\s]*)%INITRD%//gs ;
-									}
-									my $preseed_file;
-									if ( $M->{'deploymode'} =~ /^ubuntu/ ) {
-										$preseed_file = Build_preseed_filename ( $m, $TPL_UBUNTU_PRESEED, $M ) ;
-									}
-									else {
-										$preseed_file = Build_preseed_filename ( $m, $TPL_PRESEED, $M ) ;
-									}
-									# MD5sum on generated preseed file
-									$temptemplatecontent =~
-										s/%PRESEED_URL%/preseed\/$preseed_file/gs;
-									my $preseed_md5 = Get_MD5SUM_from_preseedfilename ( $preseed_file ) ;
-									if ( ! defined $preseed_md5 ) {
-										die "Unable to get md5dum for preseed filename "
-											.$preseed_file." for host ".$m."\n" ;
-									}
-									$temptemplatecontent =~ s/%PRESEED_MD5%/$preseed_md5/gs;
-								} else {
-									my $ramdisk_size = Get_Ramdisk_size_from_Initrd($M->{'initrd'} );
-									$temptemplatecontent =~ s/%RAMDISK_SIZE%/$ramdisk_size/gs;
-									$temptemplatecontent =~ s/%INITRD%/$M->{'initrd'}/gs;
-								}
-
-								my $arch = $M->{'arch'} || 'i386' ;
-								$temptemplatecontent =~ s/%ARCH%/$arch/gs;
-	
-								my $cmdline = $M->{'cmdline'} || '';
-								$temptemplatecontent =~ s/%CMDLINE%/$cmdline/gs;
-	
-								my $console = $M->{'console'} || '';
-								$console = "console=" . $console if $console;
-								$temptemplatecontent =~ s/%CONSOLE%/$console/gs;
-	
-								my $serial_speed = $M->{'serialspeed'} || '115200' ;
-								$temptemplatecontent =~ s/%SERIAL_SPEED%/$serial_speed/gs;
-	
-								$temptemplatecontent =~ s/ +/ /gs;
-	
-								print PXELINUXCFG $temptemplatecontent;
-								close PXELINUXCFG;
-							}
-						}
-					}
-				}
-			}
-		}
-	}
-}
-
-my ( $SRC, $TEMPLATE, $TFTP_DIR ) = @ARGV ;
-unless ( $SRC && $TEMPLATE ) {
-    warn "Usage: $0 src template\n";
-    die "\t(confs will be written do template's dirname)\n";
-}
-
-Mk_pxe_bootfile ( Init_lib_net ( Get_source ( $SRC ) ), Get_source ( $TEMPLATE ), $TFTP_DIR ) ;
+	my $md5sum = $md5->hexdigest;
+	close ( $hdl );
+	return $md5sum;
+}
+
+sub Mk_PXE_bootfile ($$$$) {
+	my ( $hostname, $host_props, $pxe_tpl, $preseed_tpl ) = @_;
+
+	my $iface			= Get_iface_vlan_from_hostname ( $host_props->{'deployment'}->{'dhcpvlan'}, $host_props );
+	my $mac				= $host_props->{'interfaces'}->{$iface}->{'mac'};
+	my $pxe_boot_file	= $mac;
+	$pxe_boot_file		=~ s/\:/\-/g;
+	
+	if ( ! -e $pxe_tpl ) {
+		Abort ( $CODE->{'UNDEF_KEY'},
+			"Unable to open PXE template file ".$pxe_tpl." : no such file or directory" );
+	}
+	elsif ( ! open ( PXETPL, $pxe_tpl ) ) {
+		Abort ( $CODE->{'OPEN'},
+			"Unable to open PXE template file ".$pxe_tpl );
+	}
+	my $content_pxe	= join ( "", <PXETPL> );
+	close ( PXETPL );
+	my $preseed		= Build_preseed_filename ( $hostname, $preseed_tpl, $host_props );
+	my $preseed_md5	= Get_MD5SUM_for_preseedfile ( $preseed );
+	my $tpl 		= Template::Tiny->new ( TRIM => 1 );
+	my $pxe_subst	= {
+		'iface'			=> $iface,
+		'mode'			=> $host_props->{'deployment'}->{'mode'}.'-installer',
+		'arch'			=> $host_props->{'deployment'}->{'arch'},
+		'distrib'		=> $host_props->{'deployment'}->{'distrib'},
+		'serial_speed'	=> '115200',
+		'preseed_url'	=> $preseed,
+		'preseed_md5'	=> $preseed_md5,
+		'console'		=> $host_props->{'boot'}->{'console'},
+		'cmdline'		=> $host_props->{'boot'}->{'cmdline'},
+		'kernel'		=> $host_props->{'boot'}->{'kernel'}
+	};
+	if ( $host_props->{'boot'}->{'initrd'} ) {
+		$pxe_subst->{'initrd'} = $host_props->{'boot'}->{'initrd'};
+	}
+	else {
+		$content_pxe =~ s/initrd=(([^\/]+\/)+)?\[% initrd %\]//gs ;
+	}
+	$content_pxe = $tpl->process ( \$content_pxe, $pxe_subst );
+	if ( ! open ( PXETMP, ">/tmp/tmp_pxe" ) ) {
+		Warn ( $CODE->{'OPEN'},
+			"Unable to open temporary PXE file /tmp/tmp_pxe" );
+		return undef;
+	}
+	print PXETMP $content_pxe;
+	close ( PXETMP );
+	my $src = "/tmp/tmp_pxe" ;
+	my $dst = $PF_CONFIG->{'path'}->{'pxefiles_dir'}."/".$pxe_boot_file ;
+	if ( compare ( $src, $dst ) ) {
+		move ($src, $dst) ;
+	} else {
+		if ( ! unlink ( $src ) ) {
+			Warn ( $CODE->{'UNLINK'},
+				"Unable to unlink source file ".$src );
+		}
+	}
+	return $pxe_boot_file;
+}
+
+############################################
+### MAIN
+
+GetOptions (
+	'help'			=> \$HELP,
+	'script=s'		=> \$PF_SCRIPT,
+	'site|s=s'		=> \$SITE,
+	'config|c=s'	=> \$PF_CONFIG_FILE,
+	'store=s'		=> \$GLOBAL_STORE_FILE,
+) or die "Didn't grok options (see --help).\n";
+
+if ( $HELP ) {
+	Do_help ();
+	exit 0;
+}
+
+if ( $PF_CONFIG_FILE ne '' ) {
+	if ( ! -e $PF_CONFIG_FILE ) {
+		Abort ( $CODE->{'OPEN'},
+			"Unable to open configuration file ".$PF_CONFIG_FILE." : no such file or directory" );
+	}
+	$PF_CONFIG = Init_PF_CONFIG ( $PF_CONFIG_FILE );
+}
+else {
+	$PF_CONFIG = Init_PF_CONFIG ();
+}
+
+if ( ! -e $PF_CONFIG->{'path'}->{'preseed_dir'} ) {
+	mkdir $PF_CONFIG->{'path'}->{'preseed_dir'} ;
+	my ($login,$pass,$uid,$gid) = getpwnam ( 'www-data' ) ;
+	chown $uid, $gid, $PF_CONFIG->{'path'}->{'preseed_dir'} ;
+	my $mode = '2750' ;
+	chmod ( oct ( $mode ), $PF_CONFIG->{'path'}->{'preseed_dir'} ) ;
+}
+
+$DEFAULT_PRESEED	= $PF_CONFIG->{'path'}->{'preseed_dir'}."/default_preseed.txt" ;
+$GLOBAL_STORE_FILE	= $PF_CONFIG->{'path'}->{'global_struct'} if ( $GLOBAL_STORE_FILE eq '' );
+$GLOBAL_STRUCT		= Retrieve_GLOBAL ( $GLOBAL_STORE_FILE );
+
+if ( ! defined $GLOBAL_STRUCT ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"An error occured during retrieve from the storable file ".$GLOBAL_STORE_FILE );
+}
+
+if ( $SITE eq '' && ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"A site MUST BE defined for building DNS zone forward" );
+}
+elsif ( ! defined $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"Site ".$SITE." is not defined into global configuration" );
+}
+
+my $site_part	= $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$SITE};
+my $host_part	= $site_part->{'HOST'}->{'BY_NAME'};
+foreach my $hostclass ( @{$site_part->{'HOST'}->{'__hostclass_pxe'}} ) {
+	foreach my $host ( keys %{$host_part->{$hostclass}} ) {
+		my $mode			= $host_part->{$hostclass}->{$host}->{'deployment'}->{'mode'};
+		my $pxe_template	= $PF_CONFIG->{'path'}->{'templates_dir'}.'/'.$PF_CONFIG->{'templates'}->{$mode.'_pxe'};
+		my $preseed_tpl		= $PF_CONFIG->{'path'}->{'templates_dir'}.'/'.$PF_CONFIG->{'templates'}->{$mode.'_preseed'};
+		my $pxe_file = Mk_PXE_bootfile ( $host, $host_part->{$hostclass}->{$host}, $pxe_template, $preseed_tpl );
+	}
+}
+
+exit 0;

Modified: branches/next-gen/templates/sources.list.tpl
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/sources.list.tpl?rev=788&op=diff
==============================================================================
--- branches/next-gen/templates/sources.list.tpl (original)
+++ branches/next-gen/templates/sources.list.tpl Thu Jul 29 09:11:52 2010
@@ -1,8 +1,8 @@
 # Generated by mk_sourceslist : DO NOT EDIT MANUALLY !
 # Except if you know what you're doing
 
-deb http://mirrors.private/%DISTSRC% %DISTRIB% %DEFAULT_SECTIONS%
+deb http://mirrors.private/[% mode %] [% distrib %] [% default_sections %]
 
-deb http://mirrors.private/%DISTSRC%-custom %DISTRIB%-custom %CUSTOM_SECTIONS%
+deb http://mirrors.private/[% mode %]-custom [% distrib %]-custom [% custom_sections %]
 
-deb http://mirrors.private/%DISTSRC%-security %SECURITY% %DEFAULT_SECTIONS%
+deb http://mirrors.private/[% mode %]-security %SECURITY% [% default_sections %]

Modified: branches/next-gen/templates/standard-installer
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/standard-installer?rev=788&op=diff
==============================================================================
--- branches/next-gen/templates/standard-installer (original)
+++ branches/next-gen/templates/standard-installer Thu Jul 29 09:11:52 2010
@@ -1,15 +1,15 @@
-SERIAL 0 %SERIAL_SPEED% 2
-DISPLAY %DEPLOYMODE%/%ARCH%/boot-screens/myboot.txt
+SERIAL 0 [% serial_speed %] 2
+DISPLAY [% mode %]/[% distrib %]/[% arch %]/boot-screens/myboot.txt
 
 DEFAULT linux
 
 LABEL install
-	kernel %DEPLOYMODE%/%ARCH%/linux
-	append DEBCONF_PRIORITY=critical vga=normal auto=true initrd=%DEPLOYMODE%/%ARCH%/initrd.gz interface=eth0 netcfg/no_default_route=true url=http://vip-deploy.vlan-systeme.private/%PRESEED_URL% url/checksum=%PRESEED_MD5% -- %CONSOLE% %CMDLINE%
+	kernel [% mode %]/[% distrib %]/[% arch %]/linux
+	append DEBCONF_PRIORITY=critical vga=normal auto=true initrd=[% mode %]/[% distrib %]/[% arch %]/initrd.gz interface=[% iface %] netcfg/no_default_route=true url=http://vip-deploy.vlan-systeme.private/[% preseed_url %] url/checksum=[% preseed_md5 %] -- [% console %] [% cmdline %]
 
 LABEL linux
-	kernel %KERNEL%
-	append vga=normal root=/dev/sda2 -- %CONSOLE% %CMDLINE%
+	kernel [% kernel %]
+	append vga=normal root=/dev/sda2 initrd=[% arch %]/[% initrd %] -- [% console %] [% cmdline %]
 
 PROMPT 1
 TIMEOUT 100

Modified: branches/next-gen/templates/standard-preseed.tpl
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/standard-preseed.tpl?rev=788&op=diff
==============================================================================
--- branches/next-gen/templates/standard-preseed.tpl (original)
+++ branches/next-gen/templates/standard-preseed.tpl Thu Jul 29 09:11:52 2010
@@ -23,11 +23,11 @@
 d-i mirror/protocol string http
 d-i mirror/country string enter information manually
 d-i mirror/http/hostname string mirrors.private
-d-i mirror/http/directory string /%DISTSRC%
+d-i mirror/http/directory string /[% mode %]
 d-i mirror/http/proxy string
 
 # Suite to install.
-d-i mirror/suite string %DISTRIB%
+d-i mirror/suite string [% distrib %]
 
 ### Clock and time zone setup
 d-i clock-setup/utc boolean false
@@ -66,7 +66,7 @@
 d-i partman/confirm boolean true
 
 ### Base system installation
-d-i base-installer/kernel/image string %KERNELPKG%
+d-i base-installer/kernel/image string [% kernelpkg %]
 
 ### Account setup
 d-i passwd/root-login boolean false
@@ -80,11 +80,11 @@
 d-i apt-setup/non-free boolean true
 d-i apt-setup/contrib boolean true
 d-i apt-setup/services-select string multi-select security
-d-i apt-setup/security_host string mirrors.private/%DISTSRC%-security
+d-i apt-setup/security_host string mirrors.private/[% mode %]-security
 #d-i apt-setup/volatile_host string volatile.debian.org
 # Additional repositories, local[0-9] available
 d-i apt-setup/local0/repository string \
-       http://mirrors.private/%DISTSRC%-custom %DISTRIB%-custom common
+       http://mirrors.private/[% mode %]-custom [% distrib %]-custom common
 #d-i apt-setup/local0/key string http://local.server/key
 # By default the installer requires that repositories be authenticated
 # using a known gpg key. This setting can be used to disable that
@@ -120,7 +120,7 @@
 #d-i grub-installer/bootdev  string (hd0,0) (hd1,0) (hd2,0)
 
 ### Post-install command before reboot
-d-i preseed/late_command string apt-install %KERNELPKG% ; apt-install nfs-common ; apt-install pf-tools ; in-target wget http://mirrors.private/pf-tools-config.sh -O /tmp/pf-tools-config.sh ; in-target sh /tmp/pf-tools-config.sh 
+d-i preseed/late_command string apt-install [% kernelpkg %] ; apt-install nfs-common ; apt-install pf-tools ; in-target wget http://mirrors.private/[% config_script %] -O /tmp/[% config_script %] ; in-target sh /tmp/[% config_script %] 
 
 ### Finishing up the installation
 # Avoid that last message about the install being complete.

Modified: branches/next-gen/templates/ubuntu-installer
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/ubuntu-installer?rev=788&op=diff
==============================================================================
--- branches/next-gen/templates/ubuntu-installer (original)
+++ branches/next-gen/templates/ubuntu-installer Thu Jul 29 09:11:52 2010
@@ -1,15 +1,15 @@
-SERIAL 0 %SERIAL_SPEED% 2
-DISPLAY %DEPLOYMODE%/%ARCH%/boot-screens/myboot.txt
+SERIAL 0 [% serial_speed %] 2
+DISPLAY [% mode %]/[% distrib %]/[% arch %]/boot-screens/myboot.txt
 
 DEFAULT linux
 
 LABEL install
-	kernel %DEPLOYMODE%/%ARCH%/linux
-	append DEBCONF_PRIORITY=critical vga=normal auto=true initrd=%DEPLOYMODE%/%ARCH%/initrd.gz console-setup/ask_detect=false console-setup/layoutcode=fr console-setup/codeset=. interface=eth0 netcfg/no_default_route=true netcfg/get_hostname=unassigned-hostname url=http://vip-deploy.private/%PRESEED_URL% url/checksum=%PRESEED_MD5% -- %CONSOLE% %CMDLINE%
+	kernel [% mode %]/[% distrib %]/[% arch %]/linux
+	append DEBCONF_PRIORITY=critical vga=normal auto=true initrd=[% mode %]/[% distrib %]/[% arch %]/initrd.gz console-setup/ask_detect=false console-setup/layoutcode=fr console-setup/codeset=. interface=[% iface %] netcfg/no_default_route=true netcfg/get_hostname=unassigned-hostname url=http://vip-deploy.private/[% preseed_url %] url/checksum=[% preseed_md5 %] -- [% console %] [% cmdline %]
 
 LABEL linux
-	kernel %KERNEL%
-	append vga=normal root=/dev/sda2 initrd=%INITRD% -- %CONSOLE% %CMDLINE%
+	kernel [% kernel %]
+	append vga=normal root=/dev/sda2 initrd=[% initrd %] -- [% console %] [% cmdline %]
 
 PROMPT 1
 TIMEOUT 100

Modified: branches/next-gen/templates/ubuntu-preseed.tpl
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/ubuntu-preseed.tpl?rev=788&op=diff
==============================================================================
--- branches/next-gen/templates/ubuntu-preseed.tpl (original)
+++ branches/next-gen/templates/ubuntu-preseed.tpl Thu Jul 29 09:11:52 2010
@@ -31,11 +31,11 @@
 d-i mirror/protocol string http
 d-i mirror/country string enter information manually
 d-i mirror/http/hostname string mirrors.private
-d-i mirror/http/directory string /%DISTSRC%
+d-i mirror/http/directory string /[% mode %]
 d-i mirror/http/proxy string
 
 # Suite to install.
-d-i mirror/suite string %DISTRIB%
+d-i mirror/suite string [% distrib %]
 
 ### Clock and time zone setup
 d-i clock-setup/utc boolean false
@@ -74,7 +74,7 @@
 d-i partman/confirm_nooverwrite boolean true
 
 ### Base system installation
-d-i base-installer/kernel/image string %KERNELPKG%
+d-i base-installer/kernel/image string [% kernelpkg %]
 
 ### Account setup
 d-i passwd/root-login boolean false
@@ -94,7 +94,7 @@
 #d-i apt-setup/volatile_host string volatile.debian.org
 # Additional repositories, local[0-9] available
 d-i apt-setup/local0/repository string \
-       http://mirrors.private/%DISTSRC%-custom %DISTRIB%-custom common
+       http://mirrors.private/[% mode %]-custom [% distrib %]-custom common
 #d-i apt-setup/local0/key string http://local.server/key
 # By default the installer requires that repositories be authenticated
 # using a known gpg key. This setting can be used to disable that
@@ -130,7 +130,7 @@
 #d-i grub-installer/bootdev  string (hd0,0) (hd1,0) (hd2,0)
 
 ### Post-install command before reboot
-d-i preseed/late_command string apt-install %KERNELPKG% ; apt-install nfs-common ; apt-install pf-tools ; in-target wget http://mirrors.private/pf-tools-config.sh -O /tmp/pf-tools-config.sh ; in-target sh /tmp/pf-tools-config.sh 
+d-i preseed/late_command string apt-install [% kernelpkg %] ; apt-install nfs-common ; apt-install pf-tools ; in-target wget http://mirrors.private/[% config_script %] -O /tmp/[% config_script %] ; in-target sh /tmp/[% config_script %] 
 
 ### Finishing up the installation
 # Avoid that last message about the install being complete.

Modified: branches/next-gen/templates/ubuntu-sources.list.tpl
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/ubuntu-sources.list.tpl?rev=788&op=diff
==============================================================================
--- branches/next-gen/templates/ubuntu-sources.list.tpl (original)
+++ branches/next-gen/templates/ubuntu-sources.list.tpl Thu Jul 29 09:11:52 2010
@@ -1,8 +1,8 @@
 # Generated by mk_sourceslist : DO NOT EDIT MANUALLY !
 # Except if you know what you're doing
 
-deb http://mirrors.private/%DISTSRC% %DISTRIB% %DEFAULT_SECTIONS%
+deb http://mirrors.private/[% mode %] [% distrib %] [% default_sections %]
 
-deb http://mirrors.private/%DISTSRC% %DISTRIB%-security %DEFAULT_SECTIONS%
+deb http://mirrors.private/[% mode %] [% distrib %]-security [% default_sections %]
 
-deb http://mirrors.private/%DISTSRC%-custom %DISTRIB%-custom %CUSTOM_SECTIONS%
+deb http://mirrors.private/[% mode %]-custom [% distrib %]-custom [% custom_sections %]




More information about the pf-tools-commits mailing list