tdorssers / confparser

Parse Cisco-like configuration files into a JSON-formattable structure using YAML-defined dissectors
MIT License
34 stars 13 forks source link

Unexpected value when parsing config #5

Closed mesmeridze closed 1 year ago

mesmeridze commented 2 years ago

I am trying to pare Arista EOS config, which is mostly Cisco like, however getting unexpected results:

!/usr/bin/python3

import sys import confparser

doc = '''

What I see is this: { "interface": { "Port-Channel1": { "load-interval": "30", "switchport": { "trunk": {}, "mode": {} }, "mlag": "1" }, "Port-Channel2": { "load-interval": "30", "switchport": { "trunk": {}, "mode": {} }, "mlag": "2" }, "Port-Channel3": { "load-interval": "30", "switchport": { "trunk": {}, "mode": {} }, "mlag": "3" } } } However I would expect that trunk block should became a key, "native" subkey and "vlan 100" as a value { "interface": { "Port-Channel1": { "load-interval": "30", "switchport": { "trunk": { "native": "vlan 100" }, "mode": "trunk" }, "mlag": "1" }, Sorry I am exhausted with ideas, maybe tried all what is possible ))

tdorssers commented 2 years ago

You can take a look at ios.yaml, which parses most of your Arista config.

- match: interface (\S+)
  parent: interface
  child:
  - match: switchport trunk allowed vlan (?!add)(\S+)
    name: allowed_vlan
    action: expand
  - match: switchport trunk allowed vlan add (\S+)
    name: allowed_vlan
    action: expand

will output:

{
    "interface": {
        "GigabitEthernet1/1/1": {
            "allowed_vlan": [
                "10",
                "11",
                "12",
                "15"
            ]
        }
    }
}