mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 12:06:53 -06:00
Update device/VM interface templates
This commit is contained in:
parent
6663844a86
commit
9a0bc16c86
@ -1,6 +1,6 @@
|
|||||||
import netaddr
|
import netaddr
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Count, Q
|
from django.db.models import Count
|
||||||
from django.db.models.expressions import RawSQL
|
from django.db.models.expressions import RawSQL
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
@ -11,7 +11,7 @@ from utilities.views import (
|
|||||||
BulkCreateView, BulkDeleteView, BulkEditView, BulkImportView, ObjectView, ObjectDeleteView, ObjectEditView,
|
BulkCreateView, BulkDeleteView, BulkEditView, BulkImportView, ObjectView, ObjectDeleteView, ObjectEditView,
|
||||||
ObjectListView,
|
ObjectListView,
|
||||||
)
|
)
|
||||||
from virtualization.models import VirtualMachine
|
from virtualization.models import VirtualMachine, VMInterface
|
||||||
from . import filters, forms, tables
|
from . import filters, forms, tables
|
||||||
from .choices import *
|
from .choices import *
|
||||||
from .constants import *
|
from .constants import *
|
||||||
@ -659,13 +659,18 @@ class IPAddressEditView(ObjectEditView):
|
|||||||
|
|
||||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||||
|
|
||||||
interface_id = request.GET.get('interface')
|
if 'interface' in request.GET:
|
||||||
if interface_id:
|
|
||||||
try:
|
try:
|
||||||
obj.interface = Interface.objects.get(pk=interface_id)
|
obj.assigned_object = Interface.objects.get(pk=request.GET['interface'])
|
||||||
except (ValueError, Interface.DoesNotExist):
|
except (ValueError, Interface.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
elif 'vminterface' in request.GET:
|
||||||
|
try:
|
||||||
|
obj.assigned_object = VMInterface.objects.get(pk=request.GET['vminterface'])
|
||||||
|
except (ValueError, VMInterface.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{% if iface.device_id %}{% url 'dcim:interface_edit' pk=iface.pk %}{% else %}{% url 'virtualization:vminterface_edit' pk=iface.pk %}{% endif %}?return_url={{ device.get_absolute_url }}" class="btn btn-info btn-xs" title="Edit interface">
|
<a href="{% url 'dcim:interface_edit' pk=iface.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-info btn-xs" title="Edit interface">
|
||||||
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
|
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -176,7 +176,7 @@
|
|||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
||||||
</button>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% if iface.device_id %}{% url 'dcim:interface_delete' pk=iface.pk %}{% else %}{% url 'virtualization:vminterface_delete' pk=iface.pk %}{% endif %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs" title="Delete interface">
|
<a href="{% url 'dcim:interface_delete' pk=iface.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs" title="Delete interface">
|
||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
141
netbox/templates/virtualization/inc/vminterface.html
Normal file
141
netbox/templates/virtualization/inc/vminterface.html
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
{% load helpers %}
|
||||||
|
<tr class="interface{% if not iface.enabled %} danger{% endif %}" id="interface_{{ iface.name }}">
|
||||||
|
|
||||||
|
{# Checkbox #}
|
||||||
|
{% if perms.virtualization.change_interface or perms.virtualization.delete_interface %}
|
||||||
|
<td class="pk">
|
||||||
|
<input name="pk" type="checkbox" value="{{ iface.pk }}" />
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# Name #}
|
||||||
|
<td>
|
||||||
|
<a href="{{ iface.get_absolute_url }}">{{ iface }}</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# MAC address #}
|
||||||
|
<td class="text-monospace">
|
||||||
|
{{ iface.mac_address|default:"—" }}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# MTU #}
|
||||||
|
<td>{{ iface.mtu|default:"—" }}</td>
|
||||||
|
|
||||||
|
{# 802.1Q mode #}
|
||||||
|
<td>{{ iface.get_mode_display|default:"—" }}</td>
|
||||||
|
|
||||||
|
{# Description/tags #}
|
||||||
|
<td>
|
||||||
|
{% if iface.description %}
|
||||||
|
{{ iface.description }}<br/>
|
||||||
|
{% endif %}
|
||||||
|
{% for tag in iface.tags.all %}
|
||||||
|
{% tag tag %}
|
||||||
|
{% empty %}
|
||||||
|
{% if not iface.description %}—{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# Buttons #}
|
||||||
|
<td class="text-right text-nowrap noprint">
|
||||||
|
{% if show_interface_graphs %}
|
||||||
|
<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#graphs_modal" data-obj="{{ virtualmachine.name }} - {{ iface.name }}" data-url="{% url 'virtualization-api:vminterface-graphs' pk=iface.pk %}" title="Show graphs">
|
||||||
|
<i class="glyphicon glyphicon-signal" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% if perms.ipam.add_ipaddress %}
|
||||||
|
<a href="{% url 'ipam:ipaddress_add' %}?vminterface={{ iface.pk }}&return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-xs btn-success" title="Add IP address">
|
||||||
|
<i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if perms.virtualization.change_interface %}
|
||||||
|
<a href="{% url 'virtualization:vminterface_edit' pk=iface.pk %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-info btn-xs" title="Edit interface">
|
||||||
|
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if perms.virtualization.delete_interface %}
|
||||||
|
<a href="{% url 'virtualization:vminterface_delete' pk=iface.pk %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-danger btn-xs" title="Delete interface">
|
||||||
|
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{% with ipaddresses=iface.ip_addresses.all %}
|
||||||
|
{% if ipaddresses %}
|
||||||
|
<tr class="ipaddresses">
|
||||||
|
{# Placeholder #}
|
||||||
|
{% if perms.virtualization.change_interface or perms.virtualization.delete_interface %}
|
||||||
|
<td></td>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# IP addresses table #}
|
||||||
|
<td colspan="9" style="padding: 0">
|
||||||
|
<table class="table table-condensed interface-ips">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-muted">
|
||||||
|
<th class="col-md-3">IP Address</th>
|
||||||
|
<th class="col-md-2">Status/Role</th>
|
||||||
|
<th class="col-md-3">VRF</th>
|
||||||
|
<th class="col-md-3">Description</th>
|
||||||
|
<th class="col-md-1"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% for ip in iface.ip_addresses.all %}
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
{# IP address #}
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'ipam:ipaddress' pk=ip.pk %}">{{ ip }}</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# Primary/status/role #}
|
||||||
|
<td>
|
||||||
|
{% if virtualmachine.primary_ip4 == ip or virtualmachine.primary_ip6 == ip %}
|
||||||
|
<span class="label label-success">Primary</span>
|
||||||
|
{% endif %}
|
||||||
|
<span class="label label-{{ ip.get_status_class }}">{{ ip.get_status_display }}</span>
|
||||||
|
{% if ip.role %}
|
||||||
|
<span class="label label-{{ ip.get_role_class }}">{{ ip.get_role_display }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# VRF #}
|
||||||
|
<td>
|
||||||
|
{% if ip.vrf %}
|
||||||
|
<a href="{% url 'ipam:vrf' pk=ip.vrf.pk %}" title="{{ ip.vrf.rd }}">{{ ip.vrf.name }}</a>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">Global</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# Description #}
|
||||||
|
<td>
|
||||||
|
{% if ip.description %}
|
||||||
|
{{ ip.description }}
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">—</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{# Buttons #}
|
||||||
|
<td class="text-right text-nowrap noprint">
|
||||||
|
{% if perms.ipam.change_ipaddress %}
|
||||||
|
<a href="{% url 'ipam:ipaddress_edit' pk=ip.pk %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-info btn-xs">
|
||||||
|
<i class="glyphicon glyphicon-pencil" aria-hidden="true" title="Edit IP address"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if perms.ipam.delete_ipaddress %}
|
||||||
|
<a href="{% url 'ipam:ipaddress_delete' pk=ip.pk %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-danger btn-xs">
|
||||||
|
<i class="glyphicon glyphicon-trash" aria-hidden="true" title="Delete IP address"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
@ -248,7 +248,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% if perms.dcim.change_interface or perms.dcim.delete_interface %}
|
{% if perms.virtualization.change_vminterface or perms.virtualization.delete_vminterface %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="virtual_machine" value="{{ virtualmachine.pk }}" />
|
<input type="hidden" name="virtual_machine" value="{{ virtualmachine.pk }}" />
|
||||||
@ -268,22 +268,20 @@
|
|||||||
<table id="interfaces_table" class="table table-hover table-headings panel-body component-list">
|
<table id="interfaces_table" class="table table-hover table-headings panel-body component-list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{% if perms.dcim.change_interface or perms.dcim.delete_interface %}
|
{% if perms.virtualization.change_vminterface or perms.virtualization.delete_vminterface %}
|
||||||
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>LAG</th>
|
<th>MAC Address</th>
|
||||||
<th>Description</th>
|
|
||||||
<th>MTU</th>
|
<th>MTU</th>
|
||||||
<th>Mode</th>
|
<th>Mode</th>
|
||||||
<th>Cable</th>
|
<th>Description</th>
|
||||||
<th colspan="2">Connection</th>
|
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for iface in interfaces %}
|
{% for iface in interfaces %}
|
||||||
{% include 'dcim/inc/interface.html' with device=virtualmachine %}
|
{% include 'virtualization/inc/vminterface.html' %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="8" class="text-center text-muted">— No interfaces defined —</td>
|
<td colspan="8" class="text-center text-muted">— No interfaces defined —</td>
|
||||||
@ -291,22 +289,19 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% if perms.dcim.add_interface or perms.dcim.delete_interface %}
|
{% if perms.virtualization.add_vminterface or perms.virtualization.delete_vminterface %}
|
||||||
<div class="panel-footer noprint">
|
<div class="panel-footer noprint">
|
||||||
{% if interfaces and perms.dcim.change_interface %}
|
{% if interfaces and perms.virtualization.change_vminterface %}
|
||||||
<button type="submit" name="_rename" formaction="{% url 'dcim:interface_bulk_rename' %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-warning btn-xs">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
|
||||||
</button>
|
|
||||||
<button type="submit" name="_edit" formaction="{% url 'virtualization:vminterface_bulk_edit' %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-warning btn-xs">
|
<button type="submit" name="_edit" formaction="{% url 'virtualization:vminterface_bulk_edit' %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-warning btn-xs">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if interfaces and perms.dcim.delete_interface %}
|
{% if interfaces and perms.virtualization.delete_vminterface %}
|
||||||
<button type="submit" name="_delete" formaction="{% url 'virtualization:vminterface_bulk_delete' %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-danger btn-xs">
|
<button type="submit" name="_delete" formaction="{% url 'virtualization:vminterface_bulk_delete' %}?return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-danger btn-xs">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if perms.dcim.add_interface %}
|
{% if perms.virtualization.add_vminterface %}
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<a href="{% url 'virtualization:vminterface_add' %}?virtual_machine={{ virtualmachine.pk }}&return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-primary btn-xs">
|
<a href="{% url 'virtualization:vminterface_add' %}?virtual_machine={{ virtualmachine.pk }}&return_url={{ virtualmachine.get_absolute_url }}" class="btn btn-primary btn-xs">
|
||||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add interfaces
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add interfaces
|
||||||
@ -317,7 +312,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if perms.dcim.delete_interface %}
|
{% if perms.virtualization.delete_vminterface %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user