Skip to main content

findInterface

findInterface(device: Device, ifaceName: String) : { interface: Iface, subInterface: SubInterface?}?

A single device's configuration and state files may refer to the same interface by slightly different names. For example, on a Cisco NXOS device, a port channel might appear in the configuration as "interface port- channel3", while the output of a "show interface" command on the device may refer to the same interface as "Po3", using an abbreviated form and different capitalization of letters.

The normalized data model for interfaces uses a canonical, normalized name for each interface. The findInterface function enables you to lookup an interface in the normalized data model using a name that might not be normalized; for example, you can use it to look up an interface using "port-channel3" as it appears in the config, even though it is named "po3" in the normalized data model.

Specifically, findInterface takes two arguments: a device and an interface name. For example, findInterface(device, "port-channel3") returns:

  • null if "port-channel3" returned no matches across the device's interfaces and the sub-interfaces of all the device's interfaces.
  • { interface: Iface, subInterface: null } if "port-channel3" matched one of the device's interfaces, but none of that interface's sub-interfaces were matched.
  • { interface: Iface, subInterface: SubInterface } if "port-channel3" matched one of the device's interfaces' sub-interfaces. In this case the matched sub-interface's parent interface is also returned.

As an example, the following query find interfaces on NXOS devices that have some ip ospf configuration and MTU setting above 9000. The query finds relevant interfaces in the configuration, and then uses findInterface to lookup the MTU setting in the normalized data model based on the interface name as it appears in the configuration.

foreach device in network.devices
where device.platform.os == OS.NXOS
foreach match in patternMatches(device.files.config, `interface {ifaceName:string}`)
where length(patternMatches(match.line.children, `ip ospf`)) > 0
let ifaceMatch = findInterface(device, match.data.ifaceName)
where isPresent(ifaceMatch) && ifaceMatch.interface.mtu > 9000
select {
deviceName: device.name,
iface: ifaceMatch.interface.name,
mtu: ifaceMatch.interface.mtu
}