netbox-plugin-interface-sync/netbox_interface_sync/template_content.py
Keith Knowles 6fe7da696c
Update template_content.py
Netbox 4 support
2024-05-12 12:54:13 -06:00

30 lines
1.1 KiB
Python

from netbox.plugins import PluginTemplateExtension
from dcim.models import Interface, InterfaceTemplate
class DeviceViewExtension(PluginTemplateExtension):
model = "dcim.device"
def buttons(self):
"""Implements a compare button at the top of the page"""
obj = self.context['object']
return self.render("netbox_interface_sync/compare_components_button.html", extra_context={
"device": obj
})
def right_page(self):
"""Implements a panel with the number of interfaces on the right side of the page"""
obj = self.context['object']
interfaces = Interface.objects.filter(device=obj)
real_interfaces = interfaces.exclude(type__in=["virtual", "lag"])
interface_templates = InterfaceTemplate.objects.filter(device_type=obj.device_type)
return self.render("netbox_interface_sync/number_of_interfaces_panel.html", extra_context={
"interfaces": interfaces,
"real_interfaces": real_interfaces,
"interface_templates": interface_templates
})
template_extensions = [DeviceViewExtension]