From 045c022d42f6ea6b0a7daef853256ff8e83bd870 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 29 Apr 2013 21:58:33 +0100 Subject: [PATCH] incorporate manual topo info from the topology db table --- .../lib/App/Netdisco/Util/DiscoverAndStore.pm | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm index d759503f..91683158 100644 --- a/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm +++ b/Netdisco/lib/App/Netdisco/Util/DiscoverAndStore.pm @@ -570,6 +570,9 @@ store the device's port neighbors information. If any neighbor is unknown to Netdisco, a discover job for it will immediately be queued (modulo configuration file C setting). +Entries in the Topology database table will override any discovered device +port relationships, and will also have their respective neighbors discovered. + The Device database object can be a fresh L object which is not yet stored to the database. @@ -578,6 +581,9 @@ not yet stored to the database. sub find_neighbors { my ($device, $snmp) = @_; + # first allow any manually configred topology to be set + _set_manual_topology($device, $snmp); + my $c_ip = $snmp->c_ip; unless ($snmp->hasCDP or scalar keys %$c_ip) { debug sprintf ' [%s] neigh - CDP/LLDP not enabled!', $device->ip; @@ -701,6 +707,41 @@ sub find_neighbors { } } +# take data from the topology table and update remote_ip and remote_port +# in the devices table. only use root_ips and skip any bad topo entries. +sub _set_manual_topology { + my ($device, $snmp) = @_; + + my $topo_links = schema('netdisco')->resultset('Topology'); + debug sprintf ' [%s] neigh - setting manual topology links', $device->ip; + + while (my $link = $topo_links->next) { + # could fail for broken topo, but we ignore to try the rest + try { + schema('netdisco')->txn_do(sub { + # only work on root_ips + # skip bad entries + my $left = get_device($link->dev1) or return; + my $right = get_device($link->dev2) or return; + + $left->ports + ->single({port => $link->port1}) + ->update({ + remote_ip => $right->ip, + remote_port => $link->port2, + }); + + $right->ports + ->single({port => $link->port2}) + ->update({ + remote_ip => $left->ip, + remote_port => $link->port1, + }); + }); + }; + } +} + # only enqueue if device is not already discovered, and # discover_no_type config permits the discovery sub _enqueue_discover {