pf-tools/pf-tools: 5 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Mon Sep 20 15:10:12 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/d6d4dd70265a
changeset: 787:d6d4dd70265a
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Sep 20 07:46:30 2010 +0200
description:
Exporting $DEF_SECTIONS ofr using syntax definition instead of hardcoding in Host.pm

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/8662502f3436
changeset: 788:8662502f3436
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Sep 20 07:47:31 2010 +0200
description:
Fix: wrong parameter when calling Init_GLOBAL_NETCONFIG in Init_TOOLS

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/8dea9e9b0d5d
changeset: 789:8dea9e9b0d5d
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Sep 20 16:50:36 2010 +0200
description:
Coding style for filters/filter_vlan2if

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/c27e51c66e76
changeset: 790:c27e51c66e76
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Sep 20 16:52:38 2010 +0200
description:
Factorize Add_server into Add_host and add funciton Build_host_from_server

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/6d007d250b23
changeset: 791:6d007d250b23
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Sep 20 17:08:34 2010 +0200
description:
Right call for converting server to host structure and adding it via Add_host

diffstat:

1 file changed, 2 insertions(+), 2 deletions(-)
lib/PFTools/Conf.pm |    4 ++--

diffs (875 lines):

diff -r b71a9ddb3137 -r 6d007d250b23 lib/PFTools/Conf.pm
--- a/lib/PFTools/Conf.pm	Sun Sep 19 22:26:59 2010 +0200
+++ b/lib/PFTools/Conf.pm	Mon Sep 20 17:08:34 2010 +0200
@@ -610,8 +610,12 @@
             );
         }
         elsif ( $net_parsed->{$section}->{'type'} eq 'server' ) {
-            Add_server(
-                $start_file, $section, $net_parsed->{$section},
+            my $convert = Build_host_from_server(
+                $section,
+                $net_parsed->{$section}
+            );
+            Add_host(
+                $start_file, 'server', $convert,
                 $GLOBAL, $pf_config
             );
         }
@@ -629,7 +633,10 @@
                         $hostfile, $hash_subst, 'host',
                         $pf_config
                         );
-                    Add_host( $hostfile, $host_parsed, $GLOBAL, $pf_config );
+                    Add_host(
+                        $hostfile, 'host', $host_parsed,
+                        $GLOBAL, $pf_config
+                    );
                     push @{ $service_part->{$section} }, $host;
                 }
             }
diff -r b71a9ddb3137 -r 6d007d250b23 lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm	Sun Sep 19 22:26:59 2010 +0200
+++ b/lib/PFTools/Conf/Host.pm	Mon Sep 20 17:08:34 2010 +0200
@@ -27,6 +27,7 @@
 use Fcntl ':mode';
 use POSIX qw(ceil floor);
 
+use PFTools::Conf::Syntax qw( $DEF_SECTIONS );
 use PFTools::Logger;
 use PFTools::Net;
 use PFTools::Structqueries;
@@ -34,7 +35,7 @@
 our @ISA = ('Exporter');
 
 our @EXPORT = qw(
-    Add_server
+    Build_host_from_server
     Add_host
 );
 
@@ -364,180 +365,35 @@
     return;
 }
 
-#########################################################################
-#
-# VOID Add_server ( STR, STR, HASHREF, HASHREF, HASHREF )
-#
-# This function adds server into global configuration
-# Inputs :
-#  - $srvfile		: filename where server is parsed
-#  - $srvname_model	: model for the server name
-#  - $srv2add		: hashref where are stored server 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_server ($$$$$) {
-    my ( $srvfile, $srvname_model, $srv2add, $global_config, $pf_config )
-        = @_;
-
-    $srvname_model =~ /^$pf_config->{'regex'}->{'hostname_model'}$/;
-    my $shortname = $1;
-    my $hostclass = $shortname;
-    my $site_list = Get_site_list( $srv2add, $global_config );
-    my ( $host_last, $node_last )
-        = __Get_host_indexes( $srv2add, $srvname_model );
-    my $nodes = $srv2add->{'nodes'} || 0;
-    foreach my $site ( @{$site_list} ) {
-        my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
-        if ( !defined $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} ) {
-            $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} = {};
+sub Build_host_from_server {
+    my ( $srv_name, $ref_srv ) = @_;
+    my $result = {};
+    my $iface_idx = 0;
+    $result->{'hostgroup'}->{'hostname'} = $srv_name;
+    foreach my $key ( keys %{$ref_srv} ) {
+        my $suffix;
+        next if( $key eq 'type' or $key =~ /^__/);
+        my ( $key_type, $spec, $hostnum ) = split( /\./, $key );
+        if( $key_type eq 'alias' ) {
+            $result->{'dns'}->{$key} = $ref_srv->{$key};
         }
-        my $srv_part = $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass};
-        my $zone     = $site_part->{'zone'};
-        my $prefix   = __Get_site_prefix( $site,
-            $global_config->{'SITE'}->{'BY_NAME'}->{$site} );
-        my $vlan_list = __Get_vlan_list_from_server($srv2add);
-        foreach my $hostnum ( 0 .. $host_last ) {
-            foreach my $hostnode ( 0 .. $node_last ) {
-                my $srvname
-                    = __Get_hostname_from_model( $srvname_model, $hostnum,
-                    $hostnode, $prefix );
-                if ( $srv_part->{$srvname} ) {
-                    Warn( $CODE->{'DUPLICATE_VALUE'},
-                              "Hostclass "
-                            . $hostclass
-                            . " already contains hostname "
-                            . $srvname
-                            . " definition from file "
-                            . $srvfile
-                            . " and for site "
-                            . $site
-                            . " : skipping this hostname" );
-                    next;
-                }
-                my $index
-                    = __Get_hostnumber_from_model( $srvname_model, $hostnum,
-                    $hostnode );
-                my $srv_number
-                    = ($hostnode) ? $hostnum . $hostnode : $hostnum;
-                my $short_vlan 
-                    = $srv2add->{ 'shortname.' . $srv_number }
-                    || $srv2add->{'shortname'}
-                    || "";
-                my $iface_idx = 0;
-                foreach my $ip_type ( 'ipv4', 'ipv6' ) {
-                    next if ( !$pf_config->{'features'}->{$ip_type} );
-                    my $addr_key
-                        = ( $ip_type eq 'ipv6' ) ? 'BY_ADDR6' : 'BY_ADDR';
-                    my $zone_key = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
-                    my $dhcp_key = ( $ip_type eq 'ipv6' ) ? 'DHCP6' : 'DHCP';
-                    my $suffix   = ( $ip_type eq 'ipv6' ) ? '6'     : '';
-                    my $zone_part
-                        = $global_config->{$zone_key}->{'BY_NAME'}->{$zone}
-                        ->{'BY_SITE'}->{$site};
-                    foreach my $vlan ( @{$vlan_list} ) {
-                        my $net_block = Get_netblock_from_vlan( $ip_type,
-                            $site_part->{'NETWORK'}->{'BY_NAME'}->{$vlan} );
-                        if ( !defined $net_block ) {
-                            Abort( $CODE->{'INVALID_VALUE'},
-                                "Unable to retrieve network block of type "
-                                    . $ip_type
-                                    . " for vlan "
-                                    . $vlan
-                                    . " on site "
-                                    . $site
-                                    . " for host "
-                                    . $srvname );
-                        }
-                        my $realip;
-                        if ($srv2add->{ $ip_type . '.' 
-                                    . $vlan . '.'
-                                    . $srv_number } )
-                        {
-                            $realip = __Check_host_ip(
-                                $ip_type,
-                                $net_block,
-                                $srv2add->{
-                                    $ip_type . '.' . $vlan . '.' . $srv_number
-                                    },
-                                0, 0, 0, $site,
-                                $site_part
-                            );
-                        }
-                        else {
-                            $realip = __Check_host_ip(
-                                $ip_type,
-                                $net_block,
-                                $srv2add->{ $ip_type . '.' . $vlan },
-                                $hostnum,
-                                $hostnode,
-                                $nodes,
-                                $site,
-                                $site_part
-                            );
-                        }
-                        $srv_part->{$srvname} = { 'interfaces' => {} }
-                            if ( !defined $srv_part->{$srvname} );
-                        $srv_part->{$srvname}->{'interfaces'}
-                            ->{ 'eth' . $iface_idx } = {
-                            $ip_type            => $realip->addr(),
-                            'netmask' . $suffix => $realip->mask(),
-                            'vlan'              => $vlan
-                            };
-                        $iface_idx++;
-                        $site_part->{'HOST'}->{$addr_key}->{ $realip->addr() }
-                            = $srvname . '.' . $vlan;
-                        if ( !defined $zone_part->{$hostclass} ) {
-                            $zone_part->{$hostclass} = {};
-                            push(
-                                @{  $global_config->{$zone_key}->{'BY_NAME'}
-                                        ->{$zone}->{'__hostclass_order'}
-                                        ->{$site}
-                                    },
-                                $hostclass
-                            );
-                        }
-                        $zone_part->{$hostclass}->{ $srvname . '.' . $vlan }
-                            = "A\t" . $realip->addr();
-                        if ( $short_vlan eq $vlan ) {
-                            if ( $shortname ne $srvname ) {
-                                push(
-                                    @{  $zone_part->{$hostclass}
-                                            ->{ $shortname . '.' . $vlan }
-                                        },
-                                    "A\t" . $realip->addr()
-                                );
-                            }
-                            else {
-                                $zone_part->{$hostclass}->{$shortname}
-                                    = "CNAME\t" . $shortname . '.' . $vlan;
-                            }
-                        }
-                        my $alias_list
-                            = __Get_alias_list_from_server( $srv2add, $vlan,
-                            $srv_number );
-                        foreach my $alias ( @{$alias_list} ) {
-                            $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass}
-                                ->{$alias} = $shortname;
-                            if ( !defined $zone_part->{$hostclass}
-                                ->{ $alias . '.' . $vlan } )
-                            {
-                                $zone_part->{$hostclass}->{$alias}
-                                    = "CNAME\t" . $shortname . '.' . $vlan;
-                            }
-                            if ( $shortname ne $srvname ) {
-                                $zone_part->{$hostclass}->{ $alias . $index }
-                                    = "CNAME\t" . $srvname . '.' . $vlan;
-                                $site_part->{'HOST'}->{'BY_NAME'}
-                                    ->{$hostclass}->{ $alias . $index }
-                                    = $srvname;
-                            }
-                        }
-                    }
-                }
-            }
+        elsif( $key_type =~ /^ipv/ ) {
+            $suffix = ( $hostnum ) ? "\.$hostnum" : "";
+            $result->{ 'interface::eth' . $iface_idx } = {
+                'vlan'.$suffix => $spec,
+                'ipv4'.$suffix => $ref_srv->{$key},
+            };
+            $iface_idx++;
+        }
+        elsif( $key_type eq 'shortname' ) {
+            my $key_name = ( $spec ) ? "$key_type\.$spec" : $key_type;
+            $result->{'dns'}->{$key_name} = $ref_srv->{$key};
+        }
+        elsif( $key_type =~ /^(comment|order|number|nodes|site)$/ ) {
+            $result->{'hostgroup'}->{$key_type} = $ref_srv->{$key};
         }
     }
+    return $result;
 }
 
 #####################################################################################################
@@ -797,6 +653,164 @@
     return $add_if;
 }
 
+sub __Add_dhcp_entry {
+    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} ) {
+        $dhcp_part->{$dhcpvlan} = {
+            'subnet'    => $param->{'vlan_def'}->{"network$suffix"},
+            'netmask'   => $param->{'vlan_def'}->{"netmask$suffix"},
+        };
+        if ( $param->{'vlan_def'}->{"gateway$suffix"} ) {
+            $dhcp_part->{$dhcpvlan}->{'routers'} =
+                $param->{'vlan_def'}->{"gateway$suffix"};
+        }
+    }
+    $dhcp_part->{$dhcpvlan}->{$hostclass} = {}
+        unless( $dhcp_part->{$dhcpvlan}->{$hostclass} );
+    my $fixed_addr = $param->{'iface_def'}->{$param->{'ip_type'}};
+    $fixed_addr =~ s/\/[\d]+$//;
+    $dhcp_part->{$dhcpvlan}->{$hostclass}->{$hostname} = [
+        'hardware ethernet '. $param->{'iface_def'}->{'mac'} . ";",
+        'fixed-address ' . $fixed_addr . ';',
+        'filename ' . $param->{'pxefilename'} . ';',
+        'option domain-name-servers ' . $resolver . ';',
+    ];
+}
+
+sub __Add_zone_entry {
+    my ( $param ) = @_;
+    my $host_res = {};
+    my $zone_res = {};
+
+    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]+$}{}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} ) {
+        $param->{'zone_part'}->{$hostclass} = {};
+        push( 
+            @{ $param->{'global_config'}->{$zone_key}->{'BY_NAME'}
+                    ->{$zone}->{'__hostclass_order'}->{$site} },
+                $hostclass
+        );
+    }
+    my $host_part   = $param->{'host_part'};
+    $zone_res->{ $hostname . '.' . $vlan } = "A\t$zone_ip";
+
+    $zone_part->{$hostclass}->{ $hostname . '.' . $vlan } = "A\t$zone_ip";
+    my $shortname_vlan = $param->{'dns_def'}->{"shortname\.$host_number"}
+        || $param->{'dns_def'}->{'shortname'};
+    return unless $shortname_vlan;
+    if ( $shortname ne $hostname && $shortname_vlan eq $vlan ) {
+        if ( ! $zone_part->{$hostclass}->{"$shortname\.$vlan"} ) {
+            $zone_part->{$hostclass}->{"$shortname\.$vlan"} = [
+                "A\t$zone_ip",
+            ];
+        }
+        else {
+            push(
+                @{ $zone_part->{$hostclass}->{"$shortname\.$vlan"} },
+                "A\t$zone_ip"
+            );
+            $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( /\./, $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'}} =
+                "CNAME\t$hostname\.$vlan";
+        }
+    }
+}
+
+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 =~ /^MANDATORY/ );
+        my $value = $host2add->{'boot'}->{"$key\.$host_number"}
+            || $host2add->{'boot'}->{$key};
+        unless ( $value ) {
+            if ( $key =~ /^(console|cmdline)$/ ) {
+                $value = ( $key eq 'console' )
+                    ? $site_part->{$key}
+                    : "";
+            }
+        }
+        next unless( $value );
+        if (
+            $key !~ /^(console|cdline)$/
+            && ! -e $pf_config->{'path'}->{'tftp_dir'} . $value
+        ) {
+            Warn( $CODE->{'OPEN'},
+                "$value in $pf_config->{'path'}->{'tftp_dir'} doesn't exist" );
+        }
+        $result->{$key} = $value;
+    }
+    return $result;
+}
+
+sub __Build_hostlist {
+    my ( $param ) = @_; 
+
+    my $result = {};
+    foreach my $hostnum ( 0 .. $param->{'host_last'} ) {
+        foreach my $hostnode ( 0 .. $param->{'node_last'} ) {
+            my $hostname = __Get_hostname_from_model(
+                $param->{'hostname_model'},
+                $hostnum,
+                $hostnode,
+                $param->{'prefix'}
+            );
+            if ( $param->{'host_part'}->{$hostname} ) {
+                Warn( $CODE->{'DUPLICATE_VALUE'},
+                    "Skipping $hostname : already defined"
+                );
+                next;
+            }
+            my $index = __Get_hostnumber_from_model(
+                $param->{'hostname_model'},
+                $hostnum,
+                $hostnode
+            );
+            my $host_number = ($hostnode)
+                ? $hostnum . $hostnode
+                : $hostnum;
+            $result->{$hostname} = {
+                'hostnum'       => $hostnum,
+                'index'         => $index,
+                'host_number'   => $host_number,
+            };
+            $result->{$hostname}->{'hostnode'} = $hostnode if( $hostnode );
+        }
+    }
+    return $result;
+}
+
+
 #########################################################################
 #
 # VOID Add_host ( STR, HASHREF, HASHREF, HASHREF )
@@ -809,12 +823,14 @@
 #  - $global_config	: hashref where are stored global configuration datas
 #  - $pf_config		: hashref where are stored pf-tools configuration datas
 #
-sub Add_host ($$$$) {
-    my ( $hostfile, $host2add, $global_config, $pf_config ) = @_;
+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 =~ /^$pf_config->{'regex'}->{'hostname_model'}$/;
-    my $shortname = $1;
+    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'};
@@ -824,265 +840,153 @@
 
     foreach my $site ( @{$site_list} ) {
         my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
-        if ( !defined $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} ) {
+        unless ( $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} ) {
             $site_part->{'HOST'}->{'BY_NAME'}->{$hostclass} = {};
             push( @{ $site_part->{'HOST'}->{'__hostclass_pxe'} },
-                $hostclass );
+                $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,
-            $global_config->{'SITE'}->{'BY_NAME'}->{$site} );
-        foreach my $hostnum ( 0 .. $host_last ) {
-            foreach my $hostnode ( 0 .. $node_last ) {
-                my $hostname
-                    = __Get_hostname_from_model( $hostname_model, $hostnum,
-                    $hostnode, $prefix );
-                if ( $host_part->{$hostname} ) {
-                    Warn( $CODE->{'DUPLICATE_VALUE'},
-                              "Hostclass "
-                            . $hostclass
-                            . " already contains hostname "
-                            . $hostname
-                            . " definition from file "
-                            . $hostfile
-                            . " and for site "
-                            . $site
-                            . " : skipping this hostname" );
-                    next;
+        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'};
+            if( $type eq 'host' ) {
+                $host_part->{$hostname}->{'boot'} = __Add_boot_on_host_entry (
+                    $host2add,
+                    $host_number,
+                    $site_part,
+                    $pf_config,
+                );
+                unless(
+                    $site_part->{'NETWORK'}->{'BY_NAME'}->{$dhcpvlan}
+                ) {
+                    Abort( $CODE->{'INVALID_VALUE'},
+                        "Unknown vlan " . $dhcpvlan . " on site "
+                        . $site . " for " . $hostname
+                    );
                 }
-                my $index
-                    = __Get_hostnumber_from_model( $hostname_model, $hostnum,
-                    $hostnode );
-                my $host_number
-                    = ($hostnode) ? $hostnum . $hostnode : $hostnum;
+                $host_part->{$hostname}->{'deployment'} = {
+                    'hostname_model'
+                        => $host2add->{'hostgroup'}->{'hostname'},
+                    'hosttype' => $hostclass,
+                };
+                foreach my $key ( keys %{$dep_def} ) {
+                    my $value =
+                        $host2add->{'deployment'}->{"$key\.$host_number"}
+                        || $host2add->{'deployment'}->{$key};
+                    next unless $value;
+                    $host_part->{$hostname}->{'deployment'}->{$key} =
+                        $value;
+                }
+                $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 =~ /^((eth|bond)[\d]+)(\.(TAG[\d]+))$/ ) {
+                    $iface_name 
+                        = $1 . '.'
+                        . __Get_vlan_tag_from_site( $if2add->{'vlan'},
+                        $site, $global_config );
+                }
 
-                # Checking path for PXE elements kernel, initrd ...
-                foreach my $key (
-                    'pxefilename', 'kernel',  'initrd', 'kerneluml',
-                    'initrduml',   'console', 'cmdline'
-                    )
+                # 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'} )
                 {
-                    my $value;
-                    if ( $key eq 'console' ) {
-                        $value
-                            = $host2add->{'boot'}
-                            ->{ $key . '.' . $host_number }
-                            || $host2add->{'boot'}->{$key}
-                            || $site_part->{$key};
-                    }
-                    elsif ( $key eq 'cmdline' ) {
-                        $value
-                            = $host2add->{'boot'}
-                            ->{ $key . '.' . $host_number }
-                            || $host2add->{'boot'}->{$key}
-                            || "";
-                    }
-                    else {
-                        $value
-                            = $host2add->{'boot'}
-                            ->{ $key . '.' . $host_number }
-                            || $host2add->{'boot'}->{$key};
-                        next if ( !defined $value );
-                        if ( !-e $pf_tftp_dir . $value ) {
-                            Warn( $CODE->{'OPEN'},
-                                      "Unable to find file "
-                                    . $pf_tftp_dir
-                                    . $value
-                                    . " for key "
-                                    . $key
-                                    . " for host "
-                                    . $hostname
-                                    . " from file "
-                                    . $hostfile );
+                    Abort( $CODE->{'UNDEF_KEY'},
+                        "MAC address MUST BE defined for interface "
+                        . $iface
+                        . " which is on dhcpvlan "
+                        . $dhcpvlan );
+                }
+                foreach my $ip_type ( 'ipv4', 'ipv6' ) {
+                    next if ( !$pf_config->{'features'}->{$ip_type} );
+                    my $addr_key
+                        = ( $ip_type eq 'ipv6' ) ? 'BY_ADDR6' : 'BY_ADDR';
+                    my $zone_key
+                        = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
+                    my $dhcp_key
+                        = ( $ip_type eq 'ipv6' ) ? 'DHCP6' : 'DHCP';
+                    my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
+                    my $zone_ip = $if2add->{$ip_type};
+                    $zone_ip =~ s/\/.+$//;
+                    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,
                         }
-                    }
-                    $host_part->{$hostname}->{'boot'}->{$key} = $value;
-                }
-                my $dhcpvlan
-                    = $host2add->{'deployment'}
-                    ->{ 'dhcpvlan.' . $host_number }
-                    || $host2add->{'deployment'}->{'dhcpvlan'}
-                    || $site_part->{'dhcpvlan'};
-                if ( !defined $site_part->{'NETWORK'}->{'BY_NAME'}
-                    ->{$dhcpvlan} )
-                {
-                    Abort( $CODE->{'INVALID_VALUE'},
-                              "Vlan "
-                            . $dhcpvlan
-                            . " defined for "
-                            . $hostname
-                            . " from file "
-                            . $hostfile
-                            . " doesn't exist on site "
-                            . $site );
-                }
-                foreach my $key ( 'arch', 'distrib', 'mode', 'os_type' ) {
-                    my $value
-                        = $host2add->{'deployment'}
-                        ->{ $key . '.' . $host_number }
-                        || $host2add->{'deployment'}->{$key};
-                    next if ( !defined $value );
-                    $host_part->{$hostname}->{'deployment'}->{$key} = $value;
-                }
-                $host_part->{$hostname}->{'deployment'}->{'hostname_model'}
-                    = $host2add->{'hostgroup'}->{'hostname'};
-                $host_part->{$hostname}->{'deployment'}->{'hosttype'}
-                    = $hostclass;
-                $host_part->{$hostname}->{'deployment'}->{'host_config'}
-                    = 'SITE:' . $site . '/CONFIG/update-' . $hostclass;
-                $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 =~ /^((eth|bond)[\d]+)(\.(TAG[\d]+))$/ ) {
-                        $iface_name 
-                            = $1 . '.'
-                            . __Get_vlan_tag_from_site( $if2add->{'vlan'},
-                            $site, $global_config );
-                    }
-
-                    # 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
-                        && !defined $if2add->{'mac'} )
-                    {
-                        Abort( $CODE->{'UNDEF_KEY'},
-                                  "MAC address MUST BE defined for interface "
-                                . $iface
-                                . " which is on dhcpvlan "
-                                . $dhcpvlan );
-                    }
-                    foreach my $ip_type ( 'ipv4', 'ipv6' ) {
-                        next if ( !$pf_config->{'features'}->{$ip_type} );
-                        my $addr_key
-                            = ( $ip_type eq 'ipv6' ) ? 'BY_ADDR6' : 'BY_ADDR';
-                        my $zone_key
-                            = ( $ip_type eq 'ipv6' ) ? 'ZONE6' : 'ZONE';
-                        my $dhcp_key
-                            = ( $ip_type eq 'ipv6' ) ? 'DHCP6' : 'DHCP';
-                        my $suffix = ( $ip_type eq 'ipv6' ) ? '6' : '';
-                        my $zone_ip = $if2add->{$ip_type};
-                        $zone_ip =~ s/\/.+$//;
-                        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'};
-
-                        if ( !defined $zone_part->{$hostclass} ) {
-                            $zone_part->{$hostclass} = {};
-                            push(
-                                @{  $global_config->{$zone_key}->{'BY_NAME'}
-                                        ->{$zone}->{'__hostclass_order'}
-                                        ->{$site}
-                                    },
-                                $hostclass
-                            );
-                        }
-                        $zone_part->{$hostclass}
-                            ->{ $hostname . '.' . $if2add->{'vlan'} }
-                            = "A\t" . $zone_ip;
-                        my $shortname_vlan
-                            = $host2add->{'dns'}
-                            ->{ 'shortname.' . $host_number }
-                            || $host2add->{'dns'}->{'shortname'}
-                            || "";
-                        if ( $shortname_vlan eq $if2add->{'vlan'} ) {
-                            push(
-                                @{  $zone_part->{$hostclass}->{
-                                        $shortname . '.' . $if2add->{'vlan'}
-                                        }
-                                    },
-                                "A\t" . $zone_ip
-                            );
-                            $zone_part->{$hostclass}->{$shortname}
-                                = "CNAME\t"
-                                . $shortname . '.'
-                                . $if2add->{'vlan'};
-                        }
-                        foreach my $key ( keys %{ $host2add->{'dns'} } ) {
-                            next if ( $key !~ /^alias/ );
-                            my ( $key_type, $alias, $host_num )
-                                = split( /\./, $key );
-                            $host_part->{$alias} = $shortname
-                                if ( !defined $host_part->{$alias} );
-                            $host_part->{ $alias . $index } = $hostname;
-                            if ( $host2add->{'dns'}->{$key} eq
-                                $if2add->{'vlan'} )
-                            {
-                                $zone_part->{$hostclass}->{$alias}
-                                    = "CNAME\t"
-                                    . $shortname . '.'
-                                    . $if2add->{'vlan'};
-                                $zone_part->{$hostclass}->{ $alias . $index }
-                                    = "CNAME\t"
-                                    . $hostname . '.'
-                                    . $if2add->{'vlan'};
-
-                            }
-                        }
-                        my $resolver
-                            = $host2add->{'dns'}
-                            ->{ 'resolver.' . $host_number }
-                            || $host2add->{'dns'}->{'resolver'};
-                        if ( $if2add->{'vlan'} eq $dhcpvlan ) {
-                            $host_part->{$hostname}->{'deployment'}
-                                ->{'dhcpvlan'} = $dhcpvlan;
-                            if ( !defined $dhcp_part->{$dhcpvlan} ) {
-                                $dhcp_part->{$dhcpvlan} = {};
-                                $dhcp_part->{$dhcpvlan}->{'subnet'}
-                                    = $site_part->{'NETWORK'}->{'BY_NAME'}
-                                    ->{$dhcpvlan}->{ 'network' . $suffix };
-                                $dhcp_part->{$dhcpvlan}->{'netmask'}
-                                    = $site_part->{'NETWORK'}->{'BY_NAME'}
-                                    ->{$dhcpvlan}->{ 'netmask' . $suffix };
-                                if ( $site_part->{'NETWORK'}->{'BY_NAME'}
-                                    ->{$dhcpvlan}->{ 'gateway' . $suffix } )
-                                {
-                                    $dhcp_part->{$dhcpvlan}->{'routers'}
-                                        = $site_part->{'NETWORK'}->{'BY_NAME'}
-                                        ->{$dhcpvlan}
-                                        ->{ 'gateway' . $suffix };
-                                }
-                            }
-                            $dhcp_part->{$dhcpvlan}->{$hostclass} = {}
-                                if ( !defined $dhcp_part->{$dhcpvlan}
-                                ->{$hostclass} );
-                            my $fixed_addr = $if2add->{$ip_type};
-                            $fixed_addr =~ s!/[\d]+$!!;
-                            $dhcp_part->{$dhcpvlan}->{$hostclass}->{$hostname}
-                                = [
-                                'hardware ethernet ' . $if2add->{'mac'} . ';',
-                                'fixed-address ' . $fixed_addr . ';',
-                                'filename '
-                                    . $host2add->{'boot'}->{'pxefilename'}
-                                    . ';',
-                                'option domain-name-servers '
-                                    . $resolver . ';'
-                                ];
-                        }
-                    }
+                    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'
+                    );
                 }
             }
         }
diff -r b71a9ddb3137 -r 6d007d250b23 lib/PFTools/Conf/Syntax.pm
--- a/lib/PFTools/Conf/Syntax.pm	Sun Sep 19 22:26:59 2010 +0200
+++ b/lib/PFTools/Conf/Syntax.pm	Mon Sep 20 17:08:34 2010 +0200
@@ -30,6 +30,7 @@
 our @ISA = ('Exporter');
 
 our @EXPORT = qw(
+    $DEF_SECTIONS
     $ALLOWED_PARSING_CONTEXT
     $HOST_CONFIG_REGEX
     $HOSTTYPE_CONFIG_REGEX
@@ -107,7 +108,7 @@
 #		}
 #	}
 # }
-my $DEF_SECTIONS = {
+our $DEF_SECTIONS = {
     'host' => {
         'interface' => {
             'MANDATORY_KEYS' => [ 'vlan', 'ipv4', 'slaves' ],
diff -r b71a9ddb3137 -r 6d007d250b23 lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm	Sun Sep 19 22:26:59 2010 +0200
+++ b/lib/PFTools/Utils.pm	Mon Sep 20 17:08:34 2010 +0200
@@ -99,7 +99,7 @@
         }
         Unset_deferredlog();
         $global_struct
-            = Init_GLOBAL_NETCONFIG( $source, $hostname, $pf_config );
+            = Init_GLOBAL_NETCONFIG( $source, {}, $pf_config );
         Flush2disk_GLOBAL( $global_struct, $pf_config );
     }
     else {



More information about the pf-tools-commits mailing list