Interface custom fields - default values from device type #10741
dpotter-intoto
started this conversation in
General
Replies: 3 comments 1 reply
-
I'd start by looking at Netbox Scripts which are used to create/modify Netbox records with custom code to do what you want.
https://docs.netbox.dev/en/stable/customization/custom-scripts/
You could create your own custom Add Device form. One thing to note is that the Script can specify some basic pre-made form elements, but you don't get to pass data to the Script before the form elements are rendered, so if you needed different form elements or contents for different Device Types in your scenario I think you'd need to have a fleet of copy-pasta Script classes (maybe using some shared subs to keep the copying to a minimum) or be very good at client-side JavaScript to modify/filter the forms (like how VLAN Group on Interface edit works). Another note is that the way Scripts work is that when you submit the HTML form, the submitted variables are not processed by the WSGI web service but are packaged up and queued in Redis for an independent worker daemon to process, so you no longer have access to HTTP server variables and the request object, afaict.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: dpotter-intoto ***@***.***>
Sent: Tuesday, October 25, 2022 8:30 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Interface custom fields - default values from device type (Discussion #10741)
Hi!
I'd like to create a custom field for the DCIM>Interface object, and have the default values for that field associated with a device type.
My goal, in short: Whenever I create a new device of that type, I'd like the custom fields for the device's interfaces to be filled with the values that are specified by the device type.
Can anybody recommend a technique or approach to achieving this?
Thanks!
—
Reply to this email directly, view it on GitHub<#10741>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM7G3K4MLRIPUSQOB7LWE7OILANCNFSM6AAAAAARN7HSPM>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
That sounds like a good way to go about it, that'll be easy to document for the next person who comes along and has to admin it. As far as importing devices not through your manual Add Device Script, you could use another Script (or just Report) to find cases where your cfg_note isn't populated and either offer to fix them (Script) or list them for an admin to fix (Report). Scripts have a checkbox so they can operate in a dry-run mode, showing what they would do without committing the changes to the DB, so you can validate the change before committing to it.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: dpotter-intoto ***@***.***>
Sent: Tuesday, October 25, 2022 9:16 AM
To: netbox-community/netbox ***@***.***>
Cc: Mark Tinberg ***@***.***>; Comment ***@***.***>
Subject: Re: [netbox-community/netbox] Interface custom fields - default values from device type (Discussion #10741)
Thanks for the suggestion!
If I understand your suggestion correctly, I might adopt a strategy like this:
1. Create a custom field on DCIM>Interface (e.g. cfg_note)
2. Create a custom JSON field on DCIM>Device Type (e.g. cfg_notes) that contains an array of cfg_note default values for each interface (for devices of this device type)
3. Create a custom form Add Device. This custom form won't need any new UI elements, but it will have the logic to read cfg_notes from the device type and populate the cfg_note field on each interface.
Is that about right?
Would this approach also populate cfg_note on devices that are imported? If not, what would be a good approach to handle that?
—
Reply to this email directly, view it on GitHub<#10741 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM4RCGCJGVVT6HQIGILWE7TT5ANCNFSM6AAAAAARN7HSPM>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
The more I consider this, the more I think this should be a feature: Interface templates (stored with device types) should allow/include custom fields that have been added to the DCIM>Interface model. Do you agree? Worth issue creation? This would completely solve the problem of providing default values for custom fields attached to DCIM>Interface from the device template. |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
Hi!
I'd like to create a custom field for the
DCIM>Interface
object, and have the default values for that field associated with a device type.My goal, in short: Whenever I create a new device of that type, I'd like the custom fields for the device's interfaces to be filled with the values that are specified by the device type.
Can anybody recommend a technique or approach to achieving this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions