pf-tools commit: r792 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Host.pm lib/PFTools/Logger.pm sbin/mk_grub2opt sbin/mk_grubopt sbin/mk_pxelinuxcfg templates/ubuntu-installer

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Jul 30 09:46:13 UTC 2010


Author: ccaillet-guest
Date: Fri Jul 30 09:46:12 2010
New Revision: 792

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=792
Log:
* sbin/mk_grubopt : rewrite according to new global structure, using
Getopt::Long for handling command line option(s) and Template::Tiny for
handling templates
* sbin/mk_grub2opt : removing useless code : one script to rule them all !

Removed:
    branches/next-gen/sbin/mk_grub2opt
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_grubopt
    branches/next-gen/sbin/mk_pxelinuxcfg
    branches/next-gen/templates/ubuntu-installer

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=792&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Jul 30 09:46:12 2010
@@ -57,13 +57,17 @@
   * sbin/mk_sourceslist : rewrite according to new global structure, using
   Getopt::Long for handling command line option(s) and Template::Tiny for
   handling templates
+  * sbin/mk_grubopt : rewrite according to new global structure, using
+  Getopt::Long for handling command line option(s) and Template::Tiny for
+  handling templates
+  * sbin/mk_grub2opt : removing useless code : one script to rule them all !
   * debian/control
     - 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>  Thu, 29 Jul 2010 17:20:12 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Fri, 30 Jul 2010 11:44:23 +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=792&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Fri Jul 30 09:46:12 2010
@@ -302,7 +302,9 @@
 	'pxe'				=> 'standard-installer',
 	'sources_list'		=> 'sources.list',
 	'default_sections'	=> 'main contrib non-free',
-	'custom-sections'	=> 'common'
+	'custom-sections'	=> 'common',
+	'grub'				=> '/boot/grub/menu.lst',
+	'grub2'				=> '/etc/default/grub'
 };
 $PF_CONFIG->{'ubuntu'} = {
 	'preseed'			=> 'ubuntu-preseed',

Modified: branches/next-gen/lib/PFTools/Host.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Host.pm?rev=792&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Host.pm Fri Jul 30 09:46:12 2010
@@ -30,6 +30,7 @@
 	Get_site_from_hostname
 	Get_hosttype_from_hostname
 	Get_iface_vlan_from_hostname
+	Get_cmdline_from_hostprops
 	Add_server
 	Add_host
 );
@@ -613,6 +614,7 @@
 				.$hostname ) if ( grep ( /$if/, @{$ref_if_list} ) );
 		}
 		$add_if->{'slaves'}		= join ( " ", @slaves );
+		$add_if->{'mode'}		= $ref_host->{$iface_section}->{'mode.'.$host_number} || $ref_host->{$iface_section}->{'mode'};
 		$add_if->{'options'}	= $ref_host->{$iface_section}->{'options.'.$host_number} || $ref_host->{$iface_section}->{'options'};
 	}
 	# Check vlan
@@ -854,6 +856,22 @@
 	}
 }
 
+sub Get_cmdline_from_hostprops ($) {
+	my ( $host_props ) = @_;
+	my ( $bond_cmdline, $cmdline );
+	
+	$cmdline = $host_props->{'boot'}->{'cmdline'};
+	foreach my $iface ( sort keys %{$host_props->{'interfaces'}} ) {
+		next if ( $iface !~ /^bond/ );
+		$bond_cmdline = "bonding.mode=".$host_props->{'interfaces'}->{$iface}->{'mode'}." ";
+		foreach my $opt ( split ( /\s*,\s*/, $host_props->{'interfaces'}->{$iface}->{'options'} ) ) {
+			$bond_cmdline .= "bonding.".$opt." ";
+		}
+		$bond_cmdline =~ s/\s*$//;
+		last;
+	}
+	return ( $cmdline, $bond_cmdline );
+}
 
 #### BACKWARD Compatibility
 sub Get_Host_Props ($$;$) {

Modified: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=792&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (original)
+++ branches/next-gen/lib/PFTools/Logger.pm Fri Jul 30 09:46:12 2010
@@ -56,6 +56,7 @@
 $CODE->{'SYNTAX'}			= 3;
 $CODE->{'RIGHTS'}			= 4;
 $CODE->{'UNLINK'}			= 5;
+$CODE->{'EXEC'}				= 6;
 
 $CODE->{'INVALID_CONTEXT'}	= 10;
 $CODE->{'INVALID_SECTNAME'}	= 11;

Modified: branches/next-gen/sbin/mk_grubopt
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_grubopt?rev=792&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_grubopt (original)
+++ branches/next-gen/sbin/mk_grubopt Fri Jul 30 09:46:12 2010
@@ -26,112 +26,161 @@
 
 use Sys::Hostname ;
 use Digest::MD5;
-use PFTools::Net;
-use PFTools::Update;
+use PFTools::Conf;
+use PFTools::Logger;
+use PFTools::Host;
 use File::Compare ;
 use File::Copy ;
 use Getopt::Long qw( :config ignore_case_always bundling );
+
+####################################################
+# Vars
+
+my $GRUB_VERSION		= 2;
+my $MENU_GRUB			= "";
+my $HOSTNAME			= "";
+my $SITE				= "";
+my $OUTPUT				= "";
+my $HELP				= 0 ;
+my $GLOBAL_STORE_FILE	= '';
+my $PF_CONFIG_FILE		= '';
+my $PF_CONFIG			= {};
+my $GLOBAL_STRUCT		= {};
 
 my $program = $0;
 $program =~ s%.*/%%; # cheap basename
 
 my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
 
-my $MENU_GRUB	= "/boot/grub/menu.lst" ;
-my $HOSTNAME	= hostname ;
-my $DEST	= "-" ;
-my $NET		= "GLOBAL:private-network" ;
-my $HELP	= 0 ;
-my $DEBUG	= 0 ;
-my $VERBOSE	= 0 ;
+######################################################
+# Functions
 
-sub Display_usage () {
+sub Do_help () {
 print STDERR << "# ENDHELP";
     $program - version $version
 
 Usage:	$0 [options]
-	-h --help:	print help and exit
-	-v --verbose:	be more verbose
-	-s --src	source for GRUB configuration (default: /boot/grub/menu.lst)
-	-d --dst	destination for modified GRUB configuration (default: /boot/grub/menu.lst)
-	--host		hostname on which GRUB configuration applied
-	-n --net	Possiblitiy for defining an alternate PATH for private-network file (default GLOBAL:private-network)
+	-h --help	: print help and exit
+	-h --host	: the hostname for which you want to build grub configuration
+	-s --site	: the site where the hostname is defined
+	--src		: the source for grub configuration
+	--grub		: version of brub default value is 2
+	-o --output	: destination for modified GRUB configuration
+	--store		: path for accessing storable file containing the global configuration
+	-c --config	: path for accessing pf-tools.conf file
 # ENDHELP
 }
 
 
 sub Change_kopt ($$$) {
-	my ( $cmd_line, $menulst, $dst ) = @_ ;
-
+	my ( $cmd_line, $menulst, $dst ) = @_;
+	my $tmp_grub = [];
+	
 	unless ( open ( MENU, $menulst ) ) {
-		warn "Unable top open ".$menulst."\n" ;
+		Warn ( $CODE->{'OPEN'},
+			"Unable to open current file ".$menulst." for modifying GRUB option(s)" );
 		return 0 ;
 	}
-	my @tmp_grub = <MENU> ;
-	foreach ( @tmp_grub ) {
+	@{$tmp_grub} = <MENU> ;
+	close ( MENU );
+	
+	foreach ( @{$tmp_grub} ) {
 		chomp ;
-		next if ( ! /^\# kopt=.*$/ ) ;
-		s/$/ $cmd_line/ if ( defined $cmd_line && ! /$cmd_line$/ ) ;
+		next if ( $GRUB_VERSION == 2 && ! /^GRUB_CMDLINE_LINUX_DEFAULT=".*"$/ ) ;
+		next if ( $GRUB_VERSION == 1 && ! /^\# kopt=.*$/ ) ;
+		s/\"$/ $cmd_line\"/ if ( defined $cmd_line && ! /\Q$cmd_line\E\"$/ ) ;
 	}
-	
-	if ( $dst eq '-' ) {
-		foreach ( @tmp_grub ) {
-			print $_."\n" ;
+	my $tmp_dst = ( $dst eq "-" ) ? $dst : "/tmp/menulst";
+	unless ( open ( TMPDST, ">".$tmp_dst ) ) {
+		Warn ( $CODE->{'OPEN'},
+			"Unable to open temporary destination file /tmp/menulst" );
+		return 0 ;
+	}
+	print TMPDST join ( "\n", @{$tmp_grub} );
+	close ( TMPDST ) ;
+	if ( $tmp_dst ne "-" ) {
+		if ( compare ( $tmp_dst, $dst ) ) {
+			return move ( $tmp_dst, $dst) ;
+		} else {
+			if ( ! unlink ( $tmp_dst ) ) {
+				Warn ( $CODE->{'UNLINK'},
+					"Unable to unlink source file ".$tmp_dst );
+			}
+			return 1 ;
 		}
-		return 1 ;
-	}
-	else {
-		unless ( open ( TMPDST, ">/tmp/menulst" ) ) {
-			warn "Unable to open temporary destination file /tmp/menulst\n" ;
-			return 0 ;
-		}
-		foreach ( @tmp_grub ) {
-			print TMPDST $_."\n" ;
-		}
-		close ( TMPDST ) ;
-		if ( compare ( '/tmp/menulst', $dst ) ) {
-			return move ( '/tmp/menulst', $dst) ;
-		} else {
-			if ( $DEBUG ) {
-				warn "No need to move /tmp/menulst to ".$dst." they are equals\n" ;
-				warn "Unlinking source file /tmp/menulst\n" ;
-			}
-			if ( ! unlink ( '/tmp/menulst' ) ) {
-				warn "Unable to unlink source file /tmp/menulst\n" ;
-				warn "Please clean it manually\n" ;
-			}
-		}
-		return 1 ;
 	}
 }
 
-##### MAIN
-GetOptions(
-    'src|s=s'	=> \$MENU_GRUB,
-    'dst|d=s'	=> \$DEST,
-    'host=s'	=> \$HOSTNAME,
-    'net|n=s'	=> \$NET,
-    'debug'	=> \$DEBUG,
-    'help|h'	=> \$HELP,
-    'verbose|v'	=> \$VERBOSE
-) or die "GetOptions error, try --help: $!\n";
+#######################################################""
+### MAIN
+
+GetOptions (
+	'help'			=> \$HELP,
+	'h|host=s'		=> \$HOSTNAME,
+	'site|s=s'		=> \$SITE,
+	'src=s'			=> \$MENU_GRUB,
+	'grub=s'		=> \$GRUB_VERSION,
+	'o|output=s'	=> \$OUTPUT,
+	'config|c=s'	=> \$PF_CONFIG_FILE,
+	'store=s'		=> \$GLOBAL_STORE_FILE,
+) or die "Didn't grok options (see --help).\n";
 
 if ( $HELP ) {
-	Display_usage () ;
-	exit 0 ;
-}
-elsif ( ! -e $MENU_GRUB ) {
-	die "Unexistant GRUB configuration ".$MENU_GRUB."\n" ;
-}
-elsif ( -z $MENU_GRUB ) {
-	die "Empty configuration file for GRUB ".$MENU_GRUB."\n" ;
+	Do_help ();
+	exit 0;
 }
 
-$DEST = "-" if ( $DEBUG ) ;
-$VERBOSE = 1 if ( $DEBUG ) ;
-
-my $NETWORK = Init_lib_net ( Get_source ( $NET ) ) ;
-if ( ! Change_kopt ( Get_Cmdline ( $NETWORK, $HOSTNAME ), $MENU_GRUB, $DEST ) ) {
-	die "Unable to change kernel options(s) into file ".$MENU_GRUB."\n" ;
+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 ( $OUTPUT eq "" ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"You MUST define a valid output for this command use '-' if you want to use STDOUT" );
+}
+
+if ( $HOSTNAME eq "" ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"Unable to modify grub options for an undefined hostname" );
+}
+
+$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 $host_props	= Get_host_config_from_CONFIG ( $HOSTNAME, $GLOBAL_STRUCT, $SITE );
+my $mode		= $host_props->{'deployment'}->{'mode'};
+my ( $cmdline, $bond_cmdline ) = Get_cmdline_from_hostprops ( $host_props );
+$GRUB_VERSION = "" if ( $GRUB_VERSION == 1 );
+
+$MENU_GRUB = $PF_CONFIG->{$mode}->{'grub'.$GRUB_VERSION} if ( $MENU_GRUB eq '' );
+if ( ! -e $MENU_GRUB ) {
+	Abort ( $CODE->{'UNDEF_KEY'},
+		"Unable to modify GRUB option(s) on file ".$MENU_GRUB." : no such file or directory" );
+}
+
+if ( ! Change_kopt ( $cmdline.$bond_cmdline, $MENU_GRUB, $OUTPUT ) ) {
+	Abort ( $CODE->{'EXEC'},
+		"Unable to change kernel options(s) into file ".$MENU_GRUB );
+}
+
+exit 0;

Modified: branches/next-gen/sbin/mk_pxelinuxcfg
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_pxelinuxcfg?rev=792&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_pxelinuxcfg (original)
+++ branches/next-gen/sbin/mk_pxelinuxcfg Fri Jul 30 09:46:12 2010
@@ -165,16 +165,17 @@
 	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'}
+		'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'},
+		'install_cmdline'	=> $host_props->{'boot'}->{'cmdline'},
+		'cmdline'			=> join ( " ", Get_cmdline_from_hostprops ( $host_props ) ),
+		'kernel'			=> $host_props->{'boot'}->{'kernel'}
 	};
 	if ( $host_props->{'boot'}->{'initrd'} ) {
 		$pxe_subst->{'initrd'} = $host_props->{'boot'}->{'initrd'};

Modified: branches/next-gen/templates/ubuntu-installer
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/templates/ubuntu-installer?rev=792&op=diff
==============================================================================
--- branches/next-gen/templates/ubuntu-installer (original)
+++ branches/next-gen/templates/ubuntu-installer Fri Jul 30 09:46:12 2010
@@ -5,7 +5,7 @@
 
 LABEL install
 	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 %]
+	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 %] [% install_cmdline %]
 
 LABEL linux
 	kernel [% kernel %]




More information about the pf-tools-commits mailing list