1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add bridge to InterfaceTemplate

This commit is contained in:
kkthxbye-code
2023-03-01 16:05:41 +01:00
committed by Jeremy Stretch
parent c44eb65993
commit a74ae46f86
6 changed files with 78 additions and 4 deletions

View File

@@ -350,6 +350,14 @@ class InterfaceTemplate(ModularComponentTemplateModel):
default=False,
verbose_name='Management only'
)
bridge = models.ForeignKey(
to='self',
on_delete=models.SET_NULL,
related_name='bridge_interfaces',
null=True,
blank=True,
verbose_name='Bridge interface'
)
poe_mode = models.CharField(
max_length=50,
choices=InterfacePoEModeChoices,
@@ -365,6 +373,19 @@ class InterfaceTemplate(ModularComponentTemplateModel):
component_model = Interface
def clean(self):
super().clean()
if self.bridge:
if self.device_type and self.device_type != self.bridge.device_type:
raise ValidationError({
'bridge': f"Bridge interface ({self.bridge}) must belong to the same device type"
})
if self.module_type and self.module_type != self.bridge.module_type:
raise ValidationError({
'bridge': f"Bridge interface ({self.bridge}) must belong to the same module type"
})
def instantiate(self, **kwargs):
return self.component_model(
name=self.resolve_name(kwargs.get('module')),
@@ -385,6 +406,7 @@ class InterfaceTemplate(ModularComponentTemplateModel):
'mgmt_only': self.mgmt_only,
'label': self.label,
'description': self.description,
'bridge': self.bridge.name if self.bridge else None,
'poe_mode': self.poe_mode,
'poe_type': self.poe_type,
}