Skip to main content

For a user defined function as follows, can it be used to return a number or does it only return a Bool value?

 

threshold : Number = 100;
hasManySubInterfaces(iface) : Bool = length(iface.subinterfaces) > threshold;

 

Say something like the following, is that possible?

 

threshold : Number = 100;
hasManySubInterfaces(iface) : Number= length(iface.subinterfaces) + threshold;

Hi @pjptsujit ,

Yes, functions can return any type of data.

Your example function should work. For example, you can use it in a query like this:

threshold : Number = 100;

hasManySubInterfaces(iface) : Number = length(iface.subinterfaces) + threshold;

foreach d in network.devices
foreach i in d.interfaces
select { myNumber: hasManySubInterfaces(i) }

 


You also don’t necessarily need to specify the return type. 

 

threshold : Number = 1;

greaterThanThreshold(iface) = length(iface.subinterfaces) > threshold;
plusThreshold(iface) = length(iface.subinterfaces) + threshold;

foreach device in network.devices
foreach interface in device.interfaces
select {
length: length(interface.subinterfaces),
greaterThan: greaterThanThreshold(interface),
plusThreshold: plusThreshold(interface)
}

 


Reply