pf-tools/pf-tools: 16 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Sun Nov 7 17:30:23 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/4f0db2d39120
changeset: 931:4f0db2d39120
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 13:56:21 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/de54c5315ab0
changeset: 932:de54c5315ab0
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:14:15 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/ea4bd0213c56
changeset: 933:ea4bd0213c56
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:15:13 2010 +0100
description:
perltidy

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/abaaa5be1965
changeset: 934:abaaa5be1965
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:17:33 2010 +0100
description:
perltidy

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/8a44c31796f1
changeset: 935:8a44c31796f1
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:32:46 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/1460e9a766a9
changeset: 936:1460e9a766a9
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:43:54 2010 +0100
description:
Name variables from the arguments names

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/8cfb757d986d
changeset: 937:8cfb757d986d
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:44:32 2010 +0100
description:
perltidy

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/8f3f1d115b72
changeset: 938:8f3f1d115b72
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 14:47:30 2010 +0100
description:
Move internal functions to the end of the file

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/b3477c757b1f
changeset: 939:b3477c757b1f
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 15:39:44 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/0c7b7a29757c
changeset: 940:0c7b7a29757c
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 15:41:34 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/4c365b476075
changeset: 941:4c365b476075
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 17:53:06 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/7ccf68360960
changeset: 942:7ccf68360960
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 18:02:35 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/569d953667e6
changeset: 943:569d953667e6
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 18:05:21 2010 +0100
description:
No hard tabs

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/71ccc2441374
changeset: 944:71ccc2441374
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 18:12:24 2010 +0100
description:
Style

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/5b0a34da769d
changeset: 945:5b0a34da769d
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 18:14:52 2010 +0100
description:
perltidy

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/d6a9b9a18fdc
changeset: 946:d6a9b9a18fdc
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Nov 07 18:29:34 2010 +0100
description:
Style

diffstat:

2 files changed, 2 insertions(+), 21 deletions(-)
lib/PFTools/Conf.pm |    2 +-
lib/PFTools/Net.pm  |   21 +--------------------

diffs (2160 lines):

diff -r 3673e7fc9ef9 -r d6a9b9a18fdc debian/control
--- a/debian/control	Sat Nov 06 18:36:21 2010 +0100
+++ b/debian/control	Sun Nov 07 18:29:34 2010 +0100
@@ -8,7 +8,7 @@
 
 Package: pf-tools
 Architecture: all
-Depends: perl, perl (>= 5.10.0) | libmd5-perl, libclone-perl, libconfig-inifiles-perl, libmodule-runtime-perl, libnetaddr-ip-perl, libnet-dns-perl, libproc-reliable-perl, libreadonly-xs-perl, libtemplate-tiny-perl, libtext-diff-perl, cvs, ssh, iproute, debconf, psmisc
+Depends: perl, perl (>= 5.10.0) | libmd5-perl, libclone-perl, libconfig-inifiles-perl, liblist-moreutils-perl, libmodule-runtime-perl, libnetaddr-ip-perl, libnet-dns-perl, libproc-reliable-perl, libreadonly-xs-perl, libtemplate-tiny-perl, libtext-diff-perl, cvs, ssh, iproute, debconf, psmisc
 Description: Outils de gestion de la plateforme
  Mise a jour automatique et generation de conf.
  Deploiement de machines.
diff -r 3673e7fc9ef9 -r d6a9b9a18fdc lib/PFTools/Conf.pm
--- a/lib/PFTools/Conf.pm	Sat Nov 06 18:36:21 2010 +0100
+++ b/lib/PFTools/Conf.pm	Sun Nov 07 18:29:34 2010 +0100
@@ -214,13 +214,13 @@
 
     # Initialize $PF_CONFIG with the default configuration if it is empty
     # (that means it had not been initialized yet)
-    unless ( keys %{ $PF_CONFIG } ) {
+    unless ( keys %{$PF_CONFIG} ) {
         $PF_CONFIG = clone($DEFAULT_PF_CONFIG);
     }
 
     # Return the current (possibly default) configuration if no config_file
     # was specified
-    unless ( $config_file ) {
+    unless ($config_file) {
         return $PF_CONFIG;
     }
 
@@ -426,26 +426,23 @@
     my $action_or_type
         = $context eq 'config' ? 'action' : 'type';    # compute it only once
 
-    # FIXME some code factorization seems possible, but
-    # proper tests are needed before changing things here.
-
     if ( $context eq 'host' or $context eq 'model' ) {
-        if ( defined $parsed->{'hostgroup'}->{'model'} ) {
+        my $model = $parsed->{'hostgroup'}->{'model'};
+        if ($model) {
             $parsed->{'hostgroup'}->{'__model'}
-                = Load_conf(
-                $parsed->{'hostgroup'}->{'model'},
-                $hash_subst, 'model', $pf_config
-                );
+                = Load_conf( $model, $hash_subst, 'model', $pf_config );
         }
     }
     else {
         foreach my $section ( keys %{$parsed} ) {
-            next if $section =~ m{ \A __ }xms;    # skip "internal" sections
+
+            # skip "internal" sections
+            next if $section =~ m{ \A __ }xms;
 
             my $section_type = $parsed->{$section}->{$action_or_type};
-            if ( !defined $section_type ) {
+            unless ($section_type) {
                 croak
-                    qq{Key $action_or_type must be defined in section $section from file $file};
+                    qq{Key $action_or_type must be defined in file $file section $section};
             }
 
             if ( $section_type eq 'include' ) {
@@ -461,33 +458,8 @@
     # Merging if needed
     $parsed = __Merge_conf_includes( $parsed, $hash_subst, $context );
 
-    # Basic checks
-    foreach my $section ( keys %{$parsed} ) {
-        next if $section =~ m{ \A __ }xms;    # skip "internal" sections
-
-        my $section_type;
-        if ( $context eq 'host' or $context eq 'model' ) {
-            unless ( $section =~ m{ \A ([^:]+) (?: :: (.+) )? \z }xms ) {
-                croak
-                    qq{ERROR: Unable to compute section type for section $section};
-            }
-            $section_type = $1;
-
-            # $iface_name = $2;
-        }
-        else {
-            $section_type = $parsed->{$section}->{$action_or_type};
-            if ( !defined $section_type ) {
-                croak
-                    qq{Key $action_or_type must be defined in section $section from file $file};
-            }
-        }
-
-        Chk_section_struct(
-            $section, $section_type, $parsed->{$section},
-            $context
-        );
-    }
+    # This will croak on check failures
+    __check_sections( $parsed, $context, $action_or_type, $file );
 
     return $parsed;
 }
@@ -540,7 +512,7 @@
         q{zone}    => sub { Add_zone(@_); },
         q{site}    => sub { Add_site(@_); },
         q{network} => sub { Add_network(@_); },
-        q{server}  => sub { Add_server(@_); },
+        q{server}  => sub { add_server(@_); },
         q{service} => sub { __add_service(@_); },
     );
 
@@ -764,6 +736,7 @@
     }
 
     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} ) {
@@ -896,7 +869,7 @@
 
 =head2 __add_service($args)
 
-This function does the necessary magic (including calling C<Add_host()>) for each
+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 :
 
@@ -946,7 +919,7 @@
             my $hostfile = Get_source( $host, q{}, $hash_subst, $pf_config );
             my $host_parsed
                 = Load_conf( $hostfile, $hash_subst, q{host}, $pf_config );
-            Add_host(
+            add_host(
                 $hostfile, q{host}, $host_parsed, $global_config,
                 $pf_config
             );
@@ -957,5 +930,46 @@
     return;
 }
 
+=head2 __check_sections($parsed, $context, $action_or_type, $file)
+
+Runs some checks on each section of %$parsed
+
+=cut
+
+sub __check_sections {
+    my ( $parsed, $context, $action_or_type, $file ) = @_;
+
+    foreach my $section ( keys %{$parsed} ) {
+
+        # skip "internal" sections
+        next if $section =~ m{ \A __ }xms;
+
+        # compute $section_type
+        my $section_type;
+        if ( $context eq 'host' or $context eq 'model' ) {
+            ($section_type) = $section =~ m{ \A ([^:]+) (?: :: .+ )? \z }xms;
+            unless ($section_type) {
+                croak
+                    qq{ERROR: Unable to compute section type for section $section};
+            }
+        }
+        else {
+            $section_type = $parsed->{$section}->{$action_or_type};
+            unless ($section_type) {
+                croak
+                    qq{Key $action_or_type must be defined in file $file section $section};
+            }
+        }
+
+        # Run the real checks
+        check_section_structure(
+            $section, $section_type, $parsed->{$section},
+            $context
+        );
+    }
+
+    return;
+}
+
 1;    # Magic true value required at end of module
 
diff -r 3673e7fc9ef9 -r d6a9b9a18fdc lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm	Sat Nov 06 18:36:21 2010 +0100
+++ b/lib/PFTools/Conf/Host.pm	Sun Nov 07 18:29:34 2010 +0100
@@ -25,6 +25,7 @@
 use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
 use Fcntl ':mode';
+use List::MoreUtils qw( any uniq );
 use POSIX qw(ceil floor);
 
 use PFTools::Conf::Syntax qw( $DEF_SECTIONS );
@@ -32,11 +33,241 @@
 use PFTools::Structqueries;
 
 our @EXPORT = qw(
-    Add_host
-    Add_server
+    add_host
+    add_server
 );
 
 our @EXPORT_OK = qw();
+
+
+#########################################################################
+#
+# VOID add_host ( STR, HASHREF, HASHREF, HASHREF )
+#
+# This function adds host into global configuration, zone informations
+# and dhcp entries if needed
+# Inputs :
+#  - $hostfile		: filename where host is parsed
+#  - $host2add		: hashref where are stored host definitions according to hostfile-syntax
+#  - $global_config	: hashref where are stored global configuration datas
+#  - $pf_config		: hashref where are stored pf-tools configuration datas
+#
+sub add_host {
+    my ( $hostfile, $type, $host2add, $global_config, $pf_config ) = @_;
+
+    my $boot_def       = $DEF_SECTIONS->{'host'}->{'boot'};
+    my $dep_def        = $DEF_SECTIONS->{'host'}->{'deployment'};
+    my $hostname_model = $host2add->{'hostgroup'}->{'hostname'};
+    $hostname_model
+        =~ m{ \A $pf_config->{'regex'}->{'hostname_model'} \z }xms;
+    my $shortname = $+{HOSTTYPE};
+    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 }xms;
+    my ( $host_last, $node_last )
+        = __Get_host_indexes( $host2add->{'hostgroup'}, $hostname_model );
+
+    foreach my $site ( @{$site_list} ) {
+        my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
+        unless ( $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} ) {
+            $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} = {};
+            push(
+                @{ $site_part->{'HOST'}->{'__hostclass_pxe'} },
+                $hostclass
+            ) if ( $type eq 'host' );
+        }
+        my $host_part = $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass};
+        my $zone      = $site_part->{'zone'};
+        my $prefix    = __Get_site_prefix( $site, $site_part );
+        my $host_list = __Build_hostlist(
+            {
+                'host_last'      => $host_last,
+                'node_last'      => $node_last,
+                'host_part'      => $host_part,
+                'hostname_model' => $hostname_model,
+                'prefix'         => $prefix,
+            }
+        );
+        foreach my $hostname ( sort keys %{$host_list} ) {
+            my $host_number = $host_list->{$hostname}->{'host_number'};
+            my $index       = $host_list->{$hostname}->{'index'};
+            my $hostnum     = $host_list->{$hostname}->{'hostnum'};
+            my $hostnode    = $host_list->{$hostname}->{'hostnode'} || 0;
+            my $dhcpvlan =
+                $host2add->{'deployment'}->{"dhcpvlan\.$host_number"}
+                || $host2add->{'deployment'}->{'dhcpvlan'}
+                || $site_part->{'dhcpvlan'};
+
+            unless ( $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan} ) {
+                croak qq{ERROR: Unknown DHCP vlan $dhcpvlan for $hostname};
+            }
+            $host_part->{$hostname}->{'deployment'} =
+                __Add_deployment_on_host_entry(
+                $type, $host2add, $hostclass, $host_number, $dhcpvlan
+                );
+            if ( $type eq 'host' ) {
+                $host_part->{$hostname}->{'boot'} = __Add_boot_on_host_entry(
+                    $host2add, $host_number, $site_part, $pf_config,
+                );
+                $host_part->{$hostname}->{'dns'}->{'resolver'} =
+                    $host2add->{'dns'}->{"resolver\.$host_number"}
+                    || $host2add->{'dns'}->{'resolver'};
+            }
+
+            # Check interfaces
+            my @if_list = __Get_host_interfaces($host2add);
+            foreach my $iface (@if_list) {
+                my $if2add = __Add_host_interface(
+                    $iface, $hostname, $hostnum, $hostnode,
+                    $host_number, $host2add, \@if_list, $site,
+                    $site_part, $pf_config
+                );
+                my $iface_name = $iface;
+                if ($iface =~ m{\A
+                                    (
+                                        (eth|bond)[\d]+)
+                                        (\.(TAG[\d]+)
+                                    )
+                        
+                                \z}xms
+                    )
+                {
+                    $iface_name =
+                        $1 . '.'
+                        . __Get_vlan_tag_from_site(
+                        $if2add->{'vlan'}, $site_part
+                        );
+                }
+
+                # Adding interface and IPs into site's zone
+                $host_part->{$hostname}->{'interfaces'} = {}
+                    if ( !defined $host_part->{$hostname}->{'interfaces'} );
+                $host_part->{$hostname}->{'interfaces'}->{$iface_name}
+                    = $if2add;
+                $site_part->{'HOST'}->{'BY_MAC'}->{ $if2add->{'mac'} }
+                    = $iface . '.' . $hostname . '.' . $if2add->{'vlan'}
+                    if ( $if2add->{'mac'} );
+                if ($if2add->{'vlan'} eq $dhcpvlan
+                    && $type eq 'host'
+                    && !defined $if2add->{'mac'}
+                    )
+                {
+                    croak qq{ERROR: MAC MUST BE defined for DHCP on $iface};
+                }
+                foreach my $ip_type ( 'ipv4', 'ipv6' ) {
+                    next if ( !$pf_config->{'features'}->{$ip_type} );
+                    my $suffix   = ( $ip_type eq 'ipv6' ) ? '6' : '';
+                    my $addr_key = "BY_ADDR" . $suffix;
+                    my $zone_key = "ZONE" . $suffix;
+                    my $dhcp_key = "DHCP" . $suffix;
+                    my $zone_ip  = $if2add->{$ip_type};
+                    $zone_ip =~ s{ [/] .+ \z }{}xms;
+                    my $zone_part
+                        = $global_config->{$zone_key}->{'BY_NAME'}
+                        ->{$zone}->{'BY_SITE'}->{$site};
+                    my $dhcp_part
+                        = $global_config->{$dhcp_key}->{'BY_SITE'}
+                        ->{$site};
+                    $site_part->{'HOST'}->{$addr_key}->{ $if2add->{$ip_type} }
+                        = $hostname . '.' . $if2add->{'vlan'};
+                    __Add_zone_entry(
+                        {
+                            'hostname'      => $hostname,
+                            'hostclass'     => $hostclass,
+                            'host_part'     => $host_part,
+                            'host_number'   => $host_number,
+                            'iface_def'     => $if2add,
+                            'zone_name'     => $zone,
+                            'zone_part'     => $zone_part,
+                            'ip_type'       => $ip_type,
+                            'shortname'     => $shortname,
+                            'site'          => $site,
+                            'dns_def'       => $host2add->{'dns'},
+                            'index'         => $index,
+                            'global_config' => $global_config,
+                        }
+                    );
+                    my $resolver =
+                        $host2add->{'dns'}->{"resolver\.$host_number"}
+                        || $host2add->{'dns'}->{'resolver'};
+                    __Add_dhcp_entry(
+                        {
+                            'dhcp_part' => $dhcp_part,
+                            'dhcpvlan'  => $dhcpvlan,
+                            'vlan_def' =>
+                                $site_part->{'NETWORK'}->{'BY_NAME'}
+                                ->{$dhcpvlan},
+                            'iface_def' => $if2add,
+                            'resolver'  => $resolver,
+                            'hostname'  => $hostname,
+                            'hostclass' => $hostclass,
+                            'ip_type'   => $ip_type,
+                            'pxefilename' =>
+                                $host2add->{'boot'}->{'pxefilename'},
+                        }
+                        )
+                        if (
+                        $if2add->{'vlan'} eq $dhcpvlan
+                        && $type eq 'host'
+                        );
+                }
+            }
+        }
+    }
+
+    return;
+}
+
+=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
+    );
+}
+
 
 #########################################################################
 #
@@ -52,7 +283,7 @@
 #
 # WARNING : by convention only EDGE sites are authorized for prefixing hostname
 #
-sub __Get_site_prefix ($$) {
+sub __Get_site_prefix {
     my ( $site, $ref_site ) = @_;
 
     if ( $ref_site->{'state'} eq 'EDGE' ) {
@@ -84,13 +315,13 @@
     my ( $ref_hostgroup, $hostname_model ) = @_;
     my ( $node_last, $num_last, $digits, $nodes );
 
-    unless( $ref_hostgroup or $hostname_model ) {
+    unless ( $ref_hostgroup or $hostname_model ) {
         croak q{ERROR: $ref_hostgroup and $hostname_model MUST BE defined};
     }
-    unless( ref $ref_hostgroup eq 'HASH' ) {
+    unless ( ref $ref_hostgroup eq 'HASH' ) {
         croak q{ERROR: bad ref for $ref_hostgroup};
     }
-    if( ref $hostname_model ) {
+    if ( ref $hostname_model ) {
         croak q{ERROR: $hostname_model MUST BE a string};
     }
     $node_last
@@ -98,9 +329,10 @@
         ? ( $ref_hostgroup->{'nodes'} - 1 )
         : 0;
     $num_last = $ref_hostgroup->{'number'} - 1;
-    $hostname_model =~ m{(%*)(_*)\z};
-    $digits = length($1) || 0;
-    $nodes  = length($2) || 0;
+    if ( $hostname_model =~ m{ ([%]*) ([_]*) \z }xms ) {
+        $digits = length($1) || 0;
+        $nodes  = length($2) || 0;
+    }
 
     # Checking nodes
     if ( $node_last && !$nodes ) {
@@ -122,21 +354,38 @@
 
 sub __Get_hostnumber_from_model {
     my ( $model, $num, $node ) = @_;
-    my ( $digits, $nodes, $index );
 
-    if ( $model !~ m{%+} && $model !~ m{_+} ) {
-        return "";
+    my ( $digits_string, $nodes_string )
+        = $model =~ m{
+            (           # $digits_string
+                (?:
+                    [%]+
+                )?
+            )
+            (           # $nodes_string
+                (?:
+                    [_]+
+                )?
+            )
+            \z
+        }xms;
+
+    if ( not $digits_string and not $nodes_string ) {
+        return q{};
     }
-    $model =~ m{(%*)(_*)\z};
-    $digits = length($1) || 0;
-    $nodes  = length($2) || 0;
-    $index  = "";
-    while ( $digits > length($num) ) {
+
+    my $digits = length $digits_string;
+    my $nodes  = length $nodes_string;
+
+    my $index = q{};
+    while ( $digits > length $num ) {
         $index .= "0";
         $digits--;
     }
-    $index = ($node) ? $index . $num . $node : $index . $num;
-    return $index;
+
+    $node ||= q{};
+
+    return $index . $num . $node;
 }
 
 #########################################################################
@@ -158,13 +407,14 @@
     my ( $hostname_model, $hostnum, $hostnode, $site_prefix, $ref_host ) = @_;
     my ( $hostname, $index );
 
-    $hostname   = $hostname_model;
-    $index      = __Get_hostnumber_from_model(
-        $hostname_model, $hostnum, $hostnode 
+    $hostname = $hostname_model;
+    $index    = __Get_hostnumber_from_model(
+        $hostname_model, $hostnum, $hostnode
     );
-    $hostname   =~ s{(%*)(_*)\z}{$index};
-    $hostname   = $site_prefix . $hostname
-        if ( $ref_host->{'prefix'} && $ref_host->{'prefix'} eq 'true' );
+    $hostname =~ s{ ([%]*) ([_]*) \z }{$index}xms;
+    $hostname = $site_prefix . $hostname
+        if $ref_host->{'prefix'} and $ref_host->{'prefix'} eq 'true';
+
     return $hostname;
 }
 
@@ -179,15 +429,32 @@
 # Output :
 #  Returns an arrayref containing the interfaces list
 #
-sub __Get_host_interfaces ($) {
+sub __Get_host_interfaces {
     my ($ref_src) = @_;
     my (@if_list);
 
     foreach my $section ( keys %{$ref_src} ) {
-        next if ( $section !~ /^interface/o );
-        $section =~ /^interface::(((eth|bond)[\d]+)(\.(TAG[\d]+|\d+))?)$/o;
-        push( @if_list, $1 );
+        my ($if) = $section =~ m{
+            \A
+            interface::
+            (
+                (?:             # name
+                    (?:eth|bond)
+                    [\d]+
+                )
+                (?:             # vlan
+                    [.]
+                    (?:TAG)?
+                    [\d]+
+                )?
+            )
+            \z
+        }xms;
+        next unless $if;
+
+        push @if_list, $if;
     }
+
     return @if_list;
 }
 
@@ -210,20 +477,21 @@
 #  Returns a NetAddr::IP object containing the checked IP
 #
 sub __Check_host_ip {
-    my ( $ip_type, $vlan_block, $ipstart, $hostnum, $hostnode, $nodes, $site,
-        $ref_site )
+    my ($ip_type, $vlan_block, $ipstart, $hostnum, $hostnode, $nodes, $site,
+        $ref_site
+        )
         = @_;
 
-    unless( ref( $vlan_block ) eq 'NetAddr::IP' ) {
+    unless ( ref($vlan_block) eq 'NetAddr::IP' ) {
         croak q{ERROR: Invalid $vlan_block object};
     }
     my $realip = NetAddr::IP->new(
         $vlan_block->prefix() . $ipstart, $vlan_block->mask()
     );
-    unless( $realip ) {
+    unless ($realip) {
         croak qq{ERROR: Bad IP with $vlan_block->prefix() and $ipstart};
     }
-    if( $hostnum ) {
+    if ($hostnum) {
         my $add = ($hostnode) ? ( $hostnum * $nodes ) + $hostnode : $hostnum;
         $realip = $realip + $add;
     }
@@ -231,7 +499,7 @@
     if ( defined $host_addr_site->{ $realip->cidr() } ) {
         croak qq{ERROR: $realip->addr() already defined on site $site};
     }
-    unless( $vlan_block->contains( $realip ) ) {
+    unless ( $vlan_block->contains($realip) ) {
         croak qq{ERROR: $realip->addr() is out of range $vlan_block->cidr()};
     }
     return $realip;
@@ -250,16 +518,18 @@
 #
 sub __Get_vlan_list_from_server {
     my ($ref_srv) = @_;
-    my $vlan_list = [];
+    my @vlan_list = ();
 
     foreach my $key ( keys %{$ref_srv} ) {
-        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} )
-        );
+        next unless $key =~ m{ \A ipv }xms;
+
+        my ( $type, $vlan, $num ) = split m{ [.] }xms, $key;
+        push @vlan_list, $vlan;
     }
-    return $vlan_list;
+
+    @vlan_list = uniq @vlan_list;
+
+    return \@vlan_list;
 }
 
 ########################################################################################
@@ -277,18 +547,22 @@
 #
 sub __Get_alias_list_from_server {
     my ( $ref_parsed, $vlan, $host_number ) = @_;
-    my $alias_list = [];
 
+    my @alias_list = ();
     foreach my $key ( keys %{$ref_parsed} ) {
-        next if ( $key !~ m{\Aalias}o );
-        my ( $alias, $name, $host_num ) = split( m{\.}, $key );
-        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} )
-        );
+        next unless $key =~ m{ \A alias }xms;
+
+        my ( $alias, $name, $host_num ) = split m{ [.] }xms, $key;
+        next if $host_number and $host_num and $host_num ne $host_number;
+
+        if ( $vlan eq $ref_parsed->{$key} ) {
+            push @alias_list, $name;
+        }
     }
-    return $alias_list;
+
+    @alias_list = uniq @alias_list;
+
+    return \@alias_list;
 }
 
 ########################################################################################
@@ -308,37 +582,38 @@
     my ( $vlan, $site_part ) = @_;
 
     my $net_part = $site_part->{'NETWORK'}->{'BY_TAG'};
-    foreach my $tag ( keys %{ $net_part } ) {
-        return $tag if( $net_part->{$tag} eq $vlan );
+    foreach my $tag ( keys %{$net_part} ) {
+        return $tag if ( $net_part->{$tag} eq $vlan );
     }
     return;
 }
 
 sub __build_host_from_server {
     my ( $srv_name, $ref_srv ) = @_;
-    my $result = {};
+    my $result    = {};
     my $iface_idx = 0;
     $result->{'hostgroup'}->{'hostname'} = $srv_name;
     foreach my $key ( keys %{$ref_srv} ) {
+        next if $key eq 'type' or $key =~ m{ \A __ }xms;
+
         my $suffix;
-        next if( $key eq 'type' or $key =~ /^__/);
-        my ( $key_type, $spec, $hostnum ) = split( m{\.}, $key );
-        if( $key_type eq 'alias' ) {
+        my ( $key_type, $spec, $hostnum ) = split( m{ [.] }xms, $key );
+        if ( $key_type eq 'alias' ) {
             $result->{'dns'}->{$key} = $ref_srv->{$key};
         }
-        elsif( $key_type =~ /^ipv/ ) {
-            $suffix = ( $hostnum ) ? "\.$hostnum" : "";
-            $result->{ 'interface::eth' . $iface_idx } = {
-                'vlan'.$suffix => $spec,
-                'ipv4'.$suffix => $ref_srv->{$key},
+        elsif ( $key_type =~ m{ \A ipv }xms ) {
+            $suffix = ($hostnum) ? qq{\.$hostnum} : q{};
+            $result->{qq{interface::eth$iface_idx}} = {
+                qq{vlan$suffix} => $spec,
+                qq{ipv4$suffix} => $ref_srv->{$key},
             };
             $iface_idx++;
         }
-        elsif( $key_type eq 'shortname' ) {
-            my $key_name = ( $spec ) ? "$key_type\.$spec" : $key_type;
+        elsif ( $key_type eq 'shortname' ) {
+            my $key_name = $key_type . ( $spec ? qq{\.$spec} : q{} );
             $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};
         }
     }
@@ -361,68 +636,85 @@
 #  - $ref_site		: hashref where are stored the site definition into global configuration
 #  - $pf_config		: hashref where are stored pf-tools configuration datas
 #
-sub __Add_host_interface ($$$$$$$$$$) {
+sub __Add_host_interface {
     my ($iface,    $hostname,    $hostnum, $hostnode, $index,
         $ref_host, $ref_if_list, $site,    $ref_site, $pf_config
     ) = @_;
-    my ( @if_list, $vlan, $ifraw, $iftag, $add_if, $iface_opt );
 
-    my $net_site        = $ref_site->{'NETWORK'}->{'BY_NAME'};
-    my $host_site       = $ref_site->{'HOST'};
-    my $iface_section   = 'interface::' . $iface;
-    my $iface_def       = $ref_host->{$iface_section};
-    my $nodes           = $ref_host->{'hostgroup'}->{'nodes'} || 0;
-    my $host_number     = ($hostnode) ? $hostnum . $hostnode : $hostnum;
-    $iface =~ m{\A  (
-                        (eth|bond)[\d]+
-                    )
-                    (\.
-                        (TAG[\d]+)
-                    )?
-                \z}xms;
-    ( $ifraw, $iftag ) = ( $1, $4 );
+    my $net_site      = $ref_site->{'NETWORK'}->{'BY_NAME'};
+    my $host_site     = $ref_site->{'HOST'};
+    my $iface_section = 'interface::' . $iface;
+    my $iface_def     = $ref_host->{$iface_section};
+    my $nodes         = $ref_host->{'hostgroup'}->{'nodes'} || 0;
+    my $host_number   = ($hostnode) ? $hostnum . $hostnode : $hostnum;
+
+    my ( $ifraw, $iftag ) = $iface =~ m{
+        \A
+        (                   # $ifraw
+            (?:
+                eth | bond
+            )
+            [\d]+
+        )
+        (?:
+            [.]
+            (               # $iftag
+                TAG[\d]+
+            )
+        )?
+        \z
+    }xms;
 
     # Check vlan
-    $vlan = $iface_def->{ 'vlan.' . $host_number } || $iface_def->{'vlan'};
-    unless( $net_site->{$vlan} ) {
+    my $vlan = $iface_def->{ 'vlan.' . $host_number } || $iface_def->{'vlan'};
+    unless ( $net_site->{$vlan} ) {
         croak qq{ERROR: Unknown $vlan for $iface on $hostname on site $site};
     }
-    $add_if->{'vlan'} = $vlan;
+    my $add_if = {
+        'vlan' => $vlan,
+    };
 
     # Iface option(s)
-    $iface_opt = $iface_def->{ 'iface_opt.' . $host_number }
+    my $iface_opt = $iface_def->{ 'iface_opt.' . $host_number }
         || $iface_def->{'iface_opt'};
-    $add_if->{'iface_opt'} = $iface_opt if( defined $iface_opt );
+    $add_if->{'iface_opt'} = $iface_opt if ( defined $iface_opt );
 
     # Check MAC address if defined
     my $mac = $iface_def->{ 'mac.' . $host_number } || "";
-    if( $mac ne "" ) {
+    if ( $mac ne "" ) {
         if ( $host_site->{'BY_MAC'}->{$mac} ) {
             my ( $macif, $machost, $macvlan ) = split(
-                m{\.},
+                m{ [.] }xms,
                 $host_site->{'BY_MAC'}->{$mac}
             );
             croak qq{ERROR: $mac already defined for $macif on $machost};
         }
         $add_if->{'mac'} = $mac;
     }
-    
+
     # Check tag
     my $net_tag = $net_site->{$vlan}->{'tag'};
     if ( $iftag && $iftag =~ m{\A \d+ \z}xms && $net_tag ne $iftag ) {
         croak qq{ERROR: $iftag for $iface_section differs from $vlan def};
     }
 
-    if ( $iface =~ /^bond/ && !$iftag ) {
+    if ( $iface =~ m{ \A bond }xms and not $iftag ) {
+
         # Check if slaves not in use
-        my @slaves = ( $iface_def->{ 'slaves.' . $host_number } )
-            ? split( m{\s*,\s*}, $iface_def->{ 'slaves.' . $host_number } )
-            : split( m{\s*,\s*}, $iface_def->{'slaves'} );
+        my $slaves_iface_def
+            = $iface_def->{ 'slaves.' . $host_number }
+            ? $iface_def->{ 'slaves.' . $host_number }
+            : $iface_def->{'slaves'};
+
+        my @slaves = split m{ \s* [,] \s* }xms, $slaves_iface_def;
         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 ( any { $_ eq $if } @{$ref_if_list} ) {
+                croak
+                    qq{ERROR: host $hostname: $if already in use, cannot be enslaved to $iface};
+            }
         }
-        $add_if->{'slaves'} = join( " ", @slaves );
+
+        $add_if->{'slaves'} = join q{ }, @slaves;
         $add_if->{'mode'} =
             $iface_def->{ 'mode.' . $host_number }
             || $iface_def->{'mode'};
@@ -432,109 +724,139 @@
     }
 
     # Check address and route values
-    foreach my $ip_type ( 'ipv4', 'ipv6' ) {
-        next if ( !$pf_config->{'features'}->{$ip_type} );
-        my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
-        my $netblock = Get_netblock_from_vlan(
-            $ip_type, $net_site->{$vlan}
-        );
-        unless( $netblock ) {
+    foreach my $ip_type (qw( ipv4 ipv6 )) {
+        next unless $pf_config->{'features'}->{$ip_type};
+
+        my $netblock = get_netblock_from_vlan( $ip_type, $net_site->{$vlan} );
+        unless ($netblock) {
             croak qq{ERROR: getting $ip_type subnet for $vlan on $hostname};
         }
-        my @params = ( $iface_def->{$ip_type . '.' . $host_number} )
-            ? ( $ip_type, $netblock,
-                $iface_def->{$ip_type . '.' . $host_number},
-                0, 0, 0, $site, $ref_site )
-            : ( $ip_type, $netblock, $iface_def->{$ip_type},
-                $hostnum, $hostnode, $nodes, $site, $ref_site );
-        my $realip = __Check_host_ip @params ;
+
+        my @params = ( $ip_type, $netblock );
+        my $ip_type_dot_host_number = join q{.}, $ip_type, $host_number;
+        if ( $iface_def->{$ip_type_dot_host_number} ) {
+            push @params, $iface_def->{$ip_type_dot_host_number}, 0, 0, 0;
+        }
+        else {
+            push @params, $iface_def->{$ip_type}, $hostnum, $hostnode, $nodes;
+        }
+        push @params, $site, $ref_site;
+
+        my $realip = __Check_host_ip(@params);
         $add_if->{$ip_type} = $realip->cidr();
 
-        my $route_key   = '@route'.$suffix;
-        my $gw_key      = 'gateway'.$suffix;
+        my $suffix    = $ip_type eq 'ipv6' ? '6' : q{};
+        my $route_key = '@route' . $suffix;
+        my $gw_key    = 'gateway' . $suffix;
+
         my @route_list;
         foreach my $rkey ( keys %{$iface_def} ) {
-            next unless( $rkey =~ m{\A$route_key} );
-            if ( $rkey =~ m{\.(?<number>.+)\z} ) {
-                push ( @route_list, @{$iface_def->{$rkey}} )
-                    if( $+{number} eq $host_number );
+            next unless $rkey =~ m{ \A $route_key }xmso;
+
+            # if ( $rkey =~ m{ [.] $host_number \z }xmso ) {
+            #     push @route_list, @{ $iface_def->{$rkey} };
+            # }
+
+            push @route_list, @{ $iface_def->{$rkey} };
+        }
+
+        foreach my $route (@route_list) {
+            my ( $destination, $via ) = $route =~ m{
+                \A
+                (
+                    \S+         # $destination
+                )
+                \s*
+                (?:
+                    via
+                    \s*
+                    (
+                        \S+     # $via
+                    )
+                )?
+                \z
+            }xmso;
+            next unless $destination;
+
+            my $route2add;
+            if ( $destination eq 'default' ) {
+                $route2add = $destination;
             }
-            push( @route_list, @{$iface_def->{$rkey}} );
-        }
-        foreach my $route ( @route_list ) {
-            $route =~ m{^(\S+)\s*(via\s*(\S+))?$}o;
-            my ( $dest, $via ) = ( $1, $3 );
-            my $route2add = '';
-            if ( $dest ne 'default' ) {
-                my $ip_dest;
-                if ( $dest =~ m{[g-zG-Z]+} ) {
-                    if ( $net_site->{$dest} ) {
+            else {
+                if ( $destination =~ m{ [g-zG-Z]+ }xms )
+                {    # FIXME why not a-z ??
+                    if ( $net_site->{$destination} ) {
+
                         # Dest is a defined network ... translating into IP
-                        $ip_dest = NetAddr::IP->new(
-                                $net_site->{$dest}->{'network'},
-                                $net_site->{$dest}->{'netmask'}
+                        my $ip_dest = NetAddr::IP->new(
+                            $net_site->{$destination}->{'network'},
+                            $net_site->{$destination}->{'netmask'}
                         );
-                        $route2add .= $ip_dest->cidr() . " via ";
+                        $route2add = $ip_dest->cidr();
                     }
                     else {
+
                         # Potentially not parsed host on this site
-                        $route2add .= $dest . " via ";
+                        $route2add = $destination;
                     }
                 }
                 else {
-                    $ip_dest = NetAddr::IP->new($dest);
-                    unless( $ip_dest ) {
+                    my $ip_dest = NetAddr::IP->new($destination);
+                    unless ($ip_dest) {
                         croak qq{ERROR: Bad route $route for $hostname};
                     }
-                    $route2add .= $ip_dest->cidr() . " via ";
+                    $route2add = $ip_dest->cidr();
                 }
             }
-            else {
-                $route2add .= "default via ";
-            }
+
             if ($via) {
-                my $ip_via;
+                $route2add .= q{ via };
+
                 if ( $via eq 'GATEWAY' ) {
-                    unless( $net_site->{$vlan}->{$gw_key} ) {
+                    my $gateway = $net_site->{$vlan}->{$gw_key};
+                    unless ($gateway) {
                         croak qq{ERROR: Unknown gateway for $vlan};
                     }
-                    $route2add .= $net_site->{$vlan}->{$gw_key};
+                    $route2add .= $gateway;
                 }
-                elsif ( $via =~ m{[g-zG-Z]+} ) {
+                elsif ( $via =~ m{ [g-zG-Z]+ }xms ) {   # FIXME why not a-z ??
+
                     # Potentially not parsed host ...
                     # skipping this case for now
                     $route2add .= $via;
                 }
                 else {
                     my $ip_via = NetAddr::IP->new($via);
-                    unless( $ip_via ) {
+                    unless ($ip_via) {
                         croak qq{ERROR: Bad gateway for $route on $hostname};
                     }
-                    unless( $netblock->contains($ip_via) ) {
+                    unless ( $netblock->contains($ip_via) ) {
                         croak qq{ERROR: $ip_via is not on $netblock->cidr()};
                     }
                     $route2add .= $ip_via->addr();
                 }
             }
+
             push( @{ $add_if->{$route_key} }, $route2add );
         }
     }
+
     return $add_if;
 }
 
 sub __Add_dhcp_entry {
-    my ( $param ) = @_;
+    my ($param) = @_;
 
-    my $dhcp_part   = $param->{'dhcp_part'};
-    my $dhcpvlan    = $param->{'dhcpvlan'};
-    my $resolver    = $param->{'resolver'};
-    my $hostname    = $param->{'hostname'};
-    my $hostclass   = $param->{'hostclass'};
-    my $suffix      = ( $param->{'ip_type'} eq 'ipv6' ) ? 6 : '';
-    unless( $dhcp_part->{$dhcpvlan} ) {
+    my $dhcp_part = $param->{'dhcp_part'};
+    my $dhcpvlan  = $param->{'dhcpvlan'};
+    my $resolver  = $param->{'resolver'};
+    my $hostname  = $param->{'hostname'};
+    my $hostclass = $param->{'hostclass'};
+    my $suffix    = ( $param->{'ip_type'} eq 'ipv6' ) ? 6 : '';
+    unless ( $dhcp_part->{$dhcpvlan} ) {
         $dhcp_part->{$dhcpvlan} = {
-            'subnet'    => $param->{'vlan_def'}->{"network$suffix"},
-            'netmask'   => $param->{'vlan_def'}->{"netmask$suffix"},
+            'subnet'  => $param->{'vlan_def'}->{"network$suffix"},
+            'netmask' => $param->{'vlan_def'}->{"netmask$suffix"},
         };
         if ( $param->{'vlan_def'}->{"gateway$suffix"} ) {
             $dhcp_part->{$dhcpvlan}->{'routers'} =
@@ -542,43 +864,46 @@
         }
     }
     $dhcp_part->{$dhcpvlan}->{$hostclass} = {}
-        unless( $dhcp_part->{$dhcpvlan}->{$hostclass} );
-    my $fixed_addr = $param->{'iface_def'}->{$param->{'ip_type'}};
-    $fixed_addr =~ s{/[\d]+\z}{};
+        unless ( $dhcp_part->{$dhcpvlan}->{$hostclass} );
+    my $fixed_addr = $param->{'iface_def'}->{ $param->{'ip_type'} };
+    $fixed_addr =~ s{ [/] [\d]+ \z }{}xms;
     $dhcp_part->{$dhcpvlan}->{$hostclass}->{$hostname} = [
-        'hardware ethernet '. $param->{'iface_def'}->{'mac'} . ";",
+        'hardware ethernet ' . $param->{'iface_def'}->{'mac'} . ";",
         'fixed-address ' . $fixed_addr . ';',
         'filename ' . $param->{'pxefilename'} . ';',
         'option domain-name-servers ' . $resolver . ';',
     ];
+
+    return;
 }
 
 sub __Add_zone_entry {
-    my ( $param ) = @_;
+    my ($param)  = @_;
     my $host_res = {};
     my $zone_res = {};
 
-    my $hostname    = $param->{'hostname'} or return;
-    my $hostclass   = $param->{'hostclass'} or return;
+    my $hostname  = $param->{'hostname'}  or return;
+    my $hostclass = $param->{'hostclass'} or return;
     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;
-    my $zone_part   = $param->{'zone_part'};
-    my $zone_key    = ( $param->{'ip_type'} eq 'ipv6') ? 'ZONE6' : 'ZONE';
-    my $zone        = $param->{'zone_name'};
-    my $shortname   = $param->{'shortname'};
-    my $site        = $param->{'site'};
+    my $zone_ip     = $param->{'iface_def'}->{ $param->{'ip_type'} };
+    $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'};
+    my $shortname = $param->{'shortname'};
+    my $site      = $param->{'site'};
 
-    unless( $param->{'zone_part'}->{$hostclass} ) {
+    unless ( $param->{'zone_part'}->{$hostclass} ) {
         $param->{'zone_part'}->{$hostclass} = {};
-        push( 
-            @{ $param->{'global_config'}->{$zone_key}->{'BY_NAME'}
-                    ->{$zone}->{'__hostclass_order'}->{$site} },
-                $hostclass
+        push(
+            @{  $param->{'global_config'}->{$zone_key}->{'BY_NAME'}
+                    ->{$zone}->{'__hostclass_order'}->{$site}
+                },
+            $hostclass
         );
     }
-    my $host_part   = $param->{'host_part'};
+    my $host_part = $param->{'host_part'};
     $zone_res->{ $hostname . '.' . $vlan } = "A\t$zone_ip";
 
     $zone_part->{$hostclass}->{ $hostname . '.' . $vlan } = "A\t$zone_ip";
@@ -586,7 +911,7 @@
         || $param->{'dns_def'}->{'shortname'};
     return unless $shortname_vlan;
     if ( $shortname ne $hostname && $shortname_vlan eq $vlan ) {
-        if ( ! $zone_part->{$hostclass}->{"$shortname\.$vlan"} ) {
+        if ( !$zone_part->{$hostclass}->{"$shortname\.$vlan"} ) {
             $zone_part->{$hostclass}->{"$shortname\.$vlan"} = [
                 "A\t$zone_ip",
             ];
@@ -596,33 +921,38 @@
                 @{ $zone_part->{$hostclass}->{"$shortname\.$vlan"} },
                 "A\t$zone_ip"
             );
-            $zone_part->{$hostclass}->{$shortname} = "CNAME\t$shortname\.$vlan";
+            $zone_part->{$hostclass}->{$shortname}
+                = "CNAME\t$shortname\.$vlan";
         }
     }
     foreach my $key ( keys %{ $param->{'dns_def'} } ) {
-        next if ( $key !~ /^alias/ );
-        my ( $key_type, $alias, $host_num ) = split( m{\.}, $key );
+        next unless $key =~ m{ \A alias }xms;
+
+        my ( $key_type, $alias, $host_num ) = split( m{ [.] }xms, $key );
         $host_part->{$alias} = $shortname;
         $host_part->{ $alias . $param->{'index'} } = $hostname;
         if ( $param->{'dns_def'}->{$key} eq $vlan ) {
             $zone_part->{$hostclass}->{$alias} = "CNAME\t$shortname\.$vlan";
-            $zone_part->{$hostclass}->{$alias.$param->{'index'}} =
+            $zone_part->{$hostclass}->{ $alias . $param->{'index'} } =
                 "CNAME\t$hostname\.$vlan";
         }
     }
+
+    return;
 }
 
 sub __Add_boot_on_host_entry {
     my ( $host2add, $host_number, $site_part, $pf_config ) = @_;
 
     my $result = {};
+
     # Checking path for PXE elements kernel, initrd ...
     my $boot_def = $DEF_SECTIONS->{'host'}->{'boot'};
     foreach my $key ( keys %{$boot_def} ) {
         next if $key =~ m{ \A MANDATORY }xms;
         my $value = $host2add->{'boot'}->{"$key\.$host_number"}
             || $host2add->{'boot'}->{$key};
-        unless ( $value ) {
+        unless ($value) {
             if ( $key =~ m{ \A (console|cmdline) \z }xms ) {
                 $value = ( $key eq 'console' )
                     ? $site_part->{$key}
@@ -632,8 +962,9 @@
         next unless $value;
 
         # FIXME this should be done on the deploy-host only
-        if ( $key !~ m{ \A (console|cmdline) \z }xms
-            && !-e $pf_config->{'path'}->{'tftp_dir'} . $value )
+        if ($key !~ m{ \A (console|cmdline) \z }xms
+            && !-e $pf_config->{'path'}->{'tftp_dir'} . $value
+            )
         {
             carp
                 qq{WARN: $value in $pf_config->{'path'}->{'tftp_dir'} doesn't exist};
@@ -647,22 +978,22 @@
     my ( $type, $host2add, $hostclass, $host_number, $dhcpvlan ) = @_;
     my $result = {};
 
-    unless( $type or $host2add or $hostclass ) {
+    unless ( $type or $host2add or $hostclass ) {
         croak q{ERROR: one or more parameter is not defined};
     }
-    if( ref $type || ref $hostclass ) {
+    if ( ref $type || ref $hostclass ) {
         croak q{ERROR: $type and/or $hostclass MUST BE a string};
     }
-    unless( ref $host2add eq 'HASH' ) {
+    unless ( ref $host2add eq 'HASH' ) {
         croak q{ERROR: non-ref $host2add};
     }
     my $dep_def = $DEF_SECTIONS->{'host'}->{'deployment'};
     $result = {
-        'hostname_model'    => $host2add->{'hostgroup'}->{'hostname'},
-        'hosttype'          => $hostclass,
-        'order'             => $host2add->{'hostgroup'}->{'order'},
+        'hostname_model' => $host2add->{'hostgroup'}->{'hostname'},
+        'hosttype'       => $hostclass,
+        'order'          => $host2add->{'hostgroup'}->{'order'},
     };
-    if( $type eq 'host' ) {
+    if ( $type eq 'host' ) {
         foreach my $key ( keys %{$dep_def} ) {
             my $value = $host2add->{'deployment'}->{"$key\.$host_number"}
                 || $host2add->{'deployment'}->{$key};
@@ -675,7 +1006,7 @@
 }
 
 sub __Build_hostlist {
-    my ( $param ) = @_; 
+    my ($param) = @_;
 
     my $result = {};
     foreach my $hostnum ( 0 .. $param->{'host_last'} ) {
@@ -699,224 +1030,16 @@
                 ? $hostnum . $hostnode
                 : $hostnum;
             $result->{$hostname} = {
-                'hostnum'       => $hostnum,
-                'index'         => $index,
-                'host_number'   => $host_number,
+                'hostnum'     => $hostnum,
+                'index'       => $index,
+                'host_number' => $host_number,
             };
-            $result->{$hostname}->{'hostnode'} = $hostnode if( $hostnode );
+            $result->{$hostname}->{'hostnode'} = $hostnode if ($hostnode);
         }
     }
     return $result;
 }
 
 
-#########################################################################
-#
-# VOID Add_host ( STR, HASHREF, HASHREF, HASHREF )
-#
-# This function adds host into global configuration, zone informations
-# and dhcp entries if needed
-# Inputs :
-#  - $hostfile		: filename where host is parsed
-#  - $host2add		: hashref where are stored host definitions according to hostfile-syntax
-#  - $global_config	: hashref where are stored global configuration datas
-#  - $pf_config		: hashref where are stored pf-tools configuration datas
-#
-sub Add_host {
-    my ( $hostfile, $type, $host2add, $global_config, $pf_config ) = @_;
+1;    # Magic true value required at end of module
 
-    my $boot_def = $DEF_SECTIONS->{'host'}->{'boot'};
-    my $dep_def  = $DEF_SECTIONS->{'host'}->{'deployment'};
-    my $hostname_model = $host2add->{'hostgroup'}->{'hostname'};
-    $hostname_model =~ /^$pf_config->{'regex'}->{'hostname_model'}$/;
-    my $shortname = $+{HOSTTYPE};
-    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} );
-    my ( $host_last, $node_last )
-        = __Get_host_indexes( $host2add->{'hostgroup'}, $hostname_model );
-
-    foreach my $site ( @{$site_list} ) {
-        my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
-        unless ( $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} ) {
-            $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} = {};
-            push( @{ $site_part->{'HOST'}->{'__hostclass_pxe'} },
-                $hostclass ) if( $type eq 'host' );
-        }
-        my $host_part = $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass};
-        my $zone      = $site_part->{'zone'};
-        my $prefix    = __Get_site_prefix( $site, $site_part );
-        my $host_list = __Build_hostlist (
-            {
-                'host_last'         => $host_last,
-                'node_last'         => $node_last,
-                'host_part'         => $host_part,
-                'hostname_model'    => $hostname_model,
-                'prefix'            => $prefix,
-            }
-        );
-        foreach my $hostname ( sort keys %{$host_list} ) {
-            my $host_number = $host_list->{$hostname}->{'host_number'};
-            my $index = $host_list->{$hostname}->{'index'};
-            my $hostnum = $host_list->{$hostname}->{'hostnum'};
-            my $hostnode = $host_list->{$hostname}->{'hostnode'} || 0;
-            my $dhcpvlan =
-                $host2add->{'deployment'}->{"dhcpvlan\.$host_number"}
-                || $host2add->{'deployment'}->{'dhcpvlan'}
-                || $site_part->{'dhcpvlan'};
-            unless( $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan} ) {
-               croak qq{ERROR: Unknown DHCP vlan $dhcpvlan for $hostname};
-            }
-            $host_part->{$hostname}->{'deployment'} =
-                __Add_deployment_on_host_entry (
-                    $type, $host2add, $hostclass, $host_number, $dhcpvlan
-                );
-            if( $type eq 'host' ) {
-                $host_part->{$hostname}->{'boot'} = __Add_boot_on_host_entry (
-                    $host2add, $host_number, $site_part, $pf_config,
-                );
-                $host_part->{$hostname}->{'dns'}->{'resolver'} =
-                    $host2add->{'dns'}->{"resolver\.$host_number" }
-                    || $host2add->{'dns'}->{'resolver'};
-            }
-            # Check interfaces
-            my @if_list = __Get_host_interfaces($host2add);
-            foreach my $iface (@if_list) {
-                my $if2add = __Add_host_interface(
-                    $iface,       $hostname, $hostnum,  $hostnode,
-                    $host_number, $host2add, \@if_list, $site,
-                    $site_part,   $pf_config
-                );
-                my $iface_name = $iface;
-                if ( $iface =~ m{\A
-                                    (
-                                        (eth|bond)[\d]+)
-                                        (\.(TAG[\d]+)
-                                    )
-                        
-                                \z}xms
-                ) {
-                    $iface_name =
-                        $1 . '.'
-                        . __Get_vlan_tag_from_site(
-                            $if2add->{'vlan'}, $site_part );
-                }
-
-                # Adding interface and IPs into site's zone
-                $host_part->{$hostname}->{'interfaces'} = {}
-                    if ( !defined $host_part->{$hostname}->{'interfaces'} );
-                $host_part->{$hostname}->{'interfaces'}->{$iface_name}
-                    = $if2add;
-                $site_part->{'HOST'}->{'BY_MAC'}->{ $if2add->{'mac'} }
-                    = $iface . '.' . $hostname . '.' . $if2add->{'vlan'}
-                    if ( $if2add->{'mac'} );
-                if ( $if2add->{'vlan'} eq $dhcpvlan
-                    && $type eq 'host'
-                    && !defined $if2add->{'mac'} )
-                {
-                    croak qq{ERROR: MAC MUST BE defined for DHCP on $iface};
-                }
-                foreach my $ip_type ( 'ipv4', 'ipv6' ) {
-                    next if ( !$pf_config->{'features'}->{$ip_type} );
-                    my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
-                    my $addr_key = "BY_ADDR".$suffix;
-                    my $zone_key = "ZONE".$suffix;
-                    my $dhcp_key = "DHCP".$suffix;
-                    my $zone_ip = $if2add->{$ip_type};
-                    $zone_ip =~ s{/.+\z}{};
-                    my $zone_part
-                        = $global_config->{$zone_key}->{'BY_NAME'}
-                        ->{$zone}->{'BY_SITE'}->{$site};
-                    my $dhcp_part
-                        = $global_config->{$dhcp_key}->{'BY_SITE'}
-                        ->{$site};
-                    $site_part->{'HOST'}->{$addr_key}->{ $if2add->{$ip_type} }
-                        = $hostname . '.' . $if2add->{'vlan'};
-                    __Add_zone_entry (
-                        {
-                            'hostname'      => $hostname,
-                            'hostclass'     => $hostclass,
-                            'host_part'     => $host_part,
-                            'host_number'   => $host_number,
-                            'iface_def'     => $if2add,
-                            'zone_name'     => $zone,
-                            'zone_part'     => $zone_part,
-                            'ip_type'       => $ip_type,
-                            'shortname'     => $shortname,
-                            'site'          => $site,
-                            'dns_def'       => $host2add->{'dns'},
-                            'index'         => $index,
-                            'global_config' => $global_config,
-                        }
-                    );
-                    my $resolver = 
-                        $host2add->{'dns'}->{"resolver\.$host_number"}
-                        || $host2add->{'dns'}->{'resolver'};
-                    __Add_dhcp_entry ( {
-                        'dhcp_part' => $dhcp_part,
-                        'dhcpvlan'  => $dhcpvlan,
-                        'vlan_def'  =>
-                        $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan},
-                        'iface_def' => $if2add,
-                        'resolver'  => $resolver,
-                        'hostname'  => $hostname,
-                        'hostclass' => $hostclass,
-                        'ip_type'   => $ip_type,
-                        'pxefilename'   =>
-                            $host2add->{'boot'}->{'pxefilename'},
-                    } ) if(
-                        $if2add->{'vlan'} eq $dhcpvlan
-                        && $type eq 'host'
-                    );
-                }
-            }
-        }
-    }
-}
-
-=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 3673e7fc9ef9 -r d6a9b9a18fdc lib/PFTools/Conf/Network.pm
--- a/lib/PFTools/Conf/Network.pm	Sat Nov 06 18:36:21 2010 +0100
+++ b/lib/PFTools/Conf/Network.pm	Sun Nov 07 18:29:34 2010 +0100
@@ -43,7 +43,7 @@
 =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 :
+a hash containing the following named parameters:
 
 =over
 
@@ -74,36 +74,38 @@
 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 )
+    my ($start_file,    $section_name, $section_ref,
+        $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} );
-        my $zone_key = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
+    foreach my $ip_type (qw( ipv4 ipv6 )) {
+        next unless $pf_config->{'features'}->{$ip_type};
+
+        my $zone_key = $ip_type eq 'ipv6' ? 'ZONE6' : 'ZONE';
         my $zone_part = $global_config->{$zone_key}->{'BY_NAME'};
-        if ( defined $zone_part->{$zone_name} ) {
-            carp qq{WARN: $zone_name from $netfile is already defined};
+        if ( defined $zone_part->{$section_name} ) {
+            carp qq{WARN: $section_name from $start_file is already defined};
             return;
         }
-        $zone_part->{$zone_name} = {
-            'SOA'               => $zone2add,
+
+        $zone_part->{$section_name} = {
+            'SOA'               => $section_ref,
             'BY_SITE'           => {},
             '__network_order'   => {},
-            '__hostclass_order' => {}
+            '__hostclass_order' => {},
         };
-        $zone_part->{$zone_name}->{'SOA'}     = $zone2add;
-        $zone_part->{$zone_name}->{'BY_SITE'} = {};
     }
+
+    return;
 }
 
 =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 :
+a hash containing the following named parameters:
 
 =over
 
@@ -134,59 +136,66 @@
 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 )
+    my ($start_file,    $section_name, $section_ref,
+        $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};
+    if ( defined $global_config->{'SITE'}->{'BY_NAME'}->{$section_name} ) {
+        carp qq{WARN: $section_name from $start_file already defined};
         return;
     }
 
-    if ( $site2add->{'state'} eq 'ROOT' ) {
+    if ( $section_ref->{'state'} eq 'ROOT' ) {
         if ( $global_config->{'SITE'}->{'ROOT'} ) {
-            carp qq{WARN: ROOT site is already defined : skipping $site_name};
+            carp
+                qq{WARN: ROOT site is already defined: skipping $section_name};
             return;
         }
-        $global_config->{'SITE'}->{'ROOT'} = $site_name;
+
+        $global_config->{'SITE'}->{'ROOT'} = $section_name;
     }
     else {
-        push @{ $global_config->{'SITE'}->{'EDGE'} }, $site_name;
+        push @{ $global_config->{'SITE'}->{'EDGE'} }, $section_name;
     }
 
     my $site_part = $global_config->{'SITE'}->{'BY_NAME'};
 
-    $site_part->{$site_name} = $site2add;
-    $site_part->{$site_name}->{'NETWORK'} = {
+    $site_part->{$section_name} = $section_ref;
+    $site_part->{$section_name}->{'NETWORK'} = {
         'BY_NAME' => {},
         'BY_TAG'  => {},
     };
-    $site_part->{$site_name}->{'HOST'} = {
+    $site_part->{$section_name}->{'HOST'} = {
         'BY_NAME' => {},
         'BY_MAC'  => {},
     };
-    $site_part->{$site_name}->{'SERVICE'} = {
+    $site_part->{$section_name}->{'SERVICE'} = {
         'BY_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} );
+    push @{ $global_config->{'SITE'}->{'__site_list'} }, $section_name;
 
-        my $suffix      = ( $ip_type eq 'ipv6' ) ? 6 : "";
-        my $zone_part   = $global_config->{'ZONE'.$suffix};
-        my $dhcp_part   = $global_config->{'DHCP'.$suffix};
-        my $addr_key    = 'BY_ADDR'.$suffix;
-        unless( $zone_part->{'BY_NAME'}->{$zone} ) {
-            croak qq{ERROR: Unknown $zone from $netfile};
+    my $zone     = $section_ref->{'zone'};
+    my $dhcpvlan = $section_ref->{'dhcpvlan'};
+    foreach my $ip_type (qw( ipv4 ipv6 )) {
+        next unless $pf_config->{'features'}->{$ip_type};
+
+        my $suffix    = $ip_type eq 'ipv6' ? 6 : q{};
+        my $zone_part = $global_config->{"ZONE$suffix"};
+        my $dhcp_part = $global_config->{"DHCP$suffix"};
+        my $addr_key  = "BY_ADDR$suffix";
+        unless ( $zone_part->{'BY_NAME'}->{$zone} ) {
+            croak qq{ERROR: Unknown $zone from $start_file};
         }
-        $site_part->{$site_name}->{'NETWORK'}->{$addr_key} = {};
-        $site_part->{$site_name}->{'HOST'}->{$addr_key}    = {};
-        $zone_part->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site_name} = {};
-        $zone_part->{'BY_SITE'}->{$site_name} = $zone;
-        $dhcp_part->{'BY_SITE'}->{$site_name} = {
+
+        $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->{'BY_SITE'}->{$section_name} = $zone;
+        $dhcp_part->{'BY_SITE'}->{$section_name} = {
             $dhcpvlan => {
                 'subnet'  => q{},
                 'netmask' => q{},
@@ -200,7 +209,7 @@
 =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 :
+a hash containing the following named parameters:
 
 =over
 
@@ -231,107 +240,123 @@
 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 ($start_file,    $section_name, $section_ref,
+        $global_config, $pf_config
+        )
+        = @$args{
+        qw( start_file section_name section_ref global_config pf_config )
         };
 
     my $site_part = $global_config->{'SITE'};
-    my $site_list = Get_site_list( $ref_net, $global_config );
-    my $net2add = {
-        scope => $ref_net->{'scope'},
+    my $site_list = Get_site_list( $section_ref, $global_config );
+    my $net2add   = {
+        scope => $section_ref->{'scope'},
     };
-    $net2add->{'comment'} = $ref_net->{'comment'}
-        if $ref_net->{'comment'};
+    $net2add->{'comment'} = $section_ref->{'comment'}
+        if $section_ref->{'comment'};
 
     # Check TAG
-    if ( $ref_net->{'tag'}
-        && ( $ref_net->{'tag'} < 0 || $ref_net->{'tag'} > 4095 ) )
+    if ($section_ref->{'tag'}
+        && ( $section_ref->{'tag'} < 0 || $section_ref->{'tag'} > 4095 )
+        )
     {
-        croak qq{ERROR: Invalid tag $ref_net->{'tag'} from file $netfile};
+        croak
+            qq{ERROR: Invalid tag $section_ref->{'tag'} from file $start_file};
     }
 
     # Check IP values
-    foreach my $ip_type ( 'ipv4', 'ipv6' ) {
-        next if ( !$pf_config->{'features'}->{$ip_type} );
-        my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
-        my $net_block = Get_netblock_from_vlan( $ip_type, $ref_net );
-        my $zone_key    = 'ZONE'.$suffix;
-        my $dhcp_key    = 'DHCP'.$suffix;
-        my $netaddr_key = 'BY_ADDR'.$suffix;
-        my $gw_key      = 'gateway'.$suffix;
-        $net2add->{ 'network' . $suffix } = $net_block->addr();
-        $net2add->{ 'netmask' . $suffix } = $net_block->mask();
+    foreach my $ip_type (qw( ipv4 ipv6 )) {
+        next unless $pf_config->{'features'}->{$ip_type};
 
-        if ( $ref_net->{$gw_key} ) {
+        my $suffix = $ip_type eq 'ipv6' ? '6' : q{};
+        my $net_block   = get_netblock_from_vlan( $ip_type, $section_ref );
+        my $zone_key    = qq{ZONE$suffix};
+        my $dhcp_key    = qq{DHCP$suffix};
+        my $netaddr_key = qq{BY_ADDR$suffix};
+        my $gw_key      = qq{gateway$suffix};
+        $net2add->{"network$suffix"} = $net_block->addr();
+        $net2add->{"netmask$suffix"} = $net_block->mask();
+
+        if ( $section_ref->{$gw_key} ) {
             my $ip_gw = NetAddr::IP->new(
-                $net_block->prefix() . $ref_net->{$gw_key},
+                $net_block->prefix() . $section_ref->{$gw_key},
                 $net_block->mask()
             );
-            unless( $ip_gw ) {
-                croak qq{ERROR: Invalid $ip_type gateway on $net_name};
+            unless ($ip_gw) {
+                croak qq{ERROR: Invalid $ip_type gateway on $section_name};
             }
-            unless( $net_block->contains($ip_gw) ) {
+            unless ( $net_block->contains($ip_gw) ) {
                 croak qq{ERROR: $ip_gw->addr() is not in $net_block->cidr()};
             }
             $net2add->{$gw_key} = $ip_gw->addr();
         }
-        $net2add->{'tag'} = $ref_net->{'tag'};
+
+        $net2add->{'tag'} = $section_ref->{'tag'};
+
         foreach my $site ( @{$site_list} ) {
             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};
+            if ( $net_part->{'BY_NAME'}->{$section_name} ) {
+                carp
+                    qq{WARN: $section_name from $start_file is already defined};
                 next;
             }
             if (
-                $ref_net->{'tag'}
-                && $net_part->{'BY_TAG'}->{ $ref_net->{'tag'} } )
+                $section_ref->{'tag'}
+                && $net_part->{'BY_TAG'}->{ $section_ref->{'tag'} }
+                )
             {
-                croak qq{ERROR: Duplicate tag  $ref_net->{'tag'} for $net_name};
+                croak
+                    qq{ERROR: Duplicate tag  $section_ref->{'tag'} for $section_name};
             }
             if (
                 $net_part->{'BY_ADDR'}->{ $net_block->cidr() }
                 && $net_part->{'BY_ADDR'}->{ $net_block->cidr() } ne
-                $net_name )
+                $section_name
+                )
             {
-                croak qq{ERROR: subnet for $net_name already in used};
+                croak qq{ERROR: subnet for $section_name already in use};
             }
 
             # Adding network to the network part of the global structure
             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
-                if ( $ref_net->{'tag'} );
+            $net_part->{'BY_NAME'}->{$section_name}           = $net2add;
+            $net_part->{$netaddr_key}->{ $net_block->cidr() } = $section_name;
+            $net_part->{'BY_TAG'}->{ $section_ref->{'tag'} }  = $section_name
+                if $section_ref->{'tag'};
 
-            # Adding entries for network, netmask, broadcast etc. into the DNS zone
+       # Adding entries for network, netmask, broadcast etc. into the DNS zone
             my $zone
                 = $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
             my $zone_part = $global_config->{$zone_key}->{'BY_NAME'}->{$zone};
-            push( @{ $zone_part->{'__network_order'}->{$site} }, $net_name );
-            $zone_part->{'BY_SITE'}->{$site}->{$net_name} = {};
+            push @{ $zone_part->{'__network_order'}->{$site} }, $section_name;
+            $zone_part->{'BY_SITE'}->{$site}->{$section_name} = {};
 
             # Adding IPv4 entries
-            $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'network'}
+            $zone_part->{'BY_SITE'}->{$site}->{$section_name}->{'network'}
                 = "A\t" . $net_block->addr();
-            $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'netmask'}
+            $zone_part->{'BY_SITE'}->{$site}->{$section_name}->{'netmask'}
                 = "A\t" . $net_block->mask();
-            my $broad = $net_block->broadcast();
-            $broad =~ s/\/.*$//;
-            $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'broadcast'}
-                = "A\t" . $broad;
-            $zone_part->{'BY_SITE'}->{$site}->{$net_name}->{'gateway'}
+            my $broadcast = $net_block->broadcast();
+            $broadcast =~ s{ [/].* \z }{}xms;    # remove /prefix
+            $zone_part->{'BY_SITE'}->{$site}->{$section_name}->{'broadcast'}
+                = "A\t" . $broadcast;
+            $zone_part->{'BY_SITE'}->{$site}->{$section_name}->{'gateway'}
                 = "A\t" . $net2add->{$gw_key}
-                if ( defined $net2add->{$gw_key} );
-            if ( defined $dhcp_part->{$net_name} ) {
-                $dhcp_part->{$net_name}->{'subnet'}  = $net_block->addr();
-                $dhcp_part->{$net_name}->{'netmask'} = $net_block->mask();
+
+                if defined $net2add->{$gw_key};
+
+            if ( defined $dhcp_part->{$section_name} ) {
+                $dhcp_part->{$section_name}->{'subnet'}  = $net_block->addr();
+                $dhcp_part->{$section_name}->{'netmask'} = $net_block->mask();
                 if ( defined $net2add->{'gateway'} ) {
-                    $dhcp_part->{$net_name}->{'routers'}
+                    $dhcp_part->{$section_name}->{'routers'}
                         = $net2add->{'gateway'};
                 }
             }
         }
     }
+
+    return;
 }
 
 1;
diff -r 3673e7fc9ef9 -r d6a9b9a18fdc lib/PFTools/Conf/Syntax.pm
--- a/lib/PFTools/Conf/Syntax.pm	Sat Nov 06 18:36:21 2010 +0100
+++ b/lib/PFTools/Conf/Syntax.pm	Sun Nov 07 18:29:34 2010 +0100
@@ -35,7 +35,7 @@
     $MODEL_CONFIG_REGEX
     $DEPLOY_CONFIG_REGEX
 
-    Chk_section_struct
+    check_section_structure
 );
 
 our @EXPORT_OK = qw();
@@ -65,33 +65,33 @@
 }xms;
 our $MODEL_CONFIG_REGEX = qr{
     \A
-    (?<HOSTTYPE>		# HOSTTYPE
-	(
-	    (?<POPNAME>			# POPNAME (optional)
-		[a-z]{3}\d{1}
-	    )
-	    -
-	)?
-	(
-	    [a-z0-9-]+[a-z-]	# host type (without the POP name)
-	)
+    (?<HOSTTYPE>                # HOSTTYPE
+        (
+            (?<POPNAME>                 # POPNAME (optional)
+                [a-z]{3}\d{1}
+            )
+            -
+        )?
+        (
+            [a-z0-9-]+[a-z-]    # host type (without the POP name)
+        )
     )
-    %*		        	# HOSTDIGITS MARK (optional)
-    _*		        	# HOSTNODEINDEX MARK (optional)
+    %*                          # HOSTDIGITS MARK (optional)
+    _*                          # HOSTNODEINDEX MARK (optional)
     \z
 }xms;
 our $HOST_CONFIG_REGEX = qr{
     \A
-    (?<HOSTTYPE>		# HOSTTYPE
-	(
-	    (?<POPNAME>		# POPNAME (optional)
-		[a-z]{3}\d
-	    )
-	    -
-	)?
-	(
-	    [a-z0-9-]+[a-z-]	# host type (without the POP name)
-	)
+    (?<HOSTTYPE>                # HOSTTYPE
+        (
+            (?<POPNAME>         # POPNAME (optional)
+                [a-z]{3}\d
+            )
+            -
+        )?
+        (
+            [a-z0-9-]+[a-z-]    # host type (without the POP name)
+        )
     )
     (?<HOSTDIGITS>              # HOSTDIGITS (optional)
         \d*
@@ -119,16 +119,16 @@
 #####################################
 # Structure for the hash below :
 # {
-#	<context> = {
-#		<section> = {
-#			'MANDATORY_KEYS' => ARRAYREF containing mandatory keys
-#			<key1> => <REGEX> or 'undefined', if value is not 'undefined', then
-#					use <REGEX>
-#			...
-#			<keyn> => <REGEX> or 'undefined', if value is not 'undefined', then
-#					use <REGEX>
-#		}
-#	}
+#       <context> = {
+#               <section> = {
+#                       'MANDATORY_KEYS' => ARRAYREF containing mandatory keys
+#                       <key1> => <REGEX> or 'undefined', if value is not 'undefined', then
+#                                       use <REGEX>
+#                       ...
+#                       <keyn> => <REGEX> or 'undefined', if value is not 'undefined', then
+#                                       use <REGEX>
+#               }
+#       }
 # }
 our $DEF_SECTIONS = {
     'host' => {
@@ -317,17 +317,17 @@
 
 =head2
 
-Chk_section_struct( $section_name, $section_type, $section_hash, $context )
+check_section_structure( $section_name, $section_type, $section_hash, $context )
 
 Check $section_hash validity against $DEF_SECTIONS. Returns a true value on
 success, or croaks on errors.
 
 =cut
 
-sub Chk_section_struct {
+sub check_section_structure {
     my ( $section_name, $section_type, $section_hash, $context ) = @_;
 
-    my $int_context = ( $context eq 'model' ) ? 'host' : $context;
+    my $int_context = $context eq 'model' ? 'host' : $context;
 
     if ( !defined $DEF_SECTIONS->{$int_context}->{$section_type} ) {
         croak qq{ERROR: Invalid section type $section_type};
@@ -361,7 +361,7 @@
         # Clean key names by removing .default or .%HOSTNUM% suffix
         foreach my $key ( keys %{$section_hash} ) {
             my $new = $key;
-            $new =~ s/\..*$//;
+            $new =~ s{ [.] .* \z }{}xms;
             $section_tmp->{$new}->{'ORIG_NAME'} = $key;
             $section_tmp->{$new}->{'VALUE'}     = $section_hash->{$key};
         }
@@ -375,7 +375,7 @@
     foreach my $key ( @{ $definition->{'MANDATORY_KEYS'} } ) {
         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';
+            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} ) {
@@ -395,14 +395,14 @@
         my ( $tab_values, $key_name );
         if ( $int_context eq 'host' ) {
             $tab_values
-                = ( $key !~ /^@/ )
+                = ( $key !~ m{ \A [@] }xms )
                 ? [ $section_tmp->{$key}->{'VALUE'} ]
                 : $section_tmp->{$key}->{'VALUE'};
             $key_name = $section_tmp->{$key}->{'ORIG_NAME'};
         }
         else {
             $tab_values
-                = ( $key !~ /^@/ )
+                = ( $key !~ m{ \A [@] }xms )
                 ? [ $section_tmp->{$key} ]
                 : $section_tmp->{$key};
             $key_name = $key;
@@ -411,8 +411,8 @@
         foreach my $value ( @{$tab_values} ) {
 
             # Remove surrounding spaces
-            $value =~ s{\A \s*}{}xms;
-            $value =~ s{\s* \z}{}xms;
+            $value =~ s{ \A \s* }{}xms;
+            $value =~ s{ \s* \z }{}xms;
 
             if ( $value !~ m{ \A $definition->{$key} \z }xms ) {
                 croak
@@ -424,4 +424,6 @@
     return 1;
 }
 
-1;
+
+1;    # Magic true value required at end of module
+
diff -r 3673e7fc9ef9 -r d6a9b9a18fdc lib/PFTools/Net.pm
--- a/lib/PFTools/Net.pm	Sat Nov 06 18:36:21 2010 +0100
+++ b/lib/PFTools/Net.pm	Sun Nov 07 18:29:34 2010 +0100
@@ -1,24 +1,25 @@
 package PFTools::Net;
-##
-##  Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
-##  Copyright (C) 2005-2007 Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
-##  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
-##  Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
-##
-##  This program is free software; you can redistribute it and/or
-##  modify it under the terms of the GNU General Public License
-##  as published by the Free Software Foundation; either version 2
-##  of the License, or (at your option) any later version.
-##
-##  This program is distributed in the hope that it will be useful,
-##  but WITHOUT ANY WARRANTY; without even the implied warranty of
-##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-##  GNU General Public License for more details.
-##
-##  You should have received a copy of the GNU General Public License
-##  along with this program; if not, write to the Free Software
-##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-##
+
+#
+#  Copyright (C) 2007-2010 Christophe Caillet <quadchris at free.fr>
+#  Copyright (C) 2005-2007 Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
+#  Copyright (C) 2003-2005 Damien Clermonte <damien at sitadelle.com>
+#  Copyright (C) 2001-2003 Olivier Molteni <olivier at molteni.net>
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
 
 use strict;
 use warnings;
@@ -30,74 +31,74 @@
 use NetAddr::IP;
 
 use PFTools::Logger;
+
 #use PFTools::Structqueries;
 
 our @EXPORT = qw(
-    Get_netblock_from_vlan
-    Resolv_hostname_from_DNS
+    get_netblock_from_vlan
+    resolve_hostname_from_dns
 );
 
 our @EXPORT_OK = qw();
 
-#########################################################################
-#
-# NetAddr::IP Get_netblock_from_vlan ( STR , HASHREF )
-#
-# This function build a NetAddr::IP object, in the same time permits the control
-# of IP values defined for a given network definition
-# Inputs :
-#  - $sect_hash		: hashref containing the section where site key is defined
-#  - $global_config	: hashref where is stored global configuration
-#
-# Output :
-#  Return a NetAddr::IP object containing the netblock for a specifed network definition
-#
-sub Get_netblock_from_vlan ($$) {
+=head2 Get_netblock_from_vlan ( $type, $net_hash )
+
+This function builds a NetAddr::IP object, in the same time permits the
+control of IP values defined for a given network definition.
+
+=cut
+
+sub get_netblock_from_vlan {
     my ( $type, $net_hash ) = @_;
 
-    if( ref $type ) {
-        carp q{ERROR: $type parameter MUST BE a string};
-        return;
+    if ( ref $type ) {
+        croak q{ERROR: $type parameter MUST BE a string};
     }
-    if( ref $net_hash ne 'HASH' ) {
-        carp q{ERROR: non-ref $net-hash paramter};
-        return;
+    if ( ref $net_hash ne 'HASH' ) {
+        croak q{ERROR: non-ref $net-hash paramter};
     }
-    return unless( ref $net_hash eq 'HASH' );
-    my $suffix = ( $type eq 'ipv6' ) ? '6' : '';
-    my $net_def = ( $net_hash->{ 'network' . $suffix } );
+
+    my $suffix = $type eq 'ipv6' ? '6' : q{};
+    my $net_def = $net_hash->{"network$suffix"};
+
     my $block;
-    if ( $net_hash->{ 'network' . $suffix } !~ m{\/[\d]+} ) {
-        unless ( $net_hash->{ 'netmask' } ) {
+    if ( $net_hash->{"network$suffix"} =~ m{ [/] [\d]+ }xms ) {
+        $block = NetAddr::IP->new($net_def);
+    }
+    else {
+        my $netmask = $net_hash->{'netmask'};
+        unless ($netmask) {
             croak q{ERROR: Unable to retrieve netmask};
         }
-        $block = new NetAddr::IP( $net_def, $net_hash->{ 'netmask' } );    
+        $block = NetAddr::IP->new( $net_def, $netmask );
     }
-    else {
-        $block = new NetAddr::IP( $net_def );
-    }
-    unless( $block ) {
+
+    unless ($block) {
         croak qq{ERROR: Invalid netblock definition $net_def};
     }
+
     return $block;
 }
 
-sub Resolv_hostname_from_DNS ($) {
+sub resolve_hostname_from_dns {
     my ($hostname) = @_;
-    my $resolved = [];
 
-    my $res   = Net::DNS::Resolver->new;
+    my $res   = Net::DNS::Resolver->new();
     my $query = $res->search($hostname);
 
-    unless( $query ) {
-        carp qq{ERROR: Query failed: $res->errorstring};
-        return;
+    unless ($query) {
+        croak qq{ERROR: Query failed: $res->errorstring};
     }
+
+    my @resolved = ();
     foreach my $rr ( $query->answer ) {
-        next unless $rr->type eq "A";
-        push( @{$resolved}, $rr->address );
+        next unless $rr->type eq q{A};
+        push @resolved, $rr->address;
     }
-    return $resolved;
+
+    return \@resolved;
 }
 
-1;
+
+1;    # Magic true value required at end of module
+
diff -r 3673e7fc9ef9 -r d6a9b9a18fdc lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm	Sat Nov 06 18:36:21 2010 +0100
+++ b/lib/PFTools/Utils.pm	Sun Nov 07 18:29:34 2010 +0100
@@ -49,7 +49,6 @@
     Mk_zone_for_site
     Change_kopt_for_hostname
 
-    Resolv_hostname_from_DNS
     Resolv_hostname_from_GLOBAL
     Search_and_replace
 );
@@ -493,7 +492,7 @@
             my $vlan_def = Get_vlan_config_from_CONFIG(
                 $hostvlan, $global_config, $site
             );
-            my $netblock = Get_netblock_from_vlan( $ip_type, $vlan_def );
+            my $netblock = get_netblock_from_vlan( $ip_type, $vlan_def );
             my $prefix   = $netblock->cidr();
             $prefix      =~ s{\A [^/]+\/([\d]+) \z}{$1}xms;
             return [ $prefix ];
@@ -503,7 +502,7 @@
         );
     }
     else {
-        return Resolv_hostname_from_DNS( $hostname );
+        return resolve_hostname_from_dns( $hostname );
     }
 }
 



More information about the pf-tools-commits mailing list