mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 20:02:22 -06:00
Add bridge to InterfaceTemplate
This commit is contained in:
committed by
Jeremy Stretch
parent
a8a0fd5b88
commit
82841d3767
@@ -802,6 +802,15 @@ class Device(PrimaryModel, ConfigContextModel):
|
||||
'vc_position': "A device assigned to a virtual chassis must have its position defined."
|
||||
})
|
||||
|
||||
def _update_interface_bridges(self, interface_templates, module=None):
|
||||
for interface_template in interface_templates.exclude(bridge=None):
|
||||
interface = Interface.objects.get(device=self, name=interface_template.resolve_name(module=module))
|
||||
|
||||
if interface_template.bridge:
|
||||
interface.bridge = Interface.objects.get(device=self, name=interface_template.bridge.resolve_name(module=module))
|
||||
interface.full_clean()
|
||||
interface.save()
|
||||
|
||||
def _instantiate_components(self, queryset, bulk_create=True):
|
||||
"""
|
||||
Instantiate components for the device from the specified component templates.
|
||||
@@ -854,6 +863,8 @@ class Device(PrimaryModel, ConfigContextModel):
|
||||
self._instantiate_components(self.device_type.devicebaytemplates.all())
|
||||
# Disable bulk_create to accommodate MPTT
|
||||
self._instantiate_components(self.device_type.inventoryitemtemplates.all(), bulk_create=False)
|
||||
# Interface bridges have to be set after interface instantiation
|
||||
self._update_interface_bridges(self.device_type.interfacetemplates.all())
|
||||
|
||||
# Update Site and Rack assignment for any child Devices
|
||||
devices = Device.objects.filter(parent_bay__device=self)
|
||||
@@ -1015,6 +1026,15 @@ class Module(PrimaryModel, ConfigContextModel):
|
||||
f"Module must be installed within a module bay belonging to the assigned device ({self.device})."
|
||||
)
|
||||
|
||||
def _update_interface_bridges(self, interface_templates, module=None):
|
||||
for interface_template in interface_templates.exclude(bridge=None):
|
||||
interface = Interface.objects.get(device=self.device, name=interface_template.resolve_name(module=module))
|
||||
|
||||
if interface_template.bridge:
|
||||
interface.bridge = Interface.objects.get(device=self.device, name=interface_template.bridge.resolve_name(module=module))
|
||||
interface.full_clean()
|
||||
interface.save()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
is_new = self.pk is None
|
||||
|
||||
@@ -1090,6 +1110,9 @@ class Module(PrimaryModel, ConfigContextModel):
|
||||
update_fields=update_fields
|
||||
)
|
||||
|
||||
# Interface bridges have to be set after interface instantiation
|
||||
self._update_interface_bridges(self.module_type.interfacetemplates, self)
|
||||
|
||||
|
||||
#
|
||||
# Virtual chassis
|
||||
|
||||
Reference in New Issue
Block a user