Trying to use two of the conf objects find_objects_w_child & find_objects_wo_child in a single file.
I need to find out "interfaces" from a Cisco config file which have a specific QoS "service-policy" command configured.
At the same time should not be a part of any Etherchannel.
- Using object "find_objects_w_child" I can get all 'interface' objects having the command "service-policy" configured on it, and
- Using object "find_objects_wo_child" to get all the 'interface' objects which do not have the command "channel-group".
Is it even possible to use these 2 objects on a same config file?
CiscoConfParse objects do not offer a method that allows you to find objects with specific children, but without other specific children. However, we can utilize a list comprehension to accomplish the same task with the IOSCfgLine object's
re_search_children()method, as shown below:Because regex objects are truthy, the above list comprehension will only return IOSCfgLine objects representing interfaces that do not have
channel-groupconfigured, but does haveservice-policyconfigured.