pf-tools/pf-tools: deduplication et commentaire dans le dhcpd.co...

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Apr 4 15:05:26 UTC 2014


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/2d8d0d805bcc
changeset: 1248:2d8d0d805bcc
user:      shad
date:      Fri Apr 04 17:05:18 2014 +0200
description:
deduplication et commentaire dans le dhcpd.conf et la zone

diffstat:

 lib/PFTools/Conf/Host.pm    |  14 +++++++--
 lib/PFTools/Conf/Network.pm |   5 +++
 lib/PFTools/Utils.pm        |  14 +++++++--
 t/13.conf.t                 |  66 ++++++++++++++++++++++++++++++++++++--------
 t/20.files.t                |   7 ++++-
 templates/dhcpd.conf.tpl    |   8 ++++-
 templates/zone.tpl          |   4 +-
 7 files changed, 95 insertions(+), 23 deletions(-)

diffs (343 lines):

diff -r 941865e07473 -r 2d8d0d805bcc lib/PFTools/Conf/Host.pm
--- a/lib/PFTools/Conf/Host.pm	Thu Apr 03 11:39:31 2014 +0200
+++ b/lib/PFTools/Conf/Host.pm	Fri Apr 04 17:05:18 2014 +0200
@@ -265,6 +265,10 @@
                                 'ip_type'       => $ip_type,
                                 'pxefilename' =>
                                     $host_ref->{'boot'}->{'pxefilename'},
+                                'number' =>
+                                    $host_ref->{'hostgroup'}->{'number'},
+                                'comment' =>
+                                    $host_ref->{'hostgroup'}->{'comment'},
                             }
                         );
                     }
@@ -1143,10 +1147,11 @@
         dhcp_part_ref  dhcp_vlan        resolver
         hostname       hostclass        ip_type
         vlan_def_ref   iface_def_ref    pxefilename
+        number         comment
     );
-    my ($dhcp_part_ref, $dhcp_vlan,     $resolver,
-        $hostname,      $hostclass,     $ip_type,
-        $vlan_def_ref,  $iface_def_ref, $pxefilename
+    my ($dhcp_part_ref, $dhcp_vlan, $resolver,     $hostname,
+        $hostclass,     $ip_type,   $vlan_def_ref, $iface_def_ref,
+        $pxefilename,   $number,    $comment
     ) = @{$arguments_ref}{@argument_names};
 
     my $ip_type_suffix = get_suffix_from_ip_type($ip_type);
@@ -1168,6 +1173,9 @@
         resolver    => $resolver,
     };
 
+    $dhcp_part_ref->{$dhcp_vlan}->{$hostclass}->{'number'}  = $number;
+    $dhcp_part_ref->{$dhcp_vlan}->{$hostclass}->{'comment'} = $comment;
+
     return;
 }
 
diff -r 941865e07473 -r 2d8d0d805bcc lib/PFTools/Conf/Network.pm
--- a/lib/PFTools/Conf/Network.pm	Thu Apr 03 11:39:31 2014 +0200
+++ b/lib/PFTools/Conf/Network.pm	Fri Apr 04 17:05:18 2014 +0200
@@ -35,6 +35,7 @@
 use base qw( Exporter );
 use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
+use List::MoreUtils qw( uniq );
 use Readonly;
 
 use PFTools::Logger;
@@ -232,6 +233,7 @@
     my $all_site_list = $global_config->{'SITE'}->{'__site_list'};
     if ( $section_ref->{'scope'} eq q{public} ) {
         $global_config->{'PUBLIC_NETWORK'}->{$section_name} = {};
+        $site_list = $all_site_list;
     }
     my $net2add = { scope => $section_ref->{'scope'}, };
     if ( $section_ref->{'comment'} ) {
@@ -379,6 +381,7 @@
 
     $zone_ref->{'network'} = qq{A\t} . $net_ref->{"network$suffix"};
     $zone_ref->{'netmask'} = qq{A\t} . $net_ref->{"netmask$suffix"};
+    $zone_ref->{'comment'} = $net_ref->{"comment$suffix"};
 
     my $broadcast = $subnet_ref->broadcast()->addr();
     $zone_ref->{'broadcast'} = qq{A\t} . $broadcast;
@@ -395,6 +398,8 @@
     else {
         $zone_part->{'ALL_SITES'}->{$net_name} = $zone_ref;
         push @{ $zone_part->{'ALL_SITES'}->{'__network_order'} }, $net_name;
+        @{ $zone_part->{'ALL_SITES'}->{'__network_order'} }
+            = uniq(@{ $zone_part->{'ALL_SITES'}->{'__network_order'} });
     }
 
     return 1;
diff -r 941865e07473 -r 2d8d0d805bcc lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm	Thu Apr 03 11:39:31 2014 +0200
+++ b/lib/PFTools/Utils.pm	Fri Apr 04 17:05:18 2014 +0200
@@ -1629,8 +1629,10 @@
     # Networks
     my @networks = ();
 
-    my @network_order = @{ $zone_part->{'__network_order'} };
-    push @network_order, @{ $zone_ref->{'ALL_SITES'}->{'__network_order'} };
+    my @network_order = uniq(
+        @{ $zone_part->{'__network_order'} },
+        @{ $zone_ref->{'ALL_SITES'}->{'__network_order'} },
+    );
 
     foreach my $network (@network_order) {
         my $network_ref = {
@@ -2011,13 +2013,19 @@
                 or $hostclass eq q{routers};
 
             my $host_ref = $site_ref->{$vlan}->{$hostclass};
+            my $hostsdef = {};
             foreach my $hostname ( keys %{$host_ref} ) {
-                push @hosts,
+                if ( $hostname =~ m{(number|comment)}xms ) {
+                    $hostsdef->{$1} = $host_ref->{$hostname};
+                    next;
+                }
+                push @{ $hostsdef->{hosts} },
                     {
                     hostname    => $hostname,
                     definitions => $host_ref->{$hostname},
                     };
             }
+            push @hosts, $hostsdef;
         }
     }
 
diff -r 941865e07473 -r 2d8d0d805bcc t/13.conf.t
--- a/t/13.conf.t	Thu Apr 03 11:39:31 2014 +0200
+++ b/t/13.conf.t	Fri Apr 04 17:05:18 2014 +0200
@@ -800,6 +800,8 @@
                             'pxefilename' => 'pxelinux.0',
                             'resolver' => 'nsprivate.private,spawn.private',
                         },
+                        'comment' => 'Spawning server',
+                        'number'  => '2',
                     },
                     'netmask' => '255.255.0.0',
                     'subnet'  => '10.1.0.0',
@@ -810,6 +812,8 @@
                     'netmask'      => '255.255.0.0',
                     'subnet'       => '10.1.0.0',
                     'cbv4-rdeploy' => {
+                        'comment' => 'Rdeploy server',
+                        'number'  => '2',
                         'cbv4-rdeploy01' => {
                             'hardware' => '00:1e:c9:ff:42:0b',
                             'fixed_addr' => '10.1.167.1',
@@ -1082,7 +1086,15 @@
                             'tag'     => 372,
                             'netmask' => '255.255.255.0',
                             'scope'   => 'private'
-                            }
+                        },
+                        'vlan-pfds-ext' => {
+                            'network' => '192.168.1.0',
+                            'comment' => 'something really interesting',
+                            'gateway' => '192.168.1.254',
+                            'tag'     => 40,
+                            'netmask' => '255.255.255.0',
+                            'scope'   => 'public',
+                        },
                     },
                     'BY_ADDR' => {
                         '192.168.1.0/24' => 'vlan-pfds-ext',
@@ -1204,13 +1216,23 @@
                 'dhcpvlan' => 'vlan-systeme',
                 'NETWORK'  => {
                     'BY_TAG' => {
-                        '13' => 'vlan-systeme'
+                        '13' => 'vlan-systeme',
+                        '40' => 'vlan-pfds-ext',
                     },
                     'BY_NAME' => {
-                        'vlan-systeme' => {}
+                        'vlan-systeme' => {},
+                        'vlan-pfds-ext' => {
+                            'network' => '192.168.1.0',
+                            'comment' => 'something really interesting',
+                            'gateway' => '192.168.1.254',
+                            'tag'     => 40,
+                            'netmask' => '255.255.255.0',
+                            'scope'   => 'public',
+                        },
                     },
                     'BY_ADDR' => {
-                        '10.1.0.0/16' => 'vlan-systeme'
+                        '10.1.0.0/16'    => 'vlan-systeme',
+                        '192.168.1.0/24' => 'vlan-pfds-ext'
                         }
                 },
                 'type' => 'site'
@@ -1240,10 +1262,11 @@
                             'vip-spawn.vlan-pfds-ext' => 'A	192.168.1.99',
                     },
                     'vlan-pfds-ext' => {
+                        'comment'   => 'something really interesting',
                         'broadcast' => 'A	192.168.1.255',
                         'network'   => 'A	192.168.1.0',
                         'gateway'   => 'A	192.168.1.254',
-                        'netmask'   => 'A	255.255.255.0'
+                        'netmask'   => 'A	255.255.255.0',
                     },
                 },
                 'BY_SITE' => {
@@ -1263,7 +1286,8 @@
                             'broadcast' => 'A	10.3.1.255',
                             'network'   => 'A	10.3.1.0',
                             'gateway'   => 'A	10.3.1.254',
-                            'netmask'   => 'A	255.255.255.0'
+                            'netmask'   => 'A	255.255.255.0',
+                            'comment'   => undef,
                         },
                         'vip-spawn' => {
                             'nscache'    => 'CNAME	vip-spawn.vlan-systeme',
@@ -1304,18 +1328,21 @@
                         'vlan-systeme' => {
                             'broadcast' => 'A	10.1.255.255',
                             'network'   => 'A	10.1.0.0',
-                            'netmask'   => 'A	255.255.0.0'
+                            'netmask'   => 'A	255.255.0.0',
+                            'comment'   => undef,
                         },
                         'vlan-pfds-int' => {
                             'broadcast' => 'A	10.2.255.255',
                             'network'   => 'A	10.2.0.0',
-                            'netmask'   => 'A	255.255.0.0'
+                            'netmask'   => 'A	255.255.0.0',
+                            'comment'   => undef,
                         },
                         'vlan-middledsi' => {
                             'broadcast' => 'A	10.3.2.255',
                             'network'   => 'A	10.3.2.0',
                             'gateway'   => 'A	10.3.2.254',
-                            'netmask'   => 'A	255.255.255.0'
+                            'netmask'   => 'A	255.255.255.0',
+                            'comment'   => undef,
                         }
                     },
                     'cbv4' => {
@@ -1328,7 +1355,8 @@
                         'vlan-systeme' => {
                             'broadcast' => 'A	10.1.255.255',
                             'network'   => 'A	10.1.0.0',
-                            'netmask'   => 'A	255.255.0.0'
+                            'netmask'   => 'A	255.255.0.0',
+                            'comment'   => undef,
                         },
                         'cbv4-rdeploy' => {
                             'cbv4-rdeploy00' => 'CNAME	cbv4-rdeploy00.vlan-systeme',
@@ -1751,6 +1779,8 @@
         'netmask'      => '255.255.0.0',
         'subnet'       => '10.1.0.0',
         'cbv4-rdeploy' => {
+            'comment'      => 'Rdeploy server',
+            'number'       => '2',
             'cbv4-rdeploy01' => {
                 'hardware' => '00:1e:c9:ff:42:0b',
                 'fixed_addr' => '10.1.167.1',
@@ -1908,7 +1938,8 @@
     'comment'  => 'CBV4 POP',
     'NETWORK'  => {
         'BY_TAG' => {
-            '13' => 'vlan-systeme'
+            '13' => 'vlan-systeme',
+            '40' => 'vlan-pfds-ext',
         },
         'BY_NAME' => {
             'vlan-systeme' => {
@@ -1916,10 +1947,19 @@
                 'tag'     => 13,
                 'netmask' => '255.255.0.0',
                 'scope'   => 'private'
-                }
+                },
+            'vlan-pfds-ext' => {
+                'network' => '192.168.1.0',
+                'comment' => 'something really interesting',
+                'gateway' => '192.168.1.254',
+                'tag'     => 40,
+                'netmask' => '255.255.255.0',
+                'scope'   => 'public'
+            },
         },
         'BY_ADDR' => {
-            '10.1.0.0/16' => 'vlan-systeme'
+            '10.1.0.0/16' => 'vlan-systeme',
+            '192.168.1.0/24' => 'vlan-pfds-ext',
             }
     },
     'type' => 'site'
diff -r 941865e07473 -r 2d8d0d805bcc t/20.files.t
--- a/t/20.files.t	Thu Apr 03 11:39:31 2014 +0200
+++ b/t/20.files.t	Fri Apr 04 17:05:18 2014 +0200
@@ -154,7 +154,7 @@
     qq{broadcast.vlan-middledsi\tIN A\t10.3.2.255},
     qq{gateway.vlan-middledsi\tIN A\t10.3.2.254},
     q{},
-    q{; vlan-pfds-ext},
+    q{; vlan-pfds-ext: something really interesting},
     q{;----------------------------------------------------------------------------},
     qq{network.vlan-pfds-ext\tIN A\t192.168.1.0},
     qq{netmask.vlan-pfds-ext\tIN A\t255.255.255.0},
@@ -1072,6 +1072,11 @@
 subnet 10.1.0.0 netmask 255.255.0.0 {
 }
 
+
+
+# Spawning server
+# number: 2
+
 host cbv4-spawn01 {
 \thardware ethernet 00:1e:c9:ff:42:0a;
 \tfixed-address 10.1.167.1;
diff -r 941865e07473 -r 2d8d0d805bcc templates/dhcpd.conf.tpl
--- a/templates/dhcpd.conf.tpl	Thu Apr 03 11:39:31 2014 +0200
+++ b/templates/dhcpd.conf.tpl	Fri Apr 04 17:05:18 2014 +0200
@@ -6,7 +6,12 @@
 
 [% END -%]
 
-[%- FOREACH host IN hosts -%]
+[% FOREACH hostclass IN hosts %]
+# [% hostclass.comment %]
+# number: [% hostclass.number %]
+
+
+[%- FOREACH host IN hostclass.hosts -%]
 host [% host.hostname %] {
 	hardware ethernet [% host.definitions.hardware %];
 	fixed-address [% host.definitions.fixed_addr %];
@@ -15,3 +20,4 @@
 }
 
 [% END -%]
+[% END -%]
diff -r 941865e07473 -r 2d8d0d805bcc templates/zone.tpl
--- a/templates/zone.tpl	Thu Apr 03 11:39:31 2014 +0200
+++ b/templates/zone.tpl	Fri Apr 04 17:05:18 2014 +0200
@@ -28,7 +28,7 @@
 ;;============================================================================
 
 [% FOREACH network IN networks -%]
-; [% network.name %][% IF network.comment %]: network.comment[% END %]
+; [% network.name %][% IF network.comment %]: [% network.comment %][% END %]
 ;----------------------------------------------------------------------------
 [% FOREACH rr IN network.records -%]
 [% rr.name %]	IN [% rr.value %]
@@ -42,7 +42,7 @@
 ;;============================================================================
 
 [% FOREACH server IN servers -%]
-; [% server.name %][% IF server.comment %]: server.comment[% END %]
+; [% server.name %][% IF server.comment %]: [% server.comment %][% END %]
 ;----------------------------------------------------------------------------
 [% FOREACH rr IN server.records -%]
 [% rr.name %]	IN [% rr.value %]



More information about the pf-tools-commits mailing list