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

Humanized Circuit speed display

This commit is contained in:
Jeremy Stretch
2016-06-20 15:58:18 -04:00
parent c456248e0c
commit ccc52348be
6 changed files with 34 additions and 9 deletions

View File

@ -105,7 +105,7 @@ class CircuitForm(forms.ModelForm, BootstrapMixin):
'cid': "Unique circuit ID", 'cid': "Unique circuit ID",
'install_date': "Format: YYYY-MM-DD", 'install_date': "Format: YYYY-MM-DD",
'port_speed': "Physical circuit speed", 'port_speed': "Physical circuit speed",
'commit_rate': "Commited rate (in Mbps)", 'commit_rate': "Commited rate",
'xconnect_id': "ID of the local cross-connect", 'xconnect_id': "ID of the local cross-connect",
'pp_info': "Patch panel ID and port number(s)" 'pp_info': "Patch panel ID and port number(s)"
} }

View File

@ -91,3 +91,28 @@ class Circuit(models.Model):
self.xconnect_id, self.xconnect_id,
self.pp_info, self.pp_info,
]) ])
def _humanize_speed(self, speed):
"""
Humanize speeds given in Kbps (e.g. 10000000 becomes '10 Gbps')
"""
if speed >= 1000000000 and speed % 1000000000 == 0:
return '{} Tbps'.format(speed / 1000000000)
elif speed >= 1000000 and speed % 1000000 == 0:
return '{} Gbps'.format(speed / 1000000)
elif speed >= 1000 and speed % 1000 == 0:
return '{} Mbps'.format(speed / 1000)
elif speed >= 1000:
return '{} Mbps'.format(float(speed) / 1000)
else:
return '{} Kbps'.format(speed)
@property
def port_speed_human(self):
return self._humanize_speed(self.port_speed)
@property
def commit_rate_human(self):
if not self.commit_rate:
return ''
return self._humanize_speed(self.commit_rate)

View File

@ -62,12 +62,12 @@ class CircuitTable(tables.Table):
type = tables.Column(verbose_name='Type') type = tables.Column(verbose_name='Type')
provider = tables.LinkColumn('circuits:provider', args=[Accessor('provider.slug')], verbose_name='Provider') provider = tables.LinkColumn('circuits:provider', args=[Accessor('provider.slug')], verbose_name='Provider')
site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')], verbose_name='Site') site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')], verbose_name='Site')
port_speed = tables.Column(verbose_name='Port Speed') port_speed_human = tables.Column(verbose_name='Port Speed')
commit_rate = tables.Column(verbose_name='Commit (Mbps)') commit_rate_human = tables.Column(verbose_name='Commit Rate')
class Meta: class Meta:
model = Circuit model = Circuit
fields = ('pk', 'cid', 'type', 'provider', 'site', 'port_speed', 'commit_rate') fields = ('pk', 'cid', 'type', 'provider', 'site', 'port_speed_human', 'commit_rate_human')
empty_text = "No circuits found." empty_text = "No circuits found."
attrs = { attrs = {
'class': 'table table-hover', 'class': 'table table-hover',

View File

@ -79,11 +79,11 @@
</tr> </tr>
<tr> <tr>
<td>Port Speed</td> <td>Port Speed</td>
<td>{{ circuit.port_speed }} Kbps</td> <td>{{ circuit.port_speed_human }}</td>
</tr> </tr>
<tr> <tr>
<td>Commit Rate</td> <td>Commit Rate</td>
<td>{% if circuit.commit_rate %}{{ circuit.commit_rate }} Kbps{% else %}<span class="text-muted">N/A</span>{% endif %}</td> <td>{% if circuit.commit_rate %}{{ circuit.commit_rate_human }}{% else %}<span class="text-muted">N/A</span>{% endif %}</td>
</tr> </tr>
<tr> <tr>
<td>Cross-Connect</td> <td>Cross-Connect</td>

View File

@ -55,12 +55,12 @@
</tr> </tr>
<tr> <tr>
<td>Port Speed</td> <td>Port Speed</td>
<td>Speed in Mbps (optional)</td> <td>Physical speed in Kbps/td>
<td>10000</td> <td>10000</td>
</tr> </tr>
<tr> <tr>
<td>Commit rate</td> <td>Commit rate</td>
<td>Speed in Mbps (optional)</td> <td>Commited rate in Kbps (optional)</td>
<td>2000</td> <td>2000</td>
</tr> </tr>
<tr> <tr>

View File

@ -90,7 +90,7 @@
<a href="{% url 'dcim:device' pk=c.interface.device.pk %}">{{ c.interface.device }}</a> <a href="{% url 'dcim:device' pk=c.interface.device.pk %}">{{ c.interface.device }}</a>
{% endif %} {% endif %}
</td> </td>
<td>{{ c.port_speed }} Kbps</td> <td>{{ c.port_speed_human }}</td>
</tr> </tr>
{% empty %} {% empty %}
<tr> <tr>