Update interface view templates

This commit is contained in:
Jeremy Stretch 2020-06-23 15:09:32 -04:00
parent 25d6bbf659
commit 5ad5994b9d
6 changed files with 121 additions and 144 deletions

View File

@ -5,29 +5,25 @@
<div class="row noprint">
<div class="col-md-12">
<ol class="breadcrumb">
{% if interface.device %}
<li><a href="{% url 'dcim:device_list' %}">Devices</a></li>
{% else %}
<li><a href="{% url 'virtualization:virtualmachine_list' %}">Virtual Machines</a></li>
{% endif %}
<li><a href="{{ interface.parent.get_absolute_url }}">{{ interface.parent }}</a></li>
<li><a href="{% url 'dcim:device_list' %}">Devices</a></li>
<li><a href="{{ interface.device.get_absolute_url }}">{{ interface.device }}</a></li>
<li>{{ interface }}</li>
</ol>
</div>
</div>
<div class="pull-right noprint">
{% if perms.dcim.change_interface %}
<a href="{% if interface.device %}{% url 'dcim:interface_edit' pk=interface.pk %}{% else %}{% url 'virtualization:vminterface_edit' pk=interface.pk %}{% endif %}" class="btn btn-warning">
<a href="{% url 'dcim:interface_edit' pk=interface.pk %}" class="btn btn-warning">
<span class="fa fa-pencil" aria-hidden="true"></span> Edit
</a>
{% endif %}
{% if perms.dcim.delete_interface %}
<a href="{% if interface.device %}{% url 'dcim:interface_delete' pk=interface.pk %}{% else %}{% url 'virtualization:vminterface_delete' pk=interface.pk %}{% endif %}" class="btn btn-danger">
<a href="{% url 'dcim:interface_delete' pk=interface.pk %}" class="btn btn-danger">
<span class="fa fa-trash" aria-hidden="true"></span> Delete
</a>
{% endif %}
</div>
<h1>{% block title %}{{ interface.parent }} / {{ interface.name }}{% endblock %}</h1>
<h1>{% block title %}{{ interface.device }} / {{ interface.name }}{% endblock %}</h1>
<ul class="nav nav-tabs">
<li role="presentation"{% if not active_tab %} class="active"{% endif %}>
<a href="{{ interface.get_absolute_url }}">Interface</a>
@ -49,9 +45,9 @@
</div>
<table class="table table-hover panel-body attr-table">
<tr>
<td>{% if interface.device %}Device{% else %}Virtual Machine{% endif %}</td>
<td>Device</td>
<td>
<a href="{{ interface.parent.get_absolute_url }}">{{ interface.parent }}</a>
<a href="{{ interface.device.get_absolute_url }}">{{ interface.device }}</a>
</td>
</tr>
<tr>
@ -96,7 +92,7 @@
</tr>
<tr>
<td>MAC Address</td>
<td>{{ interface.mac_address|placeholder }}</span></td>
<td><span class="text-monospace">{{ interface.mac_address|placeholder }}</span></td>
</tr>
<tr>
<td>802.1Q Mode</td>
@ -118,7 +114,7 @@
<tr>
<td>Device</td>
<td>
<a href="{{ connected_interface.parent.get_absolute_url }}">{{ connected_interface.device }}</a>
<a href="{{ connected_interface.device.get_absolute_url }}">{{ connected_interface.device }}</a>
</td>
</tr>
<tr>
@ -225,7 +221,7 @@
{% for member in interface.member_interfaces.all %}
<tr>
<td>
<a href="{{ member.parent.get_absolute_url }}">{{ member.parent }}</a>
<a href="{{ member.device.get_absolute_url }}">{{ member.device }}</a>
</td>
<td>
<a href="{{ member.get_absolute_url }}">{{ member }}</a>

View File

@ -1,120 +0,0 @@
{% extends 'base.html' %}
{% load helpers %}
{% block header %}
<div class="row noprint">
<div class="col-md-12">
<ol class="breadcrumb">
{% if interface.device %}
<li><a href="{% url 'dcim:device_list' %}">Devices</a></li>
{% else %}
<li><a href="{% url 'virtualization:virtualmachine_list' %}">Virtual Machines</a></li>
{% endif %}
<li><a href="{{ interface.parent.get_absolute_url }}">{{ interface.parent }}</a></li>
<li>{{ interface }}</li>
</ol>
</div>
</div>
<div class="pull-right noprint">
{% if perms.dcim.change_interface %}
<a href="{% if interface.device %}{% url 'dcim:interface_edit' pk=interface.pk %}{% else %}{% url 'virtualization:vminterface_edit' pk=interface.pk %}{% endif %}" class="btn btn-warning">
<span class="fa fa-pencil" aria-hidden="true"></span> Edit
</a>
{% endif %}
{% if perms.dcim.delete_interface %}
<a href="{% if interface.device %}{% url 'dcim:interface_delete' pk=interface.pk %}{% else %}{% url 'virtualization:vminterface_delete' pk=interface.pk %}{% endif %}" class="btn btn-danger">
<span class="fa fa-trash" aria-hidden="true"></span> Delete
</a>
{% endif %}
</div>
<h1>{% block title %}{{ interface.parent }} / {{ interface.name }}{% endblock %}</h1>
<ul class="nav nav-tabs">
<li role="presentation"{% if not active_tab %} class="active"{% endif %}>
<a href="{{ interface.get_absolute_url }}">Interface</a>
</li>
{% if perms.extras.view_objectchange %}
<li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
<a href="{% url 'dcim:interface_changelog' pk=interface.pk %}">Change Log</a>
</li>
{% endif %}
</ul>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Interface</strong>
</div>
<table class="table table-hover panel-body attr-table">
<tr>
<td>{% if interface.device %}Device{% else %}Virtual Machine{% endif %}</td>
<td>
<a href="{{ interface.parent.get_absolute_url }}">{{ interface.parent }}</a>
</td>
</tr>
<tr>
<td>Name</td>
<td>{{ interface.name }}</td>
</tr>
<tr>
<td>Label</td>
<td>{{ interface.label|placeholder }}</td>
</tr>
<tr>
<td>Type</td>
<td>{{ interface.get_type_display }}</td>
</tr>
<tr>
<td>Enabled</td>
<td>
{% if interface.enabled %}
<span class="text-success"><i class="fa fa-check"></i></span>
{% else %}
<span class="text-danger"><i class="fa fa-close"></i></span>
{% endif %}
</td>
</tr>
<tr>
<td>LAG</td>
<td>
{% if interface.lag%}
<a href="{{ interface.lag.get_absolute_url }}">{{ interface.lag }}</a>
{% else %}
<span class="text-muted">None</span>
{% endif %}
</td>
</tr>
<tr>
<td>Description</td>
<td>{{ interface.description|placeholder }} </td>
</tr>
<tr>
<td>MTU</td>
<td>{{ interface.mtu|placeholder }}</td>
</tr>
<tr>
<td>MAC Address</td>
<td>{{ interface.mac_address|placeholder }}</span></td>
</tr>
<tr>
<td>802.1Q Mode</td>
<td>{{ interface.get_mode_display }}</td>
</tr>
</table>
</div>
{% include 'extras/inc/tags_panel.html' with tags=interface.tags.all %}
</div>
</div>
<div class="row">
<div class="col-md-12">
{% include 'panel_table.html' with table=ipaddress_table heading="IP Addresses" %}
</div>
</div>
<div class="row">
<div class="col-md-12">
{% include 'panel_table.html' with table=vlan_table heading="VLANs" %}
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,100 @@
{% extends 'base.html' %}
{% load helpers %}
{% block header %}
<div class="row noprint">
<div class="col-md-12">
<ol class="breadcrumb">
<li><a href="{% url 'virtualization:virtualmachine_list' %}">Virtual Machines</a></li>
<li><a href="{{ vminterface.virtual_machine.get_absolute_url }}">{{ vminterface.virtual_machine }}</a></li>
<li>{{ vminterface }}</li>
</ol>
</div>
</div>
<div class="pull-right noprint">
{% if perms.virtualization.change_vminterface %}
<a href="{% url 'virtualization:vminterface_edit' pk=vminterface.pk %}" class="btn btn-warning">
<span class="fa fa-pencil" aria-hidden="true"></span> Edit
</a>
{% endif %}
{% if perms.virtualization.delete_vminterface %}
<a href="{% url 'virtualization:vminterface_delete' pk=vminterface.pk %}" class="btn btn-danger">
<span class="fa fa-trash" aria-hidden="true"></span> Delete
</a>
{% endif %}
</div>
<h1>{% block title %}{{ vminterface.virtual_machine }} / {{ vminterface.name }}{% endblock %}</h1>
<ul class="nav nav-tabs">
<li role="presentation"{% if not active_tab %} class="active"{% endif %}>
<a href="{{ vminterface.get_absolute_url }}">Interface</a>
</li>
{% if perms.extras.view_objectchange %}
<li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
<a href="{% url 'virtualization:vminterface_changelog' pk=vminterface.pk %}">Change Log</a>
</li>
{% endif %}
</ul>
{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Interface</strong>
</div>
<table class="table table-hover panel-body attr-table">
<tr>
<td>Virtual Machine</td>
<td>
<a href="{{ vminterface.parent.get_absolute_url }}">{{ vminterface.parent }}</a>
</td>
</tr>
<tr>
<td>Name</td>
<td>{{ vminterface.name }}</td>
</tr>
<tr>
<td>Enabled</td>
<td>
{% if vminterface.enabled %}
<span class="text-success"><i class="fa fa-check"></i></span>
{% else %}
<span class="text-danger"><i class="fa fa-close"></i></span>
{% endif %}
</td>
</tr>
<tr>
<td>Description</td>
<td>{{ vminterface.description|placeholder }} </td>
</tr>
<tr>
<td>MTU</td>
<td>{{ vminterface.mtu|placeholder }}</td>
</tr>
<tr>
<td>MAC Address</td>
<td><span class="text-monospace">{{ vminterface.mac_address|placeholder }}</span></td>
</tr>
<tr>
<td>802.1Q Mode</td>
<td>{{ vminterface.get_mode_display }}</td>
</tr>
</table>
</div>
</div>
<div class="col-md-6">
{% include 'extras/inc/tags_panel.html' with tags=vminterface.tags.all %}
</div>
</div>
<div class="row">
<div class="col-md-12">
{% include 'panel_table.html' with table=ipaddress_table heading="IP Addresses" %}
</div>
</div>
<div class="row">
<div class="col-md-12">
{% include 'panel_table.html' with table=vlan_table heading="VLANs" %}
</div>
</div>
{% endblock %}

View File

@ -3,7 +3,7 @@ from django.urls import path
from extras.views import ObjectChangeLogView
from ipam.views import ServiceEditView
from . import views
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
app_name = 'virtualization'
urlpatterns = [
@ -57,6 +57,7 @@ urlpatterns = [
path('interfaces/<int:pk>/', views.InterfaceView.as_view(), name='vminterface'),
path('interfaces/<int:pk>/edit/', views.InterfaceEditView.as_view(), name='vminterface_edit'),
path('interfaces/<int:pk>/delete/', views.InterfaceDeleteView.as_view(), name='vminterface_delete'),
path('interfaces/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='vminterface_changelog', kwargs={'model': VMInterface}),
path('virtual-machines/interfaces/add/', views.VirtualMachineBulkAddInterfaceView.as_view(), name='virtualmachine_bulk_add_vminterface'),
]

View File

@ -302,30 +302,30 @@ class InterfaceView(ObjectView):
def get(self, request, pk):
interface = get_object_or_404(self.queryset, pk=pk)
vminterface = get_object_or_404(self.queryset, pk=pk)
# Get assigned IP addresses
ipaddress_table = InterfaceIPAddressTable(
data=interface.ip_addresses.restrict(request.user, 'view').prefetch_related('vrf', 'tenant'),
data=vminterface.ip_addresses.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)
if vminterface.untagged_vlan is not None:
vlans.append(vminterface.untagged_vlan)
vlans[0].tagged = False
for vlan in interface.tagged_vlans.prefetch_related('site', 'group', 'tenant', 'role'):
for vlan in vminterface.tagged_vlans.prefetch_related('site', 'group', 'tenant', 'role'):
vlan.tagged = True
vlans.append(vlan)
vlan_table = InterfaceVLANTable(
interface=interface,
interface=vminterface,
data=vlans,
orderable=False
)
return render(request, 'virtualization/interface.html', {
'interface': interface,
return render(request, 'virtualization/vminterface.html', {
'vminterface': vminterface,
'ipaddress_table': ipaddress_table,
'vlan_table': vlan_table,
})
@ -342,7 +342,7 @@ class InterfaceCreateView(ComponentCreateView):
class InterfaceEditView(ObjectEditView):
queryset = VMInterface.objects.all()
model_form = forms.InterfaceForm
template_name = 'virtualization/interface_edit.html'
template_name = 'virtualization/vminterface_edit.html'
class InterfaceDeleteView(ObjectDeleteView):