pf-tools commit: r796 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Host.pm lib/PFTools/Parser.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Aug 3 10:19:03 UTC 2010
Author: ccaillet-guest
Date: Tue Aug 3 10:19:03 2010
New Revision: 796
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=796
Log:
- adding __Merge_conf_includes for merging include part or model part from
- modifying Load_conf
- 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
- adding allowcontinue which permits to have muliline value for keys.
The separator is \.
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/Parser.pm
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=796&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Tue Aug 3 10:19:03 2010
@@ -7,22 +7,25 @@
network and zone definitions
* doc/updatefile-syntax : TODO
* lib/PF-Tools/Conf.pm
- - adding __Load_conf_new for parsing new configuration file with "standard"
- ini parser and new syntax
- - adding __Merge_conf_new for merging include part or model part from
+ - adding __Merge_conf_includes for merging include part or model part from
configuration files
- adding __Chk_section_struct for checking the content of sections
(basic checks) this function is also used for old syntax files
- - modifying Load_conf as a wrapper for old or new parsing method
+ - modifying Load_conf
- using PFTools::Parser and PFTools::Logger
- adding __Translate_old2new_host for translating Parser_pftools result
to Parser_ini hash result with new syntax file
- Init_GLOBAL_NETCONFIG : similar to old function Init_lib_net
- Init_PF_CONFIG : function for parsing new style pf-tools.conf
+ - 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/Parser.pm
- introducing this package from splitting Conf.pm function with old parser
- adding parsing with ini standard parser based on Config::IniFiles
- remove allowedcommentchars parameter when callinf ini parser
+ - adding allowcontinue which permits to have muliline value for keys.
+ The separator is \.
* lib/PFTools/Logger.pm
- created by the functions extracted from Conf.pm and Update.pm
- all logging functions are now defined here
@@ -69,7 +72,7 @@
* debian/compat
- update level for avoiding warning during package build
- -- Christophe Caillet <quadchris at free.fr> Mon, 02 Aug 2010 14:07:05 +0200
+ -- Christophe Caillet <quadchris at free.fr> Tue, 03 Aug 2010 12:17:34 +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=796&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Tue Aug 3 10:19:03 2010
@@ -62,13 +62,16 @@
Load_conf
Flush2disk_GLOBAL
Retrieve_GLOBAL
+ Get_source
+ Get_config_for_hostname_on_site
);
##########################
### Prototypes
-sub __Merge_conf_new ($$$);
+sub __Merge_conf_includes ($$$);
sub __Load_conf_new ($$$);
+sub Load_conf ($$$$);
#################################
### Constants
@@ -77,21 +80,39 @@
# Syntax definitions
my $ALLOWED_PARSING_CONTEXT = '(host|network|config|model)';
+my $MODEL_CONFIG_REGEX = qr{
+ \A
+ ( # HOSTTYPE
+ (
+ ( # POPNAME (optional)
+ [a-z]{3}\d{1}
+ )
+ -
+ )?
+ (
+ [a-z0-9-]+[a-z-] # host type (without the POP name)
+ )
+ )
+ %* # HOSTDIGITS MARK (optional)
+ _* # HOSTNODEINDEX MARK (optional)
+ \z
+}xms;
my $HOST_CONFIG_REGEX = qr{
\A
( # HOSTTYPE
(
- ( # POPNAME (optional)
+ ( # POPNAME (optional)
[a-z]{3}\d{1}
- )
- -
+ )
+ -
)?
(
- [a-z0-9-]+[a-z-] # host type (without the POP name)
+ [a-z0-9-]+[a-z-] # host type (without the POP name)
)
- )
- %* # % sign designate the number of digit at the end of real hostname
- \z
+ )
+ (\d*) # HOSTDIGITS (optional)
+ ([a-z]*) # HOSTNODEINDEX (optional)
+ \z
}xms;
my $HOSTTYPE_CONFIG_REGEX = qr{
\A
@@ -136,7 +157,7 @@
'order' => '[\d]+',
'nodes' => '[\d]+',
'prefix' => '(true|false)',
- 'hostname' => $HOST_CONFIG_REGEX,
+ 'hostname' => $MODEL_CONFIG_REGEX,
'hosttype' => $HOSTTYPE_CONFIG_REGEX
};
$DEF_SECTIONS->{'host'}->{'boot'} = {
@@ -216,12 +237,33 @@
'filter' => 'undefined',
'owner' => '([\d]+|[a-z\d\-]+)',
'group' => '([\d]+|[a-z\d\-]+)',
+ 'mode' => '[0-7]?[0-7]{3}',
+ 'before_change' => 'undefined',
+ 'on_noaction' => 'undefined',
+ 'after_change' => 'undefined'
+};
+$DEF_SECTIONS->{'config'}->{'createfile'} = {
+ 'depends' => 'undefined',
+ 'source' => 'undefined',
+ 'filter' => 'undefined',
+ 'owner' => '([\d]+|[a-z\d\-]+)',
+ 'group' => '([\d]+|[a-z\d\-]+)',
+ 'mode' => '[0-7]?[0-7]{3}',
+ 'before_change' => 'undefined',
+ 'on_noaction' => 'undefined',
+ 'after_change' => 'undefined'
+};
+$DEF_SECTIONS->{'config'}->{'removefile'} = {
+
+};
+$DEF_SECTIONS->{'config'}->{'mkdir'} = {
+ 'owner' => '([\d]+|[a-z\d\-]+)',
+ 'group' => '([\d]+|[a-z\d\-]+)',
'mode' => '0?[0-7]{3}',
'before_change' => 'undefined',
'on_noaction' => 'undefined',
'after_change' => 'undefined'
};
-$DEF_SECTIONS->{'config'}->{'createfile'} = $DEF_SECTIONS->{'config'}->{'addfile'};
$DEF_SECTIONS->{'config'}->{'addlink'} = {
'MANDATORY_KEYS' => [ 'source' ],
'source' => 'undefined',
@@ -242,6 +284,7 @@
'on_noaction' => 'undefined',
'after_change' => 'undefined'
};
+$DEF_SECTIONS->{'config'}->{'dpkg-purge'} = $DEF_SECTIONS->{'config'}->{'apt-get'};
our @EXPORT_OK = qw();
@@ -280,7 +323,9 @@
'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'
+ 'checkout_dir' => '/var/lib/cvsguest',
+ 'templates_dir' => '/usr/share/pf-tools/templates',
+ 'common_config' => 'update-common'
};
$PF_CONFIG->{'features'} = {
'ipv4' => 1,
@@ -313,14 +358,16 @@
'custom-sections' => 'common'
};
$PF_CONFIG->{'regex'} = {
- 'hostname' => $HOST_CONFIG_REGEX,
- 'hosttype' => $HOSTTYPE_CONFIG_REGEX
+ 'hostname_model' => $MODEL_CONFIG_REGEX,
+ 'hostname' => $HOST_CONFIG_REGEX,
+ 'hosttype' => $HOSTTYPE_CONFIG_REGEX
};
sub Init_PF_CONFIG (;$) {
my ( $config_file ) = @_;
- if ( defined $config_file && ! -e $config_file ) {
+ return $PF_CONFIG if ( ! defined $config_file );
+ if ( ! -e $config_file ) {
Abort ( $CODE->{'UNDEF_KEY'},
"Unable to proceed with configuration file ".$config_file." : no such file or directory" );
}
@@ -332,7 +379,6 @@
"Ignoring weak rights for configuration file ".$config_file." (check owner/group/mode)" );
}
}
- return $PF_CONFIG if ( ! defined $config_file );
my $conf_parsed = Parser_ini ( $config_file );
Abort ( $CODE->{'SYNTAX'}, "Unable to parse configuration file ".$config_file ) if ( ! defined $conf_parsed );
@@ -347,9 +393,14 @@
return $PF_CONFIG;
}
-sub Init_SUBST ($;$$) {
- my ( $ref_subst, $fakehost, $fakedomain ) = @_ ;
-
+sub Init_SUBST ($;$$$) {
+ my ( $ref_subst, $pf_config, $fakehost, $fakedomain ) = @_ ;
+ my $host_regex;
+
+ if ( ! defined $pf_config ) {
+ $pf_config = Init_PF_CONFIG ();
+ }
+
if ( defined $fakehost && ! defined $fakedomain ) {
warn "Unable to init substitution hash for hostname ".$fakehost."\n" ;
return ;
@@ -371,30 +422,18 @@
}
}
chomp ( $ref_subst->{'OS_RELEASE'} = `/bin/uname -r` ) ;
- my $host_regex = qr{
- \A
- ( # HOSTTYPE
- (
- ( # POPNAME (optional)
- [a-z]{3}\d{1}
- )
- -
- )?
- (
- [a-z0-9-]+[a-z-] # host type (without the POP name)
- )
- )
- (\d*) # HOSTDIGITS (optional)
- ([a-z]*) # HOSTNODEINDEX (optional)
- \z
- }xms;
-
+ if ( defined $pf_config->{'regex'}->{'hostname'} ) {
+ $host_regex = $pf_config->{'regex'}->{'hostname'};
+ }
+ else {
+ $host_regex = $HOST_CONFIG_REGEX;
+ }
unless ($ref_subst->{'HOSTNAME'} =~ m/$host_regex/) {
Abort( $CODE->{'OPEN'}, "Init_SUBST failed: invalid hostname $ref_subst->{'HOSTNAME'}" );
}
$ref_subst->{'HOSTTYPE'} = $1 ;
$ref_subst->{'HOSTDIGITS'} = $5 ;
- $ref_subst->{'HOSTCLUSTER'} = $4.$5 ;
+ $ref_subst->{'HOSTCLUSTER'} = $4.$5 if ( defined $4 && defined $5 );
$ref_subst->{'HOSTNODEINDEX'} = $6 || "" ;
$ref_subst->{'POPNAME'} = $3 || "" ;
$ref_subst->{'HOSTNUM'} = $ref_subst->{'HOSTDIGITS'} ;
@@ -408,29 +447,37 @@
Init_SUBST ( \%SUBST ) ;
-my $HOSTNAME = $SUBST{'HOSTNAME'};
-our $CVS_WORKING_DIR = $CVS_CHECKOUT . "/" . $HOSTNAME;
-our $CVS_TMP_DIR = $CVS_CHECKOUT . "/" . $HOSTNAME . "/tmp";
-our $CVS_OLD_DIR = $CVS_CHECKOUT . "/" . $HOSTNAME . "/old";
-our $GLOBAL_CONF = $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/GLOBAL";
-our $SITES_CONF = $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/SITES";
-our $TEMPLATES = $CVS_WORKING_DIR . "/" . $CVS_CONFIG . "/TEMPLATES";
-
-sub Get_source ($;$) {
- my ($source, $hash_subst) = @_;
- my $hosttype;
-
+sub Get_source ($;$$) {
+ my ( $source, $hash_subst, $pf_config ) = @_;
+
if ( ! defined $hash_subst ) {
- $hosttype = $SUBST{'HOSTTYPE'};
- }
- else {
- $hosttype = $hash_subst->{'HOSTTYPE'};
- }
- $source =~ s!^HOST:!$CVS_WORKING_DIR/$CVS_CONFIG/$hash_subst->{'HOSTTYPE'}!;
- $source =~ s!^CONFIG:!$CVS_WORKING_DIR/$CVS_CONFIG/!;
- $source =~ s!^CVS:!$CVS_WORKING_DIR/!;
- $source =~ s!^GLOBAL:!$GLOBAL_CONF/!;
+ $hash_subst = \%SUBST;
+ }
+ elsif ( ! defined $pf_config ) {
+ $pf_config = $PF_CONFIG;
+ }
+ my $vcs_work_dir = $pf_config->{'path'}->{'checkout_dir'};
+ my $module = $pf_config->{'vcs'}->{'module'};
+ $source =~ s!^CONFSITE_([^:]+):!$vcs_work_dir/$module/SITE/$1/CONFIG!;
+ $source =~ s!^SITE(_([^:]+))?:!$vcs_work_dir/$module/SITE/$1!;
+ $source =~ s!^HOST:!$vcs_work_dir/$module/$hash_subst->{'HOSTTYPE'}!;
+ $source =~ s!^HOSTSITE_([^:]+):!$vcs_work_dir/$module/SITE/$1/$hash_subst->{'HOSTTYPE'}!;
+ $source =~ s!^CONFIG:!$vcs_work_dir/$module/CONFIG!;
+ $source =~ s!^COMMON:!$vcs_work_dir/$module/COMMON!;
+ $source =~ s!^MODVCS:!$vcs_work_dir/$module/!;
+ $source =~ s!^CVS:!$vcs_work_dir/!;
+ $source =~ s!^GLOBAL:!$vcs_work_dir/$module/GLOBAL!;
return $source;
+}
+
+sub __Get_config_path ($$$) {
+ my ( $hostvalue, $pf_config, $site ) = @_;
+
+ my $site_conf_file = Get_source ( 'CONFSITE_'.$site.':/update-'.$hostvalue, {}, $pf_config );
+ return $site_conf_file if ( -e $site_conf_file );
+ my $default_conf_file = Get_source ( 'CONFIG:/update-'.$hostvalue, {}, $pf_config );
+ return $default_conf_file if ( -e $default_conf_file );
+ return undef;
}
sub __Chk_section_struct ($$$$) {
@@ -490,9 +537,11 @@
$key_name = $key;
}
foreach my $value ( @{$tab_values} ) {
- if ( $value !~ /^$definition->{$key}$/ ) {
+ # Removing trailing space
+ $value =~ s/^\s*//; $value =~ s/\s*$//;
+ if ( "$value" !~ /^$definition->{$key}$/ ) {
return ( $CODE->{'INVALID_VALUE'},
- "Value ".$value." for key ".$key_name
+ "Value |".$value."| for key ".$key_name
." on section ".$sect_name." doesn't match ".$definition->{$key} );
}
}
@@ -500,7 +549,7 @@
return ( $CODE->{'OK'}, "" ) ;
}
-sub __Merge_conf_new ($$$) {
+sub __Merge_conf_includes ($$$) {
my ( $hash_to_merge, $hash_subst, $context ) = @_;
my $global_order = [];
my $global_parsed = {};
@@ -536,7 +585,7 @@
$global_parsed->{$section} = $hash_to_merge->{$section};
}
else {
- my $tmp_merged = __Merge_conf_new ( $hash_to_merge->{$section}->{'__content'}, $hash_subst, $context );
+ my $tmp_merged = __Merge_conf_includes ( $hash_to_merge->{$section}->{'__content'}, $hash_subst, $context );
foreach my $tomerge_section ( @{$tmp_merged->{'__sections_order'}} ) {
if ( defined $global_parsed->{$tomerge_section} ) {
if ( ! defined $tmp_merged->{$tomerge_section}->{'override'} || $tmp_merged->{$tomerge_section}->{'override'} ne 'replace' ) {
@@ -558,43 +607,6 @@
}
}
return $global_parsed;
-}
-
-sub __Load_conf_new ($$$) {
- my ( $file, $hash_subst, $context ) = @_;
- my $sect_type;
-
- my $parsed = Parser_ini ( $file );
- if ( ! defined $parsed ) {
- Abort ( $CODE->{'PARSING'}, "Parsing error for file ".$file );
- }
-
- # Basic checks
- foreach my $section ( keys %{$parsed} ) {
- next if ( $section eq '__sections_order' );
- if ( $context =~ /^host|model$/ ) {
- $section =~ /^([^:]+)(::.+)?$/;
- $sect_type = $1;
- if ( $sect_type eq 'hostgroup' && defined $parsed->{$section}->{'model'} ) {
- my $model_parsed = __Load_conf_new ( $parsed->{$section}->{'model'}, $hash_subst, 'model' );
- $parsed->{$section}->{'__model'} = $model_parsed;
- }
- }
- else {
- my $select = ( $context eq 'config' ) ? 'action' : 'type';
- if ( ! defined $parsed->{$section}->{$select} ) {
- Abort ( $CODE->{'UNDEF_KEY'}, "Key ".$select." on section ".$section." from file ".$file." MUST BE defined" );
- }
- $sect_type = $parsed->{$section}->{$select};
- if ( $sect_type eq 'include' ) {
- # We need to dive into deep ...
- my $inc_parsed = __Load_conf_new ( $section, $hash_subst, $context );
- $parsed->{$section}->{'__content'} = $inc_parsed;
- }
- }
- }
- # Merging if needed
- return __Merge_conf_new ( $parsed, $hash_subst, $context );
}
sub __Translate_old2new_host ($$) {
@@ -756,26 +768,48 @@
return $new_host;
}
-sub Load_conf ($$;$$) {
- my ( $file, $hash_subst, $context, $syntax ) = @_;
+sub Load_conf ($$$$) {
+ my ( $file, $hash_subst, $context, $pf_config ) = @_;
my ( $sect_type, $iface_name );
my $parsed;
if ( defined $context && $context !~ /^$ALLOWED_PARSING_CONTEXT$/ ) {
- Abort ( $CODE->{'INVALID_CONTEXT'}, "Context ".$context
+ Abort ( $CODE->{'INVALID_CONTEXT'},
+ "Context ".$context." for file ".$file
." doesn't match ".$ALLOWED_PARSING_CONTEXT );
}
- if ( defined $syntax && $syntax eq 'nx' ) {
- $parsed = __Load_conf_new ( $file, $hash_subst, $context );
- }
- else {
- $parsed = Parser_pftools ( $file, $hash_subst );
- # Ignoring syntax check if old parser is used
- return $parsed;
- }
+
+ $parsed = Parser_ini ( $file );
if ( ! defined $parsed ) {
- Abort ( $CODE->{'SYNTAX'}, "Parsing error for file ".$file );
- }
+ Abort ( $CODE->{'PARSING'}, "Parsing error for file ".$file );
+ }
+
+ # Basic checks
+ foreach my $section ( keys %{$parsed} ) {
+ next if ( $section eq '__sections_order' );
+ if ( $context =~ /^host|model$/ ) {
+ $section =~ /^([^:]+)(::.+)?$/;
+ $sect_type = $1;
+ if ( $sect_type eq 'hostgroup' && defined $parsed->{$section}->{'model'} ) {
+ my $model_parsed = Load_conf ( Get_source ( $parsed->{$section}->{'model'}, $hash_subst, $pf_config ), $hash_subst, 'model', $pf_config );
+ $parsed->{$section}->{'__model'} = $model_parsed;
+ }
+ }
+ else {
+ my $select = ( $context eq 'config' ) ? 'action' : 'type';
+ if ( ! defined $parsed->{$section}->{$select} ) {
+ Abort ( $CODE->{'UNDEF_KEY'}, "Key ".$select." on section ".$section." from file ".$file." MUST BE defined" );
+ }
+ $sect_type = $parsed->{$section}->{$select};
+ if ( $sect_type eq 'include' ) {
+ # We need to dive into deep ...
+ my $inc_parsed = Load_conf ( Get_source ( $section, $hash_subst, $pf_config ), $hash_subst, $context, $pf_config );
+ $parsed->{$section}->{'__content'} = $inc_parsed;
+ }
+ }
+ }
+ # Merging if needed
+ $parsed = __Merge_conf_includes ( $parsed, $hash_subst, $context );
# Basic checks
foreach my $section ( keys %{$parsed} ) {
@@ -830,7 +864,7 @@
};
}
- my $net_parsed = Load_conf ( $start_file, $hash_subst, 'network', 'nx' );
+ my $net_parsed = Load_conf ( $start_file, $hash_subst, 'network', $pf_config );
foreach my $section ( @{$net_parsed->{'__sections_order'}} ) {
if ( $net_parsed->{$section}->{'type'} eq 'zone' ) {
Add_zone ( $start_file, $section, $net_parsed->{$section}, $GLOBAL, $pf_config );
@@ -857,8 +891,8 @@
foreach my $site ( @{$site_list} ) {
my $service_part = $GLOBAL->{'SITE'}->{'BY_NAME'}->{$site}->{'SERVICE'}->{'BY_NAME'};
foreach my $host ( @{$net_parsed->{$section}->{'@host'}} ) {
- my $hostfile = Get_source ( $host );
- my $host_parsed = Load_conf ( $hostfile, $hash_subst, 'host', 'nx' );
+ my $hostfile = Get_source ( $host, $hash_subst, $pf_config );
+ my $host_parsed = Load_conf ( $hostfile, $hash_subst, 'host', $pf_config );
Add_host ( $hostfile, $host_parsed, $GLOBAL, $pf_config );
push ( @{$service_part->{$section}}, $host );
}
@@ -889,72 +923,29 @@
return retrieve ( $path_global_file );
}
-#########################################################################
-#
-# 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} ;
-# }
-
-
-# Print_conf
-sub Print_conf {
- my ($C) = @_;
-
- my $s;
- my $v;
-
- foreach $s ( keys %$C ) {
- print "[" . $s . "]\n";
- Print_v( $C->{$s}, "" );
- print "\n";
- }
-}
-
-sub Print_v {
- my ( $o, $var ) = @_;
- my $v;
-
- foreach $v ( keys %$o ) {
- if ( ref( $o->{$v} ) ) {
- Print_v( $o->{$v}, $var . $v . "." );
- }
- else {
- print $var. $v . " = ", $o->{$v}, "\n";
- }
- }
-}
-
-#Print_conf (Load_conf ("/config/config/network")) ;
+sub Get_config_for_hostname_on_site ($$$$$) {
+ my ( $hostname, $site, $hash_subst, $global_config, $pf_config ) = @_;
+
+ # Common configuration file e.g. update-common
+ my $global_host_conf = Load_conf ( Get_source ( 'COMMON:/'.$pf_config->{'path'}->{'common_config'}, $hash_subst, $pf_config ), $hash_subst, 'config', $pf_config );
+ my $hosttype = Get_hosttype_from_hostname ( $hostname, $global_config, $site );
+ if ( ! defined $hosttype ) {
+ Abort ( $CODE->{'UNDEF_KEY'},
+ "Unable to get hosttype from hostname ".$hostname." for getting hosttype configuration file" );
+ }
+ # Hosttype configuration file e.g. update-<hosttype>
+ my $hosttype_conf_file = __Get_config_path ( $hosttype, $pf_config, $site );
+ # Hostname configuration file e.g. update-<hostname>
+ my $hostname_conf_file = __Get_config_path ( $hostname, $pf_config, $site );
+ foreach my $file ( $hosttype_conf_file, $hostname_conf_file ) {
+ next if ( ! defined $file );
+ my $config = Load_conf ( $file, $hash_subst, 'config', $pf_config );
+ foreach my $section ( @{$config->{'__sections_order'}} ) {
+ push ( @{$global_host_conf->{'__sections_order'}}, $section ) if ( ! defined $global_host_conf->{$section} );
+ $global_host_conf->{$section} = $config->{$section};
+ }
+ }
+ return $global_host_conf;
+}
1;
Modified: branches/next-gen/lib/PFTools/Host.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Host.pm?rev=796&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Host.pm Tue Aug 3 10:19:03 2010
@@ -514,7 +514,7 @@
sub Add_server ($$$$$) {
my ( $srvfile, $srvname_model, $srv2add, $global_config, $pf_config ) = @_;
- $srvname_model =~ /^$pf_config->{'regex'}->{'hostname'}$/ ;
+ $srvname_model =~ /^$pf_config->{'regex'}->{'hostname_model'}$/ ;
my $shortname = $1;
my $hostclass = $shortname;
my $site_list = Get_site_list ( $srv2add, $global_config );
@@ -777,7 +777,7 @@
my ( $hostfile, $host2add, $global_config, $pf_config ) = @_;
my $hostname_model = $host2add->{'hostgroup'}->{'hostname'};
- $hostname_model =~ /^$pf_config->{'regex'}->{'hostname'}$/ ;
+ $hostname_model =~ /^$pf_config->{'regex'}->{'hostname_model'}$/ ;
my $shortname = $1;
my $hostclass = $host2add->{'hostgroup'}->{'hosttype'} || $shortname;
my $site_list = Get_site_list ( $host2add->{'hostgroup'}, $global_config );
@@ -836,6 +836,7 @@
}
$host_part->{$hostname}->{'deployment'}->{'hostname_model'} = $host2add->{'hostgroup'}->{'hostname'};
$host_part->{$hostname}->{'deployment'}->{'hosttype'} = $hostclass;
+ $host_part->{$hostname}->{'deployment'}->{'host_config'} = 'SITE:'.$site.'/CONFIG/update-'.$hostclass;
$host_part->{$hostname}->{'dns'}->{'resolver'} = $host2add->{'dns'}->{'resolver.'.$host_number} || $host2add->{'dns'}->{'resolver'};
# Check interfaces
my @if_list = __Get_host_interfaces ($host2add);
@@ -910,73 +911,6 @@
}
}
-# 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 Resolv_hostname_from_GLOBAL ($$;$$) {
-# my ( $hostname, $global_config, $site, $hosttype ) = @_;
-# my $resolved = [];
-#
-# if ( ! defined $site ) {
-# my $ref_site_list = Get_site_from_hostname ( $hostname, $global_config );
-# if ( ! defined $ref_site_list ) {
-# Warn ( $CODE->{'UNDEF_KEY'},
-# "Hostname ".$hostname." is not defined into the global configuration" );
-# return undef;
-# }
-# elsif ( scalar @{$ref_site_list} > 1 ) {
-# Warn ( $CODE->{'DUPLICATE_VALUE'},
-# "Hostname ".$hostname." is defined into multiple sites : unable to choose the right one" );
-# }
-# else {
-# ( $site ) = @{$ref_site_list};
-# }
-# }
-#
-# my $zone = Get_zone_from_hostname ( $hostname, $global_config, $site );
-# $hostname =~ s/\.$zone$//;
-# if ( ! defined $hosttype ) {
-# $hosttype = Get_hosttype_from_hostname ( $hostname, $global_config, $site );
-# return undef if ( ! defined $hosttype );
-# }
-# my $zone_part = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
-# foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
-# next if ( $entry !~ /^$hostname$/ );
-# my @fields;
-# if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
-# @fields = @{$zone_part->{$hosttype}->{$entry}}
-# }
-# else {
-# @fields = ( $zone_part->{$hosttype}->{$entry} );
-# }
-# foreach my $line ( @fields ) {
-# my ( $type, $field ) = split ( /\s+/, $line );
-# if ( $type eq 'A' ) {
-# push ( @{$resolved}, $field );
-# }
-# elsif ( $type eq 'CNAME' ) {
-# my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $hosttype );
-# push ( @{$resolved}, @{$cname_resolved} );
-# }
-# }
-# }
-# return $resolved;
-# }
-
#### BACKWARD Compatibility
sub Get_Host_Props ($$;$) {
my ( $hostname, $global_config, $site ) = @_ ;
Modified: branches/next-gen/lib/PFTools/Parser.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Parser.pm?rev=796&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Parser.pm (original)
+++ branches/next-gen/lib/PFTools/Parser.pm Tue Aug 3 10:19:03 2010
@@ -359,7 +359,7 @@
sub Parser_ini ($) {
my ( $file ) = @_;
- my $parse = new Config::IniFiles ( -file => $file );
+ my $parse = new Config::IniFiles ( -file => $file, -allowcontinue => 1 );
if ( ! defined ( $parse ) ) {
if ( $DEBUG ) {
warn "Unable to parse file ".$file." with the following errors\n" ;
More information about the pf-tools-commits
mailing list