pf-tools commit: r767 [ccaillet-guest] - in /branches/next-gen: debian/changelog doc/hostfile-syntax doc/networkfile-syntax lib/PFTools/Conf.pm lib/PFTools/Logger.pm lib/PFTools/Packages.pm lib/PFTools/Parser.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Fri Jul 2 15:29:14 UTC 2010
Author: ccaillet-guest
Date: Fri Jul 2 15:29:13 2010
New Revision: 767
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=767
Log:
* doc/networkfile-syntax : adding file describing the new grammar for
network and zone definitions
- remove allowedcommentchars parameter when callinf ini parser
- better when deferredlog* functions were really imported into package
Added:
branches/next-gen/doc/networkfile-syntax
Modified:
branches/next-gen/debian/changelog
branches/next-gen/doc/hostfile-syntax
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Logger.pm
branches/next-gen/lib/PFTools/Packages.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=767&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Jul 2 15:29:13 2010
@@ -3,6 +3,8 @@
[Christophe Caillet]
* doc/hostfile-syntax : adding file describing the new grammar for host
definition
+ * doc/networkfile-syntax : adding file describing the new grammar for
+ network and zone definitions
* lib/PF-Tools/Conf.pm
- adding __Load_conf_new for parsing new configuration file with "standard"
ini parser and new syntax
@@ -15,9 +17,11 @@
* 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
* lib/PFTools/Logger.pm
- created by the functions extracted from Conf.pm and Update.pm
- all logging functions are now defined here
+ - better when deferredlog* functions were really imported into package
* lib/PFTools/Net.pm
- using new packages Parser.pm et Logger.pm
* lib/PFTools/Packages.pm
@@ -25,7 +29,7 @@
* lib/PFTools/Update.pm
- using new packages Parser.pm et Logger.pm
- -- Christophe Caillet <tof at sitadelle.com> Fri, 02 Jul 2010 10:01:36 +0200
+ -- Christophe Caillet <tof at sitadelle.com> Fri, 02 Jul 2010 17:05:53 +0200
pf-tools (0.34.0-0WIP) unstable; urgency=low
Modified: branches/next-gen/doc/hostfile-syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/doc/hostfile-syntax?rev=767&op=diff
==============================================================================
--- branches/next-gen/doc/hostfile-syntax (original)
+++ branches/next-gen/doc/hostfile-syntax Fri Jul 2 15:29:13 2010
@@ -42,6 +42,7 @@
! dhcp[.%HOSTNUM%] ::= <VLAN_NAME>
[hostgroup]
+ ! site ::= <SITE_NAME>
? model ::= <MODEL_NAME> if model is defined then <MODEL_NAME> file is parsed from model directory and hashes are merged with right precedency
! number ::= <INT> define here the number of hosts inside this hostgroup
? order ::= <INT>
Added: branches/next-gen/doc/networkfile-syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/doc/networkfile-syntax?rev=767&op=file
==============================================================================
--- branches/next-gen/doc/networkfile-syntax (added)
+++ branches/next-gen/doc/networkfile-syntax Fri Jul 2 15:29:13 2010
@@ -1,0 +1,41 @@
+[<ZONE_NAME>]
+ ! type ::= zone
+ ? comment ::= <STR>
+ ! serial ::= AUTO|<STR> if AUTO is specified then serial will be YYYYMMDD%%%
+ ! soa ::= <HOSTNAME>
+ ! mail ::= <MAIL_ADRESS>
+ ? refresh ::= <REFRESH_DELAY> see bind doc for more infos
+ ? retry ::= <RETRY_DELAY> see bind doc for more infos
+ ? expire ::= <EXPIRE_DELAY> see bind doc for more infos
+ ? negttl ::= <NEG_TTL_DELAY> see bind doc for more infos
+ ? ttl ::= <TTL> see bind doc for more infos
+ ! ns.%NUM% ::= <NS_NAME>
+ ! mx.%NUM% ::= <WEIGHT_MX> <MX_NAME>
+ ! dhcpvlan ::= <VLAN_NAME>
+ ? console ::= (default|ttyS0,115200n8)
+
+
+[<SITE_NAME>]
+ ! type ::= site
+ ? comment ::= <STR>
+ ? location ::= <STR>
+ ? room ::= <STR>
+ ? confdir ::= <PF_TOOLS_PATH> define here the directory for accessing e.g. CONFIG:<directory>
+ if not defined use SITE:<SITE_NAME>
+
+[<NETWORK_NAME>]
+ ! type ::= network
+ ? tag ::= <INT> 802.1q tag
+ ! subnet ::= <NETWORK> define here the prefix in IPv4 format
+ ? subnet6 ::= <NETWORK> define here the prefix in IPv6 format
+ ! mask ::= <NETMASK> define here the netmask in IPv4 format or in CIDR format e.g. /XX
+ ? mask6 ::= <NETMASK> define here the netmask in IPv6 format or in CIDR format e.g. /XX
+ ! scope ::= private|public, if private is defined this network will be ONLY added on zone private for site
+
+[<FILENAME>]
+ ! type ::= include
+
+[<SERVICE_NAME>]
+ ! type ::= service
+ ? comment ::= <STR>
+ ! @hosts ::= <STR> add here the hostfile name one per hostgroup
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=767&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Fri Jul 2 15:29:13 2010
@@ -66,7 +66,7 @@
my $CVS_CHECKOUT = "/var/lib/cvsguest";
# Syntax definitions
-my $ALLOWED_PARSING_CONTEXT = '(host|model|config|network)';
+my $ALLOWED_PARSING_CONTEXT = '(host|network|config|model)';
my $HOST_CONFIG_REGEX = qr{
\A
( # HOSTTYPE
@@ -100,7 +100,7 @@
}xms;
my $DEF_SECTIONS = {};
-$DEF_SECTIONS->{'interface'} = {
+$DEF_SECTIONS->{'host'}->{'interface'} = {
'MANDATORY_KEYS' => [ 'vlan','ipv4','slaves' ],
'mac' => '([0-9a-f]{2}:){5}[0-9a-f]{2}',
'vlan' => '[a-z][a-z0-9\-]+[a-z0-9]',
@@ -110,22 +110,23 @@
'@route' => 'undefined',
'@route6' => 'undefined'
};
-$DEF_SECTIONS->{'deployment'} = {
+$DEF_SECTIONS->{'host'}->{'deployment'} = {
'MANDATORY_KEYS' => [ 'arch','mode','distrib' ],
'arch' => 'i386|amd64',
'mode' => '(debian|ubuntu)(-installer)?',
'distrib' => '[a-z]+',
'dhcp' => 'eth\d'
};
-$DEF_SECTIONS->{'hostgroup'} = {
- 'MANDATORY_KEYS' => [ 'number','hostname' ],
+$DEF_SECTIONS->{'host'}->{'hostgroup'} = {
+ 'MANDATORY_KEYS' => [ 'number','hostname','site' ],
+ 'site' => '\w+',
'model' => 'undefined',
'number' => '[\d]+',
'order' => '[\d]+',
'hostname' => $HOST_CONFIG_REGEX,
'hosttype' => $HOSTTYPE_CONFIG_REGEX
};
-$DEF_SECTIONS->{'boot'} = {
+$DEF_SECTIONS->{'host'}->{'boot'} = {
'MANDATORY_KEYS' => [ 'kernel' ],
'pxefilename' => 'undefined',
'kernel' => 'undefined',
@@ -133,11 +134,32 @@
'cmdline' => 'undefined',
'console' => '(default|ttyS0,115200n8)'
};
-$DEF_SECTIONS->{'dns'} = {
+$DEF_SECTIONS->{'host'}->{'dns'} = {
'MANDATORY_KEYS' => [ 'resolver' ],
'resolver' => 'undefined',
'shortname' => 'undefined',
'alias' => 'undefined'
+};
+$DEF_SECTIONS->{'network'}->{'site'} = {
+ 'comment' => 'undefined',
+ 'location' => 'undefined',
+ 'room' => 'undefined',
+ 'confdir' => 'undefined'
+};
+$DEF_SECTIONS->{'network'}->{'network'} = {
+ 'MANDATORY_KEYS' => [ 'subnet','mask' ],
+ 'comment' => '',
+ 'tag' => '\d{1,4}',
+ 'subnet' => '([\d]{1,3}\.){3}[\d]{1,3}',
+ 'subnet6' => 'undefined',
+ 'mask' => '(/\d{2}|([\d]{1,3}\.){3}[\d]{1,3})',
+ 'mask6' => 'undefined',
+ 'scope' => '(private|public)'
+};
+$DEF_SECTIONS->{'network'}->{'service'} = {
+ 'MANDATORY_KEYS' => [ '@host' ],
+ 'comment' => 'undefined',
+ '@host' => '\w+'
};
$DEF_SECTIONS->{'config'}->{'addfile'} = {
'MANDATORY_KEYS' => [ 'source' ],
@@ -151,6 +173,7 @@
'on_noaction' => 'undefined',
'after_change' => 'undefined'
};
+$DEF_SECTIONS->{'config'}->{'createfile'} = $DEF_SECTIONS->{'config'}->{'addfile'};
$DEF_SECTIONS->{'config'}->{'addlink'} = {
'MANDATORY_KEYS' => [ 'source' ],
'source' => 'undefined',
@@ -165,6 +188,11 @@
'fstype' => '(nfs|ext[2-4]|btrfs|cifs)',
'options' => 'undefined',
'mode' => '0?[0-7]{3}'
+};
+$DEF_SECTIONS->{'config'}->{'apt-get'} = {
+ 'before_change' => 'undefined',
+ 'on_noaction' => 'undefined',
+ 'after_change' => 'undefined'
};
our @EXPORT_OK = qw();
@@ -297,6 +325,7 @@
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 ($;$) {
@@ -318,14 +347,15 @@
sub __Chk_section_struct ($$$$) {
my ( $sect_name, $sect_type, $sect_hash, $context ) = @_;
- my $iface_type;
- my $sect_tmp = {};
- my $definition;
-
- if ( $context ne 'config' ) {
- if ( ! defined $DEF_SECTIONS->{$sect_type} ) {
- return ( $CODE->{'INVALID_SECTNAME'}, "Invalid section type ".$sect_type );
- }
+ my ( $iface_type, $definition, $int_context, $sect_tmp );
+
+ $int_context = ( $context eq 'model') ? 'host' : $context;
+
+ if ( ! defined $DEF_SECTIONS->{$int_context}->{$sect_type} ) {
+ return ( $CODE->{'INVALID_SECTNAME'}, "Invalid section type ".$sect_type );
+ }
+
+ if ( $context =~ /^(host|model)$/ ) {
if ( $sect_name =~ /^\Q$sect_type\E(::((eth|bond)[\d]+(\.TAG[\d]+)?))?$/ ) {
$iface_type = $3;
}
@@ -339,15 +369,11 @@
$sect_tmp->{$new}->{'ORIG_NAME'} = $key;
$sect_tmp->{$new}->{'VALUE'} = $sect_hash->{$key};
}
- $definition = $DEF_SECTIONS->{$sect_type};
}
else {
$sect_tmp = $sect_hash;
- if ( ! defined $DEF_SECTIONS->{'config'}->{$sect_type} ) {
- return ( $CODE->{'INVALID_SECTNAME'}, "Invalid section type ".$sect_type )
- }
- $definition = $DEF_SECTIONS->{'config'}->{$sect_type};
- }
+ }
+ $definition = $DEF_SECTIONS->{$int_context}->{$sect_type};
# Checking mandatory keys
foreach my $key ( @{$definition->{'MANDATORY_KEYS'}} ) {
@@ -365,15 +391,22 @@
|| $key =~ /^__/
|| $definition->{$key} eq 'undefined'
|| ! defined $sect_tmp->{$key} );
- if ( $context ne 'config' && $sect_tmp->{$key}->{'VALUE'} !~ /^$definition->{$key}$/ ) {
- return ( $CODE->{'INVALID_VALUE'},
- "Value ".$sect_tmp->{$key}->{'VALUE'}." for key ".$sect_tmp->{$key}->{'ORIG_NAME'}
- ." on section ".$sect_name." doesn't match ".$definition->{$key} );
- }
- elsif ( $context eq 'config' && $sect_tmp->{$key} !~ /^$definition->{$key}$/ ) {
- return ( $CODE->{'INVALID_VALUE'},
- "Invalid value ".$sect_tmp->{$key}." for key ".$key
- ." on section ".$sect_name." doesn't match ".$definition->{$key} );
+ my $tab_values = [];
+ my $key_name;
+ if ( $int_context eq 'host' ) {
+ $tab_values = ( $key !~ /^@/ ) ? [ $sect_tmp->{$key}->{'VALUE'} ] : $sect_tmp->{$key}->{'VALUE'};
+ $key_name = $sect_tmp->{$key}->{'ORIG_NAME'};
+ }
+ else {
+ $tab_values = ( $key !~ /^@/ ) ? [ $sect_tmp->{$key} ] : $sect_tmp->{$key};
+ $key_name = $key;
+ }
+ foreach my $value ( @{$tab_values} ) {
+ if ( $value !~ /^$definition->{$key}$/ ) {
+ return ( $CODE->{'INVALID_VALUE'},
+ "Value ".$value." for key ".$key_name
+ ." on section ".$sect_name." doesn't match ".$definition->{$key} );
+ }
}
}
return ( $CODE->{'SECTION_OK'}, "" ) ;
@@ -384,7 +417,7 @@
my $global_order = [];
my $global_parsed = {};
- if ( $context ne 'config' ) {
+ if ( $context =~ /^host|model$/ ) {
if ( defined $hash_to_merge->{'hostgroup'}->{'__model'} ) {
$global_parsed = $hash_to_merge->{'hostgroup'}->{'__model'};
}
@@ -408,8 +441,9 @@
undef $global_parsed->{'hostgroup'}->{'__model'};
}
else {
+ my $select = ( $context eq 'config' ) ? 'action' : 'type';
foreach my $section ( @{$hash_to_merge->{'__sections_order'}} ) {
- if ( $hash_to_merge->{$section}->{'action'} ne 'include' ) {
+ if ( $hash_to_merge->{$section}->{$select} ne 'include' ) {
push ( @{$global_parsed->{'__sections_order'}}, $section );
$global_parsed->{$section} = $hash_to_merge->{$section};
}
@@ -431,7 +465,7 @@
push ( @{$global_parsed->{'__sections_order'}}, $tomerge_section );
}
$global_parsed->{$tomerge_section} = $tmp_merged->{$tomerge_section};
- }
+ }
}
}
}
@@ -450,7 +484,7 @@
# Basic checks
foreach my $section ( keys %{$parsed} ) {
next if ( $section eq '__sections_order' );
- if ( $context ne 'config' ) {
+ if ( $context =~ /^host|model$/ ) {
$section =~ /^([^:]+)(::.+)?$/;
$sect_type = $1;
if ( $sect_type eq 'hostgroup' && defined $parsed->{$section}->{'model'} ) {
@@ -459,10 +493,11 @@
}
}
else {
- if ( ! defined $parsed->{$section}->{'action'} ) {
- Abort ( $CODE->{'UNDEF_KEY'}, "Key action on section ".$section." from file ".$file." MUST BE defined" );
- }
- $sect_type = $parsed->{$section}->{'action'};
+ 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 );
@@ -479,6 +514,10 @@
my $sect_type;
my $parsed;
+ if ( $context !~ /^$ALLOWED_PARSING_CONTEXT$/ ) {
+ Abort ( $CODE->{'INVALID_CONTEXT'}, "Context ".$context
+ ." doesn't match ".$ALLOWED_PARSING_CONTEXT );
+ }
if ( $syntax eq 'nx' ) {
$parsed = __Load_conf_new ( $file, $hash_subst, $context );
}
@@ -489,24 +528,23 @@
Abort ( $CODE->{'SYNTAX'}, "Parsing error for file ".$file );
}
- print Dumper $CODE;
# Basic checks
foreach my $section ( keys %{$parsed} ) {
next if ( $section eq '__sections_order' );
- if ( $context ne 'config' ) {
+ if ( $context =~ /^(host|model)$/ ) {
$section =~ /^([^:]+)(::.+)?$/;
$sect_type = $1;
}
else {
- if ( ! defined $parsed->{$section}->{'action'} ) {
+ my $select = ( $context eq 'config' ) ? 'action' : 'type';
+ if ( ! defined $parsed->{$section}->{$select} ) {
Abort ( $CODE->{'UNDEF_KEY'},
- "Key action on section ".$section." from file ".$file." MUST BE defined" );
- }
- $sect_type = $parsed->{$section}->{'action'};
+ "Key ".$select." on section ".$section." from file ".$file." MUST BE defined" );
+ }
+ $sect_type = $parsed->{$section}->{$select};
}
if ( $sect_type ne 'include' ) {
my ( $code, $msg ) = __Chk_section_struct ( $section, $sect_type, $parsed->{$section}, $context );
- print "$section, $sect_type, HASH $section, $context --> $msg\n" if ( ! defined $code );
if ( $code > 1 ) {
Warn ( $code, "Errors occur during parsing model from file ". $file );
Abort ( $code, $msg );
Modified: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=767&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (original)
+++ branches/next-gen/lib/PFTools/Logger.pm Fri Jul 2 15:29:13 2010
@@ -129,6 +129,54 @@
}
+# Returns undef on error
+sub deferredlogpipe {
+ my $ret = '';
+
+ DeferOutput() if $DEFERREDLOG;
+
+ unless ( open DEFERREDLOGPIPE, '-|', @_ ) {
+ Warn( $ERR_OPEN, "Unable to open pipe @_: $!" );
+ return;
+ }
+
+ while (<DEFERREDLOGPIPE>) {
+ chomp;
+ $ret .= $_;
+ }
+ close DEFERREDLOGPIPE;
+
+ UndeferOutput() if $DEFERREDLOG;
+
+ if ($deferbuffer) {
+ $deferredlogbuffer .= $deferbuffer;
+ $deferbuffer = undef;
+ }
+
+ RotateCursor() if $DEFERREDLOG;
+
+ return $ret;
+}
+
+sub deferredlogsystem {
+ my $ret;
+
+ DeferOutput() if ($DEFERREDLOG);
+
+ $ret = system(@_);
+
+ UndeferOutput() if ($DEFERREDLOG);
+
+ if ( defined $deferbuffer && $deferbuffer ne '' ) {
+ $deferredlogbuffer .= $deferbuffer;
+ $deferbuffer = undef;
+ }
+
+ RotateCursor() if ($DEFERREDLOG);
+
+ return $ret;
+}
+
sub DelLog {
$deferredlogbuffer = '';
}
Modified: branches/next-gen/lib/PFTools/Packages.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Packages.pm?rev=767&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Packages.pm (original)
+++ branches/next-gen/lib/PFTools/Packages.pm Fri Jul 2 15:29:13 2010
@@ -195,7 +195,7 @@
while ( <APTPOLICY> ) {
if (m/^ Installed: (.*)$/) {
$installed = $1;
- undef $installed if ( $installed eq '' || $installed eq '(none)' ) ;
+ undef $installed if ( $installed eq '' || $installed eq "(none)" ) ;
}
elsif (m/^ Candidate: (.*)$/) {
$available = $1;
Modified: branches/next-gen/lib/PFTools/Parser.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Parser.pm?rev=767&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Parser.pm (original)
+++ branches/next-gen/lib/PFTools/Parser.pm Fri Jul 2 15:29:13 2010
@@ -359,7 +359,7 @@
sub Parser_ini ($) {
my ( $file ) = @_;
- my $parse = new Config::IniFiles ( -file => $file, -allowedcommentchars => '@' );
+ my $parse = new Config::IniFiles ( -file => $file );
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