Changes to allow import of interfaces and show descriptions inline in interface...some work on description column display

This commit is contained in:
Joseph Kennedy 2017-08-01 16:51:42 -04:00
parent 52a490bf5d
commit 1a8913f625
7 changed files with 76 additions and 0 deletions

View File

@ -1696,6 +1696,41 @@ class InterfaceConnectionCSVForm(forms.ModelForm):
return interface
class InterfaceCSVForm(forms.ModelForm):
device = FlexibleModelChoiceField(
queryset=Device.objects.all(),
to_field_name='name',
help_text='Name or ID of device',
error_messages={'invalid_choice': 'Device not found.'}
)
name = forms.CharField(
help_text='Name of interface'
)
mac_address = forms.CharField(
required=False,
help_text='MAC address of interface'
)
description = forms.CharField(
required=False,
help_text='Description for interface'
)
class Meta:
model = Interface
fields = [
'device', 'name', 'mac_address', 'description'
]
def clean_interface(self):
interface_name = self.cleaned_data.get('interface_name')
if not interface:
return None
return interface
class InterfaceConnectionDeletionForm(ConfirmationForm):
# Used for HTTP redirect upon successful deletion
device = forms.ModelChoiceField(queryset=Device.objects.all(), widget=forms.HiddenInput(), required=False)

View File

@ -1233,6 +1233,17 @@ class Interface(models.Model):
pass
return None
# Used for export
def to_csv(self):
return csv_format([
self.device.identifier,
self.lag,
self.name,
self.mac,
self.form_factor,
self.description,
])
class InterfaceConnection(models.Model):
"""

View File

@ -523,3 +523,16 @@ class InterfaceConnectionTable(BaseTable):
class Meta(BaseTable.Meta):
model = Interface
fields = ('device_a', 'interface_a', 'device_b', 'interface_b')
class InterfaceImportTable(BaseTable):
device = tables.LinkColumn('dcim:device', accessor=Accessor('interface.device'),
args=[Accessor('interface.device.pk')], verbose_name='Device')
name = tables.Column(verbose_name='Interface')
form_factor = tables.Column(verbose_name='Form Factor')
mac_address = tables.Column(verbose_name='MAC Address')
description = tables.Column(verbose_name='Description')
class Meta(BaseTable.Meta):
model = Interface
fields = ('device', 'name', 'form_factor','mac_address', 'description')

View File

@ -177,6 +177,7 @@ urlpatterns = [
url(r'^interface-connections/(?P<pk>\d+)/delete/$', views.interfaceconnection_delete, name='interfaceconnection_delete'),
url(r'^interfaces/(?P<pk>\d+)/edit/$', views.InterfaceEditView.as_view(), name='interface_edit'),
url(r'^interfaces/(?P<pk>\d+)/delete/$', views.InterfaceDeleteView.as_view(), name='interface_delete'),
url(r'^interfaces/import/$', views.InterfacesBulkImportView.as_view(), name='interfaces_import'),
# Device bays
url(r'^devices/device-bays/add/$', views.DeviceBulkAddDeviceBayView.as_view(), name='device_bulk_add_devicebay'),

View File

@ -85,6 +85,9 @@
<li><a href="{% url 'dcim:device_add' %}"><i class="fa fa-plus" aria-hidden="true"></i> Add a Device</a></li>
<li><a href="{% url 'dcim:device_import' %}"><i class="fa fa-download" aria-hidden="true"></i> Import Devices</a></li>
{% endif %}
{% if perms.dcim.add_interface %}
<li><a href="{% url 'dcim:interfaces_import' %}"><i class="fa fa-download" aria-hidden="true"></i> Import Interfaces</a></li>
{% endif %}
{% if perms.ipam.add_device or perms.ipam.add_devicetype %}
<li class="divider"></li>
{% endif %}

View File

@ -374,6 +374,14 @@
<input type="hidden" name="device" value="{{ device.pk }}" />
{% endif %}
<div class="panel panel-default">
<div class="pull-right">
{% if perms.dcim.add_interface %}
<a href="{% url 'dcim:interfaces_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import Interfaces
</a>
{% endif %}
{% include 'inc/export_button.html' with obj_type='interfaces' %}
<div class="panel-heading">
<strong>Interfaces</strong>
<div class="pull-right">

View File

@ -13,6 +13,11 @@
{% if iface.description %}
<i class="fa fa-fw fa-comment-o" title="{{ iface.description }}"></i>
{% endif %}
<td>
{% if iface.description %}
<span title="{{ iface.description }}">{{ iface.description }}</span>
{% endif %}
</td>
</td>
<td>{{ iface.mtu|default:"" }}</td>
<td>{{ iface.mac_address|default:"" }}</td>