netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.77k stars 2.54k forks source link

Changing Device type - allowing type template to populate existing device #12348

Closed andyb2000 closed 1 year ago

andyb2000 commented 1 year ago

NetBox version

v3.4.6

Feature type

Change to existing functionality

Proposed functionality

Initially most people will populate devices with a list of existing hardware, from import, script, etc. In my case this list does not contain the device type, so I use a catch-all "Unknown". Later, devices are updated (in my case via script from netdoc) to use the correct Device Type (Mainly from the https://github.com/netbox-community/devicetype-library library). This does not then pull in associated modules, power, U size, etc, from Device Types (I assume because this could overwrite the defined values already in the device).

My request is an option to FORCE overwrite of device parameters based on a changed device type, i.e. to import the template/type regardless of overwriting fields.

Use case

This would allow devices that were created using a bulk import/script to later be updated with the correct device type and inherit the defined device type values such as interfaces, console ports, power, modules, etc.

Database changes

No response

External dependencies

No response

kkthxbye-code commented 1 year ago

For reference, this is what the FAQ states:

https://github.com/netbox-community/netbox/wiki/Frequently-Asked-Questions#why-arent-device-type-component-modifications-retroactive

At work, we just use a script similar to this one:

https://github.com/netbox-community/customizations/blob/master/scripts/add_device_type_components.py

I don't have any strong feelings about supporting this in core, personally I might lean on the side of it not being necessary. I'll leave it open to feedback.

andyb2000 commented 1 year ago

Thanks, yes I re-read that a few times before posting. It's this statement that left me a little unsure: "Once a device type has been updated, its device instances can easily have components added or removed in bulk. This approach ensures that all changes are driven by intent rather than by assumptions."

In this case i'm changing the DEVICE association to the device type, not the type itself. The script you posted is probably the way I'll go with this and incorporate it into the netdoc create scripts so it can trigger when the device type is identified, thank you for the code snippet.

It'd be nice to have an API hook to do this, but tbh the code you posted does this job.

2code4me commented 1 year ago

Hi, I have a similar issue. At the moment I need to fast compile an inventory of a data center. As you can imagine I have tons of device type to create so at the moment I've created some "Generic 1RU, Generic 2RU" and so on device type. This is to quickly have an inventory ready for consultation with the idea of adding details in the near future.

I then tried to change the device type using some that I had already created (for example a Dell Server) but I see that details like PSU, interfaces and so on are not compiled so I have to delete and recreate the object every time.

It would be a lot time saving if, when you change the device type, the object could update automatically the device details.

Even in the case of errors in the selection of the device type, you could update the data without the need to delete and recreate the object each time.

Thank you

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

github-actions[bot] commented 1 year ago

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.