Merge pull request #459 from digitalocean/develop

Release v1.5.1
This commit is contained in:
Jeremy Stretch 2016-08-11 13:53:34 -04:00 committed by GitHub
commit 6a48b310d2
19 changed files with 145 additions and 44 deletions

View File

@ -10,9 +10,10 @@ NetBox requires following system dependencies:
* libffi-dev * libffi-dev
* graphviz * graphviz
* libpq-dev * 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. You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub.

View File

@ -183,7 +183,8 @@ class DeviceAdmin(admin.ModelAdmin):
DeviceBayAdmin, DeviceBayAdmin,
ModuleAdmin, 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'] list_filter = ['device_role']
def get_queryset(self, request): def get_queryset(self, request):

View File

@ -250,8 +250,9 @@ class DeviceSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Device model = Device
fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'tenant', 'platform', 'serial', 'rack', fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'tenant', 'platform', 'serial',
'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4', 'primary_ip6', 'comments'] 'asset_tag', 'rack', 'position', 'face', 'parent_device', 'status', 'primary_ip', 'primary_ip4',
'primary_ip6', 'comments']
def get_parent_device(self, obj): def get_parent_device(self, obj):
try: try:

View File

@ -239,15 +239,16 @@ class DeviceFilter(django_filters.FilterSet):
class Meta: class Meta:
model = Device model = Device
fields = ['q', 'name', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id', 'manufacturer_id', fields = ['q', 'name', 'serial', 'asset_tag', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id',
'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server', 'is_pdu', 'manufacturer_id', 'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server',
'is_network_device'] 'is_pdu', 'is_network_device']
def search(self, queryset, value): def search(self, queryset, value):
return queryset.filter( return queryset.filter(
Q(name__icontains=value) | Q(name__icontains=value) |
Q(serial__icontains=value) | Q(serial__icontains=value.strip()) |
Q(modules__serial__icontains=value) | Q(modules__serial__icontains=value.strip()) |
Q(asset_tag=value.strip()) |
Q(comments__icontains=value) Q(comments__icontains=value)
).distinct() ).distinct()

View File

@ -425,8 +425,8 @@ class DeviceForm(forms.ModelForm, BootstrapMixin):
class Meta: class Meta:
model = Device model = Device
fields = ['name', 'device_role', 'tenant', 'device_type', 'serial', 'site', 'rack', 'position', 'face', 'status', fields = ['name', 'device_role', 'tenant', 'device_type', 'serial', 'asset_tag', 'site', 'rack', 'position',
'platform', 'primary_ip4', 'primary_ip6', 'comments'] 'face', 'status', 'platform', 'primary_ip4', 'primary_ip6', 'comments']
help_texts = { help_texts = {
'device_role': "The function this device serves", 'device_role': "The function this device serves",
'serial': "Chassis serial number", 'serial': "Chassis serial number",
@ -546,8 +546,8 @@ class DeviceFromCSVForm(BaseDeviceFromCSVForm):
face = forms.CharField(required=False) face = forms.CharField(required=False)
class Meta(BaseDeviceFromCSVForm.Meta): class Meta(BaseDeviceFromCSVForm.Meta):
fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'site', fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag',
'rack_name', 'position', 'face'] 'site', 'rack_name', 'position', 'face']
def clean(self): def clean(self):
@ -582,8 +582,8 @@ class ChildDeviceFromCSVForm(BaseDeviceFromCSVForm):
device_bay_name = forms.CharField(required=False) device_bay_name = forms.CharField(required=False)
class Meta(BaseDeviceFromCSVForm.Meta): class Meta(BaseDeviceFromCSVForm.Meta):
fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'parent', fields = ['name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag',
'device_bay_name'] 'parent', 'device_bay_name']
def clean(self): def clean(self):

View File

@ -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'),
),
]

View File

@ -373,7 +373,7 @@ class Rack(CreatedUpdatedModel):
self.tenant.name if self.tenant else '', self.tenant.name if self.tenant else '',
self.role.name if self.role else '', self.role.name if self.role else '',
self.get_type_display() if self.type else '', self.get_type_display() if self.type else '',
self.width, str(self.width),
str(self.u_height), str(self.u_height),
]) ])
@ -737,6 +737,8 @@ class Device(CreatedUpdatedModel):
platform = models.ForeignKey('Platform', related_name='devices', blank=True, null=True, on_delete=models.SET_NULL) 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) name = NullableCharField(max_length=50, blank=True, null=True, unique=True)
serial = models.CharField(max_length=50, blank=True, verbose_name='Serial number') 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) rack = models.ForeignKey('Rack', related_name='devices', on_delete=models.PROTECT)
position = models.PositiveSmallIntegerField(blank=True, null=True, validators=[MinValueValidator(1)], position = models.PositiveSmallIntegerField(blank=True, null=True, validators=[MinValueValidator(1)],
verbose_name='Position (U)', verbose_name='Position (U)',
@ -832,6 +834,7 @@ class Device(CreatedUpdatedModel):
self.device_type.model, self.device_type.model,
self.platform.name if self.platform else '', self.platform.name if self.platform else '',
self.serial, self.serial,
self.asset_tag if self.asset_tag else '',
self.rack.site.name, self.rack.site.name,
self.rack.name, self.rack.name,
str(self.position) if self.position else '', str(self.position) if self.position else '',

View File

@ -1,7 +1,7 @@
import django_tables2 as tables import django_tables2 as tables
from django_tables2.utils import Accessor from django_tables2.utils import Accessor
from utilities.tables import BaseTable, ColorColumn, ToggleColumn from utilities.tables import BaseTable, ToggleColumn
from .models import ( from .models import (
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType, ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
@ -10,6 +10,10 @@ from .models import (
) )
COLOR_LABEL = """
<label class="label {{ record.color }}">{{ record }}</label>
"""
DEVICE_LINK = """ DEVICE_LINK = """
<a href="{% url 'dcim:device' pk=record.pk %}"> <a href="{% url 'dcim:device' pk=record.pk %}">
{{ record.name|default:'<span class="label label-info">Unnamed device</span>' }} {{ record.name|default:'<span class="label label-info">Unnamed device</span>' }}
@ -28,6 +32,14 @@ RACKROLE_ACTIONS = """
{% endif %} {% endif %}
""" """
RACK_ROLE = """
{% if record.role %}
<label class="label {{ record.role.color }}">{{ value }}</label>
{% else %}
&mdash;
{% endif %}
"""
DEVICEROLE_ACTIONS = """ DEVICEROLE_ACTIONS = """
{% if perms.dcim.change_devicerole %} {% 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> <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>
@ -46,6 +58,10 @@ PLATFORM_ACTIONS = """
{% endif %} {% endif %}
""" """
DEVICE_ROLE = """
<label class="label {{ record.device_role.color }}">{{ value }}</label>
"""
STATUS_ICON = """ STATUS_ICON = """
{% if record.status %} {% if record.status %}
<span class="glyphicon glyphicon-ok-sign text-success" title="Active" aria-hidden="true"></span> <span class="glyphicon glyphicon-ok-sign text-success" title="Active" aria-hidden="true"></span>
@ -108,7 +124,7 @@ class RackRoleTable(BaseTable):
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Name') name = tables.LinkColumn(verbose_name='Name')
rack_count = tables.Column(verbose_name='Racks') 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') slug = tables.Column(verbose_name='Slug')
actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right'}}, actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
verbose_name='') verbose_name='')
@ -129,7 +145,7 @@ class RackTable(BaseTable):
group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group') group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group')
facility_id = tables.Column(verbose_name='Facility ID') facility_id = tables.Column(verbose_name='Facility ID')
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant') 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') u_height = tables.TemplateColumn("{{ record.u_height }}U", verbose_name='Height')
devices = tables.Column(accessor=Accessor('device_count'), verbose_name='Devices') devices = tables.Column(accessor=Accessor('device_count'), verbose_name='Devices')
u_consumed = tables.TemplateColumn("{{ record.u_consumed|default:'0' }}U", verbose_name='Used') u_consumed = tables.TemplateColumn("{{ record.u_consumed|default:'0' }}U", verbose_name='Used')
@ -258,7 +274,7 @@ class DeviceRoleTable(BaseTable):
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Name') name = tables.LinkColumn(verbose_name='Name')
device_count = tables.Column(verbose_name='Devices') 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') slug = tables.Column(verbose_name='Slug')
actions = tables.TemplateColumn(template_code=DEVICEROLE_ACTIONS, attrs={'td': {'class': 'text-right'}}, actions = tables.TemplateColumn(template_code=DEVICEROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
verbose_name='') verbose_name='')
@ -295,7 +311,7 @@ class DeviceTable(BaseTable):
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant') tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
site = tables.Column(accessor=Accessor('rack.site'), verbose_name='Site') site = tables.Column(accessor=Accessor('rack.site'), verbose_name='Site')
rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')], verbose_name='Rack') 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') device_type = tables.Column(verbose_name='Type')
primary_ip = tables.TemplateColumn(orderable=False, verbose_name='IP Address', primary_ip = tables.TemplateColumn(orderable=False, verbose_name='IP Address',
template_code="{{ record.primary_ip.address.ip }}") template_code="{{ record.primary_ip.address.ip }}")

View File

@ -327,6 +327,7 @@ class DeviceTest(APITestCase):
'tenant', 'tenant',
'platform', 'platform',
'serial', 'serial',
'asset_tag',
'rack', 'rack',
'position', 'position',
'face', 'face',
@ -370,6 +371,7 @@ class DeviceTest(APITestCase):
def test_get_list_flat(self, endpoint='/api/dcim/devices/?format=json_flat'): def test_get_list_flat(self, endpoint='/api/dcim/devices/?format=json_flat'):
flat_fields = [ flat_fields = [
'asset_tag',
'comments', 'comments',
'device_role_id', 'device_role_id',
'device_role_name', 'device_role_name',

View File

@ -12,7 +12,7 @@ except ImportError:
"the documentation.") "the documentation.")
VERSION = '1.5.0' VERSION = '1.5.1'
# Import local configuration # Import local configuration
for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']: for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:

View File

@ -60,7 +60,7 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Serial</td> <td>Serial Number</td>
<td> <td>
{% if device.serial %} {% if device.serial %}
<span>{{ device.serial }}</span> <span>{{ device.serial }}</span>
@ -69,6 +69,16 @@
{% endif %} {% endif %}
</td> </td>
</tr> </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> <tr>
<td>Created</td> <td>Created</td>
<td>{{ device.created }}</td> <td>{{ device.created }}</td>
@ -87,7 +97,7 @@
<tr> <tr>
<td>Role</td> <td>Role</td>
<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> </td>
</tr> </tr>
<tr> <tr>

View File

@ -16,6 +16,7 @@
{% render_field form.manufacturer %} {% render_field form.manufacturer %}
{% render_field form.device_type %} {% render_field form.device_type %}
{% render_field form.serial %} {% render_field form.serial %}
{% render_field form.asset_tag %}
</div> </div>
</div> </div>
<div class="panel panel-default"> <div class="panel panel-default">

View File

@ -57,10 +57,15 @@
<td>Juniper Junos</td> <td>Juniper Junos</td>
</tr> </tr>
<tr> <tr>
<td>Serial</td> <td>Serial number</td>
<td>Serial number (optional)</td> <td>Physical serial number (optional)</td>
<td>CAB00577291</td> <td>CAB00577291</td>
</tr> </tr>
<tr>
<td>Asset tag</td>
<td>Unique alphanumeric tag (optional)</td>
<td>ABC123456</td>
</tr>
<tr> <tr>
<td>Site</td> <td>Site</td>
<td>Site name</td> <td>Site name</td>
@ -84,7 +89,7 @@
</tbody> </tbody>
</table> </table>
<h4>Example</h4> <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>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -57,10 +57,15 @@
<td>Linux</td> <td>Linux</td>
</tr> </tr>
<tr> <tr>
<td>Serial</td> <td>Serial number</td>
<td>Serial number (optional)</td> <td>Physical serial number (optional)</td>
<td>CAB00577291</td> <td>CAB00577291</td>
</tr> </tr>
<tr>
<td>Asset tag</td>
<td>Unique alphanumeric tag (optional)</td>
<td>ABC123456</td>
</tr>
<tr> <tr>
<td>Parent device</td> <td>Parent device</td>
<td>Parent device</td> <td>Parent device</td>
@ -74,7 +79,7 @@
</tbody> </tbody>
</table> </table>
<h4>Example</h4> <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>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -17,7 +17,23 @@
</tr> </tr>
<tr> <tr>
<td>Serial Number</td> <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> </tr>
</table> </table>
</div> </div>

View File

@ -96,6 +96,16 @@
{% endif %} {% endif %}
</td> </td>
</tr> </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> <tr>
<td>Type</td> <td>Type</td>
<td> <td>

View File

@ -10,6 +10,7 @@
{% render_field form.name %} {% render_field form.name %}
{% render_field form.facility_id %} {% render_field form.facility_id %}
{% render_field form.tenant %} {% render_field form.tenant %}
{% render_field form.role %}
{% render_field form.type %} {% render_field form.type %}
{% render_field form.width %} {% render_field form.width %}
{% render_field form.u_height %} {% render_field form.u_height %}

View File

@ -3,9 +3,9 @@
{% block content %} {% block content %}
<div class="row home-search" style="padding: 15px 0px 20px"> <div class="row home-search" style="padding: 15px 0px 20px">
<div class="col-md-4"> <div class="col-md-3">
<form action="{% url 'dcim:device_list' %}" method="get"> <form action="{% url 'dcim:device_list' %}" method="get">
<div class="input-group input-group-lg"> <div class="input-group">
<input type="text" name="q" placeholder="Search devices" class="form-control" /> <input type="text" name="q" placeholder="Search devices" class="form-control" />
<span class="input-group-btn"> <span class="input-group-btn">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">
@ -17,9 +17,9 @@
</form> </form>
<p></p> <p></p>
</div> </div>
<div class="col-md-4"> <div class="col-md-3">
<form action="{% url 'ipam:prefix_list' %}" method="get"> <form action="{% url 'ipam:prefix_list' %}" method="get">
<div class="input-group input-group-lg"> <div class="input-group">
<input type="text" name="q" placeholder="Search prefixes" class="form-control" /> <input type="text" name="q" placeholder="Search prefixes" class="form-control" />
<span class="input-group-btn"> <span class="input-group-btn">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">
@ -31,9 +31,23 @@
</form> </form>
<p></p> <p></p>
</div> </div>
<div class="col-md-4"> <div class="col-md-3">
<form action="{% url 'ipam:ipaddress_list' %}" method="get">
<div class="input-group">
<input type="text" name="q" placeholder="Search IPs" class="form-control" />
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">
<span class="fa fa-search" aria-hidden="true"></span>
IPs
</button>
</span>
</div>
</form>
<p></p>
</div>
<div class="col-md-3">
<form action="{% url 'circuits:circuit_list' %}" method="get"> <form action="{% url 'circuits:circuit_list' %}" method="get">
<div class="input-group input-group-lg"> <div class="input-group">
<input type="text" name="q" placeholder="Search circuits" class="form-control" /> <input type="text" name="q" placeholder="Search circuits" class="form-control" />
<span class="input-group-btn"> <span class="input-group-btn">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">

View File

@ -28,10 +28,3 @@ class ToggleColumn(tables.CheckBoxColumn):
@property @property
def header(self): def header(self):
return mark_safe('<input type="checkbox" name="_all" title="Select all" />') return mark_safe('<input type="checkbox" name="_all" title="Select all" />')
class ColorColumn(tables.Column):
def render(self, record):
html = '<label class="label {}">{}</label>'.format(record.color, record.get_color_display())
return mark_safe(html)