Config template - interfaces under tagged VLANs? #12569
Replies: 1 comment 7 replies
-
The templating language jinja2 is quite powerful - it has variables, looping etc. You'd want to iterate over all interfaces, accumulate the list of VLANs seen; then iterate over each unique VLAN seen and find the interfaces which are a member of it (tagged or untagged). Here is something that comes close:
Unfortunately, when it sees the same vlan multiple times, it repeats the config. Fixing that seems to be tricky, because Netbox doesn't enable the "do" extension, which would allow you to update a list or a dict of vlans already seen. You could raise that as a feature request. With Jinja2, it's also possible to add your own custom filters in Python, like these which Netbox itself provides - but I don't know if there's a supported way to add your own in Netbox, without writing a complete Plugin. EDIT: I realised this doesn't handle interface setting "Tagged (all)". That's tricky; I think you'd need to get a list of all VLANs in the site. Actually, that suggests a solution for the first problem, as long as you've assigned each VLAN to the site:
It's a bit tricker to add in interfaces with tagged-all. In Python/Django it's easy to combine querysets:
But that conflicts with the pipe operator in Jinja2. The following seems to work though:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Looking to generate some VLAN configuration for MikroTik RouterOS. Unfortunately, the configuration required is a little backwards compared to the documentation, where you define a VLAN primarily, and then include relevants interfaces.
For example, if I have VLAN 5 tagged on sfp-sfpplus1, ether2 and ether3, and VLAN 10 tagged on ether2 and ether3, I need to generate the following configuration:
Is there any sane way to accomplish this?
Beta Was this translation helpful? Give feedback.
All reactions