Skip to content

Commit aeea7e0

Browse files
committed
Closes #12135: Prevent the deletion of interfaces with children
1 parent 7efbfab commit aeea7e0

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

docs/models/dcim/interface.md

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ If selected, this component will be treated as if a cable has been connected.
7777

7878
Virtual interfaces can be bound to a physical parent interface. This is helpful for modeling virtual interfaces which employ encapsulation on a physical interface, such as an 802.1Q VLAN-tagged subinterface.
7979

80+
!!! note
81+
An interface with one or more child interfaces assigned cannot be deleted until all its child interfaces have been deleted or reassigned.
82+
8083
### Bridged Interface
8184

8285
Interfaces can be bridged to other interfaces on a device in two manners: symmetric or grouped.

docs/models/virtualization/vminterface.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ The interface's name. Must be unique to the assigned VM.
1616

1717
Identifies the parent interface of a subinterface (e.g. used to employ encapsulation).
1818

19+
!!! note
20+
An interface with one or more child interfaces assigned cannot be deleted until all its child interfaces have been deleted or reassigned.
21+
1922
### Bridged Interface
2023

2124
An interface on the same VM with which this interface is bridged.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.2.6 on 2023-10-20 11:48
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('dcim', '0181_rename_device_role_device_role'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='interface',
16+
name='parent',
17+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='child_interfaces', to='dcim.interface'),
18+
),
19+
]

netbox/dcim/models/device_components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class BaseInterface(models.Model):
537537
)
538538
parent = models.ForeignKey(
539539
to='self',
540-
on_delete=models.SET_NULL,
540+
on_delete=models.PROTECT,
541541
related_name='child_interfaces',
542542
null=True,
543543
blank=True,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.2.6 on 2023-10-20 11:48
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('virtualization', '0036_virtualmachine_config_template'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='vminterface',
16+
name='parent',
17+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='child_interfaces', to='virtualization.vminterface'),
18+
),
19+
]

0 commit comments

Comments
 (0)