Skip to content

Commit

Permalink
Closes netbox-community#149: Added upstream_speed field to Circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Aug 8, 2016
1 parent d70aefa commit 377347d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 14 deletions.
4 changes: 2 additions & 2 deletions netbox/circuits/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class CircuitTypeAdmin(admin.ModelAdmin):

@admin.register(Circuit)
class CircuitAdmin(admin.ModelAdmin):
list_display = ['cid', 'provider', 'type', 'tenant', 'site', 'install_date', 'port_speed', 'commit_rate',
'xconnect_id']
list_display = ['cid', 'provider', 'type', 'tenant', 'site', 'install_date', 'port_speed_human',
'upstream_speed_human', 'commit_rate_human', 'xconnect_id']
list_filter = ['provider', 'type', 'tenant']
exclude = ['interface']

Expand Down
2 changes: 1 addition & 1 deletion netbox/circuits/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CircuitSerializer(serializers.ModelSerializer):
class Meta:
model = Circuit
fields = ['id', 'cid', 'provider', 'type', 'tenant', 'site', 'interface', 'install_date', 'port_speed',
'commit_rate', 'xconnect_id', 'comments']
'upstream_speed', 'commit_rate', 'xconnect_id', 'comments']


class CircuitNestedSerializer(CircuitSerializer):
Expand Down
6 changes: 3 additions & 3 deletions netbox/circuits/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Meta:
model = Circuit
fields = [
'cid', 'type', 'provider', 'tenant', 'site', 'rack', 'device', 'livesearch', 'interface', 'install_date',
'port_speed', 'commit_rate', 'xconnect_id', 'pp_info', 'comments'
'port_speed', 'upstream_speed', 'commit_rate', 'xconnect_id', 'pp_info', 'comments'
]
help_texts = {
'cid': "Unique circuit ID",
Expand Down Expand Up @@ -169,8 +169,8 @@ class CircuitFromCSVForm(forms.ModelForm):

class Meta:
model = Circuit
fields = ['cid', 'provider', 'type', 'tenant', 'site', 'install_date', 'port_speed', 'commit_rate',
'xconnect_id', 'pp_info']
fields = ['cid', 'provider', 'type', 'tenant', 'site', 'install_date', 'port_speed', 'upstream_speed',
'commit_rate', 'xconnect_id', 'pp_info']


class CircuitImportForm(BulkImportForm, BootstrapMixin):
Expand Down
20 changes: 20 additions & 0 deletions netbox/circuits/migrations/0005_circuit_add_upstream_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2016-08-08 20:24
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('circuits', '0004_circuit_add_tenant'),
]

operations = [
migrations.AddField(
model_name='circuit',
name='upstream_speed',
field=models.PositiveIntegerField(blank=True, help_text=b'Upstream speed, if different from port speed', null=True, verbose_name=b'Upstream speed (Kbps)'),
),
]
13 changes: 11 additions & 2 deletions netbox/circuits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class Circuit(CreatedUpdatedModel):
interface = models.OneToOneField(Interface, related_name='circuit', blank=True, null=True)
install_date = models.DateField(blank=True, null=True, verbose_name='Date installed')
port_speed = models.PositiveIntegerField(verbose_name='Port speed (Kbps)')
upstream_speed = models.PositiveIntegerField(blank=True, null=True, verbose_name='Upstream speed (Kbps)',
help_text='Upstream speed, if different from port speed')
commit_rate = models.PositiveIntegerField(blank=True, null=True, verbose_name='Commit rate (Kbps)')
xconnect_id = models.CharField(max_length=50, blank=True, verbose_name='Cross-connect ID')
pp_info = models.CharField(max_length=100, blank=True, verbose_name='Patch panel/port(s)')
Expand All @@ -96,6 +98,7 @@ def to_csv(self):
self.site.name,
self.install_date.isoformat() if self.install_date else '',
str(self.port_speed),
str(self.upstream_speed),
str(self.commit_rate) if self.commit_rate else '',
self.xconnect_id,
self.pp_info,
Expand All @@ -116,12 +119,18 @@ def _humanize_speed(self, speed):
else:
return '{} Kbps'.format(speed)

@property
def port_speed_human(self):
return self._humanize_speed(self.port_speed)
port_speed_human.admin_order_field = 'port_speed'

def upstream_speed_human(self):
if not self.upstream_speed:
return ''
return self._humanize_speed(self.upstream_speed)
upstream_speed_human.admin_order_field = 'upstream_speed'

@property
def commit_rate_human(self):
if not self.commit_rate:
return ''
return self._humanize_speed(self.commit_rate)
commit_rate_human.admin_order_field = 'commit_rate'
9 changes: 5 additions & 4 deletions netbox/templates/circuits/circuit.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ <h1>{{ circuit.provider }} - {{ circuit.cid }}</h1>
</td>
</tr>
<tr>
<td>Port Speed</td>
<td>Speed</td>
<td>
{% if circuit.port_speed %}
{{ circuit.port_speed_human }}
{% if circuit.upstream_speed %}
<i class="fa fa-arrow-down" title="Downstream"></i> {{ circuit.port_speed_human }} &nbsp;
<i class="fa fa-arrow-up" title="Upstream"></i> {{ circuit.upstream_speed_human }}
{% else %}
<span class="text-muted">N/A</span>
{{ circuit.port_speed_human }}
{% endif %}
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions netbox/templates/circuits/circuit_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<div class="panel-heading"><strong>Bandwidth</strong></div>
<div class="panel-body">
{% render_field form.port_speed %}
{% render_field form.upstream_speed %}
{% render_field form.commit_rate %}
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions netbox/templates/circuits/circuit_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ <h4>CSV Format</h4>
<tr>
<td>Port Speed</td>
<td>Physical speed in Kbps</td>
<td>10000</td>
<td>100000</td>
</tr>
<tr>
<td>Upstream Speed</td>
<td>Upstream speed in Kbps (optional)</td>
<td>20000</td>
</tr>
<tr>
<td>Commit rate</td>
Expand All @@ -81,7 +86,7 @@ <h4>CSV Format</h4>
</tbody>
</table>
<h4>Example</h4>
<pre>IC-603122,TeliaSonera,Transit,Strickland Propane,ASH-4,2016-02-23,10000,2000,937649,PP8371 ports 13/14</pre>
<pre>IC-603122,TeliaSonera,Transit,Strickland Propane,ASH-4,2016-02-23,100000,,2000,937649,PP8371 ports 13/14</pre>
</div>
</div>
{% endblock %}

0 comments on commit 377347d

Please sign in to comment.