Export-Templates containing more than one object type #13485
Answered
by
mtinberg
reduzent
asked this question in
Help Wanted!
Replies: 5 comments 4 replies
-
IPAddress records come with a dns_name field that you can fill out, by hand or by writing custom code, they also have assigned_object (at least in the REST API) which includes info about the device/interface or FHRP group they are assigned to.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: Roman Haefeli ***@***.***>
Sent: Wednesday, August 16, 2023 10:13 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Eport-Templates containting more than one Object type (Discussion #13485)
I would like to create an export template for DHCP reservations. However, there are two kind of of reservations, once is IP address based, the other hostname based. This means I need to access IPAddress objects for the former and Interface objects for the latter. Is that possible at all?
The editing page for export templates allows to define several "Content types", but obviously the queryset variable contains only one. What is the ability to set more than one "Content type" useful for, then?
—
Reply to this email directly, view it on GitHub<#13485>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM7QNPDK3KIXR5ZGA4TXVTPRBANCNFSM6AAAAAA3SWGRCY>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
I don't know what DHCP server software you are talking about, but it sounds like there is some misunderstanding about what you are trying to configure. DHCP statics map an interface MAC address to an IP Address, so I'm not sure where DNS names come in except as a way to correlate config between the DNS service and the DHCP service, like an Infoblox Host record.
As for as why allowing more than one content type for export templates, why not? If you either are exporting fields that are common to a number of data models (like name, comments, slug, id, etc) you might have a template that works for multiple things, or you might use if/then logic in the template to make it work for different data models. I'm not sure there is a benefit to Netbox restricting this kind of flexability.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: Roman Haefeli ***@***.***>
Sent: Wednesday, August 16, 2023 10:25 AM
To: netbox-community/netbox ***@***.***>
Cc: Mark Tinberg ***@***.***>; Comment ***@***.***>
Subject: Re: [netbox-community/netbox] Export-Templates containing more than one object type (Discussion #13485)
Thanks for your answer. We cannot use the IPAddress object for hostname based reservations because the DHCP then assigns an available IP address that netbox doesn't know about.
I still wonder about why it is possible to set more than one content type for export templates.
—
Reply to this email directly, view it on GitHub<#13485 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM6O7ZKW2YRPMIFAAY3XVTQ55ANCNFSM6AAAAAA3SWGRCY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
If you are using KEA DHCP Server, you can just make the reservation right from NetBox GUI using the device interface info
|
Beta Was this translation helpful? Give feedback.
1 reply
-
![]() |
Beta Was this translation helpful? Give feedback.
0 replies
-
The queryset is for the page you are looking at, so it is only ever returning one object type at a time, so if you browse /dcim/interfaces?device_id=123&enabled=True then the queryset matches what you've requested. Very similar to issuing a query using nbshell
>> Interface.objects.filter(device_id=123, enabled=True)
<RestrictedQuerySet [<Interface: Ethernet1/1>, <Interface: Ethernet1/2>, <Interface: Ethernet1/48>, <Interface: Ethernet1/49>, <Interface: Ethernet1/50>, <Interface: Ethernet1/54>, <Interface: mgmt0>, <Interface: port-channel1>, <Interface: port-channel2>, <Interface: port-channel3>, <Interface: port-channel201>]>
and the query /ipam/ip-addresses/?device_id=123 will return a similar queryset to the following in nbshell
>> IPAddress.objects.filter(interface__device_id=123 )
<RestrictedQuerySet [<IPAddress: 192.0.2.12/24>]>
When you are working on an IPAddress queryset you will get IPAddress objects and when you are working on an Interface queryset you will get Interface objects they don't have all the same fields but they do have a few, you could put if/then in your template to have different behavior, but you are only going to be seeing one object type at a time
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: Roman Haefeli ***@***.***>
Sent: Monday, August 21, 2023 5:10 AM
To: netbox-community/netbox ***@***.***>
Cc: Mark Tinberg ***@***.***>; Comment ***@***.***>
Subject: Re: [netbox-community/netbox] Export-Templates containing more than one object type (Discussion #13485)
As for as why allowing more than one content type for export templates, why not? If you either are exporting fields that are common to a number of data models (like name, comments, slug, id, etc) you might have a template that works for multiple things, or you might use if/then logic in the template to make it work for different data models. I'm not sure there is a benefit to Netbox restricting this kind of flexability
I'm not all against many content types in export templates. I just haven't figured out, how to to use them within the export template itself. The queryset variable seems to hold only a list of models of the first specified type.
If I - for instance - specify "IPAM -> IPAdress" , "DCIM -> Interface", how can I iterate through all interfaces?
—
Reply to this email directly, view it on GitHub<#13485 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM7ROGQL4I3JAFWA6YDXWMXZZANCNFSM6AAAAAA3SWGRCY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
reduzent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to create an export template for DHCP reservations. However, there are two kind of of reservations, one is IP address based, the other hostname based. This means I need to access IPAddress objects for the former and Interface objects for the latter. Is that possible at all?
The editing page for export templates allows to define several "Content types", but obviously the
queryset
variable contains only one. What is the ability to set more than one "Content type" useful for, then?Beta Was this translation helpful? Give feedback.
All reactions