Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected value when parsing config #5

Closed
mesmeridze opened this issue Sep 11, 2022 · 1 comment
Closed

Unexpected value when parsing config #5

mesmeridze opened this issue Sep 11, 2022 · 1 comment

Comments

@mesmeridze
Copy link

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 = '''

  • match: interface (\S+)
    parent: interface
    child:
    • match: load-interval (\S+)
      name: load-interval
    • match: switchport (\S+)
      parent: switchport
      child:
      • match: trunk (\S+)
        parent: trunk
        child:
        • match: native (\S+)
    • match: mlag (\S+)
      name: mlag
      '''
      cfg = '''
      interface Port-Channel1
      load-interval 30
      switchport trunk native vlan 100
      switchport trunk allowed vlan 100,200,300-303,400,500
      switchport mode trunk
      mlag 1
      spanning-tree portfast
      !
      interface Port-Channel2
      description et-50/1 Core-1-port-0
      load-interval 30
      switchport trunk native vlan 100
      switchport trunk allowed vlan 100,200,300-303,400,500
      switchport mode trunk
      mlag 2
      spanning-tree portfast
      !
      interface Port-Channel3
      description et-0/0/52-to-Core-2-port-0
      load-interval 30
      switchport trunk native vlan 100
      switchport trunk allowed vlan 100,200,300-303,400,500
      switchport mode trunk
      mlag 3
      spanning-tree portfast
      !
      '''
      print(confparser.Dissector(doc).parse_str(cfg, indent=3))

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
Copy link
Owner

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"
            ]
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants