pf-tools/pf-tools: 12 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Nov 23 10:53:56 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/7b37884d244d
changeset: 1050:7b37884d244d
user: "Christophe Caillet <quadchris at free.fr>"
date: Wed Nov 17 15:34:06 2010 +0100
description:
use Readonly and constants, perltidy
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/2276964de985
changeset: 1051:2276964de985
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Nov 19 10:07:56 2010 +0100
description:
Adding is_private_vlan for checking vlan's scope
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/2d1d3c7dc706
changeset: 1052:2d1d3c7dc706
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Nov 19 11:02:17 2010 +0100
description:
Fix some perlcritics
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/62a4a239f494
changeset: 1053:62a4a239f494
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Nov 19 11:03:24 2010 +0100
description:
Fix some perlcritics and split private and public parts of hosts
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/b5c5fbca32b8
changeset: 1054:b5c5fbca32b8
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Nov 19 11:04:08 2010 +0100
description:
Fix tests according to the split of private and public parts for networks and hosts
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/51b881d62da9
changeset: 1055:51b881d62da9
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Nov 19 23:57:50 2010 +0100
description:
Split some parts of check_section_structure, perlcritics and some optims complexity from 25 to 23
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/db81004d2b5b
changeset: 1056:db81004d2b5b
user: "Christophe Caillet <quadchris at free.fr>"
date: Fri Nov 19 23:59:32 2010 +0100
description:
Merging
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/9f9f5053b43f
changeset: 1057:9f9f5053b43f
user: "Christophe Caillet <quadchris at free.fr>"
date: Sat Nov 20 00:02:11 2010 +0100
description:
Oops ... damned semi-colon
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/7764ca70240f
changeset: 1058:7764ca70240f
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Nov 23 09:30:01 2010 +0100
description:
Better check and perlcritic
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/555fa0da8add
changeset: 1059:555fa0da8add
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Nov 23 09:30:09 2010 +0100
description:
Fix tests
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/93773cec5413
changeset: 1060:93773cec5413
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Nov 23 10:48:42 2010 +0100
description:
Removing dead code and complexity is now under 20
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/76354153ecef
changeset: 1061:76354153ecef
user: "Christophe Caillet <quadchris at free.fr>"
date: Tue Nov 23 11:53:01 2010 +0100
description:
Fix: now make_zone is compliant with the split of private and public parts
diffstat:
2 files changed, 1 insertion(+), 1 deletion(-)
lib/PFTools/Conf/Syntax.pm | 1 +
t/13.conf.cfg1/config-export/COMMON/private-network | 1 -
diffs (1235 lines):
diff -r dd4873cacd2e -r 76354153ecef lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm Mon Nov 22 11:01:19 2010 +0100
+++ b/lib/PFTools/Conf/Host.pm Tue Nov 23 11:53:01 2010 +0100
@@ -27,6 +27,7 @@
use Fcntl ':mode';
use List::MoreUtils qw( any );
use POSIX qw(ceil floor);
+use Readonly;
use PFTools::Conf::Syntax qw( $DEF_SECTIONS );
use PFTools::Net;
@@ -38,6 +39,12 @@
);
our @EXPORT_OK = qw();
+
+############################
+# Constants
+
+Readonly::Scalar my $ALPHANUM_CARDINAL => 26;
+Readonly::Scalar my $DIGITS_CARDINAL => 10;
=head2 add_host($args)
@@ -73,9 +80,7 @@
sub add_host {
my ($arguments_ref) = @_;
- my ($start_file, $host_type, $host_ref,
- $global_config, $pf_config
- )
+ my ( $start_file, $host_type, $host_ref, $global_config, $pf_config )
= @{$arguments_ref}{
qw( start_file host_type host_ref
global_config pf_config )
@@ -85,10 +90,8 @@
my $dep_def = $DEF_SECTIONS->{'host'}->{'deployment'};
my $hostname_model = $host_ref->{'hostgroup'}->{'hostname'};
- unless (
- $hostname_model
- =~ m{ \A $pf_config->{'regex'}->{'hostname_model'} \z }xms
- )
+ unless ( $hostname_model
+ =~ m{ \A $pf_config->{'regex'}->{'hostname_model'} \z }xms )
{
croak qq{Invalid hostname model name $hostname_model};
}
@@ -98,10 +101,8 @@
my ( $host_last, $node_last )
= __get_host_indexes( $host_ref->{'hostgroup'}, $hostname_model );
- my $site_list = get_site_list_from_section(
- $host_ref->{'hostgroup'},
- $global_config
- );
+ my $site_list = get_site_list_from_section( $host_ref->{'hostgroup'},
+ $global_config );
foreach my $site ( @{$site_list} ) {
my $site_part_ref = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
@@ -118,8 +119,7 @@
my $zone = $site_part_ref->{'zone'};
my $prefix = __get_site_prefix( $site, $site_part_ref );
my $host_list = __build_host_list(
- {
- 'last_hostnum' => $host_last,
+ { 'last_hostnum' => $host_last,
'last_hostnode' => $node_last,
'host_part_ref' => $host_part_ref,
'hostname_model' => $hostname_model,
@@ -132,8 +132,8 @@
my $index = $host_list->{$hostname}->{'index'};
my $hostnum = $host_list->{$hostname}->{'hostnum'};
my $hostnode = $host_list->{$hostname}->{'hostnode'} || 0;
- my $dhcpvlan =
- $host_ref->{'deployment'}->{"dhcpvlan\.$host_number"}
+ my $dhcpvlan
+ = $host_ref->{'deployment'}->{"dhcpvlan\.$host_number"}
|| $host_ref->{'deployment'}->{'dhcpvlan'}
|| $site_part_ref->{'dhcpvlan'};
@@ -143,15 +143,15 @@
$host_part_ref->{$hostname}->{'deployment'}
= __build_deployment_entry_for_host(
- $host_type, $host_ref, $hostclass,
+ $host_type, $host_ref, $hostclass,
$host_number, $dhcpvlan
);
if ( $host_type eq 'host' ) {
$host_part_ref->{$hostname}->{'boot'}
= __build_boot_entry_for_host(
- $host_ref, $host_number,
- $hostname, $site_part_ref, $pf_config,
+ $host_ref, $host_number, $hostname,
+ $site_part_ref, $pf_config,
);
$host_part_ref->{$hostname}->{'dns'}->{'resolver'}
= $host_ref->{'dns'}->{"resolver\.$host_number"}
@@ -162,8 +162,7 @@
my @if_list = __get_host_interfaces($host_ref);
foreach my $iface (@if_list) {
my $new_iface_ref = __build_iface_entry(
- {
- iface_name => $iface,
+ { iface_name => $iface,
hostname => $hostname,
hostnum => $hostnum,
hostnode => $hostnode,
@@ -188,7 +187,8 @@
)
{
my $name = $1;
- my $tag = __get_vlan_tag_from_site( $new_iface_ref->{'vlan'},
+ my $tag
+ = __get_vlan_tag_from_site( $new_iface_ref->{'vlan'},
$site_part_ref );
$iface_name = qq{$name.$tag};
}
@@ -202,35 +202,32 @@
= qq($iface.$hostname.$new_iface_ref->{'vlan'});
}
- if ($new_iface_ref->{'vlan'} eq $dhcpvlan
- and $host_type eq 'host'
- and not $new_iface_ref->{'mac'}
- )
+ if ( $new_iface_ref->{'vlan'} eq $dhcpvlan
+ and $host_type eq 'host'
+ and not $new_iface_ref->{'mac'} )
{
- croak qq{ERROR: $hostname: MAC address is mandatory on $iface for DHCP};
+ croak
+ qq{ERROR: $hostname: MAC address is mandatory on $iface for DHCP};
}
foreach my $ip_type ( 'ipv4', 'ipv6' ) {
next unless $pf_config->{'features'}->{$ip_type};
- my $ip_type_suffix = get_suffix_from_ip_type( $ip_type );
- my $addr_key = qq{BY_ADDR$ip_type_suffix};
- my $zone_key = qq{ZONE$ip_type_suffix};
- my $dhcp_key = qq{DHCP$ip_type_suffix};
+ my $ip_type_suffix = get_suffix_from_ip_type($ip_type);
+ my $addr_key = qq{BY_ADDR$ip_type_suffix};
+ my $zone_key = qq{ZONE$ip_type_suffix};
+ my $dhcp_key = qq{DHCP$ip_type_suffix};
my $zone_part_ref
- = $global_config->{$zone_key}->{'BY_NAME'}
- ->{$zone}->{'BY_SITE'}->{$site};
+ = $global_config->{$zone_key}->{'BY_NAME'}->{$zone};
my $dhcp_part_ref
- = $global_config->{$dhcp_key}->{'BY_SITE'}
- ->{$site};
+ = $global_config->{$dhcp_key}->{'BY_SITE'}->{$site};
$site_part_ref->{'HOST'}->{$addr_key}
->{ $new_iface_ref->{$ip_type} }
= qq/$hostname.$new_iface_ref->{'vlan'}/;
__add_zone_entry(
- {
- 'hostname' => $hostname,
+ { 'hostname' => $hostname,
'hostclass' => $hostclass,
'host_part_ref' => $host_part_ref,
'host_number' => $host_number,
@@ -246,17 +243,15 @@
}
);
- my $resolver =
- $host_ref->{'dns'}->{"resolver.$host_number"}
+ my $resolver
+ = $host_ref->{'dns'}->{"resolver.$host_number"}
|| $host_ref->{'dns'}->{'resolver'};
- if ($new_iface_ref->{'vlan'} eq $dhcpvlan
- and $host_type eq 'host'
- )
+ if ( $new_iface_ref->{'vlan'} eq $dhcpvlan
+ and $host_type eq 'host' )
{
__add_dhcp_entry(
- {
- 'dhcp_part_ref' => $dhcp_part_ref,
+ { 'dhcp_part_ref' => $dhcp_part_ref,
'dhcp_vlan' => $dhcpvlan,
'vlan_def_ref' =>
$site_part_ref->{'NETWORK'}->{'BY_NAME'}
@@ -269,7 +264,7 @@
'pxefilename' =>
$host_ref->{'boot'}->{'pxefilename'},
}
- )
+ );
}
}
}
@@ -314,12 +309,11 @@
sub add_server {
my ($arguments_ref) = @_;
- my ($start_file, $section_name, $section_ref,
+ my ($start_file, $section_name, $section_ref,
$global_config, $pf_config
)
- = @{$arguments_ref}{
- qw( start_file section_name section_ref global_config pf_config )
- };
+ = @{$arguments_ref}
+ { qw( start_file section_name section_ref global_config pf_config ) };
my $host_ref = __build_host_from_server( $section_name, $section_ref );
@@ -331,7 +325,7 @@
pf_config => $pf_config,
};
- return add_host( $add_host_args_ref );
+ return add_host($add_host_args_ref);
}
=head2 __get_site_prefix ( $site_name, $site_ref )
@@ -404,15 +398,18 @@
if ( $last_node and not $nodes ) {
croak qq{ERROR: $hostname_model: bad node (_) definition};
}
- if ( $last_node and ceil( log($last_node) / log(26) ) > $nodes ) {
- croak qq{ERROR: $hostname_model: $last_node exceeds maximum nodes allowed};
+ if ( $last_node
+ and ceil( log($last_node) / log($ALPHANUM_CARDINAL) ) > $nodes )
+ {
+ croak
+ qq{ERROR: $hostname_model: $last_node exceeds maximum nodes allowed};
}
# Checking hostnum
if ( $last_num and not $digits ) {
croak qq{ERROR: $hostname_model: bad num (%) definition};
}
- if ( $last_num and $last_num > 10**$digits ) {
+ if ( $last_num and $last_num > $DIGITS_CARDINAL**$digits ) {
croak qq{ERROR: $last_num exceeds maximum host numbers allowed};
}
@@ -431,8 +428,7 @@
sub __get_hostnum_from_model {
my ( $model, $num, $node ) = @_;
- my ( $digits_string, $nodes_string )
- = $model =~ m{
+ my ( $digits_string, $nodes_string ) = $model =~ m{
( # $digits_string
(?:
[%]+
@@ -560,9 +556,8 @@
ip_type subnet_ref ipstart hostnum hostnode nodes
site_name site_ref
);
- my (
- $ip_type, $subnet_ref, $ipstart, $hostnum, $hostnode, $nodes,
- $site_name, $site_ref
+ my ($ip_type, $subnet_ref, $ipstart, $hostnum,
+ $hostnode, $nodes, $site_name, $site_ref
) = @{$arguments_ref}{@argument_names};
unless ( ref $subnet_ref eq 'NetAddr::IP' ) {
@@ -622,17 +617,20 @@
sub __build_host_from_server {
my ( $server_name, $server_ref ) = @_;
- my $result = {
- hostgroup => {
- hostname => $server_name,
- },
+ my $result = { hostgroup => { hostname => $server_name, }, };
+ my $constant_keys = {
+ 'comment' => 1,
+ 'order' => 1,
+ 'number' => 1,
+ 'nodes' => 1,
+ 'site' => 1,
};
my $iface_index = 0;
foreach my $key ( keys %{$server_ref} ) {
next if $key eq 'type' or $key =~ m{ \A __ }xms;
- my ( $key_type, $spec, $hostnum ) = split( m{ [.] }xms, $key );
+ my ( $key_type, $spec, $hostnum ) = split m{ [.] }xms, $key;
if ( $key_type eq 'alias' ) {
$result->{'dns'}->{$key} = $server_ref->{$key};
next;
@@ -655,7 +653,7 @@
next;
}
- if ( $key_type =~ m{ \A (comment|order|number|nodes|site) \z }xms ) {
+ if ( $constant_keys->{$key_type} ) {
$result->{'hostgroup'}->{$key_type} = $server_ref->{$key};
next;
}
@@ -719,15 +717,12 @@
qq{ERROR: site $site_name host $hostname: unknown $vlan_name for $iface_name};
}
- my $result = {
- 'vlan' => $vlan_name,
- };
+ my $result = { 'vlan' => $vlan_name, };
# Iface option(s)
- if (my $iface_options
+ if ( my $iface_options
= $iface_section_ref->{ 'iface_opt.' . $host_number }
- || $iface_section_ref->{'iface_opt'}
- )
+ || $iface_section_ref->{'iface_opt'} )
{
$result->{'iface_opt'} = $iface_options;
}
@@ -760,10 +755,9 @@
)?
\z
}xms;
- if ($iface_tag
+ if ( $iface_tag
and $iface_tag =~ m{\A \d+ \z}xms
- and $iface_tag ne $vlan_ref->{'tag'}
- )
+ and $iface_tag ne $vlan_ref->{'tag'} )
{
croak
qq{ERROR: $iface_tag for $iface_section_name differs from $vlan_name def};
@@ -795,12 +789,10 @@
foreach my $ip_type (qw( ipv4 ipv6 )) {
next unless $pf_config->{'features'}->{$ip_type};
- my $subnet_ref
- = get_subnet_from_vlan( $ip_type, $vlan_ref );
+ my $subnet_ref = get_subnet_from_vlan( $ip_type, $vlan_ref );
$result->{$ip_type} = __get_host_real_ip(
- {
- ip_type => $ip_type,
+ { ip_type => $ip_type,
host_number => $host_number,
iface_section_ref => $iface_section_ref,
hostnum => $hostnum,
@@ -812,7 +804,7 @@
}
);
- my $suffix = get_suffix_from_ip_type( $ip_type );
+ my $suffix = get_suffix_from_ip_type($ip_type);
my $route_key = '@route' . $suffix;
my $gw_key = 'gateway' . $suffix;
@@ -825,13 +817,12 @@
foreach my $route (@route_list) {
my $new_route = __get_route(
- {
- route => $route,
- net_site_ref => $net_site_ref,
- hostname => $hostname,
- vlan_name => $vlan_name,
- gw_key => $gw_key,
- subnet_ref => $subnet_ref,
+ { route => $route,
+ net_site_ref => $net_site_ref,
+ hostname => $hostname,
+ vlan_name => $vlan_name,
+ gw_key => $gw_key,
+ subnet_ref => $subnet_ref,
}
);
@@ -851,8 +842,9 @@
ip_type host_number iface_section_ref hostnum hostnode
nodes subnet_ref site_name site_ref
);
- my ($ip_type, $host_number, $iface_section_ref, $hostnum, $hostnode,
- $nodes, $subnet_ref, $site_name, $site_ref
+ my ($ip_type, $host_number, $iface_section_ref,
+ $hostnum, $hostnode, $nodes,
+ $subnet_ref, $site_name, $site_ref
) = @{$arguments_ref}{@argument_names};
my $ip_type_dot_host_number = join q{.}, $ip_type, $host_number;
@@ -938,8 +930,7 @@
if ($via) {
my $gateway = __build_route_gateway(
- {
- via => $via,
+ { via => $via,
net_site_ref => $net_site_ref,
hostname => $hostname,
vlan_name => $vlan_name,
@@ -1079,7 +1070,7 @@
$vlan_def_ref, $iface_def_ref, $pxefilename
) = @{$arguments_ref}{@argument_names};
- my $ip_type_suffix = get_suffix_from_ip_type( $ip_type );
+ my $ip_type_suffix = get_suffix_from_ip_type($ip_type);
unless ( $dhcp_part_ref->{$dhcp_vlan} ) {
$dhcp_part_ref->{$dhcp_vlan} = {
'subnet' => $vlan_def_ref->{"network$ip_type_suffix"},
@@ -1120,8 +1111,7 @@
$iface_def, $zone_part_ref, $dns_def_ref, $ip_type,
$zone_name, $shortname, $site, $global_config,
$index
- )
- = @{$arguments_ref}{@argument_names};
+ ) = @{$arguments_ref}{@argument_names};
unless ($hostname) {
croak q{ERROR: $hostname is mandatory};
@@ -1135,16 +1125,22 @@
my $zone_key = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
- unless ( $zone_part_ref->{$hostclass} ) {
- push @{
- $global_config->{$zone_key}->{'BY_NAME'}->{$zone_name}
- ->{'__hostclass_order'}->{$site}
- },
+ my $vlan = $iface_def->{'vlan'};
+ my $zone_entry =
+ ( is_private_vlan ($vlan, $global_config, $site) )
+ ? $zone_part_ref->{'BY_SITE'}->{$site}
+ : $zone_part_ref->{'ALL_SITES'};
+ my $added_hostclass = grep m{ \A $hostclass \z }xms,
+ @{ $zone_part_ref->{'__hostclass_order'}->{$site} };
+
+ if ( not defined $zone_entry->{$hostclass} and
+ not $added_hostclass
+ ) {
+ push @{ $zone_part_ref->{'__hostclass_order'}->{$site} },
$hostclass;
}
- my $vlan = $iface_def->{'vlan'};
- $zone_part_ref->{$hostclass}->{ $hostname . '.' . $vlan } = "A\t$zone_ip";
+ $zone_entry->{$hostclass}->{"$hostname\.$vlan"} = "A\t$zone_ip";
my $shortname_vlan = $dns_def_ref->{"shortname\.$host_number"}
|| $dns_def_ref->{'shortname'};
@@ -1153,14 +1149,14 @@
}
if ( $shortname ne $hostname and $shortname_vlan eq $vlan ) {
- if ( not $zone_part_ref->{$hostclass}->{"$shortname\.$vlan"} ) {
- $zone_part_ref->{$hostclass}->{"$shortname\.$vlan"}
+ if ( not $zone_entry->{$hostclass}->{"$shortname\.$vlan"} ) {
+ $zone_entry->{$hostclass}->{"$shortname\.$vlan"}
= [ "A\t$zone_ip", ];
}
else {
- push @{ $zone_part_ref->{$hostclass}->{"$shortname\.$vlan"} },
+ push @{ $zone_entry->{$hostclass}->{"$shortname\.$vlan"} },
qq{A\t$zone_ip};
- $zone_part_ref->{$hostclass}->{$shortname}
+ $zone_entry->{$hostclass}->{$shortname}
= qq{CNAME\t$shortname.$vlan};
}
}
@@ -1173,9 +1169,9 @@
$host_part_ref->{ $alias . $index } = $hostname;
if ( $dns_def_ref->{$key} eq $vlan ) {
- $zone_part_ref->{$hostclass}->{$alias}
+ $zone_entry->{$hostclass}->{$alias}
= qq{CNAME\t$shortname\.$vlan};
- $zone_part_ref->{$hostclass}->{ $alias . $index }
+ $zone_entry->{$hostclass}->{ $alias . $index }
= qq{CNAME\t$hostname\.$vlan};
}
}
@@ -1198,6 +1194,10 @@
# Checking path for PXE elements kernel, initrd ...
my $boot_def = $DEF_SECTIONS->{'host'}->{'boot'};
+ my $excluded_keys = {
+ 'console' => 1,
+ 'cmdline' => 1,
+ };
BOOT_KEY:
foreach my $key ( keys %{$boot_def} ) {
@@ -1215,11 +1215,9 @@
# This check should be done only on the deploy hosts
if ($hostname =~ m{ \A $pf_config->{'regex'}->{'deploy_hosts'} \z }xms
- and $key !~ m{ \A (console|cmdline) \z }xms
- )
+ and $excluded_keys->{$key})
{
- my $filename = join '/', $pf_config->{'path'}->{'tftp_dir'},
- $value;
+ my $filename = "$pf_config->{'path'}->{'tftp_dir'}/$value";
carp qq{WARNING: host $hostname: $filename doesn't exist};
}
@@ -1295,21 +1293,19 @@
sub __build_host_list {
my ($arguments_ref) = @_;
- my ($last_hostnum, $last_hostnode, $host_part_ref,
+ my ($last_hostnum, $last_hostnode, $host_part_ref,
$hostname_model, $prefix
)
- = @{$arguments_ref}{
- qw( last_hostnum last_hostnode host_part_ref hostname_model prefix )
+ = @{$arguments_ref}
+ { qw( last_hostnum last_hostnode host_part_ref hostname_model prefix )
};
my $result = {};
foreach my $hostnum ( 0 .. $last_hostnum ) {
foreach my $hostnode ( 0 .. $last_hostnode ) {
my $hostname
- = __get_hostname_from_model(
- $hostname_model, $hostnum,
- $hostnode, $prefix
- );
+ = __get_hostname_from_model( $hostname_model, $hostnum,
+ $hostnode, $prefix );
# Only carp, not croak, on already defined hostname
if ( $host_part_ref->{$hostname} ) {
@@ -1317,11 +1313,8 @@
next;
}
- my $index
- = __get_hostnum_from_model(
- $hostname_model, $hostnum,
- $hostnode
- );
+ my $index = __get_hostnum_from_model( $hostname_model, $hostnum,
+ $hostnode );
my $host_number = $hostnum . ( $hostnode ? $hostnode : q{} );
$result->{$hostname} = {
'hostnum' => $hostnum,
@@ -1337,6 +1330,5 @@
return $result;
}
-
1; # Magic true value required at end of module
diff -r dd4873cacd2e -r 76354153ecef lib/PFTools/Conf/Network.pm
--- a/lib/PFTools/Conf/Network.pm Mon Nov 22 11:01:19 2010 +0100
+++ b/lib/PFTools/Conf/Network.pm Tue Nov 23 11:53:01 2010 +0100
@@ -83,7 +83,7 @@
my ($start_file, $section_name, $section_ref,
$global_config, $pf_config
)
- = @$args{
+ = @{$args}{
qw( start_file section_name section_ref global_config pf_config )
};
@@ -100,6 +100,7 @@
$zone_part->{$section_name} = {
'SOA' => $section_ref,
'BY_SITE' => {},
+ 'ALL_SITES' => {},
'__network_order' => {},
'__hostclass_order' => {},
};
@@ -145,7 +146,7 @@
my ($start_file, $section_name, $section_ref,
$global_config, $pf_config
)
- = @$args{
+ = @{$args}{
qw( start_file section_name section_ref global_config pf_config )
};
@@ -200,7 +201,6 @@
$site_part->{$section_name}->{'NETWORK'}->{$addr_key} = {};
$site_part->{$section_name}->{'HOST'}->{$addr_key} = {};
$zone_part->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$section_name} = {};
-# $zone_part->{'ALL_SITES'} = {};
$zone_part->{'BY_SITE'}->{$section_name} = $zone;
$dhcp_part->{'BY_SITE'}->{$section_name} = {
$dhcpvlan => {
@@ -250,7 +250,7 @@
my ($start_file, $section_name, $section_ref,
$global_config, $pf_config
)
- = @$args{
+ = @{$args}{
qw( start_file section_name section_ref global_config pf_config )
};
@@ -393,7 +393,7 @@
my ($args) = @_;
my ($ref_net, $subnet_ref, $site, $ip_type, $net_name, $global_config)
- = @$args{
+ = @{$args}{
qw( ref_net subnet_ref site ip_type net_name global_config )
};
@@ -416,7 +416,12 @@
}
push @{ $zone_part->{'__network_order'}->{$site} }, $net_name;
- $zone_part->{'BY_SITE'}->{$site}->{$net_name} = $zone_ref;
+ if ( is_private_vlan ($net_name, $global_config, $site) ) {
+ $zone_part->{'BY_SITE'}->{$site}->{$net_name} = $zone_ref;
+ }
+ else {
+ $zone_part->{'ALL_SITES'}->{$net_name} = $zone_ref;
+ }
return 1;
}
diff -r dd4873cacd2e -r 76354153ecef lib/PFTools/Conf/Syntax.pm
--- a/lib/PFTools/Conf/Syntax.pm Mon Nov 22 11:01:19 2010 +0100
+++ b/lib/PFTools/Conf/Syntax.pm Tue Nov 23 11:53:01 2010 +0100
@@ -135,6 +135,8 @@
'interface' => {
'MANDATORY_KEYS' => [ 'vlan', 'ipv4', 'slaves' ],
'mac' => '([0-9a-f]{2}:){5}[0-9a-f]{2}',
+ 'options' => 'undefined',
+ 'mode' => '(active-backup|802.3ad|[\d]+)',
'vlan' => '[a-z][a-z0-9\-]+[a-z0-9]',
'ipv4' => '([\d]{1,3})((\.[\d]{1,3}){1,3})?',
'slaves' => 'e(th)?\d+(\s*,\s*e(th)?\d+)+',
@@ -153,6 +155,7 @@
},
'hostgroup' => {
'MANDATORY_KEYS' => [ 'number', 'hostname' ],
+ 'comment' => 'undefined',
'site' => '(ALL|[\w\-]+(\s*,\s*[\w\-]+)*)',
'model' => 'undefined',
'number' => '[\d]+',
@@ -167,6 +170,8 @@
'pxefilename' => 'undefined',
'kernel' => 'undefined',
'initrd' => 'undefined',
+ 'kerneluml' => 'undefined',
+ 'initrduml' => 'undefined',
'cmdline' => 'undefined',
'console' => '(default|ttyS0,115200n8)',
},
@@ -221,6 +226,7 @@
'comment' => 'undefined',
'site' => '(ALL|[\w\-]+(\s*,\s*[\w\-]+)*)',
'number' => '\d+',
+ 'order' => '[\d]+',
'ipv4' => '([\d]{1,3})((\.[\d]{1,3}){1,3})?',
'ipv6' => 'undefined',
'alias' => '[a-z][a-z0-9\-]+[a-z0-9]',
@@ -229,6 +235,7 @@
'service' => {
'MANDATORY_KEYS' => [ 'site', '@host' ],
'comment' => 'undefined',
+ 'site' => '(ALL|[\w\-]+(\s*,\s*[\w\-]+)*)',
'@host' => '[\w\-\:\/]+',
},
},
@@ -260,6 +267,7 @@
},
'removefile' => {},
'mkdir' => {
+ 'depends' => 'undefined',
'owner' => '([\d]+|[a-z\d\-]+)',
'group' => '([\d]+|[a-z\d\-]+)',
'mode' => '[0-7]?[0-7]{3}',
@@ -270,6 +278,7 @@
},
'addlink' => {
'MANDATORY_KEYS' => ['source'],
+ 'depends' => 'undefined',
'source' => 'undefined',
'on_config' => 'undefined',
'before_change' => 'undefined',
@@ -280,11 +289,12 @@
'MANDATORY_KEYS' => [ 'source', 'fstype', 'options' ],
'depends' => 'undefined',
'source' => 'undefined',
- 'fstype' => '(nfs|ext[2-4]|btrfs|cifs)',
- 'options' => 'undefined',
- 'mode' => '[0-7]?[0-7]{3}',
+ 'fstype' => '(nfs|ext[2-4]|btrfs|cifs)',
+ 'options' => 'undefined',
+ 'mode' => '[0-7]?[0-7]{3}',
},
'installpkg' => {
+ 'depends' => 'undefined',
'version' => 'undefined',
'on_config' => 'undefined',
'before_change' => 'undefined',
@@ -292,6 +302,7 @@
'after_change' => 'undefined',
},
'purgepkg' => {
+ 'depends' => 'undefined',
'version' => 'undefined',
'on_config' => 'undefined',
'before_change' => 'undefined',
@@ -329,94 +340,84 @@
my $int_context = $context eq 'model' ? 'host' : $context;
- if ( !defined $DEF_SECTIONS->{$int_context}->{$section_type} ) {
+ if ( not defined $DEF_SECTIONS->{$int_context}->{$section_type} ) {
croak qq{ERROR: Invalid section type $section_type};
}
my $definition = $DEF_SECTIONS->{$int_context}->{$section_type};
-
- my ( $iface_type, $section_tmp );
- if ( $context eq 'host' or $context eq 'model' ) {
- unless (
- $section_name
- =~ m{
+ my $iface_type; my $parsed_keys_list = {};
+ my $check_mandatory = 1;
+ if ( $section_type eq 'interface' ) {
+ ( $iface_type = $section_name ) =~
+ s{
\A
- \Q$section_type\E
- (?:
- ::
- (?: # logical interface name
- (?<iftype>eth|bond) [\d]+ # real interface name
- (?: # optional 802.1Q tag
- [.]
- TAG [\d]+
- )?
- )
- )?
+ \Q$section_type\E
+ (?:
+ ::
+ (?: # logical interface name
+ (?<iftype>eth|bond) [\d]+ # real interface name
+ (?: # optional 802.1Q tag
+ [.]
+ TAG [\d]+
+ )?
+ )
+ )?
\z
- }xms
- )
- {
- croak qq{ERROR: Invalid section name $section_name in file $file};
- }
- $iface_type = $LAST_PAREN_MATCH{'iftype'};
-
- # Clean key names by removing .default or .%HOSTNUM% suffix
- foreach my $key ( keys %{$section_hash} ) {
- ( my $new = $key ) =~ s{ [.] .* \z }{}xms;
- $section_tmp->{$new}->{'ORIG_NAME'} = $key;
- $section_tmp->{$new}->{'VALUE'} = $section_hash->{$key};
- }
- }
- else {
- $section_tmp = $section_hash;
+ }
+ {
+ $+{iftype}
+ }xms;
+ $parsed_keys_list->{'slaves'} = 1;
}
- # Check mandatory keys
- foreach my $key ( @{ $definition->{'MANDATORY_KEYS'} } ) {
+ if ( $context eq 'model' ) {
+ if ( $section_type eq 'hostgroup' ) {
+ $check_mandatory = 0;
+ }
if ( $section_type eq 'interface' ) {
- next if $iface_type eq 'eth' and $key eq 'slaves';
- next if $key =~ m{ \A ipv }xms and $context eq 'model';
- }
- last if $section_type eq 'hostgroup' and $context eq 'model';
- if ( !defined $section_tmp->{$key} ) {
- croak
- qq{Mandatory key $key must be defined in section $section_name context $context file $file};
+ $parsed_keys_list->{'ipv4'} = 1;
+ $parsed_keys_list->{'ipv6'} = 1;
}
}
- # Check all keys defined
- foreach my $key ( keys %{$definition} ) {
- next
- if $key eq 'MANDATORY_KEYS'
- or $key =~ m{\A __}xms
- or $definition->{$key} eq 'undefined' # FIXME
- or not defined $section_tmp->{$key};
+ my $master_key = ( $context eq 'config' ) ? 'action' : 'type';
+ foreach my $key ( keys %{$section_hash} ) {
+ my @split = split m{[.]}xmso, $key;
+ ( my $new = $key ) =~ s{ \A ([^.]+) ([.] .*)? \z }{$1}xmso;
+ my $def_key =
+ ( $int_context eq 'host'
+ or $context eq 'network' and $section_type eq 'server'
+ )
+ ? $new
+ : $key;
- my ( $tab_values, $key_name );
- if ( $int_context eq 'host' ) {
- $tab_values
- = ( $key !~ m{ \A [@] }xms )
- ? [ $section_tmp->{$key}->{'VALUE'} ]
- : $section_tmp->{$key}->{'VALUE'};
- $key_name = $section_tmp->{$key}->{'ORIG_NAME'};
- }
- else {
- $tab_values
- = ( $key !~ m{ \A [@] }xms )
- ? [ $section_tmp->{$key} ]
- : $section_tmp->{$key};
- $key_name = $key;
+ $parsed_keys_list->{$def_key} = 1;
+
+ # Next if useless checks
+ next if (
+ $key eq $master_key
+ or $definition->{$def_key} eq 'undefined'
+ );
+
+ # Checking if key exits
+ if ( not defined $definition->{$def_key} ) {
+ croak qq{ERROR: Unknown key $key on $section_name from file $file};
}
- foreach my $value ( @{$tab_values} ) {
+ my $value = ( ref $section_hash->{$key} eq 'ARRAY' )
+ ? $section_hash->{$key}
+ : [ $section_hash->{$key} ];
- # Remove surrounding spaces
- $value =~ s{ \A \s* }{}xms;
- $value =~ s{ \s* \z }{}xms;
+ __check_key_value_from_definition (
+ $key, $value, $definition->{$def_key}, $section_name, $file
+ );
+ }
- if ( $value !~ m{ \A $definition->{$key} \z }xms ) {
+ if ( $check_mandatory ) {
+ foreach my $key ( @{ $definition->{'MANDATORY_KEYS'} } ) {
+ if ( not defined $parsed_keys_list ) {
croak
- qq{Value '$value' for key $key_name in section $section_name file $file doesn't match $definition->{$key}};
+ qq{Mandatory key $key must be defined in section $section_name context $context file $file};
}
}
}
@@ -424,6 +425,62 @@
return 1;
}
+=head2
+
+__get_key_value_from_context_key( $section, $context, $parsed_pkey )
+
+Retrieve key_name and values for checking on hash defintion structure.
+Returns a pair with key_name and tab_values
+
+=cut
+
+sub __get_key_value_from_context_key {
+ my ( $section, $context, $parsed_key ) = @_;
+
+ my ( $tab_values, $key_name );
+ if ( $context eq 'host' ) {
+ $tab_values
+ = ( $parsed_key !~ m{ \A [@] }xms )
+ ? [ $section->{$parsed_key}->{'VALUE'} ]
+ : $section->{$parsed_key}->{'VALUE'};
+ $key_name = $section->{$parsed_key}->{'ORIG_NAME'};
+ }
+ else {
+ $tab_values
+ = ( $parsed_key !~ m{ \A [@] }xms )
+ ? [ $section->{$parsed_key} ]
+ : $section->{$parsed_key};
+ $key_name = $parsed_key;
+ }
+ return ( $key_name, $tab_values );
+}
+
+=head2
+
+__check_key_value_from_definition( $key_name, $tab_values, $regexp, $sect_name, $file )
+
+Check values for a specified key_name. Returns true value on success or croaks
+on errors
+
+=cut
+
+sub __check_key_value_from_definition {
+ my ( $key_name, $tab_values, $regexp, $sect_name, $file ) = @_;
+
+ foreach my $value ( @{$tab_values} ) {
+
+ # Remove surrounding spaces
+ $value =~ s{ \A \s* }{}xms;
+ $value =~ s{ \s* \z }{}xms;
+
+ if ( $value !~ m{ \A $regexp \z }xms ) {
+ croak
+ qq{Value '$value' for key $key_name in section $sect_name file $file doesn't match $regexp};
+ }
+ }
+
+ return 1;
+}
1; # Magic true value required at end of module
diff -r dd4873cacd2e -r 76354153ecef lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm Mon Nov 22 11:01:19 2010 +0100
+++ b/lib/PFTools/Structqueries.pm Tue Nov 23 11:53:01 2010 +0100
@@ -46,6 +46,7 @@
get_pkgtype_from_hostname
get_host_config
get_vlan_config
+ is_private_vlan
resolve_hostname_from_global_config
);
@@ -309,6 +310,31 @@
return $site_part->{'NETWORK'}->{'BY_NAME'}->{$vlan_name};
}
+=head2 is_private_vlan( $vlan_name, $global_config, $site_name )
+
+This function returns true if the vlan's scope is private, false if not, for
+the specified I<$vlan_name>. I<$site_name> is mandatory.
+
+=cut
+
+sub is_private_vlan {
+ my ( $vlan_name, $global_config, $site_name ) = @_;
+
+ unless ($site_name) {
+ croak q{ERROR: $site MUST BE defined};
+ }
+
+ my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site_name};
+
+ unless ($site_part->{'NETWORK'}->{'BY_NAME'}->{$vlan_name}) {
+ croak qq{ERROR: unknown vlan $vlan_name on site $site_name};
+ }
+
+ my $scope = $site_part->{'NETWORK'}->{'BY_NAME'}->{$vlan_name}->{'scope'};
+
+ return ( $scope eq 'private' ) ? 1 : 0;
+}
+
=head2 get_pkgtype_from_hostname( $hostname, $global_config, $site_name )
This function returns the pkgtype for I<$hostname>. I<$site_name> is optional.
diff -r dd4873cacd2e -r 76354153ecef lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Mon Nov 22 11:01:19 2010 +0100
+++ b/lib/PFTools/Utils.pm Tue Nov 23 11:53:01 2010 +0100
@@ -30,6 +30,7 @@
use File::Compare;
use File::Copy;
use File::Temp;
+use Hash::Merge::Simple qw(merge);
use IO::File;
use Template::Tiny;
@@ -1186,6 +1187,9 @@
= __make_zone_header( $zone_name, $site_name, $zone_ref );
my @lines = @{$header_lines_ref};
+ # Merging private and public parts for a given zone_name
+ my $merge = merge $zone_part, $zone_ref->{'ALL_SITES'};
+
### Building Networks part
push @lines,
q{;;},
@@ -1198,8 +1202,8 @@
->{'__network_order'}->{$site_name};
foreach my $network ( @{$network_order_ref} ) {
my $head = qq{; $network};
- if ( $zone_part->{$network}->{'comment'} ) {
- $head .= ": $zone_part->{$network}->{'comment'}";
+ if ( $merge->{$network}->{'comment'} ) {
+ $head .= ": $merge->{$network}->{'comment'}";
}
push @lines,
@@ -1207,11 +1211,11 @@
q{;----------------------------------------------------------------------------};
foreach my $spec ( 'network', 'netmask', 'broadcast', 'gateway' ) {
- my $value = $zone_part->{$network}->{$spec};
+ my $value = $merge->{$network}->{$spec};
next unless defined $value;
push @lines,
sprintf( q{%-29s IN %s},
- qq{$spec.$network}, $zone_part->{$network}->{$spec} );
+ qq{$spec.$network}, $value );
}
push @lines, q{};
@@ -1232,19 +1236,19 @@
foreach my $server ( @{$hostclass_order_ref} ) {
my $head = qq{; $server};
- if ( $zone_part->{$server}->{'comment'} ) {
- $head .= ": $zone_part->{$server}->{'comment'}";
+ if ( $merge->{$server}->{'comment'} ) {
+ $head .= ": $merge->{$server}->{'comment'}";
}
push @lines,
$head,
q{;----------------------------------------------------------------------------};
- foreach my $field ( sort keys %{ $zone_part->{$server} } ) {
+ foreach my $field ( sort keys %{ $merge->{$server} } ) {
next if $field eq 'comment';
- if ( ref $zone_part->{$server}->{$field} eq 'ARRAY' ) {
- foreach my $elt ( @{ $zone_part->{$server}->{$field} } ) {
+ if ( ref $merge->{$server}->{$field} eq 'ARRAY' ) {
+ foreach my $elt ( @{ $merge->{$server}->{$field} } ) {
push @lines,
sprintf( q{%-29s IN %s}, $field, $elt );
}
@@ -1252,7 +1256,7 @@
else {
push @lines,
sprintf( q{%-29s IN %s},
- $field, $zone_part->{$server}->{$field} );
+ $field, $merge->{$server}->{$field} );
}
}
diff -r dd4873cacd2e -r 76354153ecef t/13.conf.cfg1/config-export/COMMON/private-network
--- a/t/13.conf.cfg1/config-export/COMMON/private-network Mon Nov 22 11:01:19 2010 +0100
+++ b/t/13.conf.cfg1/config-export/COMMON/private-network Tue Nov 23 11:53:01 2010 +0100
@@ -16,11 +16,10 @@
@mx = 1 mf.private.
@mx = 2 mf00.private.
@mx = 2 mf01.private.
-console = ttyS0,115200n8
[cbv4-pfds]
type = site
- coment = CBV4-PFDS root site
+ comment = CBV4-PFDS root site
location = Courbevoie
room = CBV4-PFDS Room Name
state = ROOT
@@ -30,7 +29,7 @@
[cbv4]
type = site
- coment = CBV4 POP
+ comment = CBV4 POP
location = Courbevoie
room = CBV4 Room Name
state = EDGE
diff -r dd4873cacd2e -r 76354153ecef t/13.conf.t
--- a/t/13.conf.t Mon Nov 22 11:01:19 2010 +0100
+++ b/t/13.conf.t Tue Nov 23 11:53:01 2010 +0100
@@ -500,7 +500,7 @@
'type' => 'service',
},
'cbv4' => {
- 'coment' => 'CBV4 POP',
+ 'comment' => 'CBV4 POP',
'console' => 'default',
'dhcpvlan' => 'vlan-systeme',
'location' => 'Courbevoie',
@@ -510,7 +510,7 @@
'zone' => 'private',
},
'cbv4-pfds' => {
- 'coment' => 'CBV4-PFDS root site',
+ 'comment' => 'CBV4-PFDS root site',
'console' => 'default',
'dhcpvlan' => 'vlan-systeme',
'location' => 'Courbevoie',
@@ -539,7 +539,6 @@
'deploy01.vlan-systeme.private.',
],
'comment' => 'Internal management zone',
- 'console' => 'ttyS0,115200n8',
'expire' => '7D ; Expire (7 days)',
'mail' => 'dnsmaster at private',
'negttl' => '1H ; Negative TTL (1 hours)',
@@ -863,6 +862,8 @@
'boot' => {
'kernel' =>
'vmlinuz-2.6.26.5-universal-grm2.1.12',
+ 'kerneluml' =>
+ 'linux-uml-elf-2.4.26-gr1.9.15',
'pxefilename' => 'pxelinux.0',
'console' => 'default'
},
@@ -913,6 +914,8 @@
'boot' => {
'kernel' =>
'vmlinuz-2.6.26.5-universal-grm2.1.12',
+ 'kerneluml' =>
+ 'linux-uml-elf-2.4.26-gr1.9.15',
'pxefilename' => 'pxelinux.0',
'console' => 'default'
},
@@ -1025,7 +1028,7 @@
]
}
},
- 'coment' => 'CBV4-PFDS root site',
+ 'comment' => 'CBV4-PFDS root site',
'room' => 'CBV4-PFDS Room Name',
'state' => 'ROOT',
'dhcpvlan' => 'vlan-systeme',
@@ -1097,6 +1100,8 @@
'boot' => {
'kernel' =>
'vmlinuz-2.6.26.5-universal-grm2.1.12',
+ 'kerneluml' =>
+ 'linux-uml-elf-2.4.26-gr1.9.15',
'pxefilename' => 'pxelinux.0',
'console' => 'default'
},
@@ -1125,6 +1130,8 @@
'boot' => {
'kernel' =>
'vmlinuz-2.6.26.5-universal-grm2.1.12',
+ 'kerneluml' =>
+ 'linux-uml-elf-2.4.26-gr1.9.15',
'pxefilename' => 'pxelinux.0',
'console' => 'default'
},
@@ -1181,7 +1188,7 @@
],
},
},
- 'coment' => 'CBV4 POP',
+ 'comment' => 'CBV4 POP',
'room' => 'CBV4 Room Name',
'state' => 'EDGE',
'dhcpvlan' => 'vlan-systeme',
@@ -1207,6 +1214,21 @@
'ZONE' => {
'BY_NAME' => {
'private' => {
+ 'ALL_SITES' => {
+ 'cbv4-spawn' => {
+ 'cbv4-spawn01.vlan-pfds-ext' => 'A 192.168.1.98',
+ 'cbv4-spawn00.vlan-pfds-ext' => 'A 192.168.1.97',
+ },
+ 'vip-spawn' => {
+ 'vip-spawn.vlan-pfds-ext' => 'A 192.168.1.99',
+ },
+ 'vlan-pfds-ext' => {
+ 'broadcast' => 'A 192.168.1.255',
+ 'network' => 'A 192.168.1.0',
+ 'gateway' => 'A 192.168.1.254',
+ 'netmask' => 'A 255.255.255.0'
+ },
+ },
'BY_SITE' => {
'cbv4-pfds' => {
'vlan-admindsi' => {
@@ -1216,7 +1238,6 @@
'netmask' => 'A 255.255.255.0'
},
'vip-spawn' => {
- 'vip-spawn.vlan-pfds-ext' => 'A 192.168.1.99',
'nscache' => 'CNAME vip-spawn.vlan-systeme',
'vip-deploy' => 'CNAME vip-spawn.vlan-systeme',
'mf' => 'CNAME vip-spawn.vlan-systeme',
@@ -1229,8 +1250,6 @@
'cbv4-spawn01.vlan-middledsi' => 'A 10.3.2.42',
'cbv4-spawn00.vlan-middledsi' => 'A 10.3.2.41',
'spawn00' => 'CNAME cbv4-spawn00.vlan-systeme',
- 'cbv4-spawn01.vlan-pfds-ext' => 'A 192.168.1.98',
- 'cbv4-spawn00.vlan-pfds-ext' => 'A 192.168.1.97',
'cbv4-spawn01.vlan-admindsi' => 'A 10.3.1.42',
'ntp00' => 'CNAME cbv4-spawn00.vlan-systeme',
'ntp' => 'CNAME cbv4-spawn.vlan-systeme',
@@ -1262,18 +1281,12 @@
'network' => 'A 10.2.0.0',
'netmask' => 'A 255.255.0.0'
},
- 'vlan-pfds-ext' => {
- 'broadcast' => 'A 192.168.1.255',
- 'network' => 'A 192.168.1.0',
- 'gateway' => 'A 192.168.1.254',
- 'netmask' => 'A 255.255.255.0'
- },
'vlan-middledsi' => {
'broadcast' => 'A 10.3.2.255',
'network' => 'A 10.3.2.0',
'gateway' => 'A 10.3.2.254',
'netmask' => 'A 255.255.255.0'
- }
+ }
},
'cbv4' => {
'vlan-systeme' => {
@@ -1309,7 +1322,7 @@
'cbv4-pfds' => [
'vip-spawn',
'cbv4-pfds-filer',
- 'cbv4-spawn'
+ 'cbv4-spawn',
],
'cbv4' => [
'cbv4-rdeploy',
@@ -1322,7 +1335,6 @@
],
'ttl' => '1D ; TTL (1 day)',
'serial' => 'AUTO',
- 'console' => 'ttyS0,115200n8',
'@mx' => [
'1 mf.private.',
'2 mf00.private.',
More information about the pf-tools-commits
mailing list