From 2608b3f9f391ca85a9cd9a78b3624d529a7e4e30 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 22 Jun 2020 14:33:53 -0400 Subject: [PATCH] Separate VM interface view and template --- .../templates/virtualization/interface.html | 120 ++++++++++++++++++ netbox/virtualization/views.py | 34 ++++- 2 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 netbox/templates/virtualization/interface.html diff --git a/netbox/templates/virtualization/interface.html b/netbox/templates/virtualization/interface.html new file mode 100644 index 000000000..15b432a3f --- /dev/null +++ b/netbox/templates/virtualization/interface.html @@ -0,0 +1,120 @@ +{% extends 'base.html' %} +{% load helpers %} + +{% block header %} +
+
+ +
+
+
+ {% if perms.dcim.change_interface %} + + Edit + + {% endif %} + {% if perms.dcim.delete_interface %} + + Delete + + {% endif %} +
+

{% block title %}{{ interface.parent }} / {{ interface.name }}{% endblock %}

+ +{% endblock %} + +{% block content %} +
+
+
+
+ Interface +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% if interface.device %}Device{% else %}Virtual Machine{% endif %} + {{ interface.parent }} +
Name{{ interface.name }}
Label{{ interface.label|placeholder }}
Type{{ interface.get_type_display }}
Enabled + {% if interface.enabled %} + + {% else %} + + {% endif %} +
LAG + {% if interface.lag%} + {{ interface.lag }} + {% else %} + None + {% endif %} +
Description{{ interface.description|placeholder }}
MTU{{ interface.mtu|placeholder }}
MAC Address{{ interface.mac_address|placeholder }}
802.1Q Mode{{ interface.get_mode_display }}
+
+ {% include 'extras/inc/tags_panel.html' with tags=interface.tags.all %} +
+
+
+
+ {% include 'panel_table.html' with table=ipaddress_table heading="IP Addresses" %} +
+
+
+
+ {% include 'panel_table.html' with table=vlan_table heading="VLANs" %} +
+
+{% endblock %} diff --git a/netbox/virtualization/views.py b/netbox/virtualization/views.py index a64b9b9db..bd700d16b 100644 --- a/netbox/virtualization/views.py +++ b/netbox/virtualization/views.py @@ -5,10 +5,10 @@ from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse from dcim.models import Device -from dcim.views import InterfaceView as DeviceInterfaceView from dcim.tables import DeviceTable from extras.views import ObjectConfigContextView from ipam.models import Service +from ipam.tables import InterfaceIPAddressTable, InterfaceVLANTable from utilities.views import ( BulkComponentCreateView, BulkDeleteView, BulkEditView, BulkImportView, ComponentCreateView, ObjectView, ObjectDeleteView, ObjectEditView, ObjectListView, @@ -297,9 +297,39 @@ class InterfaceListView(ObjectListView): action_buttons = ('import', 'export') -class InterfaceView(DeviceInterfaceView): +class InterfaceView(ObjectView): queryset = Interface.objects.all() + def get(self, request, pk): + + interface = get_object_or_404(self.queryset, pk=pk) + + # Get assigned IP addresses + ipaddress_table = InterfaceIPAddressTable( + data=interface.ipaddresses.restrict(request.user, 'view').prefetch_related('vrf', 'tenant'), + orderable=False + ) + + # Get assigned VLANs and annotate whether each is tagged or untagged + vlans = [] + if interface.untagged_vlan is not None: + vlans.append(interface.untagged_vlan) + vlans[0].tagged = False + for vlan in interface.tagged_vlans.prefetch_related('site', 'group', 'tenant', 'role'): + vlan.tagged = True + vlans.append(vlan) + vlan_table = InterfaceVLANTable( + interface=interface, + data=vlans, + orderable=False + ) + + return render(request, 'virtualization/interface.html', { + 'interface': interface, + 'ipaddress_table': ipaddress_table, + 'vlan_table': vlan_table, + }) + class InterfaceCreateView(ComponentCreateView): queryset = Interface.objects.all()