2021-04-20 10:22:26 +03:00
|
|
|
from extras.plugins import PluginTemplateExtension
|
|
|
|
from dcim.models import Interface, InterfaceTemplate
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceViewExtension(PluginTemplateExtension):
|
|
|
|
model = "dcim.device"
|
|
|
|
|
|
|
|
def buttons(self):
|
|
|
|
"""Implements a compare interfaces button at the top of the page"""
|
|
|
|
obj = self.context['object']
|
2022-01-12 14:59:05 +03:00
|
|
|
return self.render("netbox_interface_sync/compare_components_button.html", extra_context={
|
2021-04-20 10:22:26 +03:00
|
|
|
"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]
|