pf-tools commit: r848 [ccaillet-guest] - in /branches/next-gen: debian/ filters/ lib/PFTools/ lib/PFTools/Update/ sbin/

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Aug 26 07:56:02 UTC 2010


Author: ccaillet-guest
Date: Thu Aug 26 07:55:53 2010
New Revision: 848

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=848
Log:
* lib/PFTools/Structqueries.pm
  - library for getting informations from global structure
* 

Added:
    branches/next-gen/lib/PFTools/Structqueries.pm   (with props)
Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/filters/filter_distrib
    branches/next-gen/filters/filter_privateresolve
    branches/next-gen/filters/filter_vlan2if
    branches/next-gen/lib/PFTools/Conf.pm
    branches/next-gen/lib/PFTools/Host.pm
    branches/next-gen/lib/PFTools/Net.pm
    branches/next-gen/lib/PFTools/Update.pm
    branches/next-gen/lib/PFTools/Update/Addmount.pm
    branches/next-gen/lib/PFTools/Utils.pm
    branches/next-gen/sbin/fix_hosts
    branches/next-gen/sbin/mk_grubopt
    branches/next-gen/sbin/mk_interfaces
    branches/next-gen/sbin/mk_resolvconf
    branches/next-gen/sbin/mk_sourceslist
    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=848&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Aug 26 07:55:53 2010
@@ -46,14 +46,17 @@
     - extrating apt-get functions (action and depends) from Update.pm
   * lib/PFTools/Translation.pm
     - library for translating old configuration (pf-tools 0.X) to new syntax
+  * lib/PFTools/Structqueries.pm
+    - library for getting informations from global structure
   * debian/control
     - adding libtext-diff-perl as depends for pf-tools package
   * doc/updatefile-syntax
     - basic documentation about update file
   * TODO
     - adding more TODOs :)
-
- -- Christophe Caillet <quadchris at free.fr>  Wed, 25 Aug 2010 11:06:33 +0200
+  * 
+
+ -- Christophe Caillet <tof at sitadelle.com>  Thu, 26 Aug 2010 09:53:51 +0200
 
 pf-tools (0.99.98-1) unstable; urgency=low
 

Modified: branches/next-gen/filters/filter_distrib
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/filters/filter_distrib?rev=848&op=diff
==============================================================================
--- branches/next-gen/filters/filter_distrib (original)
+++ branches/next-gen/filters/filter_distrib Thu Aug 26 07:55:53 2010
@@ -24,6 +24,7 @@
 
 use PFTools::Utils;
 use PFTools::Logger;
+use PFTools::Structqueries;
 use Getopt::Long qw( :config ignore_case_always bundling );
 use Sys::Hostname;
 

Modified: branches/next-gen/filters/filter_privateresolve
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/filters/filter_privateresolve?rev=848&op=diff
==============================================================================
--- branches/next-gen/filters/filter_privateresolve (original)
+++ branches/next-gen/filters/filter_privateresolve Thu Aug 26 07:55:53 2010
@@ -25,6 +25,7 @@
 use warnings;
 
 use PFTools::Utils;
+use PFTools::Structqueries;
 use PFTools::Logger;
 use Getopt::Long qw( :config ignore_case_always bundling );
 

Modified: branches/next-gen/filters/filter_vlan2if
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/filters/filter_vlan2if?rev=848&op=diff
==============================================================================
--- branches/next-gen/filters/filter_vlan2if (original)
+++ branches/next-gen/filters/filter_vlan2if Thu Aug 26 07:55:53 2010
@@ -29,6 +29,7 @@
 
 use PFTools::Utils;
 use PFTools::Logger;
+use PFTools::Structqueries;
 use Getopt::Long qw( :config ignore_case_always bundling );
 use Sys::Hostname;
 

Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=848&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Thu Aug 26 07:55:53 2010
@@ -30,8 +30,9 @@
 use PFTools::Host;
 use PFTools::Parser;
 use PFTools::Logger;
+use PFTools::Structqueries;
 use Sys::Hostname;
-use NetAddr::IP;
+# use NetAddr::IP;
 use Fcntl ':mode';
 use Data::Dumper;
 use Storable;
@@ -352,7 +353,8 @@
 	'hostname_model'	=> $MODEL_CONFIG_REGEX,
 	'hostname'			=> $HOST_CONFIG_REGEX,
 	'hosttype'			=> $HOSTTYPE_CONFIG_REGEX,
-	'deploy_hosts'		=> $DEPLOY_CONFIG_REGEX
+	'deploy_hosts'		=> $DEPLOY_CONFIG_REGEX,
+	'network_fstype'	=> '(nfs|cifs)'
 };
 $PF_CONFIG->{'location'} = {
 	'site'		=> '',

Modified: branches/next-gen/lib/PFTools/Host.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Host.pm?rev=848&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Host.pm Thu Aug 26 07:55:53 2010
@@ -27,9 +27,6 @@
 our @ISA = ('Exporter');
 
 our @EXPORT = qw(
-	Get_hosttype_from_hostname
-	Get_iface_vlan_from_hostname
-	Get_zone_from_hostname
 	Add_server
 	Add_host
 );
@@ -40,6 +37,7 @@
 use POSIX qw(ceil floor);
 
 use PFTools::Logger;
+use PFTools::Structqueries;
 use PFTools::Net;
 use Data::Dumper;
 
@@ -167,7 +165,7 @@
 
 #########################################################################
 #
-# STR Get_site_from_hostname ( STR, STR, STR, STR, HASHREF )
+# STR __Get_site_from_hostname ( STR, STR, STR, STR, HASHREF )
 #
 # This function returns the sites list for a given hostname
 # Inputs :
@@ -176,8 +174,8 @@
 #
 # Output :
 #  Returns an array ref containing the sites list or undef if hostname doesn't exist
-#
-# sub Get_site_from_hostname ($$) {
+
+# sub __Get_site_from_hostname ($$) {
 # 	my ( $hostname, $global_config ) = @_;
 # 	my $site_list;
 # 	
@@ -199,135 +197,7 @@
 # 	return $site_list;
 # }
 
-#########################################################################
-#
-# STR Get_zone_from_hostname ( STR, HASHREF, STR )
-#
-# This function adds build the site list for a given section
-# Inputs :
-#  - $site			: site name
-#  - $global_config	: hashref where is stored global configuration
-#
-# Output :
-#  Return a string containing the zone name for the specified site.
-#
-sub Get_zone_from_hostname ($$;$) {
-	my ( $hostname, $global_config, $site ) = @_;
-
-	if ( ! defined $site ) {
-		my $ref_list = Get_site_from_hostname ( $hostname, $global_config );
-		if ( ! defined $ref_list ) {
-			Warn ( $CODE->{'UNDEF_KEY'},
-				"Hostname ".$hostname." is not defined into global configuration" );
-			return undef;
-		}
-		elsif ( scalar @{$ref_list} > 1 ) {
-			Warn ( $CODE->{'DUPLICATE_VALUE'},
-				"Hostname ".$hostname." is defined on multiple sites into global configuration" );
-			return undef;
-		}
-		else {
-			( $site ) = @{$ref_list};
-		}
-	}
-	return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
-}
-
-
-#########################################################################
-#
-# STR Get_hosttype_from_hostname ( STR, STR, STR, STR, HASHREF )
-#
-# This function returns the hostname for a given model, number and node
-# Inputs :
-#  - $hostname		: string containing the model definition for building hostname
-#  - $global_config	: hashref containing the parsed global configuration
-#  - $site			: define here the site where hostname is defined
-#
-# Output :
-#  Returns a string containing the hosttype or undef if hostname doesn't exist
-#
-sub Get_hosttype_from_hostname ($$;$) {
-	my ( $hostname, $global_config, $site ) = @_;
-	my $site_list;
-
-	if ( ! defined $site ) {
-		$site_list = $global_config->{'SITE'}->{'__site_list'};
-	}
-	else {
-		$site_list = [ $site ];
-	}
-	
-	foreach my $site ( @{$site_list} ) {
-		my $host_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'};
-		foreach my $hostclass ( keys %{$host_part} ) {
-			return $hostclass if ( $hostclass eq $hostname );
-			foreach my $host ( keys %{$host_part->{$hostclass}} ) {
-				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;
-}
-
-#########################################################################
-#
-# STR Get_hostname_model_from_hostname ( STR, HASHREF )
-#
-# This function returns the hostname for a given model, number and node
-# Inputs :
-#  - $hostname		: string containing the model definition for building hostname
-#  - $global_config	: hashref containing the parsed global configuration
-#
-# Output :
-#  Returns a string containing the hosttype or undef if hostname doesn't exist
-#
-sub Get_hostname_model_from_hostname ($$) {
-	my ( $hostname, $global_config ) = @_;
-	
-	my $hostclass = __Get_hosttype_from_hostname ( $hostname, $global_config );
-	if ( ! defined $hostclass ) {
-		Abort ( $CODE->{'UNDEF_KEY'},
-			"Unable to get hosttype from hostname ".$hostname." : unexistant hostname" );
-	}
-	my $site_list = Get_site_from_hostname ( $hostname, $global_config );
-	if ( ! defined $site_list ) {
-		Abort ( $CODE->{'UNDEF_KEY'},
-			"Unable to get site list from hostname ".$hostname." : unexistant hostname" );
-	}
-	else {
-		if ( scalar @{$site_list} > 1 ) {
-			Warn ( $CODE->{'DUPLICATE_VALUE'},
-				"Hostname ".$hostname." is defined on multiple sites : unable to choose the right one" );
-			return undef;
-		}
-		else {
-			my ( $site ) = @{$site_list};
-			return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'}->{$hostclass}->{'deployment'}->{'hostname_model'};
-		}
-	}
-}
+
 
 #########################################################################
 #

Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=848&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Thu Aug 26 07:55:53 2010
@@ -33,7 +33,6 @@
 	Add_network
 	Add_site
 	Add_zone
-	Get_site_list
 	Get_netblock_from_vlan
 	Resolv_hostname_from_DNS
 	Resolv_hostname_from_GLOBAL
@@ -46,6 +45,7 @@
 
 use PFTools::Logger;
 use PFTools::Parser;
+use PFTools::Structqueries;
 use NetAddr::IP;
 use Net::DNS;
 
@@ -159,31 +159,6 @@
 				'netmask'	=> ''
 			}
 		};
-	}
-}
-
-#########################################################################
-#
-# ARRAYREF __Get_site_list ( HASHREF , HASHREF )
-#
-# This function adds build the site list for a given section
-# Inputs :
-#  - $sect_hash		: hashref containing the section where site key is defined
-#  - $global_config	: hashref where is stored global configuration
-#
-# Output :
-#  Return an array reference containing the built site list.
-#
-sub Get_site_list ($$) {
-	my ( $sect_hash, $global_config ) = @_;
-	my $ref_list;
-	
-	if ( $sect_hash->{'site'} eq 'ALL' ) {
-		return $global_config->{'SITE'}->{'__site_list'};
-	}
-	else {
-		@{$ref_list} = split ( /\s*\,\s*/, $sect_hash->{'site'} );
-		return $ref_list;
 	}
 }
 

Added: branches/next-gen/lib/PFTools/Structqueries.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Structqueries.pm?rev=848&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Structqueries.pm (added)
+++ branches/next-gen/lib/PFTools/Structqueries.pm Thu Aug 26 07:55:53 2010
@@ -1,0 +1,315 @@
+package PFTools::Structqueries;
+##
+##  $Id$
+##
+##  Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
+##  Copyright (C) 2005-2007 Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
+##  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
+##  Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+##
+##  This program is free software; you can redistribute it and/or
+##  modify it under the terms of the GNU General Public License
+##  as published by the Free Software Foundation; either version 2
+##  of the License, or (at your option) any later version.
+##
+##  This program is distributed in the hope that it will be useful,
+##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+##  GNU General Public License for more details.
+##
+##  You should have received a copy of the GNU General Public License
+##  along with this program; if not, write to the Free Software
+##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+##
+
+use strict;
+use warnings;
+
+use Exporter;
+use PFTools::Parser;
+use PFTools::Logger;
+use Sys::Hostname;
+# use NetAddr::IP;
+use Data::Dumper;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+	Get_zone_from_hostname
+	Get_hosttype_from_hostname
+	Get_iface_vlan_from_hostname
+	Get_site_from_hostname
+	Get_site_list
+	Get_cmdline_from_hostprops
+	Get_pkgtype_from_hostname
+	Get_host_config_from_CONFIG
+);
+
+our @EXPORT_OK = qw ();
+
+
+#########################################################################
+#
+# STR Get_zone_from_hostname ( STR, HASHREF, STR )
+#
+# This function adds build the site list for a given section
+# Inputs :
+#  - $site			: site name
+#  - $global_config	: hashref where is stored global configuration
+#
+# Output :
+#  Return a string containing the zone name for the specified site.
+#
+sub Get_zone_from_hostname ($$;$) {
+	my ( $hostname, $global_config, $site ) = @_;
+
+	if ( ! defined $site ) {
+		my $ref_list = Get_site_from_hostname ( $hostname, $global_config );
+		if ( ! defined $ref_list ) {
+			Warn ( $CODE->{'UNDEF_KEY'},
+				"Hostname ".$hostname." is not defined into global configuration" );
+			return undef;
+		}
+		elsif ( scalar @{$ref_list} > 1 ) {
+			Warn ( $CODE->{'DUPLICATE_VALUE'},
+				"Hostname ".$hostname." is defined on multiple sites into global configuration" );
+			return undef;
+		}
+		else {
+			( $site ) = @{$ref_list};
+		}
+	}
+	return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
+}
+
+#########################################################################
+#
+# STR Get_hosttype_from_hostname ( STR, STR, STR, STR, HASHREF )
+#
+# This function returns the hostname for a given model, number and node
+# Inputs :
+#  - $hostname		: string containing the model definition for building hostname
+#  - $global_config	: hashref containing the parsed global configuration
+#  - $site			: define here the site where hostname is defined
+#
+# Output :
+#  Returns a string containing the hosttype or undef if hostname doesn't exist
+#
+sub Get_hosttype_from_hostname ($$;$) {
+	my ( $hostname, $global_config, $site ) = @_;
+	my $site_list;
+
+	if ( ! defined $site ) {
+		$site_list = $global_config->{'SITE'}->{'__site_list'};
+	}
+	else {
+		$site_list = [ $site ];
+	}
+	
+	foreach my $site ( @{$site_list} ) {
+		my $host_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'};
+		foreach my $hostclass ( keys %{$host_part} ) {
+			return $hostclass if ( $hostclass eq $hostname );
+			foreach my $host ( keys %{$host_part->{$hostclass}} ) {
+				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;
+}
+
+#########################################################################
+#
+# STR Get_hostname_model_from_hostname ( STR, HASHREF )
+#
+# This function returns the hostname for a given model, number and node
+# Inputs :
+#  - $hostname		: string containing the model definition for building hostname
+#  - $global_config	: hashref containing the parsed global configuration
+#
+# Output :
+#  Returns a string containing the hosttype or undef if hostname doesn't exist
+#
+sub Get_hostname_model_from_hostname ($$) {
+	my ( $hostname, $global_config ) = @_;
+	
+	my $hostclass = Get_hosttype_from_hostname ( $hostname, $global_config );
+	if ( ! defined $hostclass ) {
+		Abort ( $CODE->{'UNDEF_KEY'},
+			"Unable to get hosttype from hostname ".$hostname." : unexistant hostname" );
+	}
+	my $site_list = Get_site_from_hostname ( $hostname, $global_config );
+	if ( ! defined $site_list ) {
+		Abort ( $CODE->{'UNDEF_KEY'},
+			"Unable to get site list from hostname ".$hostname." : unexistant hostname" );
+	}
+	else {
+		if ( scalar @{$site_list} > 1 ) {
+			Warn ( $CODE->{'DUPLICATE_VALUE'},
+				"Hostname ".$hostname." is defined on multiple sites : unable to choose the right one" );
+			return undef;
+		}
+		else {
+			my ( $site ) = @{$site_list};
+			return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'}->{$hostclass}->{'deployment'}->{'hostname_model'};
+		}
+	}
+}
+
+#########################################################################
+#
+# STR Get_site_from_hostname ( STR, STR, STR, STR, HASHREF )
+#
+# This function returns the sites list for a given hostname
+# Inputs :
+#  - $hostname		: string containing the model definition for building hostname
+#  - $global_config	: hashref containing the parsed global configuration
+#
+# Output :
+#  Returns an array ref containing the sites list or undef if hostname doesn't exist
+#
+sub Get_site_from_hostname ($$) {
+	my ( $hostname, $global_config ) = @_;
+	my $site_list;
+	
+	foreach my $site ( @{$global_config->{'SITE'}->{'__site_list'}} ) {
+		my $host_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'};
+		foreach my $hostclass ( keys %{$host_part} ) {
+			if ( $hostclass eq $hostname ) {
+				push (  @{$site_list}, $site ) if ( ! grep ( /^$site$/, @{$site_list} ) );
+				next;
+			}
+			foreach my $host ( keys %{$host_part->{$hostclass}} ) {
+				if ( $host eq $hostname ) {
+					push (  @{$site_list}, $site ) if ( ! grep ( /^$site$/, @{$site_list} ) );
+					last;
+				}
+			}
+		}
+	}
+	return $site_list;
+}
+
+sub Get_zone_from_site_GLOBAL ($$) {
+	my ( $site, $global_config ) = @_;
+	
+	return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
+}
+
+#########################################################################
+#
+# ARRAYREF Get_site_list ( HASHREF , HASHREF )
+#
+# This function adds build the site list for a given section
+# Inputs :
+#  - $sect_hash		: hashref containing the section where site key is defined
+#  - $global_config	: hashref where is stored global configuration
+#
+# Output :
+#  Return an array reference containing the built site list.
+#
+sub Get_site_list ($$) {
+	my ( $sect_hash, $global_config ) = @_;
+	my $ref_list;
+	
+	if ( $sect_hash->{'site'} eq 'ALL' ) {
+		return $global_config->{'SITE'}->{'__site_list'};
+	}
+	else {
+		@{$ref_list} = split ( /\s*\,\s*/, $sect_hash->{'site'} );
+		return $ref_list;
+	}
+}
+
+#########################################################################
+#
+# VOID Get_host_config_from_CONFIG ( STR, HASHREF[, STR] )
+#
+# This function try to determine site from hostname if site is not defined
+# and return host definition from global configuration structure
+# Inputs :
+#  - $hostname		: filename where server is parsed
+#  - $global_config	: hashref where are stored global configuration datas
+#  - $site			: define here the site where hostname is defined (optional)
+#
+sub Get_host_config_from_CONFIG ($$;$) {
+	my ( $hostname, $global_config, $site ) = @_ ;
+
+	if ( ! defined $site ) {
+		my $site_list = Get_site_from_hostname ( $hostname, $global_config );
+		if ( ! defined $site_list ) {
+			Warn ( $CODE->{'UNDEF_KEY'},
+				"Unable to retrieve site for hostname ".$hostname." : hostname not defined" );
+		}
+		elsif ( scalar @{$site_list} > 1 ) {
+			Warn ( $CODE->{'UNDEF_KEY'},
+				"Unable to retrieve site for hostname ".$hostname." : hostname appeared in multiple sites : "
+				.join ( ",", @{$site_list} ) );
+		}
+		else {
+			( $site ) = @{$site_list};
+		}
+	}
+	my $site_part					= $global_config->{'SITE'}->{'BY_NAME'}->{$site};
+	my $zone						= $site_part->{'zone'};
+	$hostname						=~ /^([^.]+)(\.([^.]+))?(\.$zone)?$/ ;
+	my ( $hostshort, $hostvlan )	= ( $1, $3 ) ;
+	my $hosttype					= Get_hosttype_from_hostname ( $hostname, $global_config );
+	return $site_part->{'HOST'}->{'BY_NAME'}->{$hosttype}->{$hostshort} ;
+}
+
+sub Get_pkgtype_from_hostname ($$;$) {
+	my ( $hostname, $global_config, $site ) = @_;
+	
+	my $host_props = Get_host_config_from_CONFIG ( $hostname, $global_config, $site );
+	return undef if ( ! defined $host_props );
+	my $mode = $host_props->{'deployment'}->{'mode'};
+	if ( $mode =~ /^(debian|ubuntu)$/ ) {
+		return 'deb';
+	}
+	else {
+		Warn ( $CODE->{'UNDEF_KEY'},
+			"Unknown mode ".$mode." of deployment : cannot retrieve package type for this one" );
+		return undef;
+	}
+}
+
+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 );
+}
+
+1;

Propchange: branches/next-gen/lib/PFTools/Structqueries.pm
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Aug 26 07:55:53 2010
@@ -1,0 +1,2 @@
+Id
+Revision

Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=848&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Thu Aug 26 07:55:53 2010
@@ -38,8 +38,6 @@
 
 our @EXPORT_OK = qw();
 
-use File::Compare;
-use File::Copy;
 use PFTools::Update::Common;
 use PFTools::Update::Addfile;
 use PFTools::Update::Installpkg;
@@ -51,12 +49,6 @@
 use PFTools::Update::Removefile;
 use PFTools::Update::Removedir;
 use PFTools::Logger;
-use PFTools::Parser;
-use PFTools::Net;
-use PFTools::Host;
-use PFTools::Packages;
-
-use Fcntl ':mode';
 
 ###########################################
 # Global vars

Modified: branches/next-gen/lib/PFTools/Update/Addmount.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Addmount.pm?rev=848&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Addmount.pm (original)
+++ branches/next-gen/lib/PFTools/Update/Addmount.pm Thu Aug 26 07:55:53 2010
@@ -36,10 +36,16 @@
 use File::Compare;
 use File::Copy;
 use Text::Diff;
+use PFTools::Parser;
 use PFTools::Logger;
 use PFTools::Conf;
+use PFTools::Net;
+use PFTools::Disk;
+use PFTools::Utils;
+use PFTools::Structqueries;
 use PFTools::Update::Common;
 use PFTools::Update::Mkdir;
+use Data::Dumper;
 
 ###############################################
 # Constants
@@ -63,14 +69,15 @@
 sub __Get_ip_host_from_GLOBAL ($$) {
 	my ( $host, $global_config ) = @_;
 
-	my $ip							= $host;
-	my $zone						= Get_zone_from_hostname ( $host, $global_config );
+	my $ip		= $host;
+	$host		=~ /^([^\.]+)\..*$/;
+	my $zone	= Get_zone_from_hostname ( $1, $global_config );
 	if ( ! defined $zone ) {
 		Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve zone for hostname ".$host );
 		return undef;
 	}
 	$ip								=~ s/\.$zone$//;
-	$host							=~ /^([^.]+)(\.([^.]+))?$/;
+	$ip								=~ /^([^.]+)(\.([^.]+))?$/;
 	my ( $hostshort, $hostvlan )	= ( $1, $3 );
 	my $hosttype					= Get_hosttype_from_hostname ( $hostshort, $global_config );
 	if ( ! defined $hosttype ) {
@@ -87,8 +94,9 @@
 	else {
 		$site = shift @{$site_list};
 	}
-	if ( ! isipaddr ( $host ) ) {
-		my $resolved = Resolv_hostname_from_GLOBAL ( $host, $global_config, $zone, $site, $hosttype );
+	if ( ! isipaddr ( $ip ) ) {
+		my $resolved = Resolv_hostname_from_GLOBAL ( $ip, $global_config, $site, $zone, $hosttype );
+		print Dumper $resolved;
 		if ( ! defined $resolved ) {
 			Warn ( $CODE->{'RESOLV'}, "Unknown host ".$host );
 			return undef;
@@ -115,14 +123,25 @@
 				? $fs_entry->{$key} || $DEFAULT_OPTIONS
 				: $fs_entry->{$key};
 			my $val_addr = $value;
-			$val_addr =~ ( $key eq 'options' )
-				? s/^(.*,)?ip=([^,]+)(,.*)?$/$2/
-				: s/^([^:]+):(.+)$/$1/;
-			my $val_ip	= __Get_ip_host_from_GLOBAL ( $val_addr, $param->{'global_config'} ) if ( $val_addr );
+			if ( $key eq 'options' ) {
+				if ( $val_addr =~ /ip=/ ) {
+					$val_addr =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$2/;
+				}
+				else {
+					next;
+				}
+			}
+			else {
+				$val_addr =~ s/^([^\:]+):(.+)$/$1/;
+			}
+			my $val_ip	= __Get_ip_host_from_GLOBAL ( $val_addr, $param->{'global_config'} ) if ( defined $val_addr );
 			return 1 if ( ! defined $val_ip );
-			$value =~ ( $key eq 'options' )
-				? s/^(.*,)?ip=([^,]+)(,.*)?$/$1ip=$val_ip$3/
-				: s/^([^:]+):(.+)$/$val_ip:$2/;
+			if ( $key eq 'options' ) {
+				$value =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$1ip=$val_ip$3/; 
+			}
+			else {
+				$value =~ s/^([^:]+):(.+)$/$val_ip:$2/;
+			}
 			$fs_entry->{$key}	= $value;
 		}
 	}
@@ -177,15 +196,23 @@
 	}
 	my $addfstab = 0;
 	if ( ! defined $current_fstab->{$dest} ) {
-		$current_fstab->{$dest} = $add_mount;
+		print "Adding entry $dest\n";
+		print Dumper $add_mount;
+		foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+			$current_fstab->{$dest}->{$key} = $add_mount->{$key};
+		}
+		$current_fstab->{$dest} = {};
+# 		$current_fstab->{$dest} = $add_mount;
 		$addfstab = 1;
+	print "Now we have fstab structure ...\n";
+	print Dumper $current_fstab."\n";
 	}
 	else {
 		foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
 			$addfstab = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
 		}
 	}
-	
+
 	my $addproc = 0;
 	if ( ! defined $current_proc->{$dest} ) {
 		$addproc = 1;
@@ -212,17 +239,19 @@
 			Mkdir_action ( $ref_section, $dest, $options, $hash_subst, $global_config );
 		}
 		if ( $addfstab ) {
+			print "Need to add entry in fstab ...\n";
 			my $tmp = Get_tmp_dest ("/etc/fstab");
 			unless ( open ( NEWFSTAB, ">".$tmp ) ) {
-				Warn( $CODE->{'OPEN'}, "Impossible de creer " . $tmp );
+				Warn( $CODE->{'OPEN'}, "Unable to create tmp dest " . $tmp );
 				return 1;
 			}
-			$current_fstab->{$dest} = $add_mount;
+# 			$current_fstab->{$dest} = $add_mount;
 			my $new_fstab = Build_fstab_from_structure ( $current_fstab );
 			print NEWFSTAB join ( "", @{$new_fstab} );
 			close ( NEWFSTAB );
 			if ( $options->{'diff'} ) {
-				deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
+				diff ( '/etc/fstab', $tmp, { STYLE => 'Unified' } );
+# 				deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
 			}
 			if ( ! $options->{'simul'} ) {
 				if ( ! move ( $tmp, "/etc/fstab" ) ) {
@@ -232,6 +261,7 @@
 			}
 		}
 		if ( $addproc ) {
+			print "Need to do some actions ...\n";
 			if ( $options->{'diff'} ) {
 				foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
 					my $value = $current_proc->{$dest}->{$key} || '?';
@@ -251,26 +281,29 @@
 				}
 				if ( $remount ) {
 					my $cmd = "mount -o 'remount,".$add_mount->{'options'}."' '".$dest."'";
-					if ( deferredlogsystem( $cmd ) ) {
-						Warn( $CODE->{'OPEN'},
-							"Unable to remount ".$dest." with options ".$add_mount->{'options'} ); 
-						return 1;
-					}
+# 					if ( deferredlogsystem( $cmd ) ) {
+# 						Warn( $CODE->{'OPEN'},
+# 							"Unable to remount ".$dest." with options ".$add_mount->{'options'} ); 
+# 						return 1;
+# 					}
+					print "Need to execute $cmd\n";
 				}
 				else {
 					my $umount = ( $add_mount->{'source'} ne $current_proc->{$dest}->{'source'} )
 						? $current_proc->{$dest}->{'source'}
 						: $add_mount->{'source'};
-					if ( deferredlogsystem( "umount '".$umount."'" ) ) {
-						Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
-						return 1;
-					}
+# 					if ( deferredlogsystem( "umount '".$umount."'" ) ) {
+# 						Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
+# 						return 1;
+# 					}
+					print "Unmounting --> $umount\n";
 					my $mount_cmd = "mount -t '".$add_mount->{'fstype'}."' - o '".$add_mount->{'options'}."' '"
 						.$add_mount->{'source'}."' '".$add_mount->{'dest'}."'";
-					if ( deferredlogsystem ( $mount_cmd ) ) {
-						Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
-						return 1;
-					}
+# 					if ( deferredlogsystem ( $mount_cmd ) ) {
+# 						Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
+# 						return 1;
+# 					}
+					print "Mounting with command --> $mount_cmd\n";
 				}
 			}
 		}

Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=848&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Thu Aug 26 07:55:53 2010
@@ -29,11 +29,6 @@
 our @EXPORT = qw(
 	Init_TOOLS
 
-	Get_host_config_from_CONFIG
-	Get_site_from_hostname
-	Get_zone_from_site_GLOBAL
-	Get_cmdline_from_hostprops
-
 	Do_update_from_GLOBAL
 	Fix_hosts
 	Mk_dhcp
@@ -55,6 +50,7 @@
 use POSIX qw(ceil floor);
 
 use PFTools::Logger;
+use PFTools::Structqueries;
 use PFTools::Net;
 use PFTools::Conf;
 use PFTools::Host;
@@ -118,116 +114,6 @@
 		}
 	}
 	return ( $pf_config, $global_struct );
-}
-
-#########################################################################
-#
-# VOID Get_host_config_from_CONFIG ( STR, HASHREF[, STR] )
-#
-# This function try to determine site from hostname if site is not defined
-# and return host definition from global configuration structure
-# Inputs :
-#  - $hostname		: filename where server is parsed
-#  - $global_config	: hashref where are stored global configuration datas
-#  - $site			: define here the site where hostname is defined (optional)
-#
-sub Get_host_config_from_CONFIG ($$;$) {
-	my ( $hostname, $global_config, $site ) = @_ ;
-
-	if ( ! defined $site ) {
-		my $site_list = Get_site_from_hostname ( $hostname, $global_config );
-		if ( ! defined $site_list ) {
-			Warn ( $CODE->{'UNDEF_KEY'},
-				"Unable to retrieve site for hostname ".$hostname." : hostname not defined" );
-		}
-		elsif ( scalar @{$site_list} > 1 ) {
-			Warn ( $CODE->{'UNDEF_KEY'},
-				"Unable to retrieve site for hostname ".$hostname." : hostname appeared in multiple sites : "
-				.join ( ",", @{$site_list} ) );
-		}
-		else {
-			( $site ) = @{$site_list};
-		}
-	}
-	my $site_part					= $global_config->{'SITE'}->{'BY_NAME'}->{$site};
-	my $zone						= $site_part->{'zone'};
-	$hostname						=~ /^([^.]+)(\.([^.]+))?(\.$zone)?$/ ;
-	my ( $hostshort, $hostvlan )	= ( $1, $3 ) ;
-	my $hosttype					= Get_hosttype_from_hostname ( $hostname, $global_config );
-	return $site_part->{'HOST'}->{'BY_NAME'}->{$hosttype}->{$hostshort} ;
-}
-
-sub Get_pkgtype_from_hostname ($$;$) {
-	my ( $hostname, $global_config, $site ) = @_;
-	
-	my $host_props = Get_host_config_from_CONFIG ( $hostname, $global_config, $site );
-	return undef if ( ! defined $host_props );
-	my $mode = $host_props->{'deployment'}->{'mode'};
-	if ( $mode =~ /^(debian|ubuntu)$/ ) {
-		return 'deb';
-	}
-	else {
-		Warn ( $CODE->{'UNDEF_KEY'},
-			"Unknown mode ".$mode." of deployment : cannot retrieve package type for this one" );
-		return undef;
-	}
-}
-
-#########################################################################
-#
-# STR Get_site_from_hostname ( STR, STR, STR, STR, HASHREF )
-#
-# This function returns the sites list for a given hostname
-# Inputs :
-#  - $hostname		: string containing the model definition for building hostname
-#  - $global_config	: hashref containing the parsed global configuration
-#
-# Output :
-#  Returns an array ref containing the sites list or undef if hostname doesn't exist
-#
-sub Get_site_from_hostname ($$) {
-	my ( $hostname, $global_config ) = @_;
-	my $site_list;
-	
-	foreach my $site ( @{$global_config->{'SITE'}->{'__site_list'}} ) {
-		my $host_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}->{'BY_NAME'};
-		foreach my $hostclass ( keys %{$host_part} ) {
-			if ( $hostclass eq $hostname ) {
-				push (  @{$site_list}, $site ) if ( ! grep ( /^$site$/, @{$site_list} ) );
-				next;
-			}
-			foreach my $host ( keys %{$host_part->{$hostclass}} ) {
-				if ( $host eq $hostname ) {
-					push (  @{$site_list}, $site ) if ( ! grep ( /^$site$/, @{$site_list} ) );
-					last;
-				}
-			}
-		}
-	}
-	return $site_list;
-}
-
-sub Get_zone_from_site_GLOBAL ($$) {
-	my ( $site, $global_config ) = @_;
-	
-	return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
-}
-
-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 );
 }
 
 sub Get_kpkg_from_kernel ($$) {

Modified: branches/next-gen/sbin/fix_hosts
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/fix_hosts?rev=848&op=diff
==============================================================================
--- branches/next-gen/sbin/fix_hosts (original)
+++ branches/next-gen/sbin/fix_hosts Thu Aug 26 07:55:53 2010
@@ -25,6 +25,7 @@
 use warnings;
 
 use Getopt::Long qw( :config ignore_case_always bundling );
+use PFTools::Structqueries;
 use PFTools::Utils;
 use PFTools::Logger;
 use Sys::Hostname;

Modified: branches/next-gen/sbin/mk_grubopt
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_grubopt?rev=848&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_grubopt (original)
+++ branches/next-gen/sbin/mk_grubopt Thu Aug 26 07:55:53 2010
@@ -27,6 +27,7 @@
 use Sys::Hostname ;
 use PFTools::Logger;
 use PFTools::Utils;
+use PFTools::Structqueries;
 use Getopt::Long qw( :config ignore_case_always bundling );
 
 ####################################################

Modified: branches/next-gen/sbin/mk_interfaces
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_interfaces?rev=848&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_interfaces (original)
+++ branches/next-gen/sbin/mk_interfaces Thu Aug 26 07:55:53 2010
@@ -25,6 +25,7 @@
 
 use Getopt::Long qw( :config ignore_case_always bundling );
 use PFTools::Utils;
+use PFTools::Structqueries;
 use PFTools::Logger;
 use Sys::Hostname;
 

Modified: branches/next-gen/sbin/mk_resolvconf
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_resolvconf?rev=848&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_resolvconf (original)
+++ branches/next-gen/sbin/mk_resolvconf Thu Aug 26 07:55:53 2010
@@ -26,6 +26,7 @@
 use Getopt::Long qw( :config ignore_case_always bundling );
 use PFTools::Utils;
 use PFTools::Logger;
+use PFTools::Structqueries;
 use Sys::Hostname;
 
 #################################

Modified: branches/next-gen/sbin/mk_sourceslist
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_sourceslist?rev=848&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_sourceslist (original)
+++ branches/next-gen/sbin/mk_sourceslist Thu Aug 26 07:55:53 2010
@@ -26,6 +26,7 @@
 
 use PFTools::Utils;
 use PFTools::Logger;
+use PFTools::Structqueries;
 use Sys::Hostname;
 use Getopt::Long qw( :config ignore_case_always bundling );
 

Modified: branches/next-gen/sbin/update-config
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/update-config?rev=848&op=diff
==============================================================================
--- branches/next-gen/sbin/update-config (original)
+++ branches/next-gen/sbin/update-config Thu Aug 26 07:55:53 2010
@@ -29,6 +29,7 @@
 use PFTools::Utils;
 use PFTools::Conf;
 use PFTools::Logger;
+use PFTools::Structqueries;
 use Sys::Hostname;
 use Data::Dumper;
 




More information about the pf-tools-commits mailing list