networktocode / ntc-templates

TextFSM templates for parsing show commands of network devices
https://ntc-templates.readthedocs.io/
Other
1.11k stars 729 forks source link

index and filename for cisco_nxos_show_interfaces_switchport are WRONG #1888

Closed i-m-d closed 3 weeks ago

i-m-d commented 3 weeks ago

Hello,

In the index there is this entry:

cisco_nxos_show_interfaces_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[[erfaces]] sw[[itchport]]

this entry does not work for me en any Cisco Nexus (i have several types, N3000, N9000, N9500, N7000).

In Nexus CLI there is NO "show interfaces xxx" only "show interface xxx", note the "s" in interface(s).

If i add this entry to index:

cisco_nxos_show_interface_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[[erface]](?: (?:\S+))? sw[[itchport]]

and do a copy of the file with (s):

cisco_nxos_show_interface_switchport.textfsm

Works perfectly for me.

I hope this is usefull.

mjbear commented 3 weeks ago

@i-m-d

Hello,

In the index there is this entry:

cisco_nxos_show_interfaces_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[[erfaces]] sw[[itchport]]

With TextFSM, the double square brackets list the optional characters.

The command show interface switchport should have been matched. (But yes, I'll validate too.)

I've not tested this against any N9k yet, but I'll try to remember ... if not tomorrow then possibly Friday.

this entry does not work for me en any Cisco Nexus (i have several types, N3000, N9000, N9500, N7000).

In Nexus CLI there is NO "show interfaces xxx" only "show interface xxx", note the "s" in interface(s).

:dart: What NX-OS version or versions are you running against?

If i add this entry to index:

cisco_nxos_show_interface_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[erface]? sw[[itchport]]

and do a copy of the file with (s):

cisco_nxos_show_interface_switchport.textfsm

Works perfectly for me.

I hope this is usefull.

i-m-d commented 3 weeks ago

Hello,

With TextFSM, the double square brackets list the optional characters.

The command show interface switchport should have been matched. (But yes, I'll validate too.)

I need to execute this two commands:

show interface switchport show interface switchport

🎯 What NX-OS version or versions are you running against?

I have several Nexus models and several versions:

N7700 version 8.x N9500 version 10.3.x N9300 versions 9.3.x 10.2.x 10.4.x N3000 versions 7.3.x 9.3.x

mjbear commented 3 weeks ago

I need to execute this two commands:

show interface switchport

This command for all interfaces is supported just fine by the template.

While yes, the command is interface (singular) and not plural, that doesn't negatively affect the function of the template or TextFSM index.

show interface switchport

Generally the templates and parsing is a "biggest return for the investment" so rather than make two really similar templates for related commands, the more detailed one is the one that normally gets created.

The individual interface isn't supported at present, though it is possible to use the same template, but there are issues.

https://github.com/networktocode/ntc-templates/blob/138e9d934d3e537ce2a07992749f9c9e6a3f176f/ntc_templates/templates/index#L381

It's easy enough to add a .* within the index, but should we?

@i-m-d What is your process or use case that the show interface switchport output couldn't be used instead?

If adding support for a specific interface is allowed, I'd also rename files to drop the "s" while I'm at it.

@jmcgill298 @jvanderaa Thoughts before I work up a PR?

🎯 What NX-OS version or versions are you running against?

I have several Nexus models and several versions:

N7700 version 8.x N9500 version 10.3.x N9300 versions 9.3.x 10.2.x 10.4.x N3000 versions 7.3.x 9.3.x

@i-m-d I noticed you didn't provide the information the issue ticket asks for. :thinking: :neutral_face:

show interface eth1/1 switchport

Name: Ethernet1/1
  Switchport: Enabled
  Switchport Monitor: Not enabled 
  Switchport Isolated : Not enabled 
  Switchport Block Multicast: Not enabled 
  Switchport Block Unicast: Not enabled 
  Switchport mac-address static-only: Disabled
  Mac learning: Enabled
  Operational Mode: access
  Access Mode VLAN: 1 (default)
  Trunking Native Mode VLAN: 1 (default)
  Trunking VLANs Allowed: 1-4094
  Voice VLAN: none
  Extended Trust State : not trusted [COS = 0]
  Administrative private-vlan primary host-association: none
  Administrative private-vlan secondary host-association: none
  Administrative private-vlan primary mapping: none
  Administrative private-vlan secondary mapping: none
  Administrative private-vlan trunk native VLAN: none
  Administrative private-vlan trunk encapsulation: dot1q
  Administrative private-vlan trunk normal VLANs: none
  Administrative private-vlan trunk private VLANs: none
  Operational private-vlan: none
  Virtual Ethernet Bridge Forwarding : Disabled
  GTP Inner : Disabled
jmcgill298 commented 3 weeks ago

I'm fine with just adding (\s+.+?)? into the index

mjbear commented 3 weeks ago

I'm fine with just adding (\s+.+?)? into the index

@jmcgill298 Sounds better than what I had. :face_with_peeking_eye:

This seems to break the normal show interface switchport command when I test. cisco_nxos_show_interfaces_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[[erfaces]](\s+.+?)?sw[[itchport]]

Chucking a space before or after the pattern (\s+.+?)? helps fix that. Both show interface switchport and show interface eth1/1 switchport function with the below index entry. cisco_nxos_show_interfaces_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[[erfaces]](\s+.+?)? sw[[itchport]]

That \s+ helps document our intent for a space and other characters before the switchport key word. :grinning:

I'll work up a change that includes renaming to drop the unnecessary "s" from interfaces to align with the other cisco_nexus templates.

mjbear commented 3 weeks ago

Update: :arrow_right: I'm going to suggest dropping the innermost question mark since the entire group of (\s+.+)? is optional. cisco_nxos_show_interface_switchport.textfsm, .*, cisco_nxos, sh[[ow]] int[[erface]](\s+.+)? sw[[itchport]]

mjbear commented 3 weeks ago

Created PR #1889 :rocket: