pf-tools commit: r768 [ccaillet-guest] - in /branches/next-gen: doc/networkfile-syntax lib/PFTools/Conf.pm tools/old2new_syntax
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Sat Jul 3 14:50:33 UTC 2010
Author: ccaillet-guest
Date: Sat Jul 3 14:50:33 2010
New Revision: 768
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=768
Log:
AJout premier jet incomplet et en cours de tools/old2new_syntax
Added:
branches/next-gen/tools/old2new_syntax
Modified:
branches/next-gen/doc/networkfile-syntax
branches/next-gen/lib/PFTools/Conf.pm
Modified: branches/next-gen/doc/networkfile-syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/doc/networkfile-syntax?rev=768&op=diff
==============================================================================
--- branches/next-gen/doc/networkfile-syntax (original)
+++ branches/next-gen/doc/networkfile-syntax Sat Jul 3 14:50:33 2010
@@ -9,27 +9,29 @@
? 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>
+ ! @ns ::= <NS_NAME>
+ ! @mx ::= <WEIGHT_MX> <MX_NAME>
+ ? dhcpvlan ::= <VLAN_NAME>
? console ::= (default|ttyS0,115200n8)
-
[<SITE_NAME>]
! type ::= site
+ ! state ::= ROOT|EDGE
+ ! zone_priv ::= <ZONE_NAME>
+ ? zone_pub ::= <ZONE_NAME>
? 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>
+ ? confdir ::= <PATH> define here the directory for configuration access refined by Get_source
[<NETWORK_NAME>]
! type ::= network
+ ? comment ::= <STR>
? 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
+ ! network ::= <NETWORK> define here the prefix in IPv4 format
+ ? network6 ::= <NETWORK> define here the prefix in IPv6 format
+ ! netmask ::= <NETMASK> define here the netmask in IPv4 format or in CIDR format e.g. /XX
+ ? netmask6 ::= <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>]
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=768&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Sat Jul 3 14:50:33 2010
@@ -140,6 +140,22 @@
'shortname' => 'undefined',
'alias' => 'undefined'
};
+$DEF_SECTIONS->{'network'}->{'zone'} = {
+ 'MANDATORY_KEYS' => [ 'serial','soa','mail','@ns','@mx' ],
+ 'comment' => 'undefined',
+ 'serial' => '(AUTO|.+)',
+ 'soa' => '[\w\-\.]+',
+ 'mail' => 'undefined',
+ 'refresh' => '(\d(M|H|D)|\d+)',
+ 'retry' => '(\d(M|H|D)|\d+)',
+ 'expire' => '(\d(M|H|D)|\d+)',
+ 'negttl' => '(\d(M|H|D)|\d+)',
+ 'ttl' => '(\d(M|H|D)|\d+)',
+ '@ns' => '[\w\-\.]+',
+ '@mx' => '\d+\s+[\w\-\.]+',
+ 'dhcpvlan' => '[\w\-]+',
+ 'console' => '(default|ttyS0,115200n8)'
+};
$DEF_SECTIONS->{'network'}->{'site'} = {
'comment' => 'undefined',
'location' => 'undefined',
@@ -147,13 +163,13 @@
'confdir' => 'undefined'
};
$DEF_SECTIONS->{'network'}->{'network'} = {
- 'MANDATORY_KEYS' => [ 'subnet','mask' ],
- 'comment' => '',
+ 'MANDATORY_KEYS' => [ 'network','netmask' ],
+ 'comment' => 'undefined',
'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',
+ 'network' => '([\d]{1,3}\.){3}[\d]{1,3}',
+ 'network6' => 'undefined',
+ 'netmask' => '(/\d{2}|([\d]{1,3}\.){3}[\d]{1,3})',
+ 'netmask6' => 'undefined',
'scope' => '(private|public)'
};
$DEF_SECTIONS->{'network'}->{'service'} = {
@@ -197,7 +213,6 @@
our @EXPORT_OK = qw();
-
my $DEBUG = 0 ;
# Global hash for substitution
@@ -207,8 +222,8 @@
my $FAKEDOMAINNAME;
our $DEFERREDLOG = 0;
-#################################################
-### Default value for PF-TOOLS configuration
+#####################################################################
+### Default value for PF-TOOLS configuration with old configuration
our $PFTOOLSCONF = "/etc/pf-tools.conf";
our $PF_STATUS_DIR = "/var/lib/pftools";
@@ -222,41 +237,60 @@
our $CVS_COMMAND = "";
our $CVS_BRANCHE = "";
-if ( -r $PFTOOLSCONF ) {
- my $newuid;
- my $newgid;
- my $dev;
- my $ino;
- my $mode;
- my $nlink;
- my $uid;
- my $gid;
- my $rdev;
- my $size;
- my $atime;
- my $mtime;
- my $ctime;
- my $blksize;
- my $blocks;
-
- ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
- $size, $atime, $mtime, $ctime, $blksize, $blocks
- ) = lstat($PFTOOLSCONF);
-
- if ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) )
- {
-
- my $result;
- my $return;
- unless ( $result = do $PFTOOLSCONF ) {
- warn "couldn't parse $PFTOOLSCONF: $@" if $@;
- warn "couldn't do $PFTOOLSCONF: $!" unless defined $return;
- warn "couldn't run $PFTOOLSCONF" unless $return;
- }
- }
- else {
- print STDERR "Ignoring weak config (check owner/group/mode)\n";
- }
+#############################################################
+### Default value for configuration with new method
+our $PF_CONFIG = {};
+$PF_CONFIG->{'path'} = {
+ 'status_dir' => '/var/lib/pftools',
+};
+$PF_CONFIG->{'vcs'} = {
+ 'type' => 'cvs',
+ 'user' => 'cvsguest',
+ 'rsh' => '/usr/local/sbin/cvs_rsh',
+ 'server' => 'cvs.private',
+ 'cvsroot' => '/var/lib/cvs/repository',
+ 'module' => 'config',
+ 'command' => '',
+ 'branche' => ''
+};
+
+sub Init_PF_CONFIG ($;$) {
+ my ( $config_file, $syntax ) = @_;
+
+# my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
+# $size, $atime, $mtime, $ctime, $blksize, $blocks
+# ) = lstat($PFTOOLSCONF);
+ if ( -r $PFTOOLSCONF ) {
+ my ( $dev, $ino, $mode, $nlink, $uid, $gid, @lstat_vars ) = lstat($PFTOOLSCONF);
+ unless ( $uid == 0 && $gid == 0 && S_IMODE($mode) == 0600 && S_ISREG($mode) ) {
+ Warn ( $CODE->{'RIGHTS'}, "Ignoring weak config (check owner/group/mode)" );
+ return 1;
+ }
+ }
+ else {
+ if ( $syntax eq 'nx' ) {
+ my $conf_parsed = Parser_ini ( $config_file );
+ Abort ( $CODE->{'SYNTAX'}, "Unable to parse configuration file ".$config_file ) if ( ! defined $conf_parsed );
+ foreach my $section ( keys %{$PF_CONFIG} ) {
+ next if ( ! defined $conf_parsed->{$section} );
+ foreach my $key ( keys %{$PF_CONFIG->{$section}} ) {
+ if ( defined $conf_parsed->{$section}->{$key} ) {
+ $PF_CONFIG->{$section}->{$key} = $conf_parsed->{$section}->{$key};
+ }
+ }
+ }
+ }
+ else {
+ my $result;
+ my $return;
+ unless ( $result = do $PFTOOLSCONF ) {
+ warn "couldn't parse $PFTOOLSCONF: $@" if $@;
+ warn "couldn't do $PFTOOLSCONF: $!" unless defined $return;
+ warn "couldn't run $PFTOOLSCONF" unless $return;
+ }
+ }
+ }
+ return 0;
}
sub Init_SUBST ($;$$) {
@@ -509,20 +543,22 @@
return __Merge_conf_new ( $parsed, $hash_subst, $context );
}
-sub Load_conf ($$$;$) {
+sub Load_conf ($$;$$) {
my ( $file, $hash_subst, $context, $syntax ) = @_;
my $sect_type;
my $parsed;
- if ( $context !~ /^$ALLOWED_PARSING_CONTEXT$/ ) {
+ if ( defined $context && $context !~ /^$ALLOWED_PARSING_CONTEXT$/ ) {
Abort ( $CODE->{'INVALID_CONTEXT'}, "Context ".$context
." doesn't match ".$ALLOWED_PARSING_CONTEXT );
}
- if ( $syntax eq 'nx' ) {
+ 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;
}
if ( ! defined $parsed ) {
Abort ( $CODE->{'SYNTAX'}, "Parsing error for file ".$file );
Added: branches/next-gen/tools/old2new_syntax
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/tools/old2new_syntax?rev=768&op=file
==============================================================================
--- branches/next-gen/tools/old2new_syntax (added)
+++ branches/next-gen/tools/old2new_syntax Sat Jul 3 14:50:33 2010
@@ -1,0 +1,121 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+foreach my $host ( keys %{$host_parsed} ) {
+ my $new_host = {};
+ my $old = $host_parsed->{$host};
+ next if ( $old->{'type'} !~ /-server$/ );
+ $new_host->{'hostgroup'}->{'hostname'} = $host;
+ foreach my $key ( keys %{$old} ) {
+ if ( $key eq 'shortname' ) {
+ $new_host->{'dns'}->{'shortname'} = $old->{'shortname'};
+ }
+ elsif ( $key eq 'ether' ) {
+ foreach my $num ( sort keys $old->{'ether'} ) {
+ $new_host->{'interface::eth0'}->{'mac.'.$num} = $old->{$key}->{$num};
+ }
+ }
+ elsif ( $key =~ /^arch|distrib|deploymode$/ ) {
+ my $new_key = ( $key eq 'deploymode' ) ? 'mode' : $key;
+ if ( ref $old->{$key} eq 'HASH' ) {
+ foreach my $subkey ( keys %{$old->{$key}} ) {
+ if ( $subkey eq 'default' ) {
+ $new_host->{'deployment'}->{$newkey} = $old->{$key};
+ }
+ else {
+ $new_host->{'deployment'}->{$new_key.'.'.$subkey} = $old->{$key};
+ }
+ }
+ }
+ else {
+ $new_host->{'deployment'}->{$newkey} = $old->{$key};
+ }
+ }
+ elsif ( $key =~ /^order|number$/ ) {
+ $new_host->{'hostgroup'}->{$key} = $old->{$key};
+ }
+ elsif ( $key eq 'interface' ) {
+ foreach my $iface ( keys %{$old->{$key}} ){
+ my $vlan = $old->{$key}->{$iface};
+ $new_host->{'interface::'.$iface}->{'vlan'} = $vlan;
+ if ( defined $old->{'ipstart'}->{$vlan} ) {
+ $new_host->{'interface::'.$iface}->{'ipv4'} = $old->{'ipstart'}->{$vlan};
+ }
+ elsif ( defined $old->{'ip'}->{$vlan} ) {
+ foreach my $subkey ( keys %{$old->{'ip'}->{$vlan}} ) {
+ if ( $subkey eq 'default' && ! defined $new_host->{'interface::'.$iface}->{'ipv4'} ) {
+ $new_host->{'interface::'.$iface}->{'ipv4'} = $old->{'ip'}->{$vlan}->{$subkey};
+ }
+ else {
+ $new_host->{'interface::'.$iface}->{'ipv4.'$subkey} = $old->{'ip'}->{$vlan}->{$subkey};
+ }
+ }
+ }
+ else {
+ $new_host->{'interface::'.$iface}->{'ipv4'} = $old->{'ipstart'}->{'default'};
+ }
+ if ( defined $old->{$iface} ) {
+ foreach my $route ( keys %{$old->{$iface}} ) {
+ if ( ref $old->{$iface}->{$route} eq 'HASH' ) {
+ foreach my $subkey ( keys %{$old->{$iface}->{$route}} ) {
+ if ( $subkey eq 'default' ) {
+ push ( @{$new_host->{'interface::'.$iface}->{'@route'}}, $old->{$iface}->{$route}->{$subkey} );
+ }
+ else {
+ push ( @{$new_host->{'interface::'.$iface}->{'@route.'.$subkey}}, $old->{$iface}->{$route}->{$subkey} );
+ }
+ }
+ }
+ }
+ if ( $iface =~ /^bond/ ) {
+ if ( ref $old->{'bonding'}->{$iface} eq 'HASH' ) {
+ foreach my $subkey ( keys %{$old->{'bonding'}->{$iface}} ) {
+ if ( $subkey eq 'default' ) {
+ $new_host->{'interface::'.$iface}->{'slaves'} = $old->{$key}->{$bond};
+ }
+ else {
+ $new_host->{'interface::'.$iface}->{'slaves.'.$subkey} = $old->{$key}->{$bond};
+ }
+ }
+ }
+ else {
+ $new_host->{'interface::'.$iface}->{'slaves'} = $old->{$key}->{$bond};
+ }
+ }
+ }
+ }
+ }
+ elsif ( $key eq 'alias' ) {
+ foreach my $alias ( keys %{$old->{$key}} ) {
+ $new_host->{'dns'}->{'alias.'.$alias} = $old->{$key}->{$alias};
+ }
+ }
+ }
+}
+# 'cor1-spawn%%' => {
+# 'pxefilename' => {
+# 'default' => 'vmlinuz-2.6.26.5-universal-grm2.1.12'
+# },
+# 'cmdline' => {
+# 'default' => 'bonding.mode=active-backup bonding.miimon=100'
+# },
+# 'console' => {
+# 'default' => 'default'
+# },
+# 'ipstart' => {
+# 'vlan-sv2-middledsi' => '41',
+# 'vlan-sv2-admindsi' => '41',
+# 'vlan-cor1-sout' => '97',
+# 'default' => '167.0'
+# },
+# 'comment' => 'Spawning server',
+# 'filename' => {
+# 'default' => 'pxelinux.0'
+# },
+# 'umlfilename' => {
+# 'default' => 'linux-uml-elf-2.4.26-gr1.9.15'
+# }
+# }
+# };
More information about the pf-tools-commits
mailing list