NAME

App::Netdisco::Util::VRF

DESCRIPTION

Helper subroutines for collecting VRF data from devices.

There are no default exports, however the :all tag will export all subroutines.

EXPORT_OK

vrf_collection_enabled( $device )

True only when the store_vrfs setting is on, the device does not match skip_vrf_devices, and the device is not a pseudo device. A pseudo device may be read from a snapshot, so every worker treats it as if store_vrfs were off, whether it is read from a snapshot or live.

vrf_skip_test( $device )

Returns a test, $skipped->($local_name), true when vrf_no_devicevrfs skips that VRF on $device. Build it once, before a loop: the device is matched against the setting's keys here, and each name's answer is kept, so the test costs one ACL check per distinct name however often it is asked. Never true for the default table, whichever of default or the empty string names it.

vrf_no_devicevrfs is a dictionary, or a list of them, as macsuck_no_deviceports: each key is an ACL matching devices, its value an ACL matching the VRFs to skip on them. A VRF is matched as vrf:<regex>, anchored at both ends, so ., + and ( are live; (?i) ignores case.

vrf_no_devicevrfs:
  'group:__ANY__': ['vrf:(?i)mgmt', 'vrf:lab-.*']
  '192.0.2.1': 'vrf:cust:a'

A hostname or regex rule in a key costs a DNS lookup each time a test is built, which is a few times per job. A value rule without a property (a bare name) or a regex object never matches a VRF, so each warns once.

netdisco_vrf( $snmpinfo_name )

SNMP::Info names the global routing table default; Netdisco stores it as the empty string. Returns that, or the name unchanged for any other VRF.

vrf_instances_for( $device, $snmp )

Returns the hashref from $snmp->vrf_instances without the VRFs skipped by "vrf_skip_test", or undef when collection is disabled for the device or the SNMP::Info class has no VRF support (vrf_instances_complete is undef). No SNMP method is called when collection is disabled.

The instances are read here, in the default context, because update() clears SNMP::Info's cache.

each_vrf_instance( $device, $snmp, $instances, \&reader, %options )

Reads every instance of $instances (as from "vrf_instances_for") with $reader->($name, $instance, $switched), which returns whatever the caller needs from that instance.

default is read first, then the attribution-mode instances (a first context of kind none, or no contexts at all) sorted by name, all in place with no update(). Then each context-mode instance, sorted by name, in its own context; the session is returned to the default context once, after the last of them. An instance whose context this session cannot enter is not read and is reported incomplete. So is one whose contexts is empty, which SNMP::Info gives for a context-mode VRF that no context serves; it costs no SNMP call.

A read is complete only when $snmp->vrf_read_complete($name) is 1 and no walk since the read began came back short (incomplete_walks_for, with the walk_methods option naming any further methods to check).

Where the default read is partial only because other instances leak into it ($snmp->vrf_read_leaked('default'), SNMP::Info 3.985001, so far only Juniper's virtual routers), each of those instances' ports are read with i_vrf() in its own context. Once every one of them was read whole, the session returns to the default context, hands the ports to vrf_exclude_ports() and reads default a second time, which replaces the first read. Otherwise the first, partial read stands.

Returns a hashref keyed by "netdisco_vrf" of each name, of { complete => 0|1, data => <reader result or undef> }. Read anything needed from the default context before calling this.

Option log_as names the worker in log lines (default device).

SEE ALSO

SNMP::Info::VRF