Make Junos-style configs searchable #17

Closed
mpenning opened this Issue Jan 26, 2015 · 2 comments

Projects

None yet

1 participant

@mpenning
Owner

Some people want ciscoconfparse to search Junos configurations... this bug tracks implementation of the feature request.

@mpenning mpenning self-assigned this Jan 26, 2015
@mpenning
Owner

We now parse Junos configurations into Cisco IOS-style (I already hear the distant cries of "heretic")... nevertheless, if you want to see it in action, here's how I parse configs/sample_01.junos:

>>> from ciscoconfparse import CiscoConfParse
>>> parse = CiscoConfParse('configs/sample_01.junos', syntax='junos', comment='#!')
>>> for line in parse.ioscfg:
...     print line
... 
!# Last commit: 2015-06-28 13:00:59 CST by mpenning
system 
    host-name TEST01_EX
    domain-name pennington.net
    domain-search [ pennington.net lab.pennington.net ]
    location 
        country-code 001
        building HQ_005
        floor 1
    root-authentication 
        encrypted-password "$1$y7ArHxKU$zUbdeLfBirgkCsKiOJ5Qa0"
    name-server 
        172.16.3.222
    login 
        announcement "Test Lab Switch"
            class super-user
            authentication 
                encrypted-password "$1$y7ArHxKU$zUbdeLfBirgkCsKiOJ5Qa0"
    services 
        ssh 
            root-login allow
        telnet
        web-management 
            http
    syslog 
        user * 
            any emergency
        file messages 
            any notice
            authorization info
        file interactive-commands 
            interactive-commands any
    ntp 
        boot-server time.apple.com
        server 172.16.8.3
vlans 
    Management 
        vlan-id 1
        interface 
            ge-0/0/0.0
            ge-0/0/1.0
            ge-0/0/2.0
            ge-0/0/3.0
    VLAN_FOO 
        vlan-id 5
    vlan1 
        vlan-id 1
        l3-interface vlan.1
    vlan800 
        vlan-id 800
ethernet-switching-options 
    storm-control 
        interface all
interfaces 
    ge-0/0/0 
        unit 0 
            family ethernet-switching 
                port-mode access
                vlan 
                    members VLAN_FOO
    ge-0/0/1 
        unit 0 
            family ethernet-switching 
                port-mode trunk
                vlan 
                    members all
                native-vlan-id 1
    vlan 
        unit 0 
            family inet 
                address 172.16.15.5/22
routing-options 
    static 
        route 0.0.0.0/0 next-hop 172.16.12.1
        route 192.168.36.0/25 next-hop 172.16.12.1

This is a hack, to be sure... so I'm leaving the enhancement open until I get a few more details nailed down... in the mean time, if people want to experiment with searching Junos as IOS, it is here :-)

@mpenning mpenning added a commit that referenced this issue Jan 26, 2015
@mpenning Parse Junos-style as Cisco IOS, as outlined in github issue #17
--HG--
branch : ciscoconfparse
dd3f57a
@mpenning
Owner

Note: Juniper configurations are quite hierarchical... finding an IOS interface object in python just requires parse.find_objects('^interface\sGigabitEthernet0/0/1').

To get the interface object for a Junos interface such as ge-0/0/1, you'd need to use something like parse.find_objects_w_parents(r'^\s*interface', r'^\s+ge-0/0/1'), which returns the object for ge-0/0/1 in a list. Then you can iterate through for children of ge-0/0/1 as you like.

However, if you don't require the interface object itself, you can still enforce Junos interface configuration policies in python via parse.find_objects_w_child(r'^\s+ge-0/0/1', r'port-mode\saccess'); that policy checks whether ge-0/0/1 is port-mode access.

@mpenning mpenning closed this Jun 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment