Join me on an introduction to working with Lists in NQE. We cover some of the basic list comparisons and the list function length().
Code examples used in video
Return all Arista devices, and if the device is not running the approved OS, return a violation for that device
approved_os = ["4.15.0F"];
foreach device in network.devices
where device.platform.os == OS.ARISTA_EOS
select {
violation: device.platform.osVersion not in approved_os,
name: device.name,
version: device.platform.osVersion
}
There is another way to write this query. We can write it so that it will only return all devices that are violating versus returning every device and violating the devices that are not compliant. This query would look like:
approved_os = "4.15.0F"]
foreach device in network.devices
where device.platform.os == OS.ARISTA_EOS
where device.platform.osVersion not in approved_os
select {
violation: true
name: device.name,
version: device.platform.osVersion}
We are using where only to filter devices that are running a non-approved OS. Violation is set to true because the only devices that will ever appear from this NQE query are those in violation.
An example using length is if you wanted to quickly do a search and return all the devices that are chassis-based and the number of components installed in them:
foreach device in network.devices
let platform = device.platform
foreach component in platform.components
where component.partType == DevicePartType.CHASSIS
select {
deviceName: device.name,
vendor: platform.vendor,
model: platform.model,
os: platform.os,
osVersion: platform.osVersion,
components: length(platform.components),
managementIps: platform.managementIps
}
What have you done with lists in your environment? Can you think of another way to write this? Share your queries down below .