cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
764
Views
5
Helpful
3
Replies

Cisco DNA Template - Working with Lists?

magwes
Level 1
Level 1

I'm trying to create a simple template i DNAC that loops through the switches in a stack, appends the number of ports found in the product name of each switch into a list.

Using this link as reference : Platinum-PortAssign-Template.j2 

Code:

{% set StackPIDs = __device.platformId | split(",")  %}
{% set StackMemberCount = StackPIDs | length  %}
{% set PortTotal = [] %}
{% set Model = '' %}
{% for Switch in range(StackMemberCount) %}
  {% set Model = StackPIDs[Switch] %}
  {% if '48' in Model -%}
    {% set PortTotal = PortTotal.append(48) %}
  {% elif '24' in Model %}
    {% set PortTotal = PortTotal.append(24) %}
  {% endif %}
{% endfor %}
{{ PortTotal }}

This works fine when there is only one switch in the stack, but with 2 or more it fails with "Cannot find method append with 1 parameters in class java.lang.Boolean".

What am I doing wrong? Or is this a bug in DNAC?

Best regards
Magnus

3 Replies 3

pieterh
VIP
VIP

I have no experience in this field
but maybe you need to add the member-ID somewhere ?
like Port.Total[switch].append(48)

pieterh please see above...

kebaldwi
Cisco Employee
Cisco Employee

Hi Magwes
The error is clearly stating the append operator is having issues...
Thats because in my haste to put code up there somehow this one did not get tested...

I have amended it now, but the conditional block should read as shown here...

{% if '48' in Model -%}
       {% do PortTotal.append(48) %}
{% elif '24' in Model %}
       {% do PortTotal.append(24) %}
{% endif %}

Hope that helps...

Keith

Review Cisco Networking for a $25 gift card