12-28-2022 12:02 AM
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
01-04-2023 05:20 AM
I have no experience in this field
but maybe you need to add the member-ID somewhere ?
like Port.Total[switch].append(48)
01-04-2023 01:45 PM
pieterh please see above...
01-04-2023 01:43 PM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide