Skip to main content

I finally managed to write a useful NQE query with no help. Yay! This query lists all of the loopback interfaces and their IP addresses. I tested it, and it works. But I am curious if there is a more efficient or elegant way to enumerate the IP addresses. Seems to me a little clumsy.

 

getSubIfaceIpInfos(iface) =
foreach subIface in iface.subinterfaces
foreach subnet in subIface.ipv4.addresses select subnet;

foreach device in network.devices
foreach interface in device.interfaces
where interface.loopbackMode
let ifaceSubnets = getSubIfaceIpInfos(interface)

select {
deviceName: device.name,
interfaceName: interface.name,
ipAddress: foreach subnet in ifaceSubnets select ipSubnet(subnet.ip, subnet.prefixLength)
}


 

This query can definitely be re-written to be more user-friendly.

 

foreach device in network.devices
foreach int in device.interfaces
where int.loopbackMode
select {
  name:device.name, 
  int: int.name,
  ipAddress: max(foreach sub in int.subinterfaces select sub.ipv4.addresses)
}

 


Reply