Просмотр исходного кода

Update device/VM interface templates

Jeremy Stretch 5 лет назад
Родитель
Сommit
9a0bc16c86

+ 10 - 5
netbox/ipam/views.py

@@ -1,6 +1,6 @@
 import netaddr
 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.shortcuts import get_object_or_404, redirect, render
 from django_tables2 import RequestConfig
@@ -11,7 +11,7 @@ from utilities.views import (
     BulkCreateView, BulkDeleteView, BulkEditView, BulkImportView, ObjectView, ObjectDeleteView, ObjectEditView,
     ObjectListView,
 )
-from virtualization.models import VirtualMachine
+from virtualization.models import VirtualMachine, VMInterface
 from . import filters, forms, tables
 from .choices import *
 from .constants import *
@@ -659,13 +659,18 @@ class IPAddressEditView(ObjectEditView):
 
     def alter_obj(self, obj, request, url_args, url_kwargs):
 
-        interface_id = request.GET.get('interface')
-        if interface_id:
+        if 'interface' in request.GET:
             try:
-                obj.interface = Interface.objects.get(pk=interface_id)
+                obj.assigned_object = Interface.objects.get(pk=request.GET['interface'])
             except (ValueError, Interface.DoesNotExist):
                 pass
 
+        elif 'vminterface' in request.GET:
+            try:
+                obj.assigned_object = VMInterface.objects.get(pk=request.GET['vminterface'])
+            except (ValueError, VMInterface.DoesNotExist):
+                pass
+
         return obj
 
 

+ 2 - 2
netbox/templates/dcim/inc/interface.html

@@ -166,7 +166,7 @@
                     </ul>
                 </span>
             {% 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>
             </a>
         {% endif %}
@@ -176,7 +176,7 @@
                     <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                 </button>
             {% 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>
                 </a>
             {% endif %}

+ 141 - 0
netbox/templates/virtualization/inc/vminterface.html

@@ -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:"&mdash;" }}
+    </td>
+
+    {# MTU #}
+    <td>{{ iface.mtu|default:"&mdash;" }}</td>
+
+    {# 802.1Q mode #}
+    <td>{{ iface.get_mode_display|default:"&mdash;" }}</td>
+
+    {# Description/tags #}
+    <td>
+        {% if iface.description %}
+            {{ iface.description }}<br/>
+        {% endif %}
+        {% for tag in iface.tags.all %}
+            {% tag tag %}
+        {% empty %}
+            {% if not iface.description %}&mdash;{% 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">&mdash;</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 %}

+ 10 - 15
netbox/templates/virtualization/virtualmachine.html

@@ -248,7 +248,7 @@
 </div>
 <div class="row">
     <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">
             {% csrf_token %}
             <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">
                 <thead>
                     <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>
                         {% endif %}
                         <th>Name</th>
-                        <th>LAG</th>
-                        <th>Description</th>
+                        <th>MAC Address</th>
                         <th>MTU</th>
                         <th>Mode</th>
-                        <th>Cable</th>
-                        <th colspan="2">Connection</th>
+                        <th>Description</th>
                         <th></th>
                     </tr>
                 </thead>
                 <tbody>
                     {% for iface in interfaces %}
-                        {% include 'dcim/inc/interface.html' with device=virtualmachine %}
+                        {% include 'virtualization/inc/vminterface.html' %}
                     {% empty %}
                         <tr>
                             <td colspan="8" class="text-center text-muted">&mdash; No interfaces defined &mdash;</td>
@@ -291,22 +289,19 @@
                     {% endfor %}
                 </tbody>
             </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">
-                    {% if interfaces and perms.dcim.change_interface %}
-                        <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>
+                    {% if interfaces and perms.virtualization.change_vminterface %}
                         <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
                         </button>
                     {% 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">
                             <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
                         </button>
                     {% endif %}
-                    {% if perms.dcim.add_interface %}
+                    {% if perms.virtualization.add_vminterface %}
                         <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">
                                 <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add interfaces
@@ -317,7 +312,7 @@
                  </div>
             {% endif %}
         </div>
-        {% if perms.dcim.delete_interface %}
+        {% if perms.virtualization.delete_vminterface %}
             </form>
         {% endif %}
 	</div>