0% found this document useful (0 votes)
90 views17 pages

Templates Presentation

dnacenter

Uploaded by

lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views17 pages

Templates Presentation

dnacenter

Uploaded by

lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Catalyst Center:

Helpful Templates
Showcasing the value of Templates
with Real World Examples
Today’s
discussion
1 Why Real World Examples?

2 Template Examples

3 Resources

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
Cisco Confidential
Why these real world examples?
• Real World examples that prove the value of Catalyst Center
• No other competitor (that I know of) uses programmatic principles and applies them to CLI
• Direct correlation to day-to-day tasks of Network Engineering teams
• Same things need to be configured on devices regardless of industry
• Credentials, other basic configs, VLANs, SVIs and ports, AAA, ACLs, QoS, etc…
• Programmatic template of a few lines can translate to CLI consisting of thousands of lines

• Empower customers to dive deeper into templates


• If they don’t have time, they’ll have real-world examples applicable to their networks

• Incentive as well as means to standardize configs, while accounting for current lack of
standardization
• Reduces the possibility of human error when doing configs
• Simple templates that are easy to implement in either VTL or Jinja
• Most complicated template uses if/then/else statement
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Cisco Confidential
Basic Variables – Example 1
• Talking Point
• Basic substitution of a variable in a cli
• Useful for values that will change depending on device, i.e. IP address, port number, etc….

• Example: basic SVI and Interface Config


• interface Vlan400
• description Guests
• ip address $Guest_VLAN_IP 255.255.255.0
• ip helper-address 192.168.10.1
• ip helper-address 192.168.10.2

• int gig1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• switchport voice vlan 20
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
Cisco Confidential
Trigger Templates - Example 1
• Talking Point
• Run specific segments of code in a template or a specific template in a composite template
• Provides very granular control over what config is pushed to a device
• Useful in both Day-0 and Day-N templates

• Example: Yes/No trigger template with/without dropdown


• #set($VLAN_TEMPLATE_RESPONSE = $RUN_VLAN_TEMPLATE)
• #if($VLAN_TEMPLATE_RESPONSE == "Yes")
• vlan 100
• name Management
• vlan 200
• name Staff
• #else
• #end

• #set($INTERFACE_TEMPLATE_RESPONSE = $RUN_INTERFACE_TEMPLATE)
• #if($INTERFACE_TEMPLATE_RESPONSE == "Yes")
• interface Vlan100
• ip address $User_VLAN_IP 255.255.255.0
• interface Vlan200
• ip address $Staff_VLAN_IP 255.255.255.0
• #else
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
Cisco Confidential
Basic For Each Loops- Example 1
• Talking Point
• Useful for configuring a standardized range of ports

• Example: Pushing configs for access ports


• #foreach($access_port in [${first-access-port}..${end-access-port}])
• int gig1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end

• Example: Pushing configs for access ports with multiple interface types
• #foreach($access_port in [${first-access-port}..${end-access-port}])
• int ${interface_type}1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
Cisco Confidential
Multiple For Each Loops- Example 1
• Talking Point
• Useful for interfaces that need two different sets of configs, i.e. trunk ports, access ports, uplink ports, etc…

• Example: Pushing configs for trunk and access ports


• #foreach($trunk_port in [${first-trunk-port}..${end-trunk-port}])
• int ${trunk_interface_type}1/0/$trunk_port
• description Uplink port
• switchport mode trunk
• switchport trunk allowed vlan 20,100,200,300,400
• #end

• #foreach($access_port in [${first-access-port}..${end-access-port}])
• int ${interface_type}1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
Cisco Confidential
Multiple For Each Loops- Example 2
• Talking Point
• Useful for customers with switch stacks

• Example: Pushing configs for trunk and access ports w/ variable for stacks
• #foreach($trunk_port in [${first-trunk-port}..${end-trunk-port}])
• #foreach($stack_number in [${first-stack-number}..${end-stack-number}])
• int ${trunk_interface_type}${stack_number}/0/$trunk_port
• description Uplink port
• switchport mode trunk
• switchport trunk allowed vlan 20,100,200,300,400
• #end
• #end

• #foreach($access_port in [${first-access-port}..${end-access-port}])
• #foreach($stack_number in [${first-stack-number}..${end-stack-number}])
• int ${access_interface_type}${stack_number}/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end
• #end
© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
Cisco Confidential
Bind to Source - Example 1
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…

• Example: Use Bind to Source to choose trunk/uplink ports


• #foreach($trunk_port in ${trunk_port})
• int $trunk_port
• description Uplink port
• switchport mode trunk
• switchport trunk allowed vlan 20,100,200,300,400
• #end

• #foreach($access_port in [${first-access-port}..${end-access-port}])
• int ${interface_type}1/0/$access_port
• description Staff user port
• switchport access vlan 200
• switchport mode access
• switchport voice vlan 20
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root
• #end

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
Cisco Confidential
Implict Variables - Example 1
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…
• Can apply widespread change across range of devices regardless of model, i.e. make change to all access
and trunk ports
• Careful attention must be paid to logic to make exclusions, i.e. GigabitEhternet0 is considered a physical port

• Example: Use implicit variables to apply changes to all trunk and access ports
• #foreach ($interface in ${__interface})
• #if ($interface.portName.contains(“Bluetooth") || $interface.portName.contains("App") || $interface.portName.contains("GigabitEthernet0"))
• #elseif ($interface.interfaceType == "Physical" && $interface.portMode == "access")
• interface $interface.portName
• switchport access vlan 10
• switchport mode access
• switchport voice vlan 20
• spanning-tree portfast
• spanning-tree bpduguard enable
• spanning-tree guard root

• #elseif ($interface.portMode == "trunk")


• interface $interface.portName
• description Trunk Portswitchport mode trunk
• switchport trunk allowed vlan add 1500
• #else
© #end
• 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
• #end Cisco Confidential
Implict Variables - Example 2
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…
• Can apply config based on properties of the device itself, i.e. Platform ID

• Example: Use implicit variables to config based on device model


• #set($MODEL = $__device.platformId)
• #if($MODEL.contains("9300"))
• Interface GigabitEthernet1/0/2
• description 9300-L3 PORT
• no switchport
• ip address $LAN_A_IP 255.255.255.0
• no shut

• #elseif($MODEL.contains("3850"))
• interface GigabitEthernet1/0/1
• description 3850-L2 LAN PORT
• switchport mode access
• spanning-tree portfast
• no shut
• #else
• #end

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
Cisco Confidential
Implict Variables - Example 3
• Talking Point
• Apply cli based on properties of device that DNA Center has ingested into database, i.e. interface name, host
name, etc…
• Can apply config based on properties of the device itself, i.e. Platform ID

• Example: Use implicit variables to config based on number of switches in stack


• #set( $StackPIDs = $__device.platformId.split(",") )
• #set( $stack_member_count = $StackPIDs.size() )

• #foreach($switch in [1..${stack_member_count}])
• interface TenGigabitEthernet${switch}/0/1 (Can also substitute ${interface_type} instead of TenGigabitEthernet)
• description Uplink port
• switchport mode trunk
• switchport trunk allowed vlan 20,100,200,300,400

• #end

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
Cisco Confidential
Implict Variable Values - Interfaces
• Talking Point
• Template that shows the implicit variable values for interfaces that logic can be run on

• Example: Use implicit variables to config based on number of switches in stack


• {# Set the implicit variable you are interested in seeing the data for. i.e. __dnsserver or __device #}
• {% set implicit_variable = __interface %}
• {% if implicit_variable is sequence and implicit_variable[0] is not mapping %}
• {{ implicit_variable }}
• {% elif implicit_variable is mapping %}
• {% for key,value in implicit_variable.items() %}
• {{key}}: {{value}}
• {% endfor %}
• {% else %}
• {% for item in implicit_variable %}
• ---------------
• {% for key,value in item.items() %}
• {{key}}: {{value}}
• {% endfor %}
• {% endfor %}
• {% endif %}

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
Cisco Confidential
Implict Variable Values - Interfaces
• pid: C9300-48P
• vlanId: 1
• ifIndex: 70
• adminStatus: UP
• mtu: 9100
• speed: 40000000
• macAddress: 6c:71:0d:22:20:be
• status: down
• portName: FortyGigabitEthernet1/1/2
• series: Cisco Catalyst 9300 Series Switches
• deviceId: f23e88dd-9e02-4d22-97c3-a54d52f49848
• networkdevice_id: 508506000
• ospfSupport: false
• portMode: dynamic_auto
• portType: Ethernet Port
• poweroverethernet: 0
• serialNo: FJC2341E0H6
• duplex: AutoNegotiate
• interfaceType: Physical
• isisSupport: false
• description: Uplink Port

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
Cisco Confidential
Implict Variable Values - Devices
• Talking Point
• Template that shows the implicit variable values for devices that logic can be run on

• Example: Use implicit variables to config based on number of switches in stack


• {# Set the implicit variable you are interested in seeing the data for. i.e. __dnsserver or __device #}

• {% set implicit_variable = __device %}
• {% if implicit_variable is sequence and implicit_variable[0] is not mapping %}
• {{ implicit_variable }}
• {% elif implicit_variable is mapping %}
• {% for key,value in implicit_variable.items() %}
• {{key}}: {{value}}
• {% endfor %}
• {% else %}
• {% for item in implicit_variable %}
• ---------------
• {% for key,value in item.items() %}
• {{key}}: {{value}}
• {% endfor %}
• {% endfor %}
• {% endif %}

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
Cisco Confidential
Implict Variable Values - Devices
• apEthernetMacAddress:
• apManagerInterfaceIp:
• associatedWlcIp:
• description: Cisco IOS Software [Bengaluru], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.6.5, RELEASE SOFTWARE (fc2) Technical
Support: http://www.cisco.com/techsupport Copyright (c) 1986-2023 by Cisco Systems, Inc. Compiled Wed 25-Jan-23 16:15 by mcpre
netconf enabled
• deviceSupportLevel: Supported
• family: Switches and Hubs
• hostname: FIAB.pod5css.cisco.com
• lineCardCount: 0
• macAddress: 6c:71:0d:22:20:80
• managementIpAddress: 172.16.6.97
• managementState: Managed
• platformId: C9300-48P
• reachabilityStatus: Reachable
• role: ACCESS
• roleSource: MANUAL
• serialNumber: FJC2341E0H6
• series: Cisco Catalyst 9300 Series Switches
• softwareType: IOS-XE
• softwareVersion: 17.6.5
• type: Cisco Catalyst 9300 Switch
• upTime: 244 days, 5:09:44.48

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
Cisco Confidential
Resources
• Keith Baldwin’s Github Repository – https://github.com/kebaldwi?tab=repositories

• Keith Baldwin's Cisco Repository on Catalyst Center Templates -


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

• Adam Radford's Blog - https://blogs.cisco.com/author/adamradford

• Examples of Velocity Templates - Arrays, For-Each-Loops, For-Each-Indexes, Macros, If/Else statements, Functions, Math -
https://thisbridgeistheroot.com/blog/dna-center-advanced-scripting

• Velocity Language Primer


• https://velocity.apache.org/engine/1.6.2/user-guide.html#relationalandlogicaloperators
• https://velocity.apache.org/engine/1.7/user-guide.html
• https://explore.cisco.com/dnac-use-cases/apache-velocity

• Catalyst Center Template Idea Exchange room - webexteams://im?space=e7fc7ab0-780f-11ee-adf7-e7fd009d0c89


• Web-ex space dedicated to exchanging template ideas, tips/tricks, helpful hints, etc…

© 2024 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
Cisco Confidential

You might also like