Retrieve vrf interfaces (#366)
Allow to retrieve the VRF interface for some devices (used for Nexus devices). The SNMP::Info::Layer3::Nexus module should have the patch to retrieve the VRF context. And the context should have been created on Nexus device
This commit is contained in:
@@ -8,7 +8,9 @@ use App::Netdisco::Transport::SNMP ();
|
|||||||
use App::Netdisco::Util::Permission 'check_acl_no';
|
use App::Netdisco::Util::Permission 'check_acl_no';
|
||||||
use App::Netdisco::Util::FastResolver 'hostnames_resolve_async';
|
use App::Netdisco::Util::FastResolver 'hostnames_resolve_async';
|
||||||
use App::Netdisco::Util::DNS 'hostname_from_ip';
|
use App::Netdisco::Util::DNS 'hostname_from_ip';
|
||||||
|
use App::Netdisco::Util::SNMP 'snmp_comm_reindex';
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
use Scope::Guard 'guard';
|
||||||
use NetAddr::IP::Lite ':lower';
|
use NetAddr::IP::Lite ':lower';
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
@@ -23,6 +25,19 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
|||||||
my $interfaces = $snmp->interfaces;
|
my $interfaces = $snmp->interfaces;
|
||||||
my $ip_netmask = $snmp->ip_netmask;
|
my $ip_netmask = $snmp->ip_netmask;
|
||||||
|
|
||||||
|
# Get IP Table peer VRF if supported
|
||||||
|
my @vrf_list = _get_vrf_list($device, $snmp);
|
||||||
|
|
||||||
|
{
|
||||||
|
my $guard = guard { snmp_comm_reindex($snmp, $device, 0, 0) };
|
||||||
|
foreach my $vrf (@vrf_list) {
|
||||||
|
snmp_comm_reindex($snmp, $device, $vrf, 0);
|
||||||
|
$ip_index = { %$ip_index , %{$snmp->ip_index} };
|
||||||
|
$interfaces = { %$interfaces , %{$snmp->interfaces} };
|
||||||
|
$ip_netmask = { %$ip_netmask , %{$snmp->ip_netmask} };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# build device aliases suitable for DBIC
|
# build device aliases suitable for DBIC
|
||||||
my @aliases;
|
my @aliases;
|
||||||
foreach my $entry (keys %$ip_index) {
|
foreach my $entry (keys %$ip_index) {
|
||||||
@@ -242,4 +257,26 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
# return a list of VRF which are OK to connect
|
||||||
|
sub _get_vrf_list {
|
||||||
|
my ($device, $snmp) = @_;
|
||||||
|
|
||||||
|
return () if !$snmp->cisco_comm_indexing;
|
||||||
|
|
||||||
|
my @ok_vrfs = ();
|
||||||
|
my $vrf_name = $snmp->vrf_name || {};
|
||||||
|
|
||||||
|
while (my ($idx, $vrf) = each(%$vrf_name)) {
|
||||||
|
if ($vrf =~ /^\S+$/) {
|
||||||
|
my $ctx_name = pack("C*",split(/\./,$idx));
|
||||||
|
$ctx_name =~ s/.*[^[:print:]]+//;
|
||||||
|
debug sprintf(' [%s] Discover VRF %s with SNMP Context %s', $device->ip, $vrf, $ctx_name);
|
||||||
|
push (@ok_vrfs,$ctx_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return @ok_vrfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
true;
|
true;
|
||||||
|
|||||||
Reference in New Issue
Block a user