cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
445
Views
2
Helpful
5
Replies

Cisco DNAC and regexp

michal-mihaly
Level 1
Level 1

Hello, I was wondering if there is some manual for Cisco DNAC (using Jinja) and regexp expressions usage. Let me explain: I've DNAC onboarding scripts which provides initial configurations for catalyst 9300L and 9300UXG switches. I want the macro to only run (ergo exclude uplink ports) on user-ports

As we might have stack switches, the combinations are like this:

    • GigabitEthernetX/0/X (user port)
    • TenGigabitEthernetX/0/X (user port)
    • TenGigabitEthernetX/1/X (uplink port)

I've tried myriads of combinations which works elsewhere, but not in DNAC. 

GigabitEthernet[1|2]/1/

GigabitEthernet[1|2]\/1\/

GigabitEthernet\d+/1/\d+

The macro condition is defined like this:

{% for intf in __interface %}

{% if intf.interfaceType.contains('Physical') and not intf.portName.contains('App') and not intf.portName.contains('GigabitEthernet0') and not intf.portName.contains("TenGigabitEthernet[1|2]\/1\/") and not intf.portName.contains("GigabitEthernet([1|2])/1")%}

interface {{intf.portName}}

....

 

Thank you for any suggestions

 

1 Accepted Solution

Accepted Solutions

Preston Chilcote
Cisco Employee
Cisco Employee

I think you need to be using the .matches method instead of contains when doing more than just a basic string comparison.

View solution in original post

5 Replies 5

Preston Chilcote
Cisco Employee
Cisco Employee

This isn't well documented, but you cant use system variables in onboarding templates because system variables read info from Inventory stored during the last sync.  A PnP device has yet to be onboarded, so this information is unavailable.  This is one reason why we recommend simplifying your onboarding template as much as possible and use Day-N templates for the full production config.  Your regex's should work in a Day-N template.

For more advice on best practices of Onboarding Templates

https://community.cisco.com/t5/networking-knowledge-base/updating-management-ip-address-of-a-switch-during-the-pnp/ta-p/4820793 

Thank you Preston,

I might have been wrong in the statement that we're onboarding the devices. The onboard process is already completed for them and I am using Day-N template to configure access ports via calling a macro. The problem I am having is that it's far from dummy proof script and I want it to only do this for user ports. Ergo every other port except 10G uplink (Tex/1/x) ports on the 9300L switches. The macro loop is running through __interface attaching example

Preston Chilcote
Cisco Employee
Cisco Employee

I think you need to be using the .matches method instead of contains when doing more than just a basic string comparison.

Thank you Preston, that was it I am still learning my ways around DNAC. I wonder if there is some documentation on the methods which are supported in DNAC. I eventually ended up with this - which meets what I need for the function

{% macro generate_ua_interface(functional_type,datavl='1',voicevl,includedotx='1') %}
{% for intf in __interface %}
{% if intf.portName.matches("GigabitEthernet[1|2|3|4|5]/0.*") or intf.portName.matches("TenGigabitEthernet[1|2|3|4|5]/0.*")%}
interface {{intf.portName}}
description User data/phone port
switchport mode access
switchport nonegotiate
switchport access vlan {{datavl}}
{% if functional_type == "UA" %}
switchport voice vlan {{voicevl}}
{% endif -%}
no shutdown
logging event link-status
load-interval 60
speed auto
duplex auto
spanning-tree portfast
snmp trap link-status
service-policy input pm_marking_notrust
service-policy output pm_queueing
{% if includedotx=='1' and functional_type == "UA"%}
authentication control-direction in
authentication event fail action next-method
authentication event server dead action reinitialize vlan {{datavl}}
authentication event server dead action authorize voice
authentication event server alive action reinitialize
authentication host-mode multi-auth
authentication open
authentication order mab dot1x
authentication priority dot1x mab
authentication port-control auto
authentication periodic
authentication timer reauthenticate server
mab
dot1x pae authenticator
dot1x timeout tx-period 10
{% endif %}
no shutdown
!
{% endif -%}
{% endfor %}
{% endmacro %}

Preston Chilcote
Cisco Employee
Cisco Employee

Cisco devnet has some github repositories you should look through.  The best one may be: 

https://developer.cisco.com/codeexchange/github/repo/kebaldwi/DNAC-TEMPLATES/

Review Cisco Networking for a $25 gift card