Skip to content

Commit

Permalink
Merge pull request #459 from digitalocean/develop
Browse files Browse the repository at this point in the history
Release v1.5.1
  • Loading branch information
jeremystretch authored Aug 11, 2016
2 parents 2509405 + 0b4d344 commit 6a48b31
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 44 deletions.
3 changes: 2 additions & 1 deletion docs/installation/netbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ NetBox requires following system dependencies:
* libffi-dev
* graphviz
* libpq-dev
* libssl-dev

```
# sudo apt-get install -y python2.7 python-dev git python-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev
# sudo apt-get install -y python2.7 python-dev python-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev
```

You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub.
Expand Down
3 changes: 2 additions & 1 deletion netbox/dcim/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class DeviceAdmin(admin.ModelAdmin):
DeviceBayAdmin,
ModuleAdmin,
]
list_display = ['display_name', 'device_type', 'device_role', 'primary_ip', 'rack', 'position', 'serial']
list_display = ['display_name', 'device_type', 'device_role', 'primary_ip', 'rack', 'position', 'asset_tag',
'serial']
list_filter = ['device_role']

def get_queryset(self, request):
Expand Down
5 changes: 3 additions & 2 deletions netbox/dcim/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ class DeviceSerializer(serializers.ModelSerializer):

class Meta:
model = Device
fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'tenant', 'platform', 'serial', 'rack',
'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4', 'primary_ip6', 'comments']
fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'tenant', 'platform', 'serial',
'asset_tag', 'rack', 'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4',
'primary_ip6', 'comments']

def get_parent_device(self, obj):
try:
Expand Down
11 changes: 6 additions & 5 deletions netbox/dcim/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,16 @@ class DeviceFilter(django_filters.FilterSet):

class Meta:
model = Device
fields = ['q', 'name', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id', 'manufacturer_id',
'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server', 'is_pdu',
'is_network_device']
fields = ['q', 'name', 'serial', 'asset_tag', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id',
'manufacturer_id', 'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server',
'is_pdu', 'is_network_device']

def search(self, queryset, value):
return queryset.filter(
Q(name__icontains=value) |
Q(serial__icontains=value) |
Q(modules__serial__icontains=value) |
Q(serial__icontains=value.strip()) |
Q(modules__serial__icontains=value.strip()) |
Q(asset_tag=value.strip()) |
Q(comments__icontains=value)
).distinct()

Expand Down
12 changes: 6 additions & 6 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ class DeviceForm(forms.ModelForm, BootstrapMixin):

class Meta:
model = Device
fields = ['name', 'device_role', 'tenant', 'device_type', 'serial', 'site', 'rack', 'position', 'face', 'status',
'platform', 'primary_ip4', 'primary_ip6', 'comments']
fields = ['name', 'device_role', 'tenant', 'device_type', 'serial', 'asset_tag', 'site', 'rack', 'position',
'face', 'status', 'platform', 'primary_ip4', 'primary_ip6', 'comments']
help_texts = {
'device_role': "The function this device serves",
'serial': "Chassis serial number",
Expand Down Expand Up @@ -546,8 +546,8 @@ class DeviceFromCSVForm(BaseDeviceFromCSVForm):
face = forms.CharField(required=False)

class Meta(BaseDeviceFromCSVForm.Meta):
fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'site',
'rack_name', 'position', 'face']
fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag',
'site', 'rack_name', 'position', 'face']

def clean(self):

Expand Down Expand Up @@ -582,8 +582,8 @@ class ChildDeviceFromCSVForm(BaseDeviceFromCSVForm):
device_bay_name = forms.CharField(required=False)

class Meta(BaseDeviceFromCSVForm.Meta):
fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'parent',
'device_bay_name']
fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag',
'parent', 'device_bay_name']

def clean(self):

Expand Down
21 changes: 21 additions & 0 deletions netbox/dcim/migrations/0018_device_add_asset_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-11 15:42
from __future__ import unicode_literals

from django.db import migrations
import utilities.fields


class Migration(migrations.Migration):

dependencies = [
('dcim', '0017_rack_add_role'),
]

operations = [
migrations.AddField(
model_name='device',
name='asset_tag',
field=utilities.fields.NullableCharField(blank=True, help_text=b'A unique tag used to identify this device', max_length=50, null=True, unique=True, verbose_name=b'Asset tag'),
),
]
5 changes: 4 additions & 1 deletion netbox/dcim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def to_csv(self):
self.tenant.name if self.tenant else '',
self.role.name if self.role else '',
self.get_type_display() if self.type else '',
self.width,
str(self.width),
str(self.u_height),
])

Expand Down Expand Up @@ -737,6 +737,8 @@ class Device(CreatedUpdatedModel):
platform = models.ForeignKey('Platform', related_name='devices', blank=True, null=True, on_delete=models.SET_NULL)
name = NullableCharField(max_length=50, blank=True, null=True, unique=True)
serial = models.CharField(max_length=50, blank=True, verbose_name='Serial number')
asset_tag = NullableCharField(max_length=50, blank=True, null=True, unique=True, verbose_name='Asset tag',
help_text='A unique tag used to identify this device')
rack = models.ForeignKey('Rack', related_name='devices', on_delete=models.PROTECT)
position = models.PositiveSmallIntegerField(blank=True, null=True, validators=[MinValueValidator(1)],
verbose_name='Position (U)',
Expand Down Expand Up @@ -832,6 +834,7 @@ def to_csv(self):
self.device_type.model,
self.platform.name if self.platform else '',
self.serial,
self.asset_tag if self.asset_tag else '',
self.rack.site.name,
self.rack.name,
str(self.position) if self.position else '',
Expand Down
26 changes: 21 additions & 5 deletions netbox/dcim/tables.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import django_tables2 as tables
from django_tables2.utils import Accessor

from utilities.tables import BaseTable, ColorColumn, ToggleColumn
from utilities.tables import BaseTable, ToggleColumn

from .models import (
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
Expand All @@ -10,6 +10,10 @@
)


COLOR_LABEL = """
<label class="label {{ record.color }}">{{ record }}</label>
"""

DEVICE_LINK = """
<a href="{% url 'dcim:device' pk=record.pk %}">
{{ record.name|default:'<span class="label label-info">Unnamed device</span>' }}
Expand All @@ -28,6 +32,14 @@
{% endif %}
"""

RACK_ROLE = """
{% if record.role %}
<label class="label {{ record.role.color }}">{{ value }}</label>
{% else %}
&mdash;
{% endif %}
"""

DEVICEROLE_ACTIONS = """
{% if perms.dcim.change_devicerole %}
<a href="{% url 'dcim:devicerole_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
Expand All @@ -46,6 +58,10 @@
{% endif %}
"""

DEVICE_ROLE = """
<label class="label {{ record.device_role.color }}">{{ value }}</label>
"""

STATUS_ICON = """
{% if record.status %}
<span class="glyphicon glyphicon-ok-sign text-success" title="Active" aria-hidden="true"></span>
Expand Down Expand Up @@ -108,7 +124,7 @@ class RackRoleTable(BaseTable):
pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Name')
rack_count = tables.Column(verbose_name='Racks')
color = ColorColumn(verbose_name='Color')
color = tables.TemplateColumn(COLOR_LABEL, verbose_name='Color')
slug = tables.Column(verbose_name='Slug')
actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
verbose_name='')
Expand All @@ -129,7 +145,7 @@ class RackTable(BaseTable):
group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group')
facility_id = tables.Column(verbose_name='Facility ID')
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
role = tables.Column(verbose_name='Role')
role = tables.TemplateColumn(RACK_ROLE, verbose_name='Role')
u_height = tables.TemplateColumn("{{ record.u_height }}U", verbose_name='Height')
devices = tables.Column(accessor=Accessor('device_count'), verbose_name='Devices')
u_consumed = tables.TemplateColumn("{{ record.u_consumed|default:'0' }}U", verbose_name='Used')
Expand Down Expand Up @@ -258,7 +274,7 @@ class DeviceRoleTable(BaseTable):
pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Name')
device_count = tables.Column(verbose_name='Devices')
color = ColorColumn(verbose_name='Color')
color = tables.TemplateColumn(COLOR_LABEL, verbose_name='Color')
slug = tables.Column(verbose_name='Slug')
actions = tables.TemplateColumn(template_code=DEVICEROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
verbose_name='')
Expand Down Expand Up @@ -295,7 +311,7 @@ class DeviceTable(BaseTable):
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
site = tables.Column(accessor=Accessor('rack.site'), verbose_name='Site')
rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')], verbose_name='Rack')
device_role = tables.Column(verbose_name='Role')
device_role = tables.TemplateColumn(DEVICE_ROLE, verbose_name='Role')
device_type = tables.Column(verbose_name='Type')
primary_ip = tables.TemplateColumn(orderable=False, verbose_name='IP Address',
template_code="{{ record.primary_ip.address.ip }}")
Expand Down
2 changes: 2 additions & 0 deletions netbox/dcim/tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ class DeviceTest(APITestCase):
'tenant',
'platform',
'serial',
'asset_tag',
'rack',
'position',
'face',
Expand Down Expand Up @@ -370,6 +371,7 @@ def test_get_list(self, endpoint='/api/dcim/devices/'):
def test_get_list_flat(self, endpoint='/api/dcim/devices/?format=json_flat'):

flat_fields = [
'asset_tag',
'comments',
'device_role_id',
'device_role_name',
Expand Down
2 changes: 1 addition & 1 deletion netbox/netbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"the documentation.")


VERSION = '1.5.0'
VERSION = '1.5.1'

# Import local configuration
for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:
Expand Down
14 changes: 12 additions & 2 deletions netbox/templates/dcim/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</td>
</tr>
<tr>
<td>Serial</td>
<td>Serial Number</td>
<td>
{% if device.serial %}
<span>{{ device.serial }}</span>
Expand All @@ -69,6 +69,16 @@
{% endif %}
</td>
</tr>
<tr>
<td>Asset Tag</td>
<td>
{% if device.asset_tag %}
<span>{{ device.asset_tag }}</span>
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
</tr>
<tr>
<td>Created</td>
<td>{{ device.created }}</td>
Expand All @@ -87,7 +97,7 @@
<tr>
<td>Role</td>
<td>
<a href="{% url 'dcim:device_list' %}?role={{ device.device_role.slug }}">{{ device.device_role }}</a>
<a href="{{ device.device_role.get_absolute_url }}">{{ device.device_role }}</a>
</td>
</tr>
<tr>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/dcim/device_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{% render_field form.manufacturer %}
{% render_field form.device_type %}
{% render_field form.serial %}
{% render_field form.asset_tag %}
</div>
</div>
<div class="panel panel-default">
Expand Down
11 changes: 8 additions & 3 deletions netbox/templates/dcim/device_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ <h4>CSV Format</h4>
<td>Juniper Junos</td>
</tr>
<tr>
<td>Serial</td>
<td>Serial number (optional)</td>
<td>Serial number</td>
<td>Physical serial number (optional)</td>
<td>CAB00577291</td>
</tr>
<tr>
<td>Asset tag</td>
<td>Unique alphanumeric tag (optional)</td>
<td>ABC123456</td>
</tr>
<tr>
<td>Site</td>
<td>Site name</td>
Expand All @@ -84,7 +89,7 @@ <h4>CSV Format</h4>
</tbody>
</table>
<h4>Example</h4>
<pre>rack101_sw1,ToR Switch,Pied Piper,Juniper,EX4300-48T,Juniper Junos,CAB00577291,Ashburn-VA,R101,21,Rear</pre>
<pre>rack101_sw1,ToR Switch,Pied Piper,Juniper,EX4300-48T,Juniper Junos,CAB00577291,ABC123456,Ashburn-VA,R101,21,Rear</pre>
</div>
</div>
{% endblock %}
11 changes: 8 additions & 3 deletions netbox/templates/dcim/device_import_child.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ <h4>CSV Format</h4>
<td>Linux</td>
</tr>
<tr>
<td>Serial</td>
<td>Serial number (optional)</td>
<td>Serial number</td>
<td>Physical serial number (optional)</td>
<td>CAB00577291</td>
</tr>
<tr>
<td>Asset tag</td>
<td>Unique alphanumeric tag (optional)</td>
<td>ABC123456</td>
</tr>
<tr>
<td>Parent device</td>
<td>Parent device</td>
Expand All @@ -74,7 +79,7 @@ <h4>CSV Format</h4>
</tbody>
</table>
<h4>Example</h4>
<pre>Blade12,Blade Server,Pied Piper,Dell,BS2000T,Linux,CAB00577291,Server101,Slot4</pre>
<pre>Blade12,Blade Server,Pied Piper,Dell,BS2000T,Linux,CAB00577291,ABC123456,Server101,Slot4</pre>
</div>
</div>
{% endblock %}
18 changes: 17 additions & 1 deletion netbox/templates/dcim/device_inventory.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
</tr>
<tr>
<td>Serial Number</td>
<td>{{ device.serial }}</td>
<td>
{% if device.serial %}
<span>{{ device.serial }}</span>
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
</tr>
<tr>
<td>Asset Tag</td>
<td>
{% if device.asset_tag %}
<span>{{ device.asset_tag }}</span>
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
</tr>
</table>
</div>
Expand Down
10 changes: 10 additions & 0 deletions netbox/templates/dcim/rack.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ <h1>Rack {{ rack.name }}</h1>
{% endif %}
</td>
</tr>
<tr>
<td>Role</td>
<td>
{% if rack.role %}
<a href="{{ rack.role.get_absolute_url }}">{{ rack.role }}</a>
{% else %}
<span class="text-muted">None</span>
{% endif %}
</td>
</tr>
<tr>
<td>Type</td>
<td>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/dcim/rack_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{% render_field form.name %}
{% render_field form.facility_id %}
{% render_field form.tenant %}
{% render_field form.role %}
{% render_field form.type %}
{% render_field form.width %}
{% render_field form.u_height %}
Expand Down
Loading

0 comments on commit 6a48b31

Please sign in to comment.