pf-tools/pf-tools: 2 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Wed Dec 10 15:56:19 UTC 2014


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/7e22126d5c3b
changeset: 1373:7e22126d5c3b
user:      shad
date:      Wed Dec 10 16:55:25 2014 +0100
description:
simplify ip obtention on ADDMOUNT

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/fcb2cb3c461b
changeset: 1374:fcb2cb3c461b
user:      shad
date:      Wed Dec 10 16:56:14 2014 +0100
description:
fix Automagic find a file in ADDFILE

diffstat:

 lib/PFTools/Update/ADDFILE.pm  |  48 ++++++++++++++++--------------
 lib/PFTools/Update/ADDMOUNT.pm |  66 +++++++++++++++++++----------------------
 2 files changed, 56 insertions(+), 58 deletions(-)

diffs (188 lines):

diff -r 4b315cf679d4 -r fcb2cb3c461b lib/PFTools/Update/ADDFILE.pm
--- a/lib/PFTools/Update/ADDFILE.pm	Wed Dec 10 13:41:39 2014 +0100
+++ b/lib/PFTools/Update/ADDFILE.pm	Wed Dec 10 16:56:14 2014 +0100
@@ -54,7 +54,7 @@
 }
 
 sub __find_source {
-    my ( $ref_section, $options, $hash_subst ) = @_;
+    my ( $options, $hash_subst, $search_files ) = @_;
 
     # search in order into:
     # /SITE/pro1/FILE/pro1-ncdn-cache00/
@@ -68,25 +68,28 @@
     # /FILE/common/
 
     my @search_dirs = (
-        'HOSTNAMESITE',      'HOSTSITE',
-        'HOSTNAME',          'HOST',
-        'SHORTHOSTNAMESITE', 'SHORTHOSTSITE',
-        'SHORTHOSTNAME',     'SHORTHOST',
+        'HOSTNAMESITE:',      'HOSTSITE:',
+        'HOSTNAME:',          'HOST:',
+        'SHORTHOSTNAMESITE:', 'SHORTHOSTSITE:',
+        'SHORTHOSTNAME:',     'SHORTHOST:',
         'FILE:common/',
     );
 
     my $source;
 SEARCH_DIR:
     foreach my $search_dir (@search_dirs) {
-        my @search_files = (
-            qq{$search_dir:%SECTIONNAME%.%HOSTDIGITS%},
-            qq{$search_dir:%SECTIONNAME%},
-        );
-        foreach my $search_file (@search_files) {
+        if ( !$search_files ) {
+            $search_files
+                = [ qq{%SECTIONNAME%.%HOSTDIGITS%}, qq{%SECTIONNAME%}, ];
+        }
+        foreach ( @{$search_files} ) {
+            my $search_file = $search_dir . q{/} . $_;
             $source
                 = get_source( $search_file, $options->{'host'}, $hash_subst );
             if ( -e $source ) {
-                $ref_section->{source} = $search_file;
+                if ( $options->{'verbose'} || $options->{'simul'} ) {
+                    print "using file $source\n";
+                }
                 last SEARCH_DIR;
             }
         }
@@ -104,7 +107,8 @@
     $tmp = get_tmp_dest($dest);
 
     if ( !$ref_section->{'source'} ) {
-        $source = __find_source( $ref_section, $options, $hash_subst );
+        $source = __find_source( $options, $hash_subst );
+        $ref_section->{source} = $source;
     }
     else {
         # Removing trailing space from source
@@ -119,7 +123,8 @@
             foreach my $splitsource ( split q{ }, $ref_section->{'source'} ) {
 
                 if ( $splitsource =~ m{\AAUTO:(.*)\z}xms ) {
-                    $splitsource = __find_source( $1, $options, $hash_subst );
+                    $splitsource
+                        = __find_source( $options, $hash_subst, [$1] );
 
                     if ( !-f $splitsource ) {
                         next SPLITSOURCE;
@@ -137,15 +142,14 @@
                         );
                         return;
                     }
-                    if (deferredlogsystem(
-                            q{cat '} . $splitsource . q{' >> } . $source
-                        )
-                        )
-                    {
-                        carp
-                            qq{ERROR: Unable to append $splitsource to $source};
-                        return;
-                    }
+                }
+                if (deferredlogsystem(
+                        q{cat '} . $splitsource . q{' >> } . $source
+                    )
+                    )
+                {
+                    carp qq{ERROR: Unable to append $splitsource to $source};
+                    return;
                 }
             }
         }
diff -r 4b315cf679d4 -r fcb2cb3c461b lib/PFTools/Update/ADDMOUNT.pm
--- a/lib/PFTools/Update/ADDMOUNT.pm	Wed Dec 10 13:41:39 2014 +0100
+++ b/lib/PFTools/Update/ADDMOUNT.pm	Wed Dec 10 16:56:14 2014 +0100
@@ -73,51 +73,44 @@
     my ( $host, $global_config ) = @_;
 
     my ( $zone, $hostshort, $hostvlan );
-    my $ip = $host;
+
+    if ( isipaddr($host) ) {
+        return $host;
+    }
+
+    if ( $host =~ m{\A ([^.]+)\.}xms ) {
+        $host = $1;
+    }
+
+    my $hosttype = get_hosttype_from_hostname( $host, $global_config );
+    my $site_list = get_site_list_from_hostname( $host, $global_config );
+    my $site = shift @{$site_list};
+
     if ( $host =~ m{\A ( [^.]+ ) (?: [.].* )? \z}xms ) {
-        $zone = get_zone_from_hostname( $1, $global_config );
+        $zone = get_zone_from_hostname( $1, $global_config, $site );
     }
     else {
         carp qq{ERROR: no host found for $host};
         return;
     }
-    $ip =~ s{[.]$zone \z}{}xms;
-    if ( $ip =~ m{\A ( [^.]+ ) (?: [.]([^.]+) )? \z}xms ) {
-        ( $hostshort, $hostvlan ) = ( $1, $3 );
-    }
-    else {
-        carp qq{ERROR: can't extract hostshort and hostvlan from $ip};
-    }
-    my $hosttype = get_hosttype_from_hostname( $hostshort, $global_config );
-    my $site_list = get_site_list_from_hostname( $hostshort, $global_config );
-    my $site;
 
-    if ( !defined $site_list || scalar @{$site_list} > 1 ) {
-        carp qq{ERROR: Unknown or multiple site for $host};
+    my $resolved = resolve_hostname_from_global_config(
+        {   hostname      => $host,
+            global_config => $global_config,
+            site_name     => $site,
+            zone_name     => $zone,
+            hosttype      => $hosttype,
+
+            # FIXME ip_type => ????,
+        }
+    );
+    if ( !defined $resolved || scalar @{$resolved} > 1 ) {
+        carp qq{ERROR: Unknown or multiple IPs for $host};
         return;
     }
-    else {
-        $site = shift @{$site_list};
-    }
-    if ( !isipaddr($ip) ) {
-        my $resolved = resolve_hostname_from_global_config(
-            {   hostname      => $ip,
-                global_config => $global_config,
-                site_name     => $site,
-                zone_name     => $zone,
-                hosttype      => $hosttype,
 
-                # FIXME ip_type => ????,
-            }
-        );
-        if ( !defined $resolved || scalar @{$resolved} > 1 ) {
-            carp qq{ERROR: Unknown or multiple IPs for $host};
-            return;
-        }
-        else {
-            $ip = shift @{$resolved};
-        }
-    }
+    my $ip = shift @{$resolved};
+
     return $ip;
 }
 
@@ -338,7 +331,8 @@
                     if ( deferredlogsystem($cmd) ) {
                         carp colored(
                             qq{ERROR: while remounting $dest with\n$add_mount->{'options'}},
-                            q{bold red on_white} );
+                            q{bold red on_white}
+                        );
                         return;
                     }
                 }



More information about the pf-tools-commits mailing list