mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #6121: Extend parent interface assignment to VM interfaces
This commit is contained in:
@ -395,6 +395,14 @@ class VMInterface(PrimaryModel, BaseInterface):
|
||||
max_length=200,
|
||||
blank=True
|
||||
)
|
||||
parent = models.ForeignKey(
|
||||
to='self',
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='child_interfaces',
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name='Parent interface'
|
||||
)
|
||||
untagged_vlan = models.ForeignKey(
|
||||
to='ipam.VLAN',
|
||||
on_delete=models.SET_NULL,
|
||||
@ -438,6 +446,7 @@ class VMInterface(PrimaryModel, BaseInterface):
|
||||
self.virtual_machine.name,
|
||||
self.name,
|
||||
self.enabled,
|
||||
self.parent.name if self.parent else None,
|
||||
self.mac_address,
|
||||
self.mtu,
|
||||
self.description,
|
||||
@ -447,6 +456,13 @@ class VMInterface(PrimaryModel, BaseInterface):
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
# An interface's parent must belong to the same virtual machine
|
||||
if self.parent and self.parent.virtual_machine != self.virtual_machine:
|
||||
raise ValidationError({
|
||||
'parent': f"The selected parent interface ({self.parent}) belongs to a different virtual machine "
|
||||
f"({self.parent.virtual_machine})."
|
||||
})
|
||||
|
||||
# Validate untagged VLAN
|
||||
if self.untagged_vlan and self.untagged_vlan.site not in [self.virtual_machine.site, None]:
|
||||
raise ValidationError({
|
||||
|
Reference in New Issue
Block a user