1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #2643: Add description field to console/power components and device bays

This commit is contained in:
Jeremy Stretch
2019-02-20 14:34:05 -05:00
parent 0a06d92c2e
commit bb6fb81fc0
12 changed files with 181 additions and 54 deletions

View File

@ -13,6 +13,7 @@ the Config Context from being included in any results.
## Enhancements ## Enhancements
* [#2324](https://github.com/digitalocean/netbox/issues/2324) - Add color option for tags * [#2324](https://github.com/digitalocean/netbox/issues/2324) - Add color option for tags
* [#2643](https://github.com/digitalocean/netbox/issues/2643) - Add `description` field to console/power components and device bays
* [#2791](https://github.com/digitalocean/netbox/issues/2791) - Add a comment field for tags * [#2791](https://github.com/digitalocean/netbox/issues/2791) - Add a comment field for tags
--- ---

View File

@ -346,8 +346,8 @@ class ConsoleServerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer)
class Meta: class Meta:
model = ConsoleServerPort model = ConsoleServerPort
fields = [ fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable', 'id', 'device', 'name', 'description', 'connected_endpoint_type', 'connected_endpoint', 'connection_status',
'tags', 'cable', 'tags',
] ]
@ -359,8 +359,8 @@ class ConsolePortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
class Meta: class Meta:
model = ConsolePort model = ConsolePort
fields = [ fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable', 'id', 'device', 'name', 'description', 'connected_endpoint_type', 'connected_endpoint', 'connection_status',
'tags', 'cable', 'tags',
] ]
@ -372,8 +372,8 @@ class PowerOutletSerializer(TaggitSerializer, ConnectedEndpointSerializer):
class Meta: class Meta:
model = PowerOutlet model = PowerOutlet
fields = [ fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable', 'id', 'device', 'name', 'description', 'connected_endpoint_type', 'connected_endpoint', 'connection_status',
'tags', 'cable', 'tags',
] ]
@ -385,8 +385,8 @@ class PowerPortSerializer(TaggitSerializer, ConnectedEndpointSerializer):
class Meta: class Meta:
model = PowerPort model = PowerPort
fields = [ fields = [
'id', 'device', 'name', 'connected_endpoint_type', 'connected_endpoint', 'connection_status', 'cable', 'id', 'device', 'name', 'description', 'connected_endpoint_type', 'connected_endpoint', 'connection_status',
'tags', 'cable', 'tags',
] ]
@ -475,7 +475,7 @@ class DeviceBaySerializer(TaggitSerializer, ValidatedModelSerializer):
class Meta: class Meta:
model = DeviceBay model = DeviceBay
fields = ['id', 'device', 'name', 'installed_device', 'tags'] fields = ['id', 'device', 'name', 'description', 'installed_device', 'tags']
# #

View File

@ -689,7 +689,8 @@ class DeviceComponentFilterSet(django_filters.FilterSet):
if not value.strip(): if not value.strip():
return queryset return queryset
return queryset.filter( return queryset.filter(
Q(name__icontains=value) Q(name__icontains=value) |
Q(description__icontains=value)
) )
@ -702,7 +703,7 @@ class ConsolePortFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = ConsolePort model = ConsolePort
fields = ['name', 'connection_status'] fields = ['name', 'description', 'connection_status']
class ConsoleServerPortFilter(DeviceComponentFilterSet): class ConsoleServerPortFilter(DeviceComponentFilterSet):
@ -714,7 +715,7 @@ class ConsoleServerPortFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = ConsoleServerPort model = ConsoleServerPort
fields = ['name', 'connection_status'] fields = ['name', 'description', 'connection_status']
class PowerPortFilter(DeviceComponentFilterSet): class PowerPortFilter(DeviceComponentFilterSet):
@ -726,7 +727,7 @@ class PowerPortFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = PowerPort model = PowerPort
fields = ['name', 'connection_status'] fields = ['name', 'description', 'connection_status']
class PowerOutletFilter(DeviceComponentFilterSet): class PowerOutletFilter(DeviceComponentFilterSet):
@ -738,7 +739,7 @@ class PowerOutletFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = PowerOutlet model = PowerOutlet
fields = ['name', 'connection_status'] fields = ['name', 'description', 'connection_status']
class InterfaceFilter(django_filters.FilterSet): class InterfaceFilter(django_filters.FilterSet):
@ -793,13 +794,14 @@ class InterfaceFilter(django_filters.FilterSet):
class Meta: class Meta:
model = Interface model = Interface
fields = ['name', 'connection_status', 'form_factor', 'enabled', 'mtu', 'mgmt_only'] fields = ['name', 'connection_status', 'form_factor', 'enabled', 'mtu', 'mgmt_only', 'description']
def search(self, queryset, name, value): def search(self, queryset, name, value):
if not value.strip(): if not value.strip():
return queryset return queryset
return queryset.filter( return queryset.filter(
Q(name__icontains=value) Q(name__icontains=value) |
Q(description__icontains=value)
).distinct() ).distinct()
def filter_device(self, queryset, name, value): def filter_device(self, queryset, name, value):
@ -857,7 +859,7 @@ class FrontPortFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = FrontPort model = FrontPort
fields = ['name', 'type'] fields = ['name', 'type', 'description']
class RearPortFilter(DeviceComponentFilterSet): class RearPortFilter(DeviceComponentFilterSet):
@ -869,14 +871,14 @@ class RearPortFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = RearPort model = RearPort
fields = ['name', 'type'] fields = ['name', 'type', 'description']
class DeviceBayFilter(DeviceComponentFilterSet): class DeviceBayFilter(DeviceComponentFilterSet):
class Meta: class Meta:
model = DeviceBay model = DeviceBay
fields = ['name'] fields = ['name', 'description']
class InventoryItemFilter(DeviceComponentFilterSet): class InventoryItemFilter(DeviceComponentFilterSet):

View File

@ -1854,7 +1854,7 @@ class ConsolePortForm(BootstrapMixin, forms.ModelForm):
class Meta: class Meta:
model = ConsolePort model = ConsolePort
fields = [ fields = [
'device', 'name', 'tags', 'device', 'name', 'description', 'tags',
] ]
widgets = { widgets = {
'device': forms.HiddenInput(), 'device': forms.HiddenInput(),
@ -1865,6 +1865,10 @@ class ConsolePortCreateForm(ComponentForm):
name_pattern = ExpandableNameField( name_pattern = ExpandableNameField(
label='Name' label='Name'
) )
description = forms.CharField(
max_length=100,
required=False
)
tags = TagField( tags = TagField(
required=False required=False
) )
@ -1882,7 +1886,7 @@ class ConsoleServerPortForm(BootstrapMixin, forms.ModelForm):
class Meta: class Meta:
model = ConsoleServerPort model = ConsoleServerPort
fields = [ fields = [
'device', 'name', 'tags', 'device', 'name', 'description', 'tags',
] ]
widgets = { widgets = {
'device': forms.HiddenInput(), 'device': forms.HiddenInput(),
@ -1893,11 +1897,31 @@ class ConsoleServerPortCreateForm(ComponentForm):
name_pattern = ExpandableNameField( name_pattern = ExpandableNameField(
label='Name' label='Name'
) )
description = forms.CharField(
max_length=100,
required=False
)
tags = TagField( tags = TagField(
required=False required=False
) )
class ConsoleServerPortBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
pk = forms.ModelMultipleChoiceField(
queryset=ConsoleServerPort.objects.all(),
widget=forms.MultipleHiddenInput()
)
description = forms.CharField(
max_length=100,
required=False
)
class Meta:
nullable_fields = [
'description',
]
class ConsoleServerPortBulkRenameForm(BulkRenameForm): class ConsoleServerPortBulkRenameForm(BulkRenameForm):
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
queryset=ConsoleServerPort.objects.all(), queryset=ConsoleServerPort.objects.all(),
@ -1924,7 +1948,7 @@ class PowerPortForm(BootstrapMixin, forms.ModelForm):
class Meta: class Meta:
model = PowerPort model = PowerPort
fields = [ fields = [
'device', 'name', 'tags', 'device', 'name', 'description', 'tags',
] ]
widgets = { widgets = {
'device': forms.HiddenInput(), 'device': forms.HiddenInput(),
@ -1935,6 +1959,10 @@ class PowerPortCreateForm(ComponentForm):
name_pattern = ExpandableNameField( name_pattern = ExpandableNameField(
label='Name' label='Name'
) )
description = forms.CharField(
max_length=100,
required=False
)
tags = TagField( tags = TagField(
required=False required=False
) )
@ -1952,7 +1980,7 @@ class PowerOutletForm(BootstrapMixin, forms.ModelForm):
class Meta: class Meta:
model = PowerOutlet model = PowerOutlet
fields = [ fields = [
'device', 'name', 'tags', 'device', 'name', 'description', 'tags',
] ]
widgets = { widgets = {
'device': forms.HiddenInput(), 'device': forms.HiddenInput(),
@ -1963,11 +1991,31 @@ class PowerOutletCreateForm(ComponentForm):
name_pattern = ExpandableNameField( name_pattern = ExpandableNameField(
label='Name' label='Name'
) )
description = forms.CharField(
max_length=100,
required=False
)
tags = TagField( tags = TagField(
required=False required=False
) )
class PowerOutletBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
pk = forms.ModelMultipleChoiceField(
queryset=PowerOutlet.objects.all(),
widget=forms.MultipleHiddenInput()
)
description = forms.CharField(
max_length=100,
required=False
)
class Meta:
nullable_fields = [
'description',
]
class PowerOutletBulkRenameForm(BulkRenameForm): class PowerOutletBulkRenameForm(BulkRenameForm):
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
queryset=PowerOutlet.objects.all(), queryset=PowerOutlet.objects.all(),
@ -2776,7 +2824,7 @@ class DeviceBayForm(BootstrapMixin, forms.ModelForm):
class Meta: class Meta:
model = DeviceBay model = DeviceBay
fields = [ fields = [
'device', 'name', 'tags', 'device', 'name', 'description', 'tags',
] ]
widgets = { widgets = {
'device': forms.HiddenInput(), 'device': forms.HiddenInput(),

View File

@ -0,0 +1,38 @@
# Generated by Django 2.1.7 on 2019-02-20 18:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dcim', '0070_custom_tag_models'),
]
operations = [
migrations.AddField(
model_name='consoleport',
name='description',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='consoleserverport',
name='description',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='devicebay',
name='description',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='poweroutlet',
name='description',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='powerport',
name='description',
field=models.CharField(blank=True, max_length=100),
),
]

View File

@ -46,6 +46,10 @@ class ComponentTemplateModel(models.Model):
class ComponentModel(models.Model): class ComponentModel(models.Model):
description = models.CharField(
max_length=100,
blank=True
)
class Meta: class Meta:
abstract = True abstract = True
@ -1745,7 +1749,7 @@ class ConsolePort(CableTermination, ComponentModel):
objects = DeviceComponentManager() objects = DeviceComponentManager()
tags = TaggableManager(through=TaggedItem) tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name'] csv_headers = ['device', 'name', 'description']
class Meta: class Meta:
ordering = ['device', 'name'] ordering = ['device', 'name']
@ -1761,6 +1765,7 @@ class ConsolePort(CableTermination, ComponentModel):
return ( return (
self.device.identifier, self.device.identifier,
self.name, self.name,
self.description,
) )
@ -1788,7 +1793,7 @@ class ConsoleServerPort(CableTermination, ComponentModel):
objects = DeviceComponentManager() objects = DeviceComponentManager()
tags = TaggableManager(through=TaggedItem) tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name'] csv_headers = ['device', 'name', 'description']
class Meta: class Meta:
unique_together = ['device', 'name'] unique_together = ['device', 'name']
@ -1803,6 +1808,7 @@ class ConsoleServerPort(CableTermination, ComponentModel):
return ( return (
self.device.identifier, self.device.identifier,
self.name, self.name,
self.description,
) )
@ -1841,7 +1847,7 @@ class PowerPort(CableTermination, ComponentModel):
class Meta: class Meta:
ordering = ['device', 'name'] ordering = ['device', 'name']
unique_together = ['device', 'name'] unique_together = ['device', 'name', 'description']
def __str__(self): def __str__(self):
return self.name return self.name
@ -1853,6 +1859,7 @@ class PowerPort(CableTermination, ComponentModel):
return ( return (
self.device.identifier, self.device.identifier,
self.name, self.name,
self.description,
) )
@ -1883,7 +1890,7 @@ class PowerOutlet(CableTermination, ComponentModel):
csv_headers = ['device', 'name'] csv_headers = ['device', 'name']
class Meta: class Meta:
unique_together = ['device', 'name'] unique_together = ['device', 'name', 'description']
def __str__(self): def __str__(self):
return self.name return self.name
@ -1895,6 +1902,7 @@ class PowerOutlet(CableTermination, ComponentModel):
return ( return (
self.device.identifier, self.device.identifier,
self.name, self.name,
self.description,
) )
@ -1973,10 +1981,6 @@ class Interface(CableTermination, ComponentModel):
verbose_name='OOB Management', verbose_name='OOB Management',
help_text='This interface is used only for out-of-band management' help_text='This interface is used only for out-of-band management'
) )
description = models.CharField(
max_length=100,
blank=True
)
mode = models.PositiveSmallIntegerField( mode = models.PositiveSmallIntegerField(
choices=IFACE_MODE_CHOICES, choices=IFACE_MODE_CHOICES,
blank=True, blank=True,
@ -2193,10 +2197,6 @@ class FrontPort(CableTermination, ComponentModel):
default=1, default=1,
validators=[MinValueValidator(1), MaxValueValidator(64)] validators=[MinValueValidator(1), MaxValueValidator(64)]
) )
description = models.CharField(
max_length=100,
blank=True
)
objects = DeviceComponentManager() objects = DeviceComponentManager()
tags = TaggableManager(through=TaggedItem) tags = TaggableManager(through=TaggedItem)
@ -2259,10 +2259,6 @@ class RearPort(CableTermination, ComponentModel):
default=1, default=1,
validators=[MinValueValidator(1), MaxValueValidator(64)] validators=[MinValueValidator(1), MaxValueValidator(64)]
) )
description = models.CharField(
max_length=100,
blank=True
)
objects = DeviceComponentManager() objects = DeviceComponentManager()
tags = TaggableManager(through=TaggedItem) tags = TaggableManager(through=TaggedItem)
@ -2314,7 +2310,7 @@ class DeviceBay(ComponentModel):
objects = DeviceComponentManager() objects = DeviceComponentManager()
tags = TaggableManager(through=TaggedItem) tags = TaggableManager(through=TaggedItem)
csv_headers = ['device', 'name', 'installed_device'] csv_headers = ['device', 'name', 'installed_device', 'description']
class Meta: class Meta:
ordering = ['device', 'name'] ordering = ['device', 'name']
@ -2331,6 +2327,7 @@ class DeviceBay(ComponentModel):
self.device.identifier, self.device.identifier,
self.name, self.name,
self.installed_device.identifier if self.installed_device else None, self.installed_device.identifier if self.installed_device else None,
self.description,
) )
def clean(self): def clean(self):
@ -2400,10 +2397,6 @@ class InventoryItem(ComponentModel):
default=False, default=False,
verbose_name='Discovered' verbose_name='Discovered'
) )
description = models.CharField(
max_length=100,
blank=True
)
tags = TaggableManager(through=TaggedItem) tags = TaggableManager(through=TaggedItem)

View File

@ -445,6 +445,7 @@
{% endif %} {% endif %}
<th>Name</th> <th>Name</th>
<th>Status</th> <th>Status</th>
<th>Description</th>
<th colspan="2">Installed Device</th> <th colspan="2">Installed Device</th>
<th></th> <th></th>
</tr> </tr>
@ -570,6 +571,7 @@
<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>Description</th>
<th>Cable</th> <th>Cable</th>
<th colspan="2">Connection</th> <th colspan="2">Connection</th>
<th></th> <th></th>
@ -625,6 +627,7 @@
<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>Description</th>
<th>Cable</th> <th>Cable</th>
<th colspan="2">Connection</th> <th colspan="2">Connection</th>
<th></th> <th></th>

View File

@ -5,6 +5,11 @@
<i class="fa fa-fw fa-keyboard-o"></i> {{ cp }} <i class="fa fa-fw fa-keyboard-o"></i> {{ cp }}
</td> </td>
{# Description #}
<td>
{{ cp.description }}
</td>
{# Cable #} {# Cable #}
<td> <td>
{% if cp.cable %} {% if cp.cable %}

View File

@ -1,3 +1,5 @@
{% load helpers %}
<tr class="consoleserverport{% if csp.cable.status %} success{% elif csp.cable %} info{% endif %}"> <tr class="consoleserverport{% if csp.cable.status %} success{% elif csp.cable %} info{% endif %}">
{# Checkbox #} {# Checkbox #}
@ -12,12 +14,17 @@
<i class="fa fa-fw fa-keyboard-o"></i> {{ csp }} <i class="fa fa-fw fa-keyboard-o"></i> {{ csp }}
</td> </td>
{# Description #}
<td>
{{ csp.description|placeholder }}
</td>
{# Cable #} {# Cable #}
<td> <td>
{% if csp.cable %} {% if csp.cable %}
<a href="{{ csp.cable.get_absolute_url }}">{{ csp.cable }}</a> <a href="{{ csp.cable.get_absolute_url }}">{{ csp.cable }}</a>
{% else %} {% else %}
&mdash; <span class="text-muted">&mdash;</span>
{% endif %} {% endif %}
</td> </td>

View File

@ -1,16 +1,35 @@
{% load helpers %}
<tr class="devicebay"> <tr class="devicebay">
{% if perms.dcim.change_devicebay or perms.dcim.delete_devicebay %} {% if perms.dcim.change_devicebay or perms.dcim.delete_devicebay %}
<td class="pk"> <td class="pk">
<input name="pk" type="checkbox" value="{{ devicebay.pk }}" /> <input name="pk" type="checkbox" value="{{ devicebay.pk }}" />
</td> </td>
{% endif %} {% endif %}
{# Name #}
<td> <td>
<i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i> {{ devicebay.name }} <i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i> {{ devicebay.name }}
</td> </td>
{# Status #}
<td>
{% if devicebay.installed_device %}
<span class="label label-{{ devicebay.installed_device.get_status_class }}">
{{ devicebay.installed_device.get_status_display }}
</span>
{% else %}
<span class="label label-default">Vacant</span>
{% endif %}
</td>
{# Description #}
<td>
{{ devicebay.description|placeholder }}
</td>
{# Installed device #}
{% if devicebay.installed_device %} {% if devicebay.installed_device %}
<td>
<span class="label label-{{ devicebay.installed_device.get_status_class }}">{{ devicebay.installed_device.get_status_display }}</span>
</td>
<td> <td>
<a href="{% url 'dcim:device' pk=devicebay.installed_device.pk %}">{{ devicebay.installed_device }}</a> <a href="{% url 'dcim:device' pk=devicebay.installed_device.pk %}">{{ devicebay.installed_device }}</a>
</td> </td>
@ -18,11 +37,10 @@
<span>{{ devicebay.installed_device.device_type.display_name }}</span> <span>{{ devicebay.installed_device.device_type.display_name }}</span>
</td> </td>
{% else %} {% else %}
<td></td> <td colspan="2"></td>
<td colspan="2">
<span class="text-muted">Vacant</span>
</td>
{% endif %} {% endif %}
{# Actions #}
<td class="text-right"> <td class="text-right">
{% if perms.dcim.change_devicebay %} {% if perms.dcim.change_devicebay %}
{% if devicebay.installed_device %} {% if devicebay.installed_device %}

View File

@ -1,3 +1,5 @@
{% load helpers %}
<tr class="poweroutlet{% if po.cable.status %} success{% elif po.cable %} info{% endif %}"> <tr class="poweroutlet{% if po.cable.status %} success{% elif po.cable %} info{% endif %}">
{# Checkbox #} {# Checkbox #}
@ -12,12 +14,17 @@
<i class="fa fa-fw fa-bolt"></i> {{ po }} <i class="fa fa-fw fa-bolt"></i> {{ po }}
</td> </td>
{# Description #}
<td>
{{ po.description|placeholder }}
</td>
{# Cable #} {# Cable #}
<td> <td>
{% if po.cable %} {% if po.cable %}
<a href="{{ po.cable.get_absolute_url }}">{{ po.cable }}</a> <a href="{{ po.cable.get_absolute_url }}">{{ po.cable }}</a>
{% else %} {% else %}
&mdash; <span class="text-muted">&mdash;</span>
{% endif %} {% endif %}
</td> </td>

View File

@ -5,6 +5,11 @@
<i class="fa fa-fw fa-bolt"></i> {{ pp }} <i class="fa fa-fw fa-bolt"></i> {{ pp }}
</td> </td>
{# Description #}
<td>
{{ pp.description }}
</td>
{# Cable #} {# Cable #}
<td> <td>
{% if pp.cable %} {% if pp.cable %}