You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose an extension of the Custom Validators functionality to allow a NetBox administrator to prevent object deletion under certain criteria.
An example of how this would look would be the below pseudocode. (The example probably won't work exactly as listed, I'm just making up the way to count connected cables, and if it's right it's just an accident, but this is to show the idea.)
classPreventDeletingCabledDevicesValidator(CustomValidator):
defvalidate_delete(self, instance):
cable_count=len(instance.cables)
ifcable_count>0:
self.fail(f"Device still has {cable_count} cables connected to it!")
The example would prevent deleting devices that are cabled.
Implementation wise, this would happen though an overridable validate_delete() method added to the CustomValidator class which would be called prior to object deletion. Any spots in the code that perform deletion of objects would have to be identified and this hook added, hopefully there's some good chokepoint to add it to.
Use case
Deleting an object can have wide-ranging consequences in NetBox and can easilly happen accidentally. That accidental deletion is a concern is evidenced by previous Feature Request #13690. I have personally accidentally deleted an important object and caused myself an hour and a half of pain in re-creating that deleted object along with all its cable connections.
Additionally, business rules might be in place to prevent the deletion of objects under certain criteria. For example, a business rule might be that circuits or devices may not be deleted from a system if they're still active. The Permissions system might be able to do something similar (I haven't really checked) but that doesn't allow superuser actions to be validated, and that doesn't allow for custom code anyway. Or some organizations might not want to allow device deletion at all in order to keep a permanent record of scrapped devices. Anyway, you see, there's a lot of things you could do that would be for the administrator to decide.
In my opinion the inclusion of a hook like this into NetBox is a fairly small and unopinionated change that lets administrators set their own policy regarding object deletions in NetBox. It's also a natural extension of the Custom Validators functionality, covering a gap in its current functionality.
Database changes
No database changes are required. Custom validators live in configuration and code only.
External dependencies
No external dependencies are required.
The text was updated successfully, but these errors were encountered:
Yeah, I agree, it's looks like a dupe. I didn't find it when doing a quick search. Since the other FR is close enough to what I wanted to do, I'll close this one for now.
NetBox version
v3.6.1
Feature type
New functionality
Proposed functionality
I propose an extension of the Custom Validators functionality to allow a NetBox administrator to prevent object deletion under certain criteria.
An example of how this would look would be the below pseudocode. (The example probably won't work exactly as listed, I'm just making up the way to count connected cables, and if it's right it's just an accident, but this is to show the idea.)
The example would prevent deleting devices that are cabled.
Implementation wise, this would happen though an overridable
validate_delete()
method added to theCustomValidator
class which would be called prior to object deletion. Any spots in the code that perform deletion of objects would have to be identified and this hook added, hopefully there's some good chokepoint to add it to.Use case
Deleting an object can have wide-ranging consequences in NetBox and can easilly happen accidentally. That accidental deletion is a concern is evidenced by previous Feature Request #13690. I have personally accidentally deleted an important object and caused myself an hour and a half of pain in re-creating that deleted object along with all its cable connections.
Additionally, business rules might be in place to prevent the deletion of objects under certain criteria. For example, a business rule might be that circuits or devices may not be deleted from a system if they're still active. The Permissions system might be able to do something similar (I haven't really checked) but that doesn't allow superuser actions to be validated, and that doesn't allow for custom code anyway. Or some organizations might not want to allow device deletion at all in order to keep a permanent record of scrapped devices. Anyway, you see, there's a lot of things you could do that would be for the administrator to decide.
In my opinion the inclusion of a hook like this into NetBox is a fairly small and unopinionated change that lets administrators set their own policy regarding object deletions in NetBox. It's also a natural extension of the Custom Validators functionality, covering a gap in its current functionality.
Database changes
No database changes are required. Custom validators live in configuration and code only.
External dependencies
No external dependencies are required.
The text was updated successfully, but these errors were encountered: