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

recursive application of field pattern for list type values #11

Closed
sjtarik opened this issue Jan 19, 2017 · 4 comments
Closed

recursive application of field pattern for list type values #11

sjtarik opened this issue Jan 19, 2017 · 4 comments

Comments

@sjtarik
Copy link

sjtarik commented Jan 19, 2017

There are cases where a field of List type should capture space/comma separated words in a single line. Currently in these cases last value replaces the previous values and only one item ends up in the list. Is it fairly easy to implement that feature or major refactoring required? Creating the issue for collecting input before start working on it. Thanks. Attaching the following example, Member Ports should be a Value field in List type.

@sjtarik
Copy link
Author

sjtarik commented Jan 19, 2017

> host# show port-channel summary 
> Flags:  D - Down        P - Up in port-channel (members)
>         I - Individual  H - Hot-standby (LACP only)
>         s - Suspended   r - Module-removed
>         S - Switched    R - Routed
>         U - Up (port-channel)
>         M - Not in use. Min-links not met
> --------------------------------------------------------------------------------
> Group Port-       Type     Protocol  Member Ports
>       Channel
> --------------------------------------------------------------------------------
> 1     Po1(SD)     Eth      NONE      Eth1/7(D)    Eth1/8(D)    Eth1/9(D)
>                                      Eth1/10(D)   Eth1/11(D)   Eth1/12(D)
>                                      Eth1/13(D)   Eth1/14(D)   Eth1/15(D)
>                                      Eth1/16(D)   Eth1/17(D)   
> 

@buxtronix
Copy link
Collaborator

Whilst not exactly elegant, the following use of 'Continue' will capture the port names:

Value List Ports (\S+)

StateName
  ^\s+${Ports} -> Continue
  ^\s+\S+\s+${Ports} -> Continue
  ^\s+\S+\s+\S+\s+${Ports}

Variants on this can be used to capture the first line in each port channel group.

@bewing
Copy link

bewing commented Jan 19, 2017

I used something similar to capture interfaces in a VRF:

veos1#show vrf
Maximum number of vrfs allowed: 14
 Vrf     RD           Protocols    State                    Interfaces
------- ------------ ------------ ------------------------- -------------------
 MGMT    0:0          ipv4,ipv6    v4:routing,              Vlan2, Vlan3, Vlan4
                                   v6:no routing

 NON     <not set>                 v4:incomplete,
                                   v6:incomplete

 TEST    0:1          ipv4,ipv6    v4:routing; multicast,   Vlan100, Vlan101,
                                   v6:no routing            Vlan102, Vlan103,
                                                            Vlan104
 TEST2   1234:4321    ipv4,ipv6    v4:no routing,
                                   v6:routing


Value Required Name (\S+)
Value Route_Distinguisher (\d+:\d+|<not set>)
Value List Interfaces (\S.+)


Start
  ^\s\S+\s+(\d|<) -> Continue.Record
  ^\s+${Name}\s+${Route_Distinguisher}\s+(ipv4,ipv6\s+)?v4:(incomplete|(no )?routing(; multicast)?),\s+$Interfaces
  ^\s+${Name}\s+${Route_Distinguisher}\s+(ipv4,ipv6\s+)?v4:(incomplete|(no )?routing(; multicast)?),
  ^\s+v6:(incomplete|(no )?routing)\s+$Interfaces
  ^\s+v6:(incomplete|(no )?routing) -> Record
  ^\s+$Interfaces
{u'MGMT': {u'interfaces': {u'interface': {u'Vlan2': {},
                                          u'Vlan3': {},
                                          u'Vlan4': {}}},
           u'name': u'MGMT',
           u'state': {u'route_distinguisher': u'0:0'},
           u'type': u'L3VRF'},
 u'NON': {u'interfaces': {u'interface': {}},
          u'name': u'NON',
          u'state': {u'route_distinguisher': u''},
          u'type': u'L3VRF'},
 u'TEST': {u'interfaces': {u'interface': {u'Vlan100': {},
                                          u'Vlan101': {},
                                          u'Vlan102': {},
                                          u'Vlan103': {},
                                          u'Vlan104': {}}},
           u'name': u'TEST',
           u'state': {u'route_distinguisher': u'0:1'},
           u'type': u'L3VRF'},
 u'TEST2': {u'interfaces': {u'interface': {}},
            u'name': u'TEST2',
            u'state': {u'route_distinguisher': u'1234:4321'},
            u'type': u'L3VRF'},
 u'default': {u'interfaces': {u'interface': {u'Ethernet1': {},
                                             u'Management1': {}}},
              u'name': u'default',
              u'state': {u'route_distinguisher': u''},
              u'type': u'DEFAULT_INSTANCE'}}

note: I stripped the commas off in Python

@harro
Copy link
Contributor

harro commented May 9, 2017

This final example makes a good point. By over matching on the 'Interfaces' Value, the whole row is captured by each entry. It is then possible to post-process the entries to split the rows into individual elements.

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

4 participants