1

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?

nitinr708
  • 1,393
  • 2
  • 19
  • 29
arbaz
  • 27
  • 7

1 Answers1

2

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:

from ciscoconfparse import CiscoConfParse

parse = CiscoConfParse("ios_cfg.txt")
phys_intfs_w_qos = [obj for obj in parse.find_objects_wo_child(r"^interface", "channel-group") if obj.re_search_children(r"service-policy")]

Because regex objects are truthy, the above list comprehension will only return IOSCfgLine objects representing interfaces that do not have channel-group configured, but does have service-policy configured.