Newbie trying to improve on cisco_s300_show_lldp_neighbors.textfsm - Multiline Variable
Closed this issue · 1 comments
ntaken commented
ISSUE TYPE
- Feature Idea
TEMPLATE USING
Value List NEIGHBOR (\S+)
Value LOCAL_INTERFACE (\S+)
Value List NEIGHBOR_INTERFACE (\S+)
Value DEVICE_ID (([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))
Start
^System\s+capability\s+legend
^\S+\s*-
^\s*Port\s+Device\s+ID\s+Port\s+ID\s+System\s+Name\s+Capabilities\s+TTL -> Begin
^\s*$$
^. -> Error
Begin
^-+
^\S+ -> Continue.Record
^${LOCAL_INTERFACE}\s+${DEVICE_ID}\s+${NEIGHBOR_INTERFACE}\s+${NEIGHBOR}
^\s{28}${NEIGHBOR_INTERFACE}
^\s{42}${NEIGHBOR}
^\s*$$
^. -> Error
SAMPLE COMMAND OUTPUT
System capability legend:
B - Bridge; R - Router; W - Wlan Access Point; T - telephone;
D - DOCSIS Cable Device; H - Host; r - Repeater;
TP - Two Ports MAC Relay; S - S-VLAN; C - C-VLAN; O - Other
Port Device ID Port ID System Name Capabilities TTL
--------- ----------------- ------------- ----------------- ------------ -----
gi10 f8:b1:56:ac:07:64 f8:b1:56:ac:0 O 3482
7:64
gi21 28:6f:7f:0b:75:a0 Gi0 Fjallarodgardsfor B 105
skola-AP03.net.no
rob.se
gi22 a0:e0:af:ec:e9:d0 Gi0 Fjallarodgardsfor B 118
skola-AP01.net.no
rob.se
gi23 a0:e0:af:b1:c8:a0 Gi0 Fjallarodgardsfor B 105
skola-AP04.net.no
rob.se
gi24 a0:e0:af:22:3d:40 Gi0 Fjallarodgardsfor B 114
skola-AP02.net.no
rob.se
SUMMARY
My current modification collect all relevant information but requries som further scripting to display it correcly (Add the lists variables together).
Is there a better way to collect a multiline variable or is this a limitation of TEXTFSM?
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
[
{'neighbor': ['O'],
'local_interface': 'gi10',
'neighbor_interface': ['f8:b1:56:ac:0', '7:64'],
'device_id': 'f8:b1:56:ac:07:64'},
{'neighbor': ['Fjallarodgardsfor', 'skola-AP03.net.no', 'rob.se'],
'local_interface': 'gi21',
'neighbor_interface': ['Gi0'],
'device_id': '28:6f:7f:0b:75:a0'},
{'neighbor': ['Fjallarodgardsfor', 'skola-AP01.net.no', 'rob.se'],
'local_interface': 'gi22',
'neighbor_interface': ['Gi0'],
'device_id': 'a0:e0:af:ec:e9:d0'},
{'neighbor': ['Fjallarodgardsfor', 'skola-AP04.net.no', 'rob.se'],
'local_interface': 'gi23',
'neighbor_interface': ['Gi0'],
'device_id': 'a0:e0:af:b1:c8:a0'},
{'neighbor': ['Fjallarodgardsfor', 'skola-AP02.net.no', 'rob.se'],
'local_interface': 'gi24',
'neighbor_interface': ['Gi0'],
'device_id': 'a0:e0:af:22:3d:40'}]
diepes commented
@ntaken it looks good.
Yes it is a TEXTFSM limitation i'm not aware of a cleaner way to capture multiline wrapped text in tables. Would be great if there was a new values listappend (xyz)
type. For now you need to post-process join the list into string.
Next step: OptionA i can try to add the fix+pr or OptionB someone here can give it a go when they have time.
- checkout (clone) the git networktocode master branch, and create new branch fixes#1052-cisco_s300_show_lldp_neighbors
- Add the cisco output as new raw test file
tests/cisco_s300/show_lldp_neighbors/cisco_s300_show_lldp_neighbors2.raw
- update the existing TEXTFSM template to work for existing and new test
ntc_templates/templates/cisco_s300_show_lldp_neighbors.textfsm
- Test with
- tox
- single template with
b=tests/cisco_s300/show_lldp_neighbors/cisco_s300_show_lldp_neighbors2 ;python3 development_scripts.py -c ${fb}.raw && cat ${fb}.yml
- Test with
- commit (squash to single commit)
- create PR for review