Send Netdot-devel mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://osl.uoregon.edu/mailman/listinfo/netdot-devel
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Netdot-devel digest..."


Today's Topics:

   1. [SCM] Netdot Git repository branch master updated.
      b540960baa83a0951baa79b70c4a5cab0f1f0d59 (Apache)
   2. [SCM] Netdot Git repository branch master updated.
      fc949eeaa423961861396542b499d1bab4197b6c (Apache)


----------------------------------------------------------------------

Message: 1
Date: Fri, 15 Jun 2012 12:21:45 -0700
From: Apache <[email protected]>
Subject: [Netdot-devel] [SCM] Netdot Git repository branch master
        updated.        b540960baa83a0951baa79b70c4a5cab0f1f0d59
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot Git repository".

The branch, master has been updated
       via  b540960baa83a0951baa79b70c4a5cab0f1f0d59 (commit)
      from  843d8cfc008cf7ec091f29d92c0064260ecbc923 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b540960baa83a0951baa79b70c4a5cab0f1f0d59
Author: Carlos Vicente <[email protected]>
Date:   Fri Jun 15 15:20:52 2012 -0400

    Avoid retrieving all MACs and IPs when updating ARP and FWT

diff --git a/lib/Netdot/Model/ArpCacheEntry.pm 
b/lib/Netdot/Model/ArpCacheEntry.pm
index 2689e7a..023254d 100644
--- a/lib/Netdot/Model/ArpCacheEntry.pm
+++ b/lib/Netdot/Model/ArpCacheEntry.pm
@@ -29,12 +29,12 @@ Arp Cache Entry class
     objects.  We use direct SQL commands for improved speed.
 
   Arguments: 
-    Array ref containing hash refs with following keys:
-    arpcache  - id of ArpCache table record
-    interface - id of Interface
-    ipaddr    - ip address in numeric format
-    physaddr  - string with mac address
-   
+    Array ref containing these keys:
+    list = Arrayref of hash refs with following keys:
+           arpcache  - id of ArpCache table record
+           interface - id of Interface
+           ipaddr    - ip address in numeric format
+           physaddr  - string with mac address
   Returns:   
     True if successul
   Examples:
@@ -44,34 +44,28 @@ Arp Cache Entry class
 sub fast_insert{
     my ($class, %argv) = @_;
     $class->isa_class_method('fast_insert');
-
-    my $list    = $argv{list};
-    my $db_macs = PhysAddr->retrieve_all_hashref();
-    my $db_ips  = Ipblock->retrieve_all_hashref();
-
-    my $dbh = $class->db_Main;
-
+    my $list = $argv{list} || $class->throw_fatal("Missing list arg");
+    
     # Build SQL query
+    my $dbh = $class->db_Main;
     my $sth = $dbh->prepare_cached("INSERT INTO arpcacheentry 
                                     (arpcache,interface,ipaddr,physaddr)
-                                    VALUES (?, ?, ?, ?)");     
+                                    VALUES (?, ?, 
+                                    (SELECT id FROM ipblock WHERE address=? 
AND version=?), 
+                                    (SELECT id FROM physaddr WHERE 
address=?))");      
     # Now walk our list and insert
     foreach my $r ( @$list ){
-       if ( !exists $db_macs->{$r->{physaddr}} ){
-           $logger->error(sprintf("Netdot::Model::arpcacheentry::fast_insert: 
Error: MAC: %s not found in database.", 
-                                  $r->{physaddr}));
-           next;
-       }
-       if ( !exists $db_ips->{$r->{ipaddr}} ){
-           $logger->error(sprintf("Netdot::Model::arpcacheentry::fast_insert: 
Error: IP: %s not found in database.", 
-                                  $r->{ipaddr}));
-           next;
+       eval {
+           $sth->execute($r->{arpcache}, 
+                         $r->{interface},
+                         $r->{ipaddr},
+                         $r->{version},
+                         $r->{physaddr},
+               );
+       };
+       if ( my $e = $@ ){
+           $logger->warn("Problem inserting arpcacheentry: $e");
        }
-       $sth->execute($r->{arpcache}, 
-                     $r->{interface},
-                     $db_ips->{$r->{ipaddr}},
-                     $db_macs->{$r->{physaddr}},
-           );
     }
     
     return 1;
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index 31d7482..eccd7be 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -2025,6 +2025,7 @@ sub arp_update {
                    arpcache  => $ac->id,
                    interface => $intid,
                    ipaddr    => Ipblock->ip2int($ip),
+                   version   => $version,
                    physaddr  => $mac,
                };
            }
diff --git a/lib/Netdot/Model/FWTableEntry.pm b/lib/Netdot/Model/FWTableEntry.pm
index b7e8666..cf82d66 100644
--- a/lib/Netdot/Model/FWTableEntry.pm
+++ b/lib/Netdot/Model/FWTableEntry.pm
@@ -44,22 +44,22 @@ sub fast_insert{
     my ($class, %argv) = @_;
     $class->isa_class_method('fast_insert');
 
-    my $list    = $argv{list};
-    my $db_macs = PhysAddr->retrieve_all_hashref;
-
-    my $dbh = $class->db_Main;
+    my $list = $argv{list} || $class->throw_fatal('Missing list arg');
 
     # Build SQL query
+    my $dbh = $class->db_Main;
     my $sth= $dbh->prepare_cached("INSERT INTO fwtableentry 
                                    (fwtable,interface,physaddr)
-                                   VALUES (?, ?, ?)
-                                    ");        
+                                   VALUES (?, ?, (SELECT id FROM physaddr 
WHERE address=?))"); 
     foreach my $r ( @$list ){
-       if ( exists $db_macs->{$r->{physaddr}} ){
+       eval {
            $sth->execute($r->{fwtable}, 
                          $r->{interface},
-                         $db_macs->{$r->{physaddr}},
+                         $r->{physaddr},
                );
+       };
+       if ( my $e = $@ ){
+           $logger->warn("Problem inserting FWT entry: $e");
        }
     }
     return 1;
diff --git a/lib/Netdot/Model/Ipblock.pm b/lib/Netdot/Model/Ipblock.pm
index 9d82ec9..bda0407 100644
--- a/lib/Netdot/Model/Ipblock.pm
+++ b/lib/Netdot/Model/Ipblock.pm
@@ -908,7 +908,6 @@ sub build_tree {
        my $b = $parents->{$_};
        if ( (defined $a && !defined $b) || (!defined $a && defined $b) || 
             (defined $a && defined $b && ($a ne $b)) ){
-           $logger->debug("Ipblock id: $_ has new parent");
            $sth->execute($parents->{$_}, $_);
        }
     }
@@ -3062,7 +3061,6 @@ sub _update_tree{
                                               tree     => $tree,
                    );
                    if ( defined $node && $node->data != $par ){
-                       $logger->debug("Ipblock::_update_tree: node $id has new 
parent");
                        $parents{$id} = $node->data;
                    }
                }else{
@@ -3073,7 +3071,6 @@ sub _update_tree{
                        );
                    if ( defined $node && $node->parent 
                         && $node->parent->data != $par ){
-                       $logger->debug("Ipblock::_update_tree: node $id has new 
parent");
                        $parents{$id} = $node->parent->data;
                    }
                }

-----------------------------------------------------------------------

Summary of changes:
 lib/Netdot/Model/ArpCacheEntry.pm |   50 ++++++++++++++++--------------------
 lib/Netdot/Model/Device.pm        |    1 +
 lib/Netdot/Model/FWTableEntry.pm  |   16 ++++++------
 lib/Netdot/Model/Ipblock.pm       |    3 --
 4 files changed, 31 insertions(+), 39 deletions(-)


hooks/post-receive
-- 
Netdot Git repository


------------------------------

Message: 2
Date: Fri, 15 Jun 2012 15:48:14 -0700
From: Apache <[email protected]>
Subject: [Netdot-devel] [SCM] Netdot Git repository branch master
        updated.        fc949eeaa423961861396542b499d1bab4197b6c
To: [email protected]
Message-ID: <[email protected]>

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Netdot Git repository".

The branch, master has been updated
       via  fc949eeaa423961861396542b499d1bab4197b6c (commit)
      from  b540960baa83a0951baa79b70c4a5cab0f1f0d59 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fc949eeaa423961861396542b499d1bab4197b6c
Author: Carlos Vicente <[email protected]>
Date:   Fri Jun 15 18:47:21 2012 -0400

    Add option to only update devices matching a given name pattern. This helps 
split the update load among several machines

diff --git a/bin/updatedevices.pl b/bin/updatedevices.pl
index ffff734..beba628 100755
--- a/bin/updatedevices.pl
+++ b/bin/updatedevices.pl
@@ -14,17 +14,19 @@ use Getopt::Long qw(:config no_ignore_case bundling);
 use Log::Log4perl::Level;
 
 # Variables that will hold given values
-my ($host, $blocks, $db, $file, $commstrs, $version, $sec_name, $sec_level, 
$auth_proto, $auth_pass, $priv_proto, $priv_pass);
+my ($host, $blocks, $db, $matching, $file, $commstrs, $version, $sec_name, 
+    $sec_level, $auth_proto, $auth_pass, $priv_proto, $priv_pass);
 
 # Default values
 my $retries         = Netdot->config->get('DEFAULT_SNMPRETRIES');
 my $timeout         = Netdot->config->get('DEFAULT_SNMPTIMEOUT');
 
 # Flags
-my ($ATOMIC, $ADDSUBNETS, $SUBSINHERIT, $BGPPEERS, $RECURSIVE, $INFO, $FWT, 
$TOPO, $ARP, $PRETEND, $HELP, $_DEBUG);
+my ($ATOMIC, $ADDSUBNETS, $SUBSINHERIT, $BGPPEERS, $RECURSIVE, $INFO, $FWT, 
+    $TOPO, $ARP, $PRETEND, $HELP, $_DEBUG);
 
 # This will be reflected in the history tables
-$ENV{REMOTE_USER}   = "netdot";
+$ENV{REMOTE_USER} = "netdot";
 
 my $USAGE = <<EOF;
  usage: $0 [ optional args ]
@@ -36,13 +38,15 @@ my $USAGE = <<EOF;
         -I, --info  | -F, --fwt  | -A, --arp | -T, --topology
 
     Optional args:
-        [c, --community] [r, --retries] [o, --timeout] [v, --version] [d, 
--debug]
-        [--add-subnets <0|1>] [--subs-inherit <0|1>] [--with-bgp-peers <0|1>] 
[--pretend] [--atomic]
+        [-c, --community] [-r, --retries] [-o, --timeout] [-v, --version] [-d, 
--debug] 
+        [--add-subnets <0|1>] [--subs-inherit <0|1>] [--with-bgp-peers <0|1>] 
+        [-m, --matching] [--pretend] [--atomic]
         
     Argument Detail: 
     -H, --host <hostname|address>        Update given host only.
     -B, --blocks <address/prefix>[, ...] Specify an IP block (or blocks) to 
discover
     -D, --db                             Update only DB existing devices
+    -m, --matching <regex>               Update only devices whose names match 
pattern (with -B, -D, -E)
     -E, --file                           Update devices listed in given file
     -c, --communities <string>[, ...]    SNMP community string(s)
     -r, --retries <integer >             SNMP retries (default: $retries)
@@ -75,6 +79,7 @@ EOF
 my $result = GetOptions( "H|host=s"          => \$host,
                         "B|blocks=s"        => \$blocks,
                         "D|db"              => \$db,
+                        "m|matching=s"      => \$matching,
                         "E|file=s"          => \$file,
                         "I|info"            => \$INFO,
                         "F|fwt"             => \$FWT,
@@ -155,7 +160,6 @@ $logger->info(sprintf("$0 started at %s", scalar 
localtime($start)));
 
 if ( $INFO || $FWT || $ARP ){
     
-    
     my %uargs = (version      => $version,
                 timeout      => $timeout,
                 retries      => $retries,
@@ -173,6 +177,7 @@ if ( $INFO || $FWT || $ARP ){
                 do_info      => $INFO,
                 do_fwt       => $FWT,
                 do_arp       => $ARP,
+                matching     => $matching,
        );
     $uargs{communities} = \@communities if @communities;
     
diff --git a/lib/Netdot/Model/Device.pm b/lib/Netdot/Model/Device.pm
index eccd7be..2f0d273 100644
--- a/lib/Netdot/Model/Device.pm
+++ b/lib/Netdot/Model/Device.pm
@@ -1183,6 +1183,7 @@ sub get_snmp_info {
     subs_inherit  Flag. When adding subnets, have them inherit information 
from the Device
     bgp_peers     Flag. When discovering routers, update bgp_peers
     pretend       Flag. Do not commit changes to the database
+    matching      Regex. Only update devices whose names match regex
   Returns:
     True if successful
     
@@ -1220,6 +1221,7 @@ sub snmp_update_all {
     subs_inherit  Flag. When adding subnets, have them inherit information 
from the Device
     bgp_peers     Flag. When discovering routers, update bgp_peers
     pretend       Flag. Do not commit changes to the database
+    matching      Regex. Only update devices whose names match regex
 
   Returns:
     True if successful
@@ -1275,6 +1277,7 @@ sub snmp_update_block {
     subs_inherit  Flag. When adding subnets, have them inherit information 
from the Device
     bgp_peers     Flag. When discovering routers, update bgp_peers
     pretend       Flag. Do not commit changes to the database
+    matching      Regex. Only update devices whose names match regex
 
   Returns:
     True if successful
@@ -4112,6 +4115,7 @@ sub _fork_end {
 #     subs_inherit   Flag. When adding subnets, have them inherit information 
from the Device
 #     bgp_peers      Flag. When discovering routers, update bgp_peers
 #     pretend        Flag. Do not commit changes to the database
+#     matching       Regex. Only update devices whose names match regex
 #   Returns: 
 #     Device count
 #
@@ -4186,7 +4190,12 @@ sub snmp_update_parallel {
     
     # Go over list of existing devices
     while ( my ($id, $dev) = each %do_devs ){
-       
+
+       if ( my $regex = $argv{matching} ){
+           unless ( $dev->fqdn =~ /$regex/o ){
+               next;
+           }
+       }
        # Make sure we don't launch a process unless necessary
        if ( $dev->is_in_downtime() ){
            $logger->debug(sub{ sprintf("Model::Device::_snmp_update_parallel: 
%s in downtime.  Skipping", $dev->fqdn) });

-----------------------------------------------------------------------

Summary of changes:
 bin/updatedevices.pl       |   17 +++++++++++------
 lib/Netdot/Model/Device.pm |   11 ++++++++++-
 2 files changed, 21 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
Netdot Git repository


------------------------------

_______________________________________________
Netdot-devel mailing list
[email protected]
https://osl.uoregon.edu/mailman/listinfo/netdot-devel


End of Netdot-devel Digest, Vol 63, Issue 15
********************************************

Reply via email to