Netbox custom script: how do I retrieve existing VLAN object which shall be added to a new Prefix? #22069
Replies: 2 comments 3 replies
-
|
Hi, NetBox uses Django as its framework, so the Django ORM documentation is a good reference here. The main issue is that corporate_vlan = VLAN.objects.get(vid=2099, name="corporate")If VLAN Also note that Django lookups use double underscores. For example, That said, I would avoid using corporate_prefix = Prefix(
prefix=data["corporate_ipsubnet"],
scope=site,
vlan=corporate_vlan,
)
corporate_prefix.full_clean()
corporate_prefix.save()Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
In my custom script I create a new site with switches etc and also to prefixes.
In my code below I attempt to create two prefixes for my site.
For prefix iot_prefix, where I just add the prefix without any additional attributes, I succeed.
For prefix corporate_vlan, where I attempt to add attribute vlan, if fails. I want to add existing VLAN id 2099, name corporate.
However my code line corporate_vlan = VLAN.objects.filter(vid_gt="2099") does not return a valid VLAN object. The same applies when I use attribute filter iname_contains="corporate".
How do I get the VLAN object VLAN id 2099, name corporate, such that I can add that attribute to my corporate_prefix, when I create that.
Generate Prefixes for site
Beta Was this translation helpful? Give feedback.
All reactions