Closed rishikeshr closed 9 years ago
Thank you for asking. This is not a bug, in fact it is covered both in the API documentation and the FAQ.
If you only need to match against "interface VlanAlpha1" and its children, call find_all_children(r"interface VlanAlpha1", exactmatch=True)
Hello Mike,
Appreciate your prompt response on the issue I am facing. I tried exact match as well, but I dont see all the child nodes being listed.
allChildren = parseObject.find_all_children('interface VlanAlpha1',exactmatch=True)
print allChildren
['interface VlanAlpha1', 'interface VlanAlpha1', ' vrf member alpha011']
CiscoConfParse requires exclaimation points (!
) instead of blank lines... this script seems to work correctly...
(py27_test)[mpenning@tsunami ~]$ cat github_8.py
from ciscoconfparse import CiscoConfParse
config = """interface VlanAlpha3
!
interface VlanAlpha2
!
interface VlanAlpha1
!
interface VlanAlpha
vrf member alpha01
some config1
ip address 100.100.102.0/24
some config2
blah blah blah
!
interface VlanAlpha32
!
interface VlanAlpha22
!
interface VlanAlpha12
!
interface VlanAlpha2
vrf member alpha012
some config1
ip address 100.100.101.0/24
some config2
blah blah blah
!
interface VlanAlpha31
!
interface VlanAlpha21
!
interface VlanAlpha11
!
interface VlanAlpha1
vrf member alpha011
no shutdown
ip flow monitor netflow-monitor input
no ip redirects
ip address 100.100.100.0/24
ip ospf passive-interface
ip router ospf 1 area 0.0.0.3
ip pim sparse-mode
hsrp version 2
hsrp 224
"""
parse = CiscoConfParse(config.split('\n'))
allChildren = parse.find_all_children('interface VlanAlpha1',exactmatch=True)
print allChildren
When I run that...
(py27_test)[mpenning@tsunami ~]$ python github_8.py
['interface VlanAlpha1', 'interface VlanAlpha1', ' vrf member alpha011', ' no shutdown',
' ip flow monitor netflow-monitor input ', ' no ip redirects', ' ip address 100.100.100.0/24',
' ip ospf passive-interface', ' ip router ospf 1 area 0.0.0.3', ' ip pim sparse-mode',
' hsrp version 2', ' hsrp 224']
(py27_test)[mpenning@tsunami ~]$
(py27_test)[mpenning@tsunami ~]$
Yes, that seems to work!! ! seems to be the key.
Thanks, will use that!! Again, appreciate your prompt response for the issue!!
Hi, I am parsing a config file and I can see that the results are varying and not consistent.
To begin with, my test config file is
With the following code, I get an output, which seems incorrect.
Shouldnt this list all the child nodes of Interface VlanAlpha1 I am using Python v 2.7.5 and CiscoConfParse v 1.1.1