pf-tools commit: r805 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Logger.pm lib/PFTools/Update.pm lib/PFTools/Utils.pm sbin/update-config

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Aug 6 10:20:47 UTC 2010


Author: ccaillet-guest
Date: Fri Aug  6 10:20:44 2010
New Revision: 805

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=805
Log:
* The road to RC1 release for Next-Gen pf-tools
* lib/PFTools/Disk.pm
  - adding Build_fstab_from_structure for building fstab file from a defined
  hash structure
  - adding Build_structure_from_fstab for building hash structure from fstab
  or assimilated file like /proc/mounts. This struture is equal to the 
  addmount structure in configuration file
* sbin/update-config : rewrite with new structures and packages

Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/lib/PFTools/Logger.pm
    branches/next-gen/lib/PFTools/Update.pm
    branches/next-gen/lib/PFTools/Utils.pm
    branches/next-gen/sbin/update-config

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=805&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Aug  6 10:20:44 2010
@@ -1,5 +1,6 @@
-pf-tools (0.99.0-0) unstable; urgency=low
-
+pf-tools (0.99.98-1) unstable; urgency=low
+
+  * The road to RC1 release for Next-Gen pf-tools
   [Christophe Caillet]
   * doc/hostfile-syntax : adding file describing the new grammar for host
   definition
@@ -20,6 +21,12 @@
     - Get_config_for_hostname_on_site : function for getting and parsing
     configuration for a specified hostname on site. Similar to old Get_conf
     which was on lib/PFTools/Update.pm
+  * lib/PFTools/Disk.pm
+    - adding Build_fstab_from_structure for building fstab file from a defined
+    hash structure
+    - adding Build_structure_from_fstab for building hash structure from fstab
+    or assimilated file like /proc/mounts. This struture is equal to the 
+    addmount structure in configuration file
   * lib/PFTools/Parser.pm
     - introducing this package from splitting Conf.pm function with old parser
     - adding parsing with ini standard parser based on Config::IniFiles
@@ -74,6 +81,7 @@
   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 !
+  * sbin/update-config : rewrite with new structures and packages
   * debian/control
     - deps update according to usage of NetAddr::IP, Net::DNS, Template::Tiny
     - uploaders and maintainers update
@@ -89,7 +97,7 @@
   useless and deprecated
   * tools/Display_IP_list : rewrite of dumpiplist.pl
 
- -- Christophe Caillet <tof at sitadelle.com>  Thu, 05 Aug 2010 16:36:03 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Fri, 06 Aug 2010 12:18:59 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=805&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (original)
+++ branches/next-gen/lib/PFTools/Logger.pm Fri Aug  6 10:20:44 2010
@@ -143,7 +143,7 @@
 }
 
 # Returns undef on error
-sub deferredlogpipe {
+sub deferredlogpipe ($;$) {
 	my ( $pipe_cmd, $deferredlog ) = @_;
 	my $ret = '';
 
@@ -192,18 +192,18 @@
 	return $ret;
 }
 
-sub DelLog {
+sub DelLog () {
     $deferredlogbuffer = '';
 }
 
-sub FlushLog {
+sub FlushLog () {
     print STDERR $deferredlogbuffer;
     DelLog();
 }
 
 
 # Log
-sub Log {
+sub Log (@) {
 	my ( @msg ) = @_;
 
 	my @words = split( /\s+/, join ( "", @msg ) );
@@ -252,7 +252,7 @@
 }
 
 # Warn
-sub Warn ($$) {
+sub Warn ($@) {
     my ( $err, @msg ) = @_;
     my $basename;
 
@@ -262,7 +262,7 @@
 }
 
 # Abort
-sub Abort ($$) {
+sub Abort ($@) {
     my ( $err, @msg ) = @_;
     my $basename;
 

Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=805&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Fri Aug  6 10:20:44 2010
@@ -555,12 +555,9 @@
 	}
 	my $site_list					= Get_site_from_hostname ( $hostshort, $global_config );
 	my $site;
-	if ( ! defined $site_list ) {
-		Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve site for hostname ".$host );
-		return undef;
-	}
-	elsif ( scalar @{$site_list} > 1 ) {
-		Warn ( $CODE->{'UNDEF_KEY'}, "Multiple site for hostname ".$host );
+	if ( ! defined $site_list  || scalar @{$site_list} > 1 ) {
+		Warn ( $CODE->{'UNDEF_KEY'},
+			"Unable to retrieve site for hostname ".$host." : unknown or multiple declaration" );
 		return undef;
 	}
 	else {
@@ -611,8 +608,8 @@
 sub __Build_fstab_entry_from_config {
 	my ( $param ) = @_;
 	
-	my $fs_entry = $param->{'ref_section'};
-	$fs_entry->{'dest'}		= $param->{'dest'};
+	my $fs_entry		= $param->{'ref_section'};
+	$fs_entry->{'dest'}	= $param->{'dest'};
 	foreach my $key ( 'source', 'options' ) {
 		$fs_entry->{$key}	= Subst_vars ( $fs_entry->{$key}, $param->{'subst'} );
 	}
@@ -634,6 +631,7 @@
 	my $add_mount	= __Build_fstab_entry_from_config (
 		{
 			'dest'			=> $dest,
+			'subst'			=> $hash_subst,
 			'global_config'	=> $global_config,
 			'ref_section'	=> $ref_section
 		}
@@ -1036,7 +1034,7 @@
 	my ( $host_config, $section ) = @_;
 
 	my $prio	= 0;
-	my $action	= $host_config->{'section'}->{'action'};
+	my $action	= $host_config->{$section}->{'action'};
 
 	# First : authentication parts
 	return $prio if ( $section eq "/etc/passwd" );

Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=805&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Fri Aug  6 10:20:44 2010
@@ -34,6 +34,7 @@
 	Get_zone_from_site_GLOBAL
 	Get_cmdline_from_hostprops
 
+	Do_update_from_GLOBAL
 	Fix_hosts
 	Mk_dhcp
 	Mk_interfaces
@@ -69,7 +70,7 @@
 #########################################################################
 # Prototypes : needed by recursive calls
 
-sub __Do_updateloop ($$$$$);
+sub __Do_updateloop ($$$$@);
 
 #########################################################################
 # Functions
@@ -86,7 +87,12 @@
 		$pf_config = Init_PF_CONFIG ( $pf_config_file );
 	}
 	else {
-		$pf_config = Init_PF_CONFIG ();
+		if ( -e '/etc/pf-tools.conf' ) {
+			$pf_config = Init_PF_CONFIG ( '/etc/pf-tools.conf' );
+		}
+		else {
+			$pf_config = Init_PF_CONFIG ();
+		}
 	}
 
 	$global_store_file	= $pf_config->{'path'}->{'global_struct'} if ( $global_store_file eq '' );
@@ -879,17 +885,17 @@
 	return $interfaces;
 }
 
-sub __Do_updateloop ($$$$$) {
+sub __Do_updateloop ($$$$@) {
     my ( $host_config, $options, $hash_subst, $global_config, @sortedkeys ) = @_;
     my $errorcount = 0;
 
     foreach my $section (@sortedkeys) {
-		if (   defined( $host_config->{$section} )
-			&& ! defined( $host_config->{$section}->{'doing'} )
+		if (
+			! defined( $host_config->{$section}->{'doing'} )
 			&& ! defined( $host_config->{$section}->{'done'} )
 		) {
 			$host_config->{$section}->{'doing'} = 1;
-			Get_depends_for action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options );
+			Get_depends_for_action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options );
 			if ( defined( $host_config->{$section}->{'depends'} ) ) {
 				my @dependsraw;
 				my @depends;
@@ -906,7 +912,7 @@
 						push @depends, $depend;
 						if ( $host_config->{$depend}->{'action'} eq 'addmount' ) {
 							Warn( $CODE->{'OPEN'},
-								"[".$section."] depends on addmount [".$d."], it may not work during install!" );
+								"[".$section."] depends on addmount [".$depend."], it may not work during install!" );
 							FlushLog();
 						}
 					}
@@ -930,15 +936,15 @@
 	return $errorcount;
 }
 
-sub Do_update_from_GLOBAL ($$$$$$) {
-	my ( $hostname, $site, $options, $hash_subst, $global_config, $pf_config ) = @_;
+sub Do_update_from_GLOBAL ($$$$$) {
+	my ( $hostname, $site, $options, $global_config, $pf_config ) = @_;
 	my $errorcount = 0;
 
 	if ( ! VCS_Update ( $hostname, $pf_config, $options, $options->{'branche'} ) ) {
 		Abort ( $CODE->{'EXEC'},
 			"Unable to checkout configuration from VCS system" );
 	}
-
+	my $hash_subst	= Init_SUBST ( $hostname, $pf_config );
 	my $host_config = Get_config_for_hostname_on_site ( $hostname, $site, $hash_subst, $global_config, $pf_config );
 	if ( ! defined $host_config ) {
 		Abort( $CODE->{'OPEN'},
@@ -950,7 +956,7 @@
 			"Unable to update configuration : update feature is deactivated in pf-tools configuration file" );
 	}
 
-	my @sortedkeys = sort { Trie_dependances( $host_config, $a, $b ) } $host_config->{'__sections_order'} ;
+	my @sortedkeys = sort { Trie_dependances( $host_config, $a, $b ) } @{$host_config->{'__sections_order'}};
 
 	$| = 1;
 	$errorcount = __Do_updateloop ( $host_config, $options, $hash_subst, $global_config, @sortedkeys );

Modified: branches/next-gen/sbin/update-config
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/update-config?rev=805&op=diff
==============================================================================
--- branches/next-gen/sbin/update-config (original)
+++ branches/next-gen/sbin/update-config Fri Aug  6 10:20:44 2010
@@ -26,46 +26,97 @@
 
 use Getopt::Long qw( :config ignore_case_always bundling );
 
-use PFTools::Update;
-use PFTools::Conf;
+use PFTools::Utils;
+use PFTools::Logger;
+use Sys::Hostname;
+use Data::Dumper;
+
+#################################
+# VARS
+my $PF_CONFIG			= {};
+my $GLOBAL_STRUCT		= {};
 
 my $program = $0;
 $program =~ s%.*/%%; # cheap basename
 
 my $version = sprintf( "svn-r%s", q$Revision$ =~ /([\d.]+)/ );
 
+###################################
+# Funtions
+
 sub Do_help {
     print STDERR << "# ENDHELP";
     $program - version $version
 
 Usage:	$0 [options]
-	-d --debug:	print debug info
-        -u --diff:	diff files, versions, mountpoints, links => --simul
-	-h --help:	print help and exit
-	-i --install:	install mode
-	-s --simul:	simulation mode, fake everything
-	-v --verbose:	be more verbose
-  --branche-cvs=: update based on a specific CVS branche.
+	--help		: print help and exit
+	-h --host	: hostname for update-config
+	--site		: site for hostname (optional)
+	-c --config	: path to access to pf-tools.conf file (optional)
+	--store		: path to storable file which contains gloabl configuration
+	-d --debug	: print debug info
+	-u --diff	: diff files, versions, mountpoints, links => --simul
+	-i --install	: install mode
+	-s --simul	: simulation mode, fake everything
+	-v --verbose	: be more verbose
+	--branche	: update based on a specific VCS branche.
     
 # ENDHELP
 }
+
+##################################
+### MAIN
 
 # All options are disabled by default
 my $options = {};
 
 GetOptions(
     $options,
-    'branche-cvs=s',
+    'branche=s',
     'debug|d',
     'diff|u',
-    'help|h',
+    'help',
     'install|i',
     'noaction',
     'noupdate',
     'quiet|q',
     'simul|s',
     'verbose|v',
+    'config|c=s',
+    'store=s',
+    'host|h=s',
+    'site=s'
 ) or die "GetOptions error, try --help: $!\n";
+
+if ( $options->{'help'} ) {
+	Do_help ();
+	exit 0;
+}
+$options->{'store'} = "" if ( ! defined $options->{'store'} );
+( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS ( $options->{'config'}, $options->{'store'} );
+my $SITE		= $options->{'site'} || "";
+my $HOSTNAME	= $options->{'host'} || hostname; 
+if ( $SITE eq '' ) {
+	if ( ! defined $PF_CONFIG->{'location'}->{'site'} ) {
+		my $site_list = Get_site_from_hostname ( $HOSTNAME, $GLOBAL_STRUCT );
+		if ( ! defined $site_list ) {
+			Abort ( $CODE->{'UNDEF_KEY'},
+				"Unable to retrieve site for hostname ".$HOSTNAME." : hostname not defined" );
+		}
+		elsif ( scalar @{$site_list} > 1 ) {
+			Abort ( $CODE->{'DUPLICATE_VALUE'},
+				"Unable to retrieve site for hostname ".$HOSTNAME." : hostname appeared in multiple sites : "
+				.join ( ",", @{$site_list} ).".\n"
+				."Please relaunch this command with the right site" );
+		}
+		else {
+			( $SITE ) = @{$site_list};
+		}
+	}
+	else {
+		$SITE = $PF_CONFIG->{'location'}->{'site'}
+	}
+}
 
 if ( $options->{'help'} ) {
 	Do_help();
@@ -74,7 +125,7 @@
 
 if ( $options->{'quiet'} ) {
 	Log("update-config started in quiet mode...");
-	$DEFERREDLOG = 1;
+	Set_deferredlog ();
 }
 
 if ( $options->{'diff'} ) {
@@ -82,13 +133,16 @@
 }
 
 if ( defined( $ARGV[0] ) && $ARGV[0] eq ':NO-ACTION:' ) {
-	Warn( $ERR_OPEN, ":NO-ACTION: depreciated, please use --noaction" );
+	Warn( $CODE->{'OPEN'}, ":NO-ACTION: depreciated, please use --noaction" );
 	$options->{'noaction'} = 1;
 }
 if ( defined( $ARGV[0] ) && $ARGV[0] eq ':NO-UPDATE:' ) {
-	Warn( $ERR_OPEN, ":NO-UPDATE: depreciated, please use --noupdate" );
+	Warn( $CODE->{'OPEN'}, ":NO-UPDATE: depreciated, please use --noupdate" );
 	$options->{'noupdate'} = 1;
 }
 
-Do_update( $options ) ;
+Do_update_from_GLOBAL ( $HOSTNAME, $SITE, $options, $GLOBAL_STRUCT, $PF_CONFIG );
 
+Unset_deferredlog () if ( $options->{'quiet'} );
+
+exit 0;




More information about the pf-tools-commits mailing list