pf-tools/pf-tools: 11 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Sat Nov 6 17:41:54 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/59e76fe36bbd
changeset: 920:59e76fe36bbd
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 08:17:44 2010 +0100
description:
update-config: perlcritic-related small improvements
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/b1070bc80629
changeset: 921:b1070bc80629
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 08:18:16 2010 +0100
description:
update-config: perltidy
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/2af4f150fc1f
changeset: 922:2af4f150fc1f
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 08:25:21 2010 +0100
description:
update-config: style + move function to the end of the source file
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/8625fe6588f3
changeset: 923:8625fe6588f3
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 08:35:16 2010 +0100
description:
regexps: \Z -> \z
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/e81285ba83e7
changeset: 924:e81285ba83e7
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 08:37:35 2010 +0100
description:
README.coding.style: document q{} and qq{}
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/8950a36908b0
changeset: 925:8950a36908b0
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 18:17:51 2010 +0100
description:
Conf.pm: perlcritic
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/1a639972a234
changeset: 926:1a639972a234
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 04 18:33:34 2010 +0100
description:
New Add_server() function
It takes exactly the same arguments than Add_zone() and friends.
This should allow future improvements in Init_GLOBAL_NETCONFIG().
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/6dcabe1e984b
changeset: 927:6dcabe1e984b
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Fri Nov 05 07:41:44 2010 +0100
description:
code factorization
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/fc88522f80f9
changeset: 928:fc88522f80f9
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Fri Nov 05 07:53:53 2010 +0100
description:
if/elsif/elsif/.... -> hash lookup
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/995f8bec1ad9
changeset: 929:995f8bec1ad9
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Fri Nov 05 19:18:13 2010 +0100
description:
Too many args -> named parameters
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/3673e7fc9ef9
changeset: 930:3673e7fc9ef9
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Sat Nov 06 18:36:21 2010 +0100
description:
\Z -> \z
diffstat:
9 files changed, 19 insertions(+), 22 deletions(-)
README.coding.style | 2 ++
lib/PFTools/Conf.pm | 1 +
lib/PFTools/Conf/Host.pm | 1 -
lib/PFTools/Conf/Network.pm | 27 +++++++++++++--------------
lib/PFTools/Packages/DEB.pm | 2 +-
lib/PFTools/Structqueries.pm | 2 +-
lib/PFTools/Update/ADDMOUNT.pm | 2 +-
lib/PFTools/Update/Common.pm | 1 -
sbin/update-config | 3 ---
diffs (1192 lines):
diff -r 6a6f53210e6f -r 3673e7fc9ef9 README.coding.style
--- a/README.coding.style Fri Nov 05 14:11:57 2010 +0100
+++ b/README.coding.style Sat Nov 06 18:36:21 2010 +0100
@@ -30,6 +30,11 @@
* Always add tests in the t/ directory _before_ correcting a bug or adding a
new feature.
+* Always use {}xms style for regexps, as well as \A and \z (NOT \Z).
+
+* Always use q{} and qq{} instead of '' and "". Only use qq{} when
+ interpolating of variables or escape sequences is needed.
+
--
The following line is only here to tell Vim my preferences when editing this
file :
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Conf.pm
--- a/lib/PFTools/Conf.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Conf.pm Sat Nov 06 18:36:21 2010 +0100
@@ -175,6 +175,8 @@
sub reset_pf_config {
$PF_CONFIG = {};
+
+ return;
}
=head2 Subst_vars( $text, $variables_ref )
@@ -533,57 +535,32 @@
my @sortnetkeys
= sort { __sort_net_section( $net_parsed, $a, $b ) }
@{ $net_parsed->{'__sections_order'} };
+
+ my %add_function_for = (
+ q{zone} => sub { Add_zone(@_); },
+ q{site} => sub { Add_site(@_); },
+ q{network} => sub { Add_network(@_); },
+ q{server} => sub { Add_server(@_); },
+ q{service} => sub { __add_service(@_); },
+ );
+
foreach my $section (@sortnetkeys) {
- if ( $net_parsed->{$section}->{'type'} eq 'zone' ) {
- Add_zone(
- $start_file, $section, $net_parsed->{$section},
- $GLOBAL, $pf_config
- );
+ my $section_type = $net_parsed->{$section}->{'type'};
+
+ unless ( exists $add_function_for{$section_type} ) {
+ croak qq{ERROR: Unknown section type $section_type};
}
- elsif ( $net_parsed->{$section}->{'type'} eq 'site' ) {
- Add_site(
- $start_file, $section, $net_parsed->{$section},
- $GLOBAL, $pf_config
- );
- }
- elsif ( $net_parsed->{$section}->{'type'} eq 'network' ) {
- Add_network(
- $start_file, $section, $net_parsed->{$section},
- $GLOBAL, $pf_config
- );
- }
- elsif ( $net_parsed->{$section}->{'type'} eq 'server' ) {
- my $convert = Build_host_from_server(
- $section,
- $net_parsed->{$section}
- );
- Add_host(
- $start_file, 'server', $convert,
- $GLOBAL, $pf_config
- );
- }
- elsif ( $net_parsed->{$section}->{'type'} eq 'service' ) {
- my $site_list = Get_site_list( $net_parsed->{$section}, $GLOBAL );
- 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, q{}, $hash_subst, $pf_config );
- my $host_parsed
- = Load_conf(
- $hostfile, $hash_subst, 'host',
- $pf_config
- );
- Add_host(
- $hostfile, 'host', $host_parsed,
- $GLOBAL, $pf_config
- );
- push @{ $service_part->{$section} }, $host;
- }
- }
- }
+
+ my $args = {
+ start_file => $start_file,
+ section_name => $section,
+ section_ref => $net_parsed->{$section},
+ global_config => $GLOBAL,
+ pf_config => $pf_config,
+ hash_subst => $hash_subst,
+ };
+
+ $add_function_for{$section_type}->($args);
}
return $GLOBAL;
@@ -787,12 +764,13 @@
}
foreach my $section ( @{ $hash_to_merge->{'__sections_order'} } ) {
+ # If the section is defined in the model, we need to update
+ # it key by key
if ( defined $merge->{$section} ) {
foreach my $key ( keys %{ $hash_to_merge->{$section} } ) {
next if $section eq 'hostgroup' and $key eq '__model';
- # Adding key if not defined into model else overriding it
- if ( $key =~ /^\@/ ) {
+ if ( $key =~ m{ \A [@] }xms ) {
push @{ $merge->{$section}->{$key} },
@{ $hash_to_merge->{$section}->{$key} };
}
@@ -835,7 +813,7 @@
croak q{ERROR: Invalid empty $context};
}
- if ( $context =~ /^host|model$/ ) {
+ if ( $context eq q{host} or $context eq q{model} ) {
return __Merge_host_config( $hash_to_merge, $hash_subst );
}
@@ -916,5 +894,68 @@
return $net_prio_for{$a_type} <=> $net_prio_for{$b_type};
}
+=head2 __add_service($args)
+
+This function does the necessary magic (including calling C<Add_host()>) for each
+host composing a service. I<$args> is a reference to a hash containing the
+following named parameters :
+
+=over
+
+=item I<start_file>
+
+Filename containing the service definition
+
+=item I<section_name>
+
+The service name
+
+=item I<section_ref>
+
+Reference to a hash containing the parsed service
+
+=item I<global_config>
+
+Reference to the global configuration hash (the hosts will be added in this hash)
+
+=item I<pf_config>
+
+Reference to the pf-tools configuration hash
+
+=back
+
+=cut
+
+sub __add_service {
+ my ($args) = @_;
+
+ my ($start_file, $section_name, $section_ref,
+ $global_config, $pf_config, $hash_subst
+ )
+ = @$args{
+ qw( start_file section_name section_ref global_config pf_config hash_subst )
+ };
+
+ my $site_list = Get_site_list( $section_ref, $global_config );
+ foreach my $site ( @{$site_list} ) {
+ my $service_part
+ = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'SERVICE'}
+ ->{'BY_NAME'};
+
+ foreach my $host ( @{ $section_ref->{'@host'} } ) {
+ my $hostfile = Get_source( $host, q{}, $hash_subst, $pf_config );
+ my $host_parsed
+ = Load_conf( $hostfile, $hash_subst, q{host}, $pf_config );
+ Add_host(
+ $hostfile, q{host}, $host_parsed, $global_config,
+ $pf_config
+ );
+ push @{ $service_part->{$section_name} }, $host;
+ }
+ }
+
+ return;
+}
+
1; # Magic true value required at end of module
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Conf/Host.pm Sat Nov 06 18:36:21 2010 +0100
@@ -32,8 +32,8 @@
use PFTools::Structqueries;
our @EXPORT = qw(
- Build_host_from_server
Add_host
+ Add_server
);
our @EXPORT_OK = qw();
@@ -98,7 +98,7 @@
? ( $ref_hostgroup->{'nodes'} - 1 )
: 0;
$num_last = $ref_hostgroup->{'number'} - 1;
- $hostname_model =~ m{(%*)(_*)\Z};
+ $hostname_model =~ m{(%*)(_*)\z};
$digits = length($1) || 0;
$nodes = length($2) || 0;
@@ -127,7 +127,7 @@
if ( $model !~ m{%+} && $model !~ m{_+} ) {
return "";
}
- $model =~ m{(%*)(_*)\Z};
+ $model =~ m{(%*)(_*)\z};
$digits = length($1) || 0;
$nodes = length($2) || 0;
$index = "";
@@ -162,7 +162,7 @@
$index = __Get_hostnumber_from_model(
$hostname_model, $hostnum, $hostnode
);
- $hostname =~ s{(%*)(_*)\Z}{$index};
+ $hostname =~ s{(%*)(_*)\z}{$index};
$hostname = $site_prefix . $hostname
if ( $ref_host->{'prefix'} && $ref_host->{'prefix'} eq 'true' );
return $hostname;
@@ -256,7 +256,7 @@
next if ( $key !~ m{\Aipv}o );
my ( $type, $vlan, $num ) = split( m{\.}, $key );
push( @{$vlan_list}, $vlan ) if (
- !grep ( m{\A$vlan\Z}, @{$vlan_list} )
+ !grep ( m{\A$vlan\z}, @{$vlan_list} )
);
}
return $vlan_list;
@@ -285,7 +285,7 @@
next if ( $host_number && $host_num && $host_num ne $host_number );
push( @{$alias_list}, $name ) if (
$vlan eq $ref_parsed->{$key}
- && !grep ( m{\A$name\Z}, @{$alias_list} )
+ && !grep ( m{\A$name\z}, @{$alias_list} )
);
}
return $alias_list;
@@ -314,7 +314,7 @@
return;
}
-sub Build_host_from_server {
+sub __build_host_from_server {
my ( $srv_name, $ref_srv ) = @_;
my $result = {};
my $iface_idx = 0;
@@ -338,7 +338,7 @@
my $key_name = ( $spec ) ? "$key_type\.$spec" : $key_type;
$result->{'dns'}->{$key_name} = $ref_srv->{$key};
}
- elsif( $key_type =~ m{\A (comment|order|number|nodes|site) \Z}xms ) {
+ elsif( $key_type =~ m{\A (comment|order|number|nodes|site) \z}xms ) {
$result->{'hostgroup'}->{$key_type} = $ref_srv->{$key};
}
}
@@ -379,7 +379,7 @@
(\.
(TAG[\d]+)
)?
- \Z}xms;
+ \z}xms;
( $ifraw, $iftag ) = ( $1, $4 );
# Check vlan
@@ -409,7 +409,7 @@
# Check tag
my $net_tag = $net_site->{$vlan}->{'tag'};
- if ( $iftag && $iftag =~ m{\A \d+ \Z}xms && $net_tag ne $iftag ) {
+ if ( $iftag && $iftag =~ m{\A \d+ \z}xms && $net_tag ne $iftag ) {
croak qq{ERROR: $iftag for $iface_section differs from $vlan def};
}
@@ -420,7 +420,7 @@
: split( m{\s*,\s*}, $iface_def->{'slaves'} );
foreach my $if (@slaves) {
croak qq{ERROR: $if cannot be enslaved to $iface for $hostname}
- if ( grep ( m{\A $if \Z}xms, @{$ref_if_list} ) );
+ if ( grep ( m{\A $if \z}xms, @{$ref_if_list} ) );
}
$add_if->{'slaves'} = join( " ", @slaves );
$add_if->{'mode'} =
@@ -455,7 +455,7 @@
my @route_list;
foreach my $rkey ( keys %{$iface_def} ) {
next unless( $rkey =~ m{\A$route_key} );
- if ( $rkey =~ m{\.(?<number>.+)\Z} ) {
+ if ( $rkey =~ m{\.(?<number>.+)\z} ) {
push ( @route_list, @{$iface_def->{$rkey}} )
if( $+{number} eq $host_number );
}
@@ -470,7 +470,7 @@
if ( $dest =~ m{[g-zG-Z]+} ) {
if ( $net_site->{$dest} ) {
# Dest is a defined network ... translating into IP
- $ip_dest = new NetAddr::IP(
+ $ip_dest = NetAddr::IP->new(
$net_site->{$dest}->{'network'},
$net_site->{$dest}->{'netmask'}
);
@@ -482,7 +482,7 @@
}
}
else {
- $ip_dest = new NetAddr::IP($dest);
+ $ip_dest = NetAddr::IP->new($dest);
unless( $ip_dest ) {
croak qq{ERROR: Bad route $route for $hostname};
}
@@ -506,7 +506,7 @@
$route2add .= $via;
}
else {
- my $ip_via = new NetAddr::IP($via);
+ my $ip_via = NetAddr::IP->new($via);
unless( $ip_via ) {
croak qq{ERROR: Bad gateway for $route on $hostname};
}
@@ -544,7 +544,7 @@
$dhcp_part->{$dhcpvlan}->{$hostclass} = {}
unless( $dhcp_part->{$dhcpvlan}->{$hostclass} );
my $fixed_addr = $param->{'iface_def'}->{$param->{'ip_type'}};
- $fixed_addr =~ s{/[\d]+\Z}{};
+ $fixed_addr =~ s{/[\d]+\z}{};
$dhcp_part->{$dhcpvlan}->{$hostclass}->{$hostname} = [
'hardware ethernet '. $param->{'iface_def'}->{'mac'} . ";",
'fixed-address ' . $fixed_addr . ';',
@@ -563,7 +563,7 @@
my $host_number = $param->{'host_number'};
my $vlan = $param->{'iface_def'}->{'vlan'};
my $zone_ip = $param->{'iface_def'}->{$param->{'ip_type'}};
- $zone_ip =~ s{/[\d]+ \Z}{}xms;
+ $zone_ip =~ s{/[\d]+ \z}{}xms;
my $zone_part = $param->{'zone_part'};
my $zone_key = ( $param->{'ip_type'} eq 'ipv6') ? 'ZONE6' : 'ZONE';
my $zone = $param->{'zone_name'};
@@ -733,7 +733,7 @@
my $hostclass = $host2add->{'hostgroup'}->{'hosttype'} || $shortname;
my $site_list = Get_site_list( $host2add->{'hostgroup'}, $global_config );
my $pf_tftp_dir = $pf_config->{'path'}->{'tftp_dir'};
- $pf_tftp_dir .= '/' if ( $pf_tftp_dir !~ m{/\Z} );
+ $pf_tftp_dir .= '/' if ( $pf_tftp_dir !~ m{/\z} );
my ( $host_last, $node_last )
= __Get_host_indexes( $host2add->{'hostgroup'}, $hostname_model );
@@ -795,7 +795,7 @@
(\.(TAG[\d]+)
)
- \Z}xms
+ \z}xms
) {
$iface_name =
$1 . '.'
@@ -824,7 +824,7 @@
my $zone_key = "ZONE".$suffix;
my $dhcp_key = "DHCP".$suffix;
my $zone_ip = $if2add->{$ip_type};
- $zone_ip =~ s{/.+\Z}{};
+ $zone_ip =~ s{/.+\z}{};
my $zone_part
= $global_config->{$zone_key}->{'BY_NAME'}
->{$zone}->{'BY_SITE'}->{$site};
@@ -875,4 +875,48 @@
}
}
+=head2 Add_server($args)
+
+Build a host definition from a server definition, then call C<Add_host()>.
+I<$args> is a reference to a hash containing the following named parameters :
+
+=over
+
+=item I<start_file>
+
+Filename containing the server definition
+
+=item I<section_name>
+
+The server name
+
+=item I<section_ref>
+
+Reference to a hash containing the parsed server
+
+=item I<global_config>
+
+Reference to the global configuration hash (the server will be added in this hash)
+
+=item I<pf_config>
+
+Reference to the pf-tools configuration hash
+
+=back
+
+=cut
+
+sub Add_server {
+ my ($args) = @_;
+
+ my ($start_file, $section_name, $section_ref, $global_config, $pf_config)
+ = @$args{ qw( start_file section_name section_ref global_config pf_config )
+ };
+
+ my $host = __build_host_from_server( $section_name, $section_ref );
+
+ return Add_host( $start_file, q{server}, $host, $global_config, $pf_config);
+}
+
+
1;
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Conf/Network.pm
--- a/lib/PFTools/Conf/Network.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Conf/Network.pm Sat Nov 06 18:36:21 2010 +0100
@@ -40,20 +40,46 @@
our @EXPORT_OK = qw();
-#########################################################################
-#
-# VOID Add_zone ( STR , STR, HASHREF , HASHREF, HASHREF )
-#
-# This function adds zone into global configuration
-# Inputs :
-# - $netfile : filename where zone is parsed
-# - $zone_name : zone name
-# - $zone2add : hashref where are stored zone definitions according to networkfile-syntax
-# - $global_config : hashref where are stored datas
-# - $pf_config : hashref where are stored pf-tools configuration
-#
-sub Add_zone ($$$$$) {
- my ( $netfile, $zone_name, $zone2add, $global_config, $pf_config ) = @_;
+=head2 Add_zone($args)
+
+This function adds a zone to the global configuration. $args is a reference to
+a hash containing the following named parameters :
+
+=over
+
+=item I<start_file>
+
+Filename containing the zone definition
+
+=item I<section_name>
+
+The zone name
+
+=item I<section_ref>
+
+Reference to a hash containing the parsed zone
+
+=item I<global_config>
+
+Reference to the global configuration hash (the zone will be added in this hash)
+
+=item I<pf_config>
+
+Reference to the pf-tools configuration hash
+
+=back
+
+=cut
+
+sub Add_zone {
+ my ($args) = @_;
+
+# my ($start_file, $section_name, $section_ref,
+# $global_config, $pf_config, $hash_subst
+# )
+ my ( $netfile, $zone_name, $zone2add, $global_config, $pf_config )
+ = @$args{ qw( start_file section_name section_ref global_config pf_config )
+ };
foreach my $ip_type ( 'ipv4', 'ipv6' ) {
next if ( !$pf_config->{'features'}->{$ip_type} );
@@ -74,55 +100,81 @@
}
}
-#########################################################################
-#
-# VOID Add_site ( STR , STR, HASHREF , HASHREF, HASHREF )
-#
-# This function adds zone into global configuration
-# Inputs :
-# - $netfile : filename where zone is parsed
-# - $site_name : site name
-# - $site2add : hashref where are stored site definitions according to networkfile-syntax
-# - $global_config : hashref where are stored datas
-# - $pf_config : hashref where are stored pf-tools configuration
-#
-sub Add_site ($$$$$) {
- my ( $netfile, $site_name, $site2add, $global_config, $pf_config ) = @_;
+=head2 Add_site($args)
+
+This function adds a site to the global configuration. $args is a reference to
+a hash containing the following named parameters :
+
+=over
+
+=item I<start_file>
+
+Filename containing the site definition
+
+=item I<section_name>
+
+The site name
+
+=item I<section_ref>
+
+Reference to a hash containing the parsed site
+
+=item I<global_config>
+
+Reference to the global configuration hash (the site will be added in this hash)
+
+=item I<pf_config>
+
+Reference to the pf-tools configuration hash
+
+=back
+
+=cut
+
+sub Add_site {
+ my ($args) = @_;
+
+ my ( $netfile, $site_name, $site2add, $global_config, $pf_config )
+ = @$args{ qw( start_file section_name section_ref global_config pf_config )
+ };
if ( defined $global_config->{'SITE'}->{'BY_NAME'}->{$site_name} ) {
carp qq{WARN: $site_name from $netfile already defined};
return;
}
+
if ( $site2add->{'state'} eq 'ROOT' ) {
if ( $global_config->{'SITE'}->{'ROOT'} ) {
carp qq{WARN: ROOT site is already defined : skipping $site_name};
+ return;
}
- else {
- $global_config->{'SITE'}->{'ROOT'} = $site_name;
- }
+ $global_config->{'SITE'}->{'ROOT'} = $site_name;
}
else {
- push( @{ $global_config->{'SITE'}->{'EDGE'} }, $site_name );
+ push @{ $global_config->{'SITE'}->{'EDGE'} }, $site_name;
}
+
my $site_part = $global_config->{'SITE'}->{'BY_NAME'};
$site_part->{$site_name} = $site2add;
$site_part->{$site_name}->{'NETWORK'} = {
'BY_NAME' => {},
- 'BY_TAG' => {}
+ 'BY_TAG' => {},
};
$site_part->{$site_name}->{'HOST'} = {
'BY_NAME' => {},
- 'BY_MAC' => {}
+ 'BY_MAC' => {},
};
$site_part->{$site_name}->{'SERVICE'} = {
- 'BY_NAME' => {}
+ 'BY_NAME' => {},
};
- push( @{ $global_config->{'SITE'}->{'__site_list'} }, $site_name );
+ push @{ $global_config->{'SITE'}->{'__site_list'} }, $site_name;
+
my $zone = $site2add->{'zone'};
my $dhcpvlan = $site2add->{'dhcpvlan'};
foreach my $ip_type ( 'ipv4', 'ipv6' ) {
next if ( !$pf_config->{'features'}->{$ip_type} );
+
my $suffix = ( $ip_type eq 'ipv6' ) ? 6 : "";
my $zone_part = $global_config->{'ZONE'.$suffix};
my $dhcp_part = $global_config->{'DHCP'.$suffix};
@@ -136,36 +188,60 @@
$zone_part->{'BY_SITE'}->{$site_name} = $zone;
$dhcp_part->{'BY_SITE'}->{$site_name} = {
$dhcpvlan => {
- 'subnet' => '',
- 'netmask' => ''
- }
+ 'subnet' => q{},
+ 'netmask' => q{},
+ },
};
}
+
+ return;
}
-#########################################################################
-#
-# VOID Add_network ( STR , STR, HASHREF , HASHREF, HASHREF )
-#
-# This function adds zone into global configuration
-# Inputs :
-# - $netfile : filename where network is parsed
-# - $net_name : network name
-# - $ref_net : hashref where are stored network definitions according to networkfile-syntax
-# - $global_config : hashref where are stored global configuration datas
-# - $pf_config : hashref where are stored pf-tools configuration datas
-#
-sub Add_network ($$$$$) {
- my ( $netfile, $net_name, $ref_net, $global_config, $pf_config ) = @_;
- my ($block, $block6, $site_list, $net_part,
- $dhcp_part, $net2add, $ip_gw, $ip6_gw
- );
+=head2 Add_network($args)
+
+This function adds a network to the global configuration. $args is a reference to
+a hash containing the following named parameters :
+
+=over
+
+=item I<start_file>
+
+Filename containing the network definition
+
+=item I<section_name>
+
+The network name
+
+=item I<section_ref>
+
+Reference to a hash containing the parsed network
+
+=item I<global_config>
+
+Reference to the global configuration hash (the network will be added in this hash)
+
+=item I<pf_config>
+
+Reference to the pf-tools configuration hash
+
+=back
+
+=cut
+
+sub Add_network {
+ my ($args) = @_;
+
+ my ( $netfile, $net_name, $ref_net, $global_config, $pf_config )
+ = @$args{ qw( start_file section_name section_ref global_config pf_config )
+ };
my $site_part = $global_config->{'SITE'};
- $site_list = Get_site_list( $ref_net, $global_config );
- $net2add->{'scope'} = $ref_net->{'scope'};
+ my $site_list = Get_site_list( $ref_net, $global_config );
+ my $net2add = {
+ scope => $ref_net->{'scope'},
+ };
$net2add->{'comment'} = $ref_net->{'comment'}
- if ( $ref_net->{'comment'} );
+ if $ref_net->{'comment'};
# Check TAG
if ( $ref_net->{'tag'}
@@ -187,7 +263,7 @@
$net2add->{ 'netmask' . $suffix } = $net_block->mask();
if ( $ref_net->{$gw_key} ) {
- $ip_gw = new NetAddr::IP(
+ my $ip_gw = NetAddr::IP->new(
$net_block->prefix() . $ref_net->{$gw_key},
$net_block->mask()
);
@@ -201,7 +277,7 @@
}
$net2add->{'tag'} = $ref_net->{'tag'};
foreach my $site ( @{$site_list} ) {
- $net_part = $site_part->{'BY_NAME'}->{$site}->{'NETWORK'};
+ my $net_part = $site_part->{'BY_NAME'}->{$site}->{'NETWORK'};
if ( $net_part->{'BY_NAME'}->{$net_name} ) {
carp qq{WARN: $net_name from $netfile is already defined};
next;
@@ -221,8 +297,7 @@
}
# Adding network to the network part of the global structure
- $net_part = $site_part->{'BY_NAME'}->{$site}->{'NETWORK'};
- $dhcp_part = $global_config->{$dhcp_key}->{'BY_SITE'}->{$site};
+ my $dhcp_part = $global_config->{$dhcp_key}->{'BY_SITE'}->{$site};
$net_part->{'BY_NAME'}->{$net_name} = $net2add;
$net_part->{$netaddr_key}->{ $net_block->cidr() } = $net_name;
$net_part->{'BY_TAG'}->{ $ref_net->{'tag'} } = $net_name
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Packages/DEB.pm
--- a/lib/PFTools/Packages/DEB.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Packages/DEB.pm Sat Nov 06 18:36:21 2010 +0100
@@ -70,14 +70,14 @@
}
while (<$output_fh>) {
if( m{\A Status:\s+}xms ) {
- if ( ! m{\A Status:\s+install\s+ok\s+installed\s* \Z}xms ) {
+ if ( ! m{\A Status:\s+install\s+ok\s+installed\s* \z}xms ) {
$result->{'installed'} = 0;
}
else {
$result->{'installed'} = 1;
}
}
- if ( m{\A Version:\s+(.+)\s* \Z}xms ) {
+ if ( m{\A Version:\s+(.+)\s* \z}xms ) {
$result->{'version'} = $1;
last;
}
@@ -129,7 +129,7 @@
return;
}
while( <$output_fh> ) {
- if( m{\A Depends: (.*) \Z}xms ) {
+ if( m{\A Depends: (.*) \z}xms ) {
foreach my $pkg ( split( m{,}, $1 ) ) {
if ( $pkg =~ m{|} ) {
$pkg =~ s{\([^\)]+\)}{}g;
@@ -153,7 +153,7 @@
}
#Removing trailing spaces
$dep_list =~ s{\A \s*}{}xms;
- $dep_list =~ s{\s* \Z}{}xms;
+ $dep_list =~ s{\s* \z}{}xms;
return $dep_list;
}
@@ -174,11 +174,11 @@
}
while( <$output_fh> ) {
chomp;
- if( m{\A \s+Installed: (.*) \Z}xms ) {
+ if( m{\A \s+Installed: (.*) \z}xms ) {
$installed = $1;
undef $installed if ( $installed eq '' or $installed eq "(none)" );
}
- elsif( m{\A \s*Candidate: (.*) \Z}xms ) {
+ elsif( m{\A \s*Candidate: (.*) \z}xms ) {
$available = $1;
}
elsif ( defined $version && m{\Q$version\E} ) {
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Structqueries.pm Sat Nov 06 18:36:21 2010 +0100
@@ -201,13 +201,13 @@
foreach my $hostclass ( keys %{$host_part} ) {
if ( $hostclass eq $hostname ) {
push( @{$site_list}, $site )
- if( !grep( m{\A $site \Z}xms, @{$site_list} ) );
+ if( !grep( m{\A $site \z}xms, @{$site_list} ) );
next;
}
foreach my $host ( keys %{ $host_part->{$hostclass} } ) {
if( $host eq $hostname ) {
push( @{$site_list}, $site )
- if( !grep( m{\A $site \Z}xms, @{$site_list} ) );
+ if( !grep( m{\A $site \z}xms, @{$site_list} ) );
last;
}
}
@@ -267,7 +267,7 @@
my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
my $zone = $site_part->{'zone'};
- my ( $hostshort, $hostvlan ) = $hostname =~ m{\A ([^.]+)(\.([^.]+))?(\.$zone)? \Z}xms;
+ my ( $hostshort, $hostvlan ) = $hostname =~ m{\A ([^.]+)(\.([^.]+))?(\.$zone)? \z}xms;
unless ($hostshort) {
croak qq{ERROR: Unable to get hostshort/hostvlan from hostname $hostname};
}
@@ -295,7 +295,7 @@
);
return unless( $host_props );
my $mode = $host_props->{'deployment'}->{'mode'};
- if ( $mode =~ m{\A (debian|ubuntu) \Z}xms ) {
+ if ( $mode =~ m{\A (debian|ubuntu) \z}xms ) {
return 'deb';
}
else {
@@ -321,7 +321,7 @@
{
$bond_cmdline .= "bonding." . $opt . " ";
}
- $bond_cmdline =~ s{\s* \Z}{}xms;
+ $bond_cmdline =~ s{\s* \z}{}xms;
last;
}
return ( $cmdline, $bond_cmdline );
@@ -348,7 +348,7 @@
my $resolved = [];
my $zone_key = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
- $hostname =~ m{\A ([^.]+)(\.([^.]+))? \Z}xms;
+ $hostname =~ m{\A ([^.]+)(\.([^.]+))? \z}xms;
my ( $hostshort, $hostvlan ) = ( $1, $3 );
my $zone_part
= $global_config->{$zone_key}->{'BY_NAME'}->{$zone}->{'BY_SITE'}
@@ -361,7 +361,7 @@
}
else {
foreach my $entry ( keys %{ $zone_part->{$hosttype} } ) {
- next if ( $entry !~ m{\A $hostname \Z}xms );
+ next if ( $entry !~ m{\A $hostname \z}xms ); # FIXME next unless $entry eq $hostname
my @fields;
if ( ref( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
@fields = @{ $zone_part->{$hosttype}->{$entry} };
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Update/ADDFILE.pm
--- a/lib/PFTools/Update/ADDFILE.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Update/ADDFILE.pm Sat Nov 06 18:36:21 2010 +0100
@@ -59,7 +59,7 @@
$tmp = Get_tmp_dest( $dest );
# Removing trailing space from source
$ref_section->{'source'} =~ s{\A\s*}{};
- $ref_section->{'source'} =~ s{\s*\Z}{};
+ $ref_section->{'source'} =~ s{\s*\z}{};
if ( $ref_section->{'source'} =~ m{\s} ) {
$source = Get_tmp_dest($dest) . ".merged";
unlink( $source );
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Update/ADDMOUNT.pm
--- a/lib/PFTools/Update/ADDMOUNT.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Update/ADDMOUNT.pm Sat Nov 06 18:36:21 2010 +0100
@@ -69,14 +69,14 @@
my ( $host, $global_config ) = @_;
my $ip = $host;
- $host =~ m{\A ([^\.]+)(\..*)? \Z}xms;
+ $host =~ m{\A ([^\.]+)(\..*)? \z}xms;
my $zone = Get_zone_from_hostname( $1, $global_config );
unless( $zone ) {
carp qq{ERROR: Unable to retrieve zone for $host};
return;
}
- $ip =~ s{\.$zone \Z}{}xms;
- $ip =~ m{\A ([^.]+)(\.([^.]+))? \Z}xms;
+ $ip =~ s{\.$zone \z}{}xms;
+ $ip =~ m{\A ([^.]+)(\.([^.]+))? \z}xms;
my ( $hostshort, $hostvlan ) = ( $1, $3 );
my $hosttype = Get_hosttype_from_hostname( $hostshort, $global_config );
unless( $hosttype ) {
@@ -113,7 +113,7 @@
my $pf_config = Init_PF_CONFIG();
my $fs_entry = $param->{'fs_entry'};
if ( $fs_entry->{'fstype'}
- =~ m{\A $pf_config->{'regex'}->{'network_fstype'} \Z}xms )
+ =~ m{\A $pf_config->{'regex'}->{'network_fstype'} \z}xms )
{
foreach my $key ( 'source', 'options' ) {
my $value
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Update/Common.pm
--- a/lib/PFTools/Update/Common.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Update/Common.pm Sat Nov 06 18:36:21 2010 +0100
@@ -131,8 +131,8 @@
$file =~ s{//}{/}g;
if ( $file =~ m{/} ) {
- $file =~ s{\A (.*)/[^/]+/? \Z}{$1}xms;
- $file = "." if( $file =~ m{\A \s* \Z}xms );
+ $file =~ s{\A (.*)/[^/]+/? \z}{$1}xms;
+ $file = "." if( $file =~ m{\A \s* \z}xms );
}
else {
$file = '.';
@@ -273,10 +273,10 @@
# FIXME rewrite this part, it's really unreadable!!
$dir =~ s{//}{/}g; # supprimer // sinon ca marche moins bien
- $dir =~ s{/[^/]+/* \Z}{}xms;
+ $dir =~ s{/[^/]+/* \z}{}xms;
my $dir2 = $dir;
while ( $dir2 ne "" && !-e $dir2 ) {
- $dir2 =~ s{/[^/]+/* \Z}{}xms;
+ $dir2 =~ s{/[^/]+/* \z}{}xms;
}
if ( $dir2 ne "" && -e $dir2 && !-d $dir2 ) {
unlink($dir2);
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Update/INSTALLPKG.pm
--- a/lib/PFTools/Update/INSTALLPKG.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Update/INSTALLPKG.pm Sat Nov 06 18:36:21 2010 +0100
@@ -131,7 +131,7 @@
);
}
if( defined( $ref_section->{'delay'} ) && ! $options->{'noaction'} ) {
- $hash_subst->{'HOSTNAME'} =~ m{\d+ \Z}xms;
+ $hash_subst->{'HOSTNAME'} =~ m{\d+ \z}xms;
if ( $& ne "" ) {
sleep( 120 * $& );
}
@@ -142,7 +142,7 @@
foreach my $key ( keys %{$ref_section} ) {
next if ( $key !~ m{\A debconf}xmso );
$debconf = 1;
- $key =~ m{\A debconf\.(.*) \Z}xmso;
+ $key =~ m{\A debconf\.(.*) \z}xmso;
$debconf_vars->{$1} = $ref_section->{$key};
}
if( $debconf ) {
diff -r 6a6f53210e6f -r 3673e7fc9ef9 lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Fri Nov 05 14:11:57 2010 +0100
+++ b/lib/PFTools/Utils.pm Sat Nov 06 18:36:21 2010 +0100
@@ -101,7 +101,7 @@
my ( $pxefilename, $deploymode ) = @_;
if ( $deploymode =~ m{\A ubuntu}xms ) {
- $pxefilename =~ m{vmlinuz-(.+) \Z}xms;
+ $pxefilename =~ m{vmlinuz-(.+) \z}xms;
return "linux-image-" . $1;
}
else {
@@ -456,11 +456,11 @@
sub Resolv {
my ( $type_resolve, $ip_type, $hostname, $global_config, $site, $hosttype ) = @_;
- unless( $ip_type =~ m{\A ipv(4|6) \Z}xms ) {
+ unless( $ip_type =~ m{\A ipv(4|6) \z}xms ) {
carp qq{ERROR: Invalid ip_type $ip_type};
return;
}
- unless( $type_resolve =~ m{\A (cnf|dns) \Z}xms ) {
+ unless( $type_resolve =~ m{\A (cnf|dns) \z}xms ) {
carp qq{ERROR: Invalid type_resolv $type_resolve};
return;
}
@@ -475,8 +475,8 @@
return;
}
my $zone = Get_zone_from_hostname( $hostname, $global_config, $site );
- $hostname =~ s{\.$zone \Z}{}xms;
- $hostname =~ m{\A ([^.]+)(\.([^.]+))? \Z}xms;
+ $hostname =~ s{\.$zone \z}{}xms;
+ $hostname =~ m{\A ([^.]+)(\.([^.]+))? \z}xms;
my ( $hostshort, $hostvlan ) = ( $1, $3 );
if ( !defined $hosttype
&& $hostshort !~ m{\A (network|netmask|broadcast|gateway|prefix)}xms )
@@ -489,13 +489,13 @@
return;
}
}
- elsif( $hostshort =~ m{\A prefix \Z}xms ) {
+ elsif( $hostshort =~ m{\A prefix \z}xms ) {
my $vlan_def = Get_vlan_config_from_CONFIG(
$hostvlan, $global_config, $site
);
my $netblock = Get_netblock_from_vlan( $ip_type, $vlan_def );
my $prefix = $netblock->cidr();
- $prefix =~ s{\A [^/]+\/([\d]+) \Z}{$1}xms;
+ $prefix =~ s{\A [^/]+\/([\d]+) \z}{$1}xms;
return [ $prefix ];
}
return Resolv_hostname_from_GLOBAL(
@@ -522,7 +522,7 @@
(\\?)
(\.$zone)
([^A-Za-z0-9.-].*)?
- \Z}xmso
+ \z}xmso
) {
my $before = $1;
my $back = $3;
@@ -580,7 +580,7 @@
([A-Za-z0-9-]+)
)
([^A-Za-z0-9.-].*)?
- \Z}xmso
+ \z}xmso
)
{
my $before = $1;
@@ -599,10 +599,10 @@
if( defined $eth ) {
my $neweth = $eth;
if( $type eq "." ) {
- $neweth =~ s{:.*\Z}{};
+ $neweth =~ s{:.*\z}{};
}
elsif( $type eq "-" ) {
- $neweth =~ s{[.:].*\Z}{};
+ $neweth =~ s{[.:].*\z}{};
}
substr( $line, $lengthbefore, length $match ) = $neweth;
$pos = $lengthbefore;
@@ -665,7 +665,7 @@
= @_;
my $tmp_hosts = [];
- if ( $ip_type !~ m{\A ipv4 \Z}xms ) {
+ if ( $ip_type !~ m{\A ipv4 \z}xms ) {
carp qq{ERROR: $ip_type is not implemented for fixing $input_file};
return;
}
@@ -688,7 +688,7 @@
$host_props->{'deployment'}->{'dhcpvlan'}, $host_props
);
my $ip_deploy = $host_props->{'interfaces'}->{$iface_dhcpvlan}->{'ipv4'};
- $ip_deploy =~ s{\/[\d]+\Z}{};
+ $ip_deploy =~ s{\/[\d]+\z}{};
foreach ( @{$tmp_hosts} ) {
next if ( !m{$hostname} );
s{\A 127.0.([\d]{1,3}\.[\d]{1,3})}{$ip_deploy}xms;
@@ -724,7 +724,7 @@
. " netmask " . $site_part->{$vlan}->{'netmask'} . " {\n}\n"
);
foreach my $hostclass ( keys %{ $site_part->{$vlan} } ) {
- next if ( $hostclass =~ m{\A (subnet|netmask|routers) \Z}xmso );
+ next if ( $hostclass =~ m{\A (subnet|netmask|routers) \z}xmso );
my $host_part = $site_part->{$vlan}->{$hostclass};
foreach my $host ( keys %{$host_part} ) {
push( @{$dhcp_hosts}, "host " . $host . " {" );
diff -r 6a6f53210e6f -r 3673e7fc9ef9 sbin/update-config
--- a/sbin/update-config Fri Nov 05 14:11:57 2010 +0100
+++ b/sbin/update-config Sat Nov 06 18:36:21 2010 +0100
@@ -33,13 +33,10 @@
#################################
# VARS
-my $PF_CONFIG = {};
-my $GLOBAL_STRUCT = {};
-
my $program = basename $PROGRAM_NAME;
my @options_specs = (
- 'branch=s',
+ 'branch=s',
'debug|d',
'diff|u',
'force-reload|f',
@@ -60,17 +57,59 @@
my $options = {
'help' => 0,
'host' => hostname,
+ 'store' => q{},
};
+
+##################################
+### MAIN
+
+# All options are disabled by default
+
+GetOptions( $options, @options_specs )
+ or die "GetOptions error, try --help: $OS_ERROR\n";
+
+if ( $options->{'help'} ) {
+ do_help();
+ exit 0;
+}
+
+my ( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+ $options->{'host'},
+ $options->{'config'},
+ $options->{'store'},
+ $options->{'force-reload'}
+);
+
+unless ( $PF_CONFIG->{'features'}->{'update'} ) {
+ die qq{$program command has been desactivated in pf-tools.conf\n};
+}
+
+$options->{'site'} ||= $PF_CONFIG->{'location'}->{'site'}
+ || Get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
+
+if ( $options->{'quiet'} ) {
+ print qq{$program started in quiet mode...\n};
+}
+
+$options->{'simul'} = 1 if $options->{'diff'};
+
+Do_update_from_GLOBAL(
+ $options,
+ $GLOBAL_STRUCT,
+ $PF_CONFIG
+);
+
+exit 0;
###################################
# Funtions
-sub Do_help {
- print STDERR << "# ENDHELP";
+sub do_help {
+ print STDERR << "END_OF_HELP";
Usage: $program [options]
--help : print help and exit
- -h --host : hostname for update-config
+ -h --host : hostname
--site : site for hostname (optional)
-c --config : path to access to pf-tools.conf file (optional)
--store : path to storable file which contains gloabl configuration
@@ -83,50 +122,8 @@
-p --pkg_type : specify the package type default is deb (optional)
--branch : update based on a specific VCS branche.
-# ENDHELP
+END_OF_HELP
+
+ return;
}
-##################################
-### MAIN
-
-# All options are disabled by default
-
-GetOptions( $options, @options_specs )
- or die "GetOptions error, try --help: $!\n";
-
-if ( $options->{'help'} ) {
- Do_help();
- exit 0;
-}
-
-$options->{'store'} = "" unless( $options->{'store'} );
-( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
- $options->{'host'},
- $options->{'config'},
- $options->{'store'},
- $options->{'force-reload'}
-);
-
-#### VERIFYING UPDATE FEATURE IN PF-TOOLS CONFIG ABORTING IF DEACTIVATED !!!
-unless( $PF_CONFIG->{'features'}->{'update'} ) {
- die "update-config command has been deactivated in pf-tools.conf";
-}
-
-unless( $options->{'site'} ) {
- $options->{'site'} = $PF_CONFIG->{'location'}->{'site'}
- || Get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
-}
-
-if ( $options->{'quiet'} ) {
- print "update-config started in quiet mode...\n";
-}
-
-$options->{'simul'} = 1 if ( $options->{'diff'} );
-
-Do_update_from_GLOBAL(
- $options,
- $GLOBAL_STRUCT,
- $PF_CONFIG
-);
-
-exit 0;
diff -r 6a6f53210e6f -r 3673e7fc9ef9 t/13.conf.t
--- a/t/13.conf.t Fri Nov 05 14:11:57 2010 +0100
+++ b/t/13.conf.t Sat Nov 06 18:36:21 2010 +0100
@@ -428,7 +428,7 @@
my $test_hostname = hostname;
my $test_hash_subst = Init_SUBST($test_hostname, undef, $test_pf_config, 'private');
-# FIXME bypass cvs/svn/whatever for the moment
+# bypass cvs/svn/whatever for the moment
unlink q{/tmp/pf-test/var/lib/cvsguest/config};
make_path( q{/tmp/pf-test/var/lib/cvsguest} );
symlink qq{$cwd/t/13.conf.cfg1/config-export}, q{/tmp/pf-test/var/lib/cvsguest/config}
diff -r 6a6f53210e6f -r 3673e7fc9ef9 tools/Translate_old_config
--- a/tools/Translate_old_config Fri Nov 05 14:11:57 2010 +0100
+++ b/tools/Translate_old_config Sat Nov 06 18:36:21 2010 +0100
@@ -107,7 +107,7 @@
# Need to see if it is a "virtual pf-tools" host
# or a "real pf-tools" host
foreach my $key ( keys %{ $old_parsing->{$section} } ) {
- if ( $key =~ m{\A ether\.\d+ \Z}xms ) {
+ if ( $key =~ m{\A ether\.\d+ \z}xms ) {
$pftools++;
last;
}
More information about the pf-tools-commits
mailing list