Issues with export templates after upgrade to 2.11

136 views
Skip to first unread message

lee.p...@gmail.com

unread,
Jun 4, 2021, 11:54:30 AM6/4/21
to NetBox
Hi,

I recently upgraded from Netbox 2.8.8 to 2.11.4, and have been having some issues with export templates. Due to the adjustments with circuit terminations, I have been trying to get the template adjusted to the new cable_peer model but I am not sure what I am doing wrong.

To test, I cut it down to a really simple export template is from DCIM -> Device:

{%- for device in queryset -%}
## {{ device.name }} ({{ device.device_type.model }})
{%- for interface in device.interfaces.all() %} {#- Begin Interfaces Loop #}

{{ interface.name }},{{ interface.mode.value }},{{ interface.cable.peer.circuit.cid }}

{%- endfor %} {#- End Interfaces Loop #}
{%- endfor %} {#- End of main loop #}

I keep getting errors like the following:

There was an error rendering the selected export template (Interface Listing Test): 'dcim.models.device_components.Interface object' has no attribute 'cable_peer'

It seems I can't access data outside of the interface scope any longer.

Previously, this would have been {{ interface.connected_endpoint.circuit.cid }} and has been working ok for me until this point.

Can anyone point me in the right direction with this?

Thanks!

Brian Candler

unread,
Jun 4, 2021, 1:36:37 PM6/4/21
to NetBox
The way to explore the data model interactively is with nbshell.

>>> d = Device.objects.get(name="ont1")
>>> d
<Device: ont1>
>>> i = d.interfaces.get(name="WAN")
>>> i
<Interface: WAN>
>>> dir(i)
... shows lots of attributes ...
>>> [n for n in dir(i) if "peer" in n]
['_cable_peer', '_cable_peer_id', '_cable_peer_type', '_cable_peer_type_id', 'get_cable_peer']
>>> i.get_cable_peer
<bound method CableTermination.get_cable_peer of <Interface: WAN>>
>>> i.get_cable_peer()
<CircuitTermination: Termination A: XYZ Site>
>>> i.get_cable_peer().circuit
<Circuit: 20115>
>>> i.get_cable_peer().circuit.cid
'20115'


lee.p...@gmail.com

unread,
Jun 7, 2021, 3:33:13 AM6/7/21
to NetBox
Many thanks for the pointers Brian. Up to now I have been using the API web views, but I will use nbshell from now on.

I just did a quick modification and test on the export template, and this provides me with the circuit IDs once again:

{%- for device in queryset -%}
## {{ device.name }} ({{ device.device_type.model }})
{%- for interface in device.interfaces.all() %} {#- Begin Interfaces Loop #}

{% if interface.get_cable_peer().circuit %}
{{ interface.get_cable_peer().circuit.cid }}
{% endif %}

{%- endfor %} {#- End Interfaces Loop #}
{%- endfor %} {#- End of main loop #}

Output:

## abc-sw1 (EX2200-C-12P-2G)

ge-0/0/0

C0123/S1/IP


ge-0/0/1

C01223/S1/ST


ge-0/0/2


ge-0/0/3


ge-0/0/4
Reply all
Reply to author
Forward
0 new messages