This issue is a safe guard for a situation where someone accidentally adds a parent.
Scenario #1: Mistakably adding a top level network
Before this change, a situation of adding a quad0 would have been impossible to revert. Let's explore what this would look like:
Notice that simply running remove raises an error:
$ nsot networks remove -i 17
[FAILURE] Cannot delete some instances of model 'Network' because they are referenced through a protected foreign key: 'Network.parent'
Enter the force-delete flag! The force-delete flag (added in this pynsot PR) overrides the native django PROTECT method on Network.parent. Forceful deletion allows us to forcefully delete a network that has children:
Scenario #2: Deleting a parent with child leaf nodes
Forceful deletion does not work when trying to delete a parent network whose children are leaf nodes:
$ nsot networks remove -i 1 --force-delete
[FAILURE] You cannot forcefully delete a network that does not have a parent, and whose children are leaf nodes.
Scenario #3: Deleting a network that has a parent
In a scenario where we try to delete a network that has a parent, the children of that network will be reparented to the deleted network's parent.
Notice we've added a new network: 185.45.0.0/17, which is now the parent of 185.45.19.0/24:
$ nsot networks remove -i 1
[FAILURE] Cannot delete some instances of model 'Network' because they are referenced through a protected foreign key: 'Network.parent'
It fails, as expected. Now let's try with the force-delete flag:
This issue is a safe guard for a situation where someone accidentally adds a parent.
Scenario #1: Mistakably adding a top level network Before this change, a situation of adding a quad0 would have been impossible to revert. Let's explore what this would look like:
Oops, now the
/24
now has quad0 as it's parent (and all other parent networks would as well):Notice that simply running
remove
raises an error:Enter the force-delete flag! The force-delete flag (added in this pynsot PR) overrides the native django PROTECT method on
Network.parent
. Forceful deletion allows us to forcefully delete a network that has children:Notice that the
/24
no longer has a parent:Scenario #2: Deleting a parent with child leaf nodes Forceful deletion does not work when trying to delete a parent network whose children are leaf nodes:
Scenario #3: Deleting a network that has a parent In a scenario where we try to delete a network that has a parent, the children of that network will be reparented to the deleted network's parent.
Notice we've added a new network:
185.45.0.0/17
, which is now the parent of185.45.19.0/24
:Now let's try to delete
185.45.19.0/24
:It fails, as expected. Now let's try with the force-delete flag:
Notice all children have now been reparented to
185.45.0.0/17
.