pf-tools/pf-tools: 4 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Tue Oct 5 08:38:53 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/9cefb4d536b9
changeset: 845:9cefb4d536b9
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Oct 04 18:33:29 2010 +0200
description:
ADD: more TODOs

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/6bfefeee92b7
changeset: 846:6bfefeee92b7
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Oct 04 18:35:51 2010 +0200
description:
* using Module::Runtime for handling actions with a common API
* using Module::Runtime for handling packages functions with a common API

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/82f75bd6aedc
changeset: 847:82f75bd6aedc
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Oct 04 19:14:08 2010 +0200
description:
Coding style and factorization for PFTools::Structqueries

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/92e3151737a4
changeset: 848:92e3151737a4
user:      "Christophe Caillet <quadchris at free.fr>"
date:      Mon Oct 04 19:29:19 2010 +0200
description:
Adding minimal action API documentation in source code

diffstat:

3 files changed, 4 insertions(+), 6 deletions(-)
debian/changelog             |    2 ++
lib/PFTools/Structqueries.pm |    3 ++-
lib/PFTools/Update.pm        |    5 -----

diffs (475 lines):

diff -r 494d020bfacd -r 92e3151737a4 TODO
--- a/TODO	Mon Oct 04 13:49:20 2010 +0200
+++ b/TODO	Mon Oct 04 19:29:19 2010 +0200
@@ -9,7 +9,7 @@
     - the IPs of hosts which are into a public scope network appear on all sites
 LH finishing IPv6 implementation and testing it for zones and DHCP handlers
 LH implementing strong authentication like X509 when accessing to repository instead
-   of hostname vlaue, with CA and all functions for adding or revoking new hosts
+   of hostname value, with CA and all functions for adding or revoking new hosts
 NH definition of group actions e.g. reloading a server like postfix or apache only once
 MH creating into the sort funtion for update-* file the actiongroup trigger which
    check the dependances validity with the following rules :
@@ -27,6 +27,10 @@
 LH implementing a web interface for building pf-tools configurator
 NM permit interface with no IP in promisc mode (ex: for probing hosts)
 NH implementing monitoring as defined in hostfile-syntax with PFTools::Monitoring
+NH creating a tool like update-config for building all configuration files for
+   a given host in a VCS module which can be retrieve by this host. Some files
+   were updated by the current update-config bu tonly those who need a local
+   file instead of VCS file(s) only
 
 MH rewrite pflaunch and other tools
 UH br0/trunk sur uml (2e couche bridge?)
diff -r 494d020bfacd -r 92e3151737a4 debian/changelog
--- a/debian/changelog	Mon Oct 04 13:49:20 2010 +0200
+++ b/debian/changelog	Mon Oct 04 19:29:19 2010 +0200
@@ -24,8 +24,10 @@
   * using Module::Runtime in Packages.pm and creating Packages::DEB
   * correctly handle an undefined pf-tools configuration when checking out 
   * style for handling options for sbin/*
+  * using Module::Runtime for handling actions with a common API
+  * using Module::Runtime for handling packages functions with a common API 
 
- -- Christophe Caillet <quadchris at free.fr>  Mon, 13 Sep 2010 12:00:47 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Mon, 04 Oct 2010 18:33:39 +0200
 
 pf-tools (1.0-1) unstable; urgency=low
 
diff -r 494d020bfacd -r 92e3151737a4 lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm	Mon Oct 04 13:49:20 2010 +0200
+++ b/lib/PFTools/Structqueries.pm	Mon Oct 04 19:29:19 2010 +0200
@@ -25,15 +25,17 @@
 use warnings;
 
 use base qw( Exporter );
+use Carp;
 use English qw( -no_match_vars );    # Avoids regex performance penalty
 
-use PFTools::Logger;
+#use PFTools::Logger;
 
 our @EXPORT = qw(
     Get_zone_from_hostname
     Get_zone_from_site_GLOBAL
     Get_hosttype_from_hostname
     Get_iface_vlan_from_hostname
+    Get_uniq_site_from_hostname
     Get_site_from_hostname
     Get_site_list
     Get_cmdline_from_hostprops
@@ -46,10 +48,20 @@
 
 our @EXPORT_OK = qw ();
 
-##############################################################
-### Prototypes
+sub Get_uniq_site_from_hostname {
+    my ( $hostname, $global_config ) = @_;
 
-sub Resolv_hostname_from_GLOBAL ($$$$$);
+    my $ref_list = Get_site_from_hostname( $hostname, $global_config );
+    unless( $ref_list ) {
+        carp qq{ERROR: Uknown host $hostname};
+        return;
+    }
+    if ( scalar @{$ref_list} > 1 ) {
+        carp qq{ERROR: Multiple sites for hostname $hostname};
+        return;
+    }
+    return shift @{$ref_list};
+}
 
 #########################################################################
 #
@@ -63,29 +75,11 @@
 # Output :
 #  Return a string containing the zone name for the specified site.
 #
-sub Get_zone_from_hostname ($$;$) {
+sub Get_zone_from_hostname {
     my ( $hostname, $global_config, $site ) = @_;
 
-    if ( !defined $site ) {
-        my $ref_list = Get_site_from_hostname( $hostname, $global_config );
-        if ( !defined $ref_list ) {
-            Warn( $CODE->{'UNDEF_KEY'},
-                      "Hostname "
-                    . $hostname
-                    . " is not defined into global configuration" );
-            return undef;
-        }
-        elsif ( scalar @{$ref_list} > 1 ) {
-            Warn( $CODE->{'DUPLICATE_VALUE'},
-                      "Hostname "
-                    . $hostname
-                    . " is defined on multiple sites into global configuration"
-            );
-            return undef;
-        }
-        else {
-            ($site) = @{$ref_list};
-        }
+    unless( $site ) {
+        $site = Get_uniq_site_from_hostname ( $hostname, $global_config );
     }
     return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
 }
@@ -103,16 +97,12 @@
 # Output :
 #  Returns a string containing the hosttype or undef if hostname doesn't exist
 #
-sub Get_hosttype_from_hostname ($$;$) {
+sub Get_hosttype_from_hostname {
     my ( $hostname, $global_config, $site ) = @_;
-    my $site_list;
 
-    if ( !defined $site ) {
-        $site_list = $global_config->{'SITE'}->{'__site_list'};
-    }
-    else {
-        $site_list = [$site];
-    }
+    my $site_list = ( $site )
+        ? [ $site ]
+        : $global_config->{'SITE'}->{'__site_list'};
 
     foreach my $site ( @{$site_list} ) {
         my $host_part
@@ -125,7 +115,7 @@
             }
         }
     }
-    return undef;
+    return;
 }
 
 #########################################################################
@@ -140,14 +130,14 @@
 # Output :
 #  Returns a string containing the interface or undef
 #
-sub Get_iface_vlan_from_hostname ($$) {
+sub Get_iface_vlan_from_hostname {
     my ( $vlan, $ref_host ) = @_;
 
     foreach my $iface ( keys %{ $ref_host->{'interfaces'} } ) {
         return $iface
             if ( $ref_host->{'interfaces'}->{$iface}->{'vlan'} eq $vlan );
     }
-    return undef;
+    return;
 }
 
 #########################################################################
@@ -162,39 +152,17 @@
 # Output :
 #  Returns a string containing the hosttype or undef if hostname doesn't exist
 #
-sub Get_hostname_model_from_hostname ($$) {
+sub Get_hostname_model_from_hostname {
     my ( $hostname, $global_config ) = @_;
 
     my $hostclass = Get_hosttype_from_hostname( $hostname, $global_config );
-    if ( !defined $hostclass ) {
-        Abort( $CODE->{'UNDEF_KEY'},
-                  "Unable to get hosttype from hostname "
-                . $hostname
-                . " : unexistant hostname" );
+    unless( $hostclass ) {
+        croak qq{ERROR: Unable to get hosttype from unknown $hostname};
     }
-    my $site_list = Get_site_from_hostname( $hostname, $global_config );
-    if ( !defined $site_list ) {
-        Abort( $CODE->{'UNDEF_KEY'},
-                  "Unable to get site list from hostname "
-                . $hostname
-                . " : unexistant hostname" );
-    }
-    else {
-        if ( scalar @{$site_list} > 1 ) {
-            Warn( $CODE->{'DUPLICATE_VALUE'},
-                      "Hostname "
-                    . $hostname
-                    . " is defined on multiple sites : unable to choose the right one"
-            );
-            return undef;
-        }
-        else {
-            my ($site) = @{$site_list};
-            return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}
+    my $site = Get_uniq_site_from_hostname ( $hostname, $global_config );
+    return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}
                 ->{'BY_NAME'}->{$hostclass}->{'deployment'}
                 ->{'hostname_model'};
-        }
-    }
 }
 
 #########################################################################
@@ -209,7 +177,7 @@
 # Output :
 #  Returns an array ref containing the sites list or undef if hostname doesn't exist
 #
-sub Get_site_from_hostname ($$) {
+sub Get_site_from_hostname {
     my ( $hostname, $global_config ) = @_;
     my $site_list;
 
@@ -220,13 +188,13 @@
         foreach my $hostclass ( keys %{$host_part} ) {
             if ( $hostclass eq $hostname ) {
                 push( @{$site_list}, $site )
-                    if ( !grep ( /^$site$/, @{$site_list} ) );
+                    if( !grep( m{\A $site \Z}xms, @{$site_list} ) );
                 next;
             }
             foreach my $host ( keys %{ $host_part->{$hostclass} } ) {
-                if ( $host eq $hostname ) {
+                if( $host eq $hostname ) {
                     push( @{$site_list}, $site )
-                        if ( !grep ( /^$site$/, @{$site_list} ) );
+                        if( !grep( m{\A $site \Z}xms, @{$site_list} ) );
                     last;
                 }
             }
@@ -235,7 +203,7 @@
     return $site_list;
 }
 
-sub Get_zone_from_site_GLOBAL ($$) {
+sub Get_zone_from_site_GLOBAL {
     my ( $site, $global_config ) = @_;
 
     return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'zone'};
@@ -253,7 +221,7 @@
 # Output :
 #  Return an array reference containing the built site list.
 #
-sub Get_site_list ($$) {
+sub Get_site_list {
     my ( $sect_hash, $global_config ) = @_;
     my $ref_list;
 
@@ -261,7 +229,7 @@
         return $global_config->{'SITE'}->{'__site_list'};
     }
     else {
-        @{$ref_list} = split( /\s*\,\s*/, $sect_hash->{'site'} );
+        @{$ref_list} = split( m{\s*\,\s*}, $sect_hash->{'site'} );
         return $ref_list;
     }
 }
@@ -272,114 +240,95 @@
 #
 # This function try to determine site from hostname if site is not defined
 # and return host definition from global configuration structure
-# Inputs :
+# Inputs :u
 #  - $hostname		: filename where server is parsed
 #  - $global_config	: hashref where are stored global configuration datas
 #  - $site			: define here the site where hostname is defined (optional)
 #
-sub Get_host_config_from_CONFIG ($$;$) {
+sub Get_host_config_from_CONFIG {
     my ( $hostname, $global_config, $site ) = @_;
 
-    if ( !defined $site ) {
-        my $site_list = Get_site_from_hostname( $hostname, $global_config );
-        if ( !defined $site_list ) {
-            Warn( $CODE->{'UNDEF_KEY'},
-                      "Unable to retrieve site for hostname "
-                    . $hostname
-                    . " : hostname not defined" );
-        }
-        elsif ( scalar @{$site_list} > 1 ) {
-            Warn( $CODE->{'UNDEF_KEY'},
-                      "Unable to retrieve site for hostname "
-                    . $hostname
-                    . " : hostname appeared in multiple sites : "
-                    . join( ",", @{$site_list} ) );
-        }
-        else {
-            ($site) = @{$site_list};
-        }
+    unless( $site ) {
+        $site = Get_uniq_site_from_hostname( $hostname, $global_config );
     }
     my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
     my $zone      = $site_part->{'zone'};
-    $hostname =~ /^([^.]+)(\.([^.]+))?(\.$zone)?$/;
+    $hostname =~ m{\A ([^.]+)(\.([^.]+))?(\.$zone)? \Z}xms;
     my ( $hostshort, $hostvlan ) = ( $1, $3 );
     my $hosttype = Get_hosttype_from_hostname( $hostname, $global_config );
     return $site_part->{'HOST'}->{'BY_NAME'}->{$hosttype}->{$hostshort};
 }
 
-sub Get_pkgtype_from_hostname ($$;$) {
+sub Get_pkgtype_from_hostname {
     my ( $hostname, $global_config, $site ) = @_;
 
-    my $host_props
-        = Get_host_config_from_CONFIG( $hostname, $global_config, $site );
-    return undef if ( !defined $host_props );
+    my $host_props = Get_host_config_from_CONFIG(
+        $hostname, $global_config, $site
+    );
+    return unless( $host_props );
     my $mode = $host_props->{'deployment'}->{'mode'};
-    if ( $mode =~ /^(debian|ubuntu)$/ ) {
+    if ( $mode =~ m{\A (debian|ubuntu) \Z}xms ) {
         return 'deb';
     }
     else {
-        Warn( $CODE->{'UNDEF_KEY'},
-                  "Unknown mode " 
-                . $mode
-                . " of deployment : cannot retrieve package type for this one"
-        );
-        return undef;
+        carp qq{ERROR: Unknown or not implemented deployment mode $mode};
+        return;
     }
 }
 
-sub Get_cmdline_from_hostprops ($) {
+sub Get_cmdline_from_hostprops {
     my ($host_props) = @_;
     my ( $bond_cmdline, $cmdline );
 
     $cmdline = $host_props->{'boot'}->{'cmdline'};
     foreach my $iface ( sort keys %{ $host_props->{'interfaces'} } ) {
-        next if ( $iface !~ /^bond/ );
+        next unless( $iface =~ m{\A bond}xms );
         $bond_cmdline = "bonding.mode="
             . $host_props->{'interfaces'}->{$iface}->{'mode'} . " ";
         foreach my $opt (
             split(
-                /\s*,\s*/, $host_props->{'interfaces'}->{$iface}->{'options'}
+                m{\s*,\s*}, $host_props->{'interfaces'}->{$iface}->{'options'}
             )
             )
         {
             $bond_cmdline .= "bonding." . $opt . " ";
         }
-        $bond_cmdline =~ s/\s*$//;
+        $bond_cmdline =~ s{\s* \Z}{}xms;
         last;
     }
     return ( $cmdline, $bond_cmdline );
 }
 
-sub Get_distrib_from_hostprops ($) {
+sub Get_distrib_from_hostprops {
     my ($host_props) = @_;
 
     return $host_props->{'deployment'}->{'distrib'};
 }
 
-sub Get_mode_from_hostprops ($) {
+sub Get_mode_from_hostprops {
     my ($host_props) = @_;
 
     return $host_props->{'deployment'}->{'mode'};
 }
 
-sub Resolv_hostname_from_GLOBAL ($$$$$) {
+sub Resolv_hostname_from_GLOBAL {
     my ( $hostname, $global_config, $site, $zone, $hosttype ) = @_;
     my $resolved = [];
 
-    $hostname =~ /^([^.]+)(\.([^.]+))?$/;
+    $hostname =~ m{\A ([^.]+)(\.([^.]+))? \Z}xms;
     my ( $hostshort, $hostvlan ) = ( $1, $3 );
     my $zone_part
         = $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}
         ->{$site};
-    if ( $hostname =~ /^(network|netmask|broadcast|gateway)/ ) {
-        return undef if ( $hostvlan && !defined $zone_part->{$hostvlan} );
+    if ( $hostname =~ m{\A (network|netmask|broadcast|gateway) }xms ) {
+        return if ( $hostvlan && !defined $zone_part->{$hostvlan} );
         my ( $type, $field )
-            = split( /\s+/, $zone_part->{$hostvlan}->{$hostshort} );
+            = split( m{\s+}, $zone_part->{$hostvlan}->{$hostshort} );
         push( @{$resolved}, $field );
     }
     else {
         foreach my $entry ( keys %{ $zone_part->{$hosttype} } ) {
-            next if ( $entry !~ /^$hostname$/ );
+            next if ( $entry !~ m{\A $hostname \Z}xms );
             my @fields;
             if ( ref( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
                 @fields = @{ $zone_part->{$hosttype}->{$entry} };
@@ -388,14 +337,14 @@
                 @fields = ( $zone_part->{$hosttype}->{$entry} );
             }
             foreach my $line (@fields) {
-                my ( $type, $field ) = split( /\s+/, $line );
+                my ( $type, $field ) = split( m{\s+}, $line );
                 if ( $type eq 'A' ) {
                     push( @{$resolved}, $field );
                 }
                 elsif ( $type eq 'CNAME' ) {
-                    my $cname_resolved
-                        = Resolv_hostname_from_GLOBAL( $field, $global_config,
-                        $site, $zone, $hosttype );
+                    my $cname_resolved = Resolv_hostname_from_GLOBAL(
+                        $field, $global_config, $site, $zone, $hosttype
+                    );
                     push( @{$resolved}, @{$cname_resolved} );
                 }
             }
diff -r 494d020bfacd -r 92e3151737a4 lib/PFTools/Update.pm
--- a/lib/PFTools/Update.pm	Mon Oct 04 13:49:20 2010 +0200
+++ b/lib/PFTools/Update.pm	Mon Oct 04 19:29:19 2010 +0200
@@ -32,16 +32,6 @@
 
 use PFTools::Logger;
 use PFTools::Packages;
-#use PFTools::Update::Addfile;
-#use PFTools::Update::Addlink;
-#use PFTools::Update::Addmount;
-#use PFTools::Update::Common;
-#use PFTools::Update::Createfile;
-#use PFTools::Update::Installpkg;
-#use PFTools::Update::Mkdir;
-#use PFTools::Update::Purgepkg;
-#use PFTools::Update::Removedir;
-#use PFTools::Update::Removefile;
 
 our @EXPORT = qw(
     Get_depends_for_action
@@ -50,6 +40,33 @@
 );
 
 our @EXPORT_OK = qw();
+
+###########################################
+# API documentation
+#
+# Each new action MUST BE a package with name :
+#       PFTools::Update::<action>
+# where action is in UPPER case
+#
+# Each action's package is loaded at runtime with Module::Runtime
+#
+# Each new action must provide at least two exported function
+#   - Action_depends    : for building potentially implicit depend(s)
+#   - Action_exec       : the action itself
+#
+# Action_depends is a VOID funtion with 3 parameters
+#   - $ref_section  : HASHREF where parsed section is stored
+#   - $dest         : parsed section name
+#   - $options      : HASHREF with update-config options
+#
+# Action_exec is a BOOLEAN function with 5 parameters
+#   - $ref_section  : HASHREF where parsed section is stored
+#   - $dest         : parsed section name
+#   - $options      : HASHREF with update-config options
+#   - $hash_subst   : HASHREF with pf-tools vars substitutions
+#   - $global_config: HASHREF with parsed "network and host" configuration
+#
+
 
 ###########################################
 # Global vars



More information about the pf-tools-commits mailing list