[Python] Python CiscoConfParse. How to get full block by command in middle?

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    I need to get full config of block by some command in middle. In the following example, I got an incomplete block where more indented children 'ip 10.2.2.1' were missing.

    from ciscoconfparse import CiscoConfParse
    from pprint import pprint

    config = """
    hostname switch
    interface Vlan2
    description vlan2
    ip address 10.2.2.3/24
    hsrp 2
    ip 10.2.2.1
    interface Vlan3
    description vlan3
    ip address 10.3.3.3/24
    hsrp 3
    ip 10.3.3.1
    """.splitlines()
    ccp = CiscoConfParse(config=config)
    blocks = ccp.find_blocks("10.2.2.3/24")
    print(blocks) # ['interface Vlan2', ' description vlan2', ' ip address 10.2.2.3/24', ' hsrp 2']


    Help me to find elegant way to get next output (with 'ip 10.2.2.1')

    ['interface Vlan2', ' description vlan2', ' ip address 10.2.2.3/24', ' hsrp 2', 'ip 10.2.2.1']

    Continue reading...

Compartilhe esta Página